Merge pull request #10786 from pchote/mappreview-packages
Remove internal use of map paths.
This commit is contained in:
@@ -34,8 +34,9 @@ namespace OpenRA.FileSystem
|
|||||||
|
|
||||||
Cache<string, List<IReadOnlyPackage>> fileIndex = new Cache<string, List<IReadOnlyPackage>>(_ => new List<IReadOnlyPackage>());
|
Cache<string, List<IReadOnlyPackage>> fileIndex = new Cache<string, List<IReadOnlyPackage>>(_ => new List<IReadOnlyPackage>());
|
||||||
|
|
||||||
public IReadWritePackage CreatePackage(string filename, Dictionary<string, byte[]> content)
|
public IReadWritePackage CreatePackage(string filename)
|
||||||
{
|
{
|
||||||
|
var content = new Dictionary<string, byte[]>();
|
||||||
if (filename.EndsWith(".zip", StringComparison.InvariantCultureIgnoreCase))
|
if (filename.EndsWith(".zip", StringComparison.InvariantCultureIgnoreCase))
|
||||||
return new ZipFile(this, filename, content);
|
return new ZipFile(this, filename, content);
|
||||||
if (filename.EndsWith(".oramap", StringComparison.InvariantCultureIgnoreCase))
|
if (filename.EndsWith(".oramap", StringComparison.InvariantCultureIgnoreCase))
|
||||||
|
|||||||
@@ -114,12 +114,13 @@ namespace OpenRA
|
|||||||
|
|
||||||
public const int MaxTilesInCircleRange = 50;
|
public const int MaxTilesInCircleRange = 50;
|
||||||
public readonly MapGrid Grid;
|
public readonly MapGrid Grid;
|
||||||
|
readonly ModData modData;
|
||||||
|
|
||||||
[FieldLoader.Ignore] public readonly WVec[] SubCellOffsets;
|
[FieldLoader.Ignore] public readonly WVec[] SubCellOffsets;
|
||||||
public readonly SubCell DefaultSubCell;
|
public readonly SubCell DefaultSubCell;
|
||||||
public readonly SubCell LastSubCell;
|
public readonly SubCell LastSubCell;
|
||||||
[FieldLoader.Ignore] public IReadWritePackage Container;
|
|
||||||
public string Path { get; private set; }
|
public IReadOnlyPackage Package { get; private set; }
|
||||||
|
|
||||||
// Yaml map data
|
// Yaml map data
|
||||||
public string Uid { get; private set; }
|
public string Uid { get; private set; }
|
||||||
@@ -252,7 +253,7 @@ namespace OpenRA
|
|||||||
|
|
||||||
void AssertExists(string filename)
|
void AssertExists(string filename)
|
||||||
{
|
{
|
||||||
using (var s = Container.GetStream(filename))
|
using (var s = Package.GetStream(filename))
|
||||||
if (s == null)
|
if (s == null)
|
||||||
throw new InvalidOperationException("Required file {0} not present in this map".F(filename));
|
throw new InvalidOperationException("Required file {0} not present in this map".F(filename));
|
||||||
}
|
}
|
||||||
@@ -261,10 +262,11 @@ namespace OpenRA
|
|||||||
/// Initializes a new map created by the editor or importer.
|
/// Initializes a new map created by the editor or importer.
|
||||||
/// The map will not receive a valid UID until after it has been saved and reloaded.
|
/// The map will not receive a valid UID until after it has been saved and reloaded.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Map(TileSet tileset, int width, int height)
|
public Map(ModData modData, TileSet tileset, int width, int height)
|
||||||
{
|
{
|
||||||
|
this.modData = modData;
|
||||||
var size = new Size(width, height);
|
var size = new Size(width, height);
|
||||||
Grid = Game.ModData.Manifest.Get<MapGrid>();
|
Grid = modData.Manifest.Get<MapGrid>();
|
||||||
var tileRef = new TerrainTile(tileset.Templates.First().Key, 0);
|
var tileRef = new TerrainTile(tileset.Templates.First().Key, 0);
|
||||||
|
|
||||||
Title = "Name your map here";
|
Title = "Name your map here";
|
||||||
@@ -301,20 +303,19 @@ namespace OpenRA
|
|||||||
PostInit();
|
PostInit();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Initializes a map loaded from disk.</summary>
|
public Map(ModData modData, IReadOnlyPackage package)
|
||||||
public Map(string path)
|
|
||||||
{
|
{
|
||||||
Path = path;
|
this.modData = modData;
|
||||||
Container = Game.ModData.ModFiles.OpenWritablePackage(path);
|
Package = package;
|
||||||
|
|
||||||
AssertExists("map.yaml");
|
AssertExists("map.yaml");
|
||||||
AssertExists("map.bin");
|
AssertExists("map.bin");
|
||||||
|
|
||||||
var yaml = new MiniYaml(null, MiniYaml.FromStream(Container.GetStream("map.yaml"), path));
|
var yaml = new MiniYaml(null, MiniYaml.FromStream(Package.GetStream("map.yaml"), package.Name));
|
||||||
FieldLoader.Load(this, yaml);
|
FieldLoader.Load(this, yaml);
|
||||||
|
|
||||||
if (MapFormat != SupportedMapFormat)
|
if (MapFormat != SupportedMapFormat)
|
||||||
throw new InvalidDataException("Map format {0} is not supported.\n File: {1}".F(MapFormat, path));
|
throw new InvalidDataException("Map format {0} is not supported.\n File: {1}".F(MapFormat, package.Name));
|
||||||
|
|
||||||
SpawnPoints = Exts.Lazy(() =>
|
SpawnPoints = Exts.Lazy(() =>
|
||||||
{
|
{
|
||||||
@@ -346,25 +347,19 @@ namespace OpenRA
|
|||||||
MapResources = Exts.Lazy(LoadResourceTiles);
|
MapResources = Exts.Lazy(LoadResourceTiles);
|
||||||
MapHeight = Exts.Lazy(LoadMapHeight);
|
MapHeight = Exts.Lazy(LoadMapHeight);
|
||||||
|
|
||||||
Grid = Game.ModData.Manifest.Get<MapGrid>();
|
Grid = modData.Manifest.Get<MapGrid>();
|
||||||
|
|
||||||
SubCellOffsets = Grid.SubCellOffsets;
|
SubCellOffsets = Grid.SubCellOffsets;
|
||||||
LastSubCell = (SubCell)(SubCellOffsets.Length - 1);
|
LastSubCell = (SubCell)(SubCellOffsets.Length - 1);
|
||||||
DefaultSubCell = (SubCell)Grid.SubCellDefaultIndex;
|
DefaultSubCell = (SubCell)Grid.SubCellDefaultIndex;
|
||||||
|
|
||||||
if (Container.Contains("map.png"))
|
if (Package.Contains("map.png"))
|
||||||
using (var dataStream = Container.GetStream("map.png"))
|
using (var dataStream = Package.GetStream("map.png"))
|
||||||
CustomPreview = new Bitmap(dataStream);
|
CustomPreview = new Bitmap(dataStream);
|
||||||
|
|
||||||
PostInit();
|
PostInit();
|
||||||
|
|
||||||
// The Uid is calculated from the data on-disk, so
|
Uid = ComputeUID(Package);
|
||||||
// format changes must be flushed to disk.
|
|
||||||
// TODO: this isn't very nice
|
|
||||||
if (MapFormat < 8)
|
|
||||||
Save(path);
|
|
||||||
|
|
||||||
Uid = ComputeUID(Container);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PostInit()
|
void PostInit()
|
||||||
@@ -373,7 +368,7 @@ namespace OpenRA
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return Game.ModData.RulesetCache.Load(this, this);
|
return modData.RulesetCache.Load(this, this);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
@@ -381,7 +376,7 @@ namespace OpenRA
|
|||||||
Log.Write("debug", "Failed to load rules for {0} with error {1}", Title, e.Message);
|
Log.Write("debug", "Failed to load rules for {0} with error {1}", Title, e.Message);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Game.ModData.DefaultRules;
|
return modData.DefaultRules;
|
||||||
});
|
});
|
||||||
|
|
||||||
cachedTileSet = Exts.Lazy(() => Rules.TileSets[Tileset]);
|
cachedTileSet = Exts.Lazy(() => Rules.TileSets[Tileset]);
|
||||||
@@ -495,7 +490,7 @@ namespace OpenRA
|
|||||||
return rules.Value;
|
return rules.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Save(string toPath)
|
public void Save(IReadWritePackage toContainer)
|
||||||
{
|
{
|
||||||
MapFormat = 8;
|
MapFormat = 8;
|
||||||
|
|
||||||
@@ -545,37 +540,31 @@ namespace OpenRA
|
|||||||
entries.Add("map.yaml", Encoding.UTF8.GetBytes(s));
|
entries.Add("map.yaml", Encoding.UTF8.GetBytes(s));
|
||||||
|
|
||||||
// Add any custom assets
|
// Add any custom assets
|
||||||
if (Container != null)
|
if (Package != null)
|
||||||
{
|
{
|
||||||
foreach (var file in Container.Contents)
|
foreach (var file in Package.Contents)
|
||||||
{
|
{
|
||||||
if (file == "map.bin" || file == "map.yaml")
|
if (file == "map.bin" || file == "map.yaml")
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
entries.Add(file, Container.GetStream(file).ReadAllBytes());
|
entries.Add(file, Package.GetStream(file).ReadAllBytes());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Saving the map to a new location
|
// Saving the map to a new location
|
||||||
if (toPath != Path || Container == null)
|
Package = toContainer;
|
||||||
{
|
|
||||||
Path = toPath;
|
|
||||||
|
|
||||||
// Create a new map package
|
|
||||||
Container = Game.ModData.ModFiles.CreatePackage(Path, entries);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update existing package
|
// Update existing package
|
||||||
Container.Write(entries);
|
toContainer.Write(entries);
|
||||||
|
|
||||||
// Update UID to match the newly saved data
|
// Update UID to match the newly saved data
|
||||||
Uid = ComputeUID(Container);
|
Uid = ComputeUID(toContainer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CellLayer<TerrainTile> LoadMapTiles()
|
public CellLayer<TerrainTile> LoadMapTiles()
|
||||||
{
|
{
|
||||||
var tiles = new CellLayer<TerrainTile>(this);
|
var tiles = new CellLayer<TerrainTile>(this);
|
||||||
using (var s = Container.GetStream("map.bin"))
|
using (var s = Package.GetStream("map.bin"))
|
||||||
{
|
{
|
||||||
var header = new BinaryDataHeader(s, MapSize);
|
var header = new BinaryDataHeader(s, MapSize);
|
||||||
if (header.TilesOffset > 0)
|
if (header.TilesOffset > 0)
|
||||||
@@ -607,7 +596,7 @@ namespace OpenRA
|
|||||||
public CellLayer<byte> LoadMapHeight()
|
public CellLayer<byte> LoadMapHeight()
|
||||||
{
|
{
|
||||||
var tiles = new CellLayer<byte>(this);
|
var tiles = new CellLayer<byte>(this);
|
||||||
using (var s = Container.GetStream("map.bin"))
|
using (var s = Package.GetStream("map.bin"))
|
||||||
{
|
{
|
||||||
var header = new BinaryDataHeader(s, MapSize);
|
var header = new BinaryDataHeader(s, MapSize);
|
||||||
if (header.HeightsOffset > 0)
|
if (header.HeightsOffset > 0)
|
||||||
@@ -629,7 +618,7 @@ namespace OpenRA
|
|||||||
{
|
{
|
||||||
var resources = new CellLayer<ResourceTile>(this);
|
var resources = new CellLayer<ResourceTile>(this);
|
||||||
|
|
||||||
using (var s = Container.GetStream("map.bin"))
|
using (var s = Package.GetStream("map.bin"))
|
||||||
{
|
{
|
||||||
var header = new BinaryDataHeader(s, MapSize);
|
var header = new BinaryDataHeader(s, MapSize);
|
||||||
if (header.ResourcesOffset > 0)
|
if (header.ResourcesOffset > 0)
|
||||||
@@ -1180,16 +1169,16 @@ namespace OpenRA
|
|||||||
public Stream Open(string filename)
|
public Stream Open(string filename)
|
||||||
{
|
{
|
||||||
// Explicit package paths never refer to a map
|
// Explicit package paths never refer to a map
|
||||||
if (!filename.Contains("|") && Container.Contains(filename))
|
if (!filename.Contains("|") && Package.Contains(filename))
|
||||||
return Container.GetStream(filename);
|
return Package.GetStream(filename);
|
||||||
|
|
||||||
return Game.ModData.DefaultFileSystem.Open(filename);
|
return modData.DefaultFileSystem.Open(filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool TryGetPackageContaining(string path, out IReadOnlyPackage package, out string filename)
|
public bool TryGetPackageContaining(string path, out IReadOnlyPackage package, out string filename)
|
||||||
{
|
{
|
||||||
// Packages aren't supported inside maps
|
// Packages aren't supported inside maps
|
||||||
return Game.ModData.DefaultFileSystem.TryGetPackageContaining(path, out package, out filename);
|
return modData.DefaultFileSystem.TryGetPackageContaining(path, out package, out filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool TryOpen(string filename, out Stream s)
|
public bool TryOpen(string filename, out Stream s)
|
||||||
@@ -1197,21 +1186,21 @@ namespace OpenRA
|
|||||||
// Explicit package paths never refer to a map
|
// Explicit package paths never refer to a map
|
||||||
if (!filename.Contains("|"))
|
if (!filename.Contains("|"))
|
||||||
{
|
{
|
||||||
s = Container.GetStream(filename);
|
s = Package.GetStream(filename);
|
||||||
if (s != null)
|
if (s != null)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Game.ModData.DefaultFileSystem.TryOpen(filename, out s);
|
return modData.DefaultFileSystem.TryOpen(filename, out s);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Exists(string filename)
|
public bool Exists(string filename)
|
||||||
{
|
{
|
||||||
// Explicit package paths never refer to a map
|
// Explicit package paths never refer to a map
|
||||||
if (!filename.Contains("|") && Container.Contains(filename))
|
if (!filename.Contains("|") && Package.Contains(filename))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return Game.ModData.DefaultFileSystem.Exists(filename);
|
return modData.DefaultFileSystem.Exists(filename);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,13 +61,11 @@ namespace OpenRA
|
|||||||
{
|
{
|
||||||
using (new Support.PerfTimer(path.Key))
|
using (new Support.PerfTimer(path.Key))
|
||||||
{
|
{
|
||||||
using (var package = modData.ModFiles.OpenPackage(path.Key))
|
var package = modData.ModFiles.OpenPackage(path.Key);
|
||||||
{
|
|
||||||
var uid = Map.ComputeUID(package);
|
var uid = Map.ComputeUID(package);
|
||||||
previews[uid].UpdateFromMap(package, path.Value, modData.Manifest.MapCompatibility, mapGrid.Type);
|
previews[uid].UpdateFromMap(package, path.Value, modData.Manifest.MapCompatibility, mapGrid.Type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Failed to load map: {0}", path);
|
Console.WriteLine("Failed to load map: {0}", path);
|
||||||
@@ -190,7 +188,7 @@ namespace OpenRA
|
|||||||
if (bitmap == null)
|
if (bitmap == null)
|
||||||
{
|
{
|
||||||
createdPreview = true;
|
createdPreview = true;
|
||||||
var map = new Map(p.Path);
|
var map = new Map(modData, p.Package);
|
||||||
bitmap = Minimap.RenderMapPreview(modData.DefaultRules.TileSets[map.Tileset], map, modData.DefaultRules, true);
|
bitmap = Minimap.RenderMapPreview(modData.DefaultRules.TileSets[map.Tileset], map, modData.DefaultRules, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ namespace OpenRA
|
|||||||
MapCache cache;
|
MapCache cache;
|
||||||
|
|
||||||
public readonly string Uid;
|
public readonly string Uid;
|
||||||
public string Path { get; private set; }
|
public IReadOnlyPackage Package { get; private set; }
|
||||||
|
|
||||||
public string Title { get; private set; }
|
public string Title { get; private set; }
|
||||||
public string Type { get; private set; }
|
public string Type { get; private set; }
|
||||||
@@ -127,7 +127,7 @@ namespace OpenRA
|
|||||||
yaml = new MiniYaml(null, MiniYaml.FromStream(yamlStream, "map.yaml")).ToDictionary();
|
yaml = new MiniYaml(null, MiniYaml.FromStream(yamlStream, "map.yaml")).ToDictionary();
|
||||||
}
|
}
|
||||||
|
|
||||||
Path = p.Name;
|
Package = p;
|
||||||
GridType = gridType;
|
GridType = gridType;
|
||||||
Class = classification;
|
Class = classification;
|
||||||
|
|
||||||
|
|||||||
@@ -166,7 +166,7 @@ namespace OpenRA
|
|||||||
throw new InvalidDataException("Invalid map uid: {0}".F(uid));
|
throw new InvalidDataException("Invalid map uid: {0}".F(uid));
|
||||||
|
|
||||||
// Operate on a copy of the map to avoid gameplay state leaking into the cache
|
// Operate on a copy of the map to avoid gameplay state leaking into the cache
|
||||||
var map = new Map(MapCache[uid].Path);
|
var map = new Map(this, MapCache[uid].Package);
|
||||||
|
|
||||||
LoadTranslations(map);
|
LoadTranslations(map);
|
||||||
|
|
||||||
|
|||||||
@@ -949,7 +949,7 @@ namespace OpenRA.Mods.Common.Server
|
|||||||
|
|
||||||
static void LoadMap(S server)
|
static void LoadMap(S server)
|
||||||
{
|
{
|
||||||
server.Map = new Map(server.ModData.MapCache[server.LobbyInfo.GlobalSettings.Map].Path);
|
server.Map = new Map(server.ModData, server.ModData.MapCache[server.LobbyInfo.GlobalSettings.Map].Package);
|
||||||
|
|
||||||
server.MapPlayers = new MapPlayers(server.Map.PlayerDefinitions);
|
server.MapPlayers = new MapPlayers(server.Map.PlayerDefinitions);
|
||||||
server.LobbyInfo.Slots = server.MapPlayers.Players
|
server.LobbyInfo.Slots = server.MapPlayers.Players
|
||||||
|
|||||||
@@ -79,10 +79,10 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
|||||||
modData.MapCache.LoadMaps();
|
modData.MapCache.LoadMaps();
|
||||||
maps.AddRange(modData.MapCache
|
maps.AddRange(modData.MapCache
|
||||||
.Where(m => m.Status == MapStatus.Available)
|
.Where(m => m.Status == MapStatus.Available)
|
||||||
.Select(m => new Map(m.Path)));
|
.Select(m => new Map(modData, m.Package)));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
maps.Add(new Map(args[1]));
|
maps.Add(new Map(modData, modData.ModFiles.OpenPackage(args[1])));
|
||||||
|
|
||||||
foreach (var testMap in maps)
|
foreach (var testMap in maps)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
|||||||
{
|
{
|
||||||
Game.ModData = modData;
|
Game.ModData = modData;
|
||||||
|
|
||||||
var map = new Map(args[1]);
|
var map = new Map(modData, modData.ModFiles.OpenPackage(args[1]));
|
||||||
var minimap = Minimap.RenderMapPreview(map.Rules.TileSets[map.Tileset], map, true);
|
var minimap = Minimap.RenderMapPreview(map.Rules.TileSets[map.Tileset], map, true);
|
||||||
|
|
||||||
var dest = Path.GetFileNameWithoutExtension(args[1]) + ".png";
|
var dest = Path.GetFileNameWithoutExtension(args[1]) + ".png";
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
|||||||
ValidateMapFormat(format);
|
ValidateMapFormat(format);
|
||||||
|
|
||||||
var tileset = GetTileset(mapSection);
|
var tileset = GetTileset(mapSection);
|
||||||
Map = new Map(Rules.TileSets[tileset], MapSize, MapSize)
|
Map = new Map(modData, Rules.TileSets[tileset], MapSize, MapSize)
|
||||||
{
|
{
|
||||||
Title = basic.GetValue("Name", Path.GetFileNameWithoutExtension(filename)),
|
Title = basic.GetValue("Name", Path.GetFileNameWithoutExtension(filename)),
|
||||||
Author = "Westwood Studios"
|
Author = "Westwood Studios"
|
||||||
@@ -94,9 +94,9 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
|||||||
|
|
||||||
Map.FixOpenAreas(Rules);
|
Map.FixOpenAreas(Rules);
|
||||||
|
|
||||||
var fileName = Path.GetFileNameWithoutExtension(args[1]);
|
var dest = Path.GetFileNameWithoutExtension(args[1]) + ".oramap";
|
||||||
var dest = fileName + ".oramap";
|
var package = modData.ModFiles.CreatePackage(dest);
|
||||||
Map.Save(dest);
|
Map.Save(package);
|
||||||
Console.WriteLine(dest + " saved.");
|
Console.WriteLine(dest + " saved.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using OpenRA.FileSystem;
|
||||||
|
|
||||||
namespace OpenRA.Mods.Common.UtilityCommands
|
namespace OpenRA.Mods.Common.UtilityCommands
|
||||||
{
|
{
|
||||||
@@ -48,7 +49,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
|||||||
public void Run(ModData modData, string[] args)
|
public void Run(ModData modData, string[] args)
|
||||||
{
|
{
|
||||||
Game.ModData = modData;
|
Game.ModData = modData;
|
||||||
map = new Map(args[1]);
|
map = new Map(modData, modData.ModFiles.OpenPackage(args[1]));
|
||||||
Console.WriteLine("Resizing map {0} from {1} to {2},{3}", map.Title, map.MapSize, width, height);
|
Console.WriteLine("Resizing map {0} from {1} to {2},{3}", map.Title, map.MapSize, width, height);
|
||||||
map.Resize(width, height);
|
map.Resize(width, height);
|
||||||
|
|
||||||
@@ -68,7 +69,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
|||||||
foreach (var kv in forRemoval)
|
foreach (var kv in forRemoval)
|
||||||
map.ActorDefinitions.Remove(kv);
|
map.ActorDefinitions.Remove(kv);
|
||||||
|
|
||||||
map.Save(map.Path);
|
map.Save((IReadWritePackage)map.Package);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,8 @@
|
|||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
using OpenRA.FileSystem;
|
||||||
|
|
||||||
namespace OpenRA.Mods.Common.UtilityCommands
|
namespace OpenRA.Mods.Common.UtilityCommands
|
||||||
{
|
{
|
||||||
class UpgradeMapCommand : IUtilityCommand
|
class UpgradeMapCommand : IUtilityCommand
|
||||||
@@ -26,15 +28,16 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
|||||||
// HACK: The engine code assumes that Game.modData is set.
|
// HACK: The engine code assumes that Game.modData is set.
|
||||||
Game.ModData = modData;
|
Game.ModData = modData;
|
||||||
|
|
||||||
UpgradeRules.UpgradeMapFormat(modData, args[1]);
|
var package = modData.ModFiles.OpenWritablePackage(args[1]);
|
||||||
|
UpgradeRules.UpgradeMapFormat(modData, package);
|
||||||
|
|
||||||
var map = new Map(args[1]);
|
var map = new Map(modData, package);
|
||||||
var engineDate = Exts.ParseIntegerInvariant(args[2]);
|
var engineDate = Exts.ParseIntegerInvariant(args[2]);
|
||||||
UpgradeRules.UpgradeWeaponRules(engineDate, ref map.WeaponDefinitions, null, 0);
|
UpgradeRules.UpgradeWeaponRules(engineDate, ref map.WeaponDefinitions, null, 0);
|
||||||
UpgradeRules.UpgradeActorRules(engineDate, ref map.RuleDefinitions, null, 0);
|
UpgradeRules.UpgradeActorRules(engineDate, ref map.RuleDefinitions, null, 0);
|
||||||
UpgradeRules.UpgradePlayers(engineDate, ref map.PlayerDefinitions, null, 0);
|
UpgradeRules.UpgradePlayers(engineDate, ref map.PlayerDefinitions, null, 0);
|
||||||
UpgradeRules.UpgradeActors(engineDate, ref map.ActorDefinitions, null, 0);
|
UpgradeRules.UpgradeActors(engineDate, ref map.ActorDefinitions, null, 0);
|
||||||
map.Save(args[1]);
|
map.Save(package);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using OpenRA.FileSystem;
|
||||||
|
|
||||||
namespace OpenRA.Mods.Common.UtilityCommands
|
namespace OpenRA.Mods.Common.UtilityCommands
|
||||||
{
|
{
|
||||||
@@ -100,21 +101,21 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
|||||||
}
|
}
|
||||||
|
|
||||||
Console.WriteLine("Processing Maps:");
|
Console.WriteLine("Processing Maps:");
|
||||||
var mapPaths = modData.MapCache
|
var mapPreviews = modData.MapCache
|
||||||
.Where(m => m.Status == MapStatus.Available)
|
.Where(m => m.Status == MapStatus.Available);
|
||||||
.Select(m => m.Path);
|
|
||||||
|
|
||||||
foreach (var path in mapPaths)
|
foreach (var p in mapPreviews)
|
||||||
{
|
{
|
||||||
Console.WriteLine("\t" + path);
|
var package = (IReadWritePackage)p.Package;
|
||||||
UpgradeRules.UpgradeMapFormat(modData, path);
|
Console.WriteLine("\t" + package.Name);
|
||||||
|
UpgradeRules.UpgradeMapFormat(modData, package);
|
||||||
|
|
||||||
var map = new Map(path);
|
var map = new Map(modData, package);
|
||||||
UpgradeRules.UpgradeActorRules(engineDate, ref map.RuleDefinitions, null, 0);
|
UpgradeRules.UpgradeActorRules(engineDate, ref map.RuleDefinitions, null, 0);
|
||||||
UpgradeRules.UpgradeWeaponRules(engineDate, ref map.WeaponDefinitions, null, 0);
|
UpgradeRules.UpgradeWeaponRules(engineDate, ref map.WeaponDefinitions, null, 0);
|
||||||
UpgradeRules.UpgradePlayers(engineDate, ref map.PlayerDefinitions, null, 0);
|
UpgradeRules.UpgradePlayers(engineDate, ref map.PlayerDefinitions, null, 0);
|
||||||
UpgradeRules.UpgradeActors(engineDate, ref map.ActorDefinitions, null, 0);
|
UpgradeRules.UpgradeActors(engineDate, ref map.ActorDefinitions, null, 0);
|
||||||
map.Save(map.Path);
|
map.Save(package);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ using System.Globalization;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using OpenRA.FileSystem;
|
||||||
using OpenRA.Graphics;
|
using OpenRA.Graphics;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
|
|
||||||
@@ -3602,9 +3603,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void UpgradeMapFormat(ModData modData, string path)
|
internal static void UpgradeMapFormat(ModData modData, IReadWritePackage package)
|
||||||
{
|
|
||||||
using (var package = modData.ModFiles.OpenWritablePackage(path))
|
|
||||||
{
|
{
|
||||||
if (package == null)
|
if (package == null)
|
||||||
return;
|
return;
|
||||||
@@ -3613,11 +3612,11 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
|||||||
if (yamlStream == null)
|
if (yamlStream == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var yaml = new MiniYaml(null, MiniYaml.FromStream(yamlStream, path));
|
var yaml = new MiniYaml(null, MiniYaml.FromStream(yamlStream, package.Name));
|
||||||
var nd = yaml.ToDictionary();
|
var nd = yaml.ToDictionary();
|
||||||
var mapFormat = FieldLoader.GetValue<int>("MapFormat", nd["MapFormat"].Value);
|
var mapFormat = FieldLoader.GetValue<int>("MapFormat", nd["MapFormat"].Value);
|
||||||
if (mapFormat < 6)
|
if (mapFormat < 6)
|
||||||
throw new InvalidDataException("Map format {0} is not supported.\n File: {1}".F(mapFormat, path));
|
throw new InvalidDataException("Map format {0} is not supported.\n File: {1}".F(mapFormat, package.Name));
|
||||||
|
|
||||||
// Nothing to do
|
// Nothing to do
|
||||||
if (mapFormat >= 8)
|
if (mapFormat >= 8)
|
||||||
@@ -3662,18 +3661,18 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
|||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
throw new InvalidDataException("Invalid ColorRamp value.\n File: " + path);
|
throw new InvalidDataException("Invalid ColorRamp value.\n File: " + package.Name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (parts.Length != 1 || !HSLColor.TryParseRGB(parts[0], out dummy))
|
else if (parts.Length != 1 || !HSLColor.TryParseRGB(parts[0], out dummy))
|
||||||
throw new InvalidDataException("Invalid ColorRamp value.\n File: " + path);
|
throw new InvalidDataException("Invalid ColorRamp value.\n File: " + package.Name);
|
||||||
|
|
||||||
colorRampNode.Key = "Color";
|
colorRampNode.Key = "Color";
|
||||||
noteColorRamp = true;
|
noteColorRamp = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Console.WriteLine("Converted " + path + " to MapFormat 8.");
|
Console.WriteLine("Converted " + package.Name + " to MapFormat 8.");
|
||||||
if (noteHexColors)
|
if (noteHexColors)
|
||||||
Console.WriteLine("ColorRamp is now called Color and uses rgb(a) hex value - rrggbb[aa].");
|
Console.WriteLine("ColorRamp is now called Color and uses rgb(a) hex value - rrggbb[aa].");
|
||||||
else if (noteColorRamp)
|
else if (noteColorRamp)
|
||||||
@@ -3692,5 +3691,4 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
|
|
||||||
var maxTerrainHeight = world.Map.Grid.MaximumTerrainHeight;
|
var maxTerrainHeight = world.Map.Grid.MaximumTerrainHeight;
|
||||||
var tileset = modRules.TileSets[tilesetDropDown.Text];
|
var tileset = modRules.TileSets[tilesetDropDown.Text];
|
||||||
var map = new Map(tileset, width + 2, height + maxTerrainHeight + 2);
|
var map = new Map(Game.ModData, tileset, width + 2, height + maxTerrainHeight + 2);
|
||||||
|
|
||||||
var tl = new PPos(1, 1);
|
var tl = new PPos(1, 1);
|
||||||
var br = new PPos(width, height + maxTerrainHeight);
|
var br = new PPos(width, height + maxTerrainHeight);
|
||||||
|
|||||||
@@ -76,6 +76,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
var mapDirectories = modData.Manifest.MapFolders
|
var mapDirectories = modData.Manifest.MapFolders
|
||||||
.ToDictionary(kv => makeMapDirectory(kv.Key), kv => Enum<MapClassification>.Parse(kv.Value));
|
.ToDictionary(kv => makeMapDirectory(kv.Key), kv => Enum<MapClassification>.Parse(kv.Value));
|
||||||
|
|
||||||
|
var mapPath = map.Package != null ? map.Package.Name : null;
|
||||||
var directoryDropdown = widget.Get<DropDownButtonWidget>("DIRECTORY_DROPDOWN");
|
var directoryDropdown = widget.Get<DropDownButtonWidget>("DIRECTORY_DROPDOWN");
|
||||||
{
|
{
|
||||||
Func<string, ScrollItemWidget, ScrollItemWidget> setupItem = (option, template) =>
|
Func<string, ScrollItemWidget, ScrollItemWidget> setupItem = (option, template) =>
|
||||||
@@ -87,7 +88,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
return item;
|
return item;
|
||||||
};
|
};
|
||||||
|
|
||||||
var mapDirectory = map.Path != null ? Platform.UnresolvePath(Path.GetDirectoryName(map.Path)) : null;
|
// TODO: This won't work for maps inside oramod packages
|
||||||
|
var mapDirectory = mapPath != null ? Platform.UnresolvePath(Path.GetDirectoryName(mapPath)) : null;
|
||||||
var initialDirectory = mapDirectories.Keys.FirstOrDefault(f => f == mapDirectory);
|
var initialDirectory = mapDirectories.Keys.FirstOrDefault(f => f == mapDirectory);
|
||||||
|
|
||||||
// Prioritize MapClassification.User directories over system directories
|
// Prioritize MapClassification.User directories over system directories
|
||||||
@@ -101,14 +103,15 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
|
|
||||||
var mapIsUnpacked = false;
|
var mapIsUnpacked = false;
|
||||||
|
|
||||||
if (map.Path != null)
|
// TODO: This won't work for maps inside oramod packages
|
||||||
|
if (mapPath != null)
|
||||||
{
|
{
|
||||||
var attr = File.GetAttributes(map.Path);
|
var attr = File.GetAttributes(mapPath);
|
||||||
mapIsUnpacked = attr.HasFlag(FileAttributes.Directory);
|
mapIsUnpacked = attr.HasFlag(FileAttributes.Directory);
|
||||||
}
|
}
|
||||||
|
|
||||||
var filename = widget.Get<TextFieldWidget>("FILENAME");
|
var filename = widget.Get<TextFieldWidget>("FILENAME");
|
||||||
filename.Text = mapIsUnpacked ? Path.GetFileName(map.Path) : Path.GetFileNameWithoutExtension(map.Path);
|
filename.Text = mapIsUnpacked ? Path.GetFileName(mapPath) : Path.GetFileNameWithoutExtension(mapPath);
|
||||||
var fileType = mapIsUnpacked ? MapFileType.Unpacked : MapFileType.OraMap;
|
var fileType = mapIsUnpacked ? MapFileType.Unpacked : MapFileType.OraMap;
|
||||||
|
|
||||||
var fileTypes = new Dictionary<MapFileType, MapFileTypeInfo>()
|
var fileTypes = new Dictionary<MapFileType, MapFileTypeInfo>()
|
||||||
@@ -159,17 +162,19 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
// Create the map directory if required
|
// Create the map directory if required
|
||||||
Directory.CreateDirectory(Platform.ResolvePath(directoryDropdown.Text));
|
Directory.CreateDirectory(Platform.ResolvePath(directoryDropdown.Text));
|
||||||
|
|
||||||
|
// TODO: This won't work for maps inside oramod packages
|
||||||
var combinedPath = Platform.ResolvePath(Path.Combine(directoryDropdown.Text, filename.Text + fileTypes[fileType].Extension));
|
var combinedPath = Platform.ResolvePath(Path.Combine(directoryDropdown.Text, filename.Text + fileTypes[fileType].Extension));
|
||||||
|
|
||||||
// Invalidate the old map metadata
|
// Invalidate the old map metadata
|
||||||
if (map.Uid != null && combinedPath == map.Path)
|
if (map.Uid != null && combinedPath == mapPath)
|
||||||
modData.MapCache[map.Uid].Invalidate();
|
modData.MapCache[map.Uid].Invalidate();
|
||||||
|
|
||||||
map.Save(combinedPath);
|
var package = modData.ModFiles.CreatePackage(combinedPath);
|
||||||
|
map.Save(package);
|
||||||
|
|
||||||
// Update the map cache so it can be loaded without restarting the game
|
// Update the map cache so it can be loaded without restarting the game
|
||||||
var classification = mapDirectories[directoryDropdown.Text];
|
var classification = mapDirectories[directoryDropdown.Text];
|
||||||
modData.MapCache[map.Uid].UpdateFromMap(map.Container, classification, null, map.Grid.Type);
|
modData.MapCache[map.Uid].UpdateFromMap(map.Package, classification, null, map.Grid.Type);
|
||||||
|
|
||||||
Console.WriteLine("Saved current map at {0}", combinedPath);
|
Console.WriteLine("Saved current map at {0}", combinedPath);
|
||||||
Ui.CloseWindow();
|
Ui.CloseWindow();
|
||||||
|
|||||||
@@ -738,14 +738,15 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
if (MapPreview.Uid == uid)
|
if (MapPreview.Uid == uid)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
MapPreview = Game.ModData.MapCache[uid];
|
var modData = Game.ModData;
|
||||||
|
MapPreview = modData.MapCache[uid];
|
||||||
Map = null;
|
Map = null;
|
||||||
if (MapPreview.Status == MapStatus.Available)
|
if (MapPreview.Status == MapStatus.Available)
|
||||||
{
|
{
|
||||||
// Maps need to be validated and pre-loaded before they can be accessed
|
// Maps need to be validated and pre-loaded before they can be accessed
|
||||||
new Thread(_ =>
|
new Thread(_ =>
|
||||||
{
|
{
|
||||||
var currentMap = Map = new Map(MapPreview.Path);
|
var currentMap = Map = new Map(modData, MapPreview.Package);
|
||||||
currentMap.PreloadRules();
|
currentMap.PreloadRules();
|
||||||
Game.RunAfterTick(() =>
|
Game.RunAfterTick(() =>
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -285,7 +285,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
|
|
||||||
string DeleteMap(string map)
|
string DeleteMap(string map)
|
||||||
{
|
{
|
||||||
var path = Game.ModData.MapCache[map].Path;
|
var path = Game.ModData.MapCache[map].Package.Name;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (File.Exists(path))
|
if (File.Exists(path))
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
readonly ScrollPanelWidget missionList;
|
readonly ScrollPanelWidget missionList;
|
||||||
readonly ScrollItemWidget headerTemplate;
|
readonly ScrollItemWidget headerTemplate;
|
||||||
readonly ScrollItemWidget template;
|
readonly ScrollItemWidget template;
|
||||||
readonly Cache<MapPreview, Map> mapCache = new Cache<MapPreview, Map>(p => new Map(p.Path));
|
readonly Cache<MapPreview, Map> mapCache;
|
||||||
|
|
||||||
MapPreview selectedMapPreview;
|
MapPreview selectedMapPreview;
|
||||||
Map selectedMap;
|
Map selectedMap;
|
||||||
@@ -56,6 +56,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
public MissionBrowserLogic(Widget widget, World world, Action onStart, Action onExit)
|
public MissionBrowserLogic(Widget widget, World world, Action onStart, Action onExit)
|
||||||
{
|
{
|
||||||
modData = Game.ModData;
|
modData = Game.ModData;
|
||||||
|
mapCache = new Cache<MapPreview, Map>(p => new Map(modData, p.Package));
|
||||||
this.onStart = onStart;
|
this.onStart = onStart;
|
||||||
|
|
||||||
missionList = widget.Get<ScrollPanelWidget>("MISSION_LIST");
|
missionList = widget.Get<ScrollPanelWidget>("MISSION_LIST");
|
||||||
@@ -109,8 +110,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
var missionMapPaths = kv.Value.Nodes.Select(n => Path.GetFullPath(n.Key)).ToList();
|
var missionMapPaths = kv.Value.Nodes.Select(n => Path.GetFullPath(n.Key)).ToList();
|
||||||
|
|
||||||
var previews = modData.MapCache
|
var previews = modData.MapCache
|
||||||
.Where(p => p.Status == MapStatus.Available && missionMapPaths.Contains(Path.GetFullPath(p.Path)))
|
.Where(p => p.Status == MapStatus.Available && missionMapPaths.Contains(p.Package.Name))
|
||||||
.OrderBy(p => missionMapPaths.IndexOf(Path.GetFullPath(p.Path)));
|
.OrderBy(p => missionMapPaths.IndexOf(p.Package.Name));
|
||||||
|
|
||||||
CreateMissionGroup(kv.Key, previews);
|
CreateMissionGroup(kv.Key, previews);
|
||||||
allPreviews.AddRange(previews);
|
allPreviews.AddRange(previews);
|
||||||
|
|||||||
@@ -310,7 +310,7 @@ namespace OpenRA.Mods.D2k.UtilityCommands
|
|||||||
|
|
||||||
tileSet = rules.TileSets["ARRAKIS"];
|
tileSet = rules.TileSets["ARRAKIS"];
|
||||||
|
|
||||||
map = new Map(tileSet, mapSize.Width + 2 * MapCordonWidth, mapSize.Height + 2 * MapCordonWidth)
|
map = new Map(Game.ModData, tileSet, mapSize.Width + 2 * MapCordonWidth, mapSize.Height + 2 * MapCordonWidth)
|
||||||
{
|
{
|
||||||
Title = Path.GetFileNameWithoutExtension(mapFile),
|
Title = Path.GetFileNameWithoutExtension(mapFile),
|
||||||
Author = "Westwood Studios"
|
Author = "Westwood Studios"
|
||||||
|
|||||||
@@ -36,9 +36,9 @@ namespace OpenRA.Mods.D2k.UtilityCommands
|
|||||||
if (map == null)
|
if (map == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var fileName = Path.GetFileNameWithoutExtension(args[1]);
|
var dest = Path.GetFileNameWithoutExtension(args[1]) + ".oramap";
|
||||||
var dest = fileName + ".oramap";
|
var package = modData.ModFiles.CreatePackage(dest);
|
||||||
map.Save(dest);
|
map.Save(package);
|
||||||
Console.WriteLine(dest + " saved.");
|
Console.WriteLine(dest + " saved.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -172,9 +172,9 @@ namespace OpenRA.Mods.TS.UtilityCommands
|
|||||||
var mapPlayers = new MapPlayers(map.Rules, spawnCount);
|
var mapPlayers = new MapPlayers(map.Rules, spawnCount);
|
||||||
map.PlayerDefinitions = mapPlayers.ToMiniYaml();
|
map.PlayerDefinitions = mapPlayers.ToMiniYaml();
|
||||||
|
|
||||||
var fileName = Path.GetFileNameWithoutExtension(filename);
|
var dest = Path.GetFileNameWithoutExtension(args[1]) + ".oramap";
|
||||||
var dest = fileName + ".oramap";
|
var package = modData.ModFiles.CreatePackage(dest);
|
||||||
map.Save(dest);
|
map.Save(package);
|
||||||
Console.WriteLine(dest + " saved.");
|
Console.WriteLine(dest + " saved.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -222,7 +222,7 @@ namespace OpenRA.Mods.TS.UtilityCommands
|
|||||||
|
|
||||||
fullSize = new int2(iniSize[2], iniSize[3]);
|
fullSize = new int2(iniSize[2], iniSize[3]);
|
||||||
|
|
||||||
var map = new Map(modData.DefaultRules.TileSets[tileset], size.Width, size.Height);
|
var map = new Map(Game.ModData, modData.DefaultRules.TileSets[tileset], size.Width, size.Height);
|
||||||
map.Title = basic.GetValue("Name", Path.GetFileNameWithoutExtension(filename));
|
map.Title = basic.GetValue("Name", Path.GetFileNameWithoutExtension(filename));
|
||||||
map.Author = "Westwood Studios";
|
map.Author = "Westwood Studios";
|
||||||
map.Bounds = new Rectangle(iniBounds[0], iniBounds[1], iniBounds[2], 2 * iniBounds[3] + 2 * iniBounds[1]);
|
map.Bounds = new Rectangle(iniBounds[0], iniBounds[1], iniBounds[2], 2 * iniBounds[3] + 2 * iniBounds[1]);
|
||||||
|
|||||||
Reference in New Issue
Block a user