diff --git a/OpenRA.Game/Map/Map.cs b/OpenRA.Game/Map/Map.cs index 114b656702..986f98271b 100644 --- a/OpenRA.Game/Map/Map.cs +++ b/OpenRA.Game/Map/Map.cs @@ -254,47 +254,6 @@ namespace OpenRA [FieldLoader.Ignore] public CellRegion CellsInsideBounds; [FieldLoader.Ignore] public CellRegion AllCells; - public static Map FromTileset(TileSet tileset) - { - var size = new Size(1, 1); - var tileShape = Game.ModData.Manifest.TileShape; - var tileRef = new TerrainTile(tileset.Templates.First().Key, (byte)0); - - var makeMapTiles = Exts.Lazy(() => - { - var ret = new CellLayer(tileShape, size); - ret.Clear(tileRef); - return ret; - }); - - var makeMapHeight = Exts.Lazy(() => - { - var ret = new CellLayer(tileShape, size); - ret.Clear(0); - return ret; - }); - - var map = new Map() - { - Title = "Name your map here", - Description = "Describe your map here", - Author = "Your name here", - MapSize = new int2(size), - Tileset = tileset.Id, - Videos = new MapVideos(), - Options = new MapOptions(), - MapResources = Exts.Lazy(() => new CellLayer(tileShape, size)), - MapTiles = makeMapTiles, - MapHeight = makeMapHeight, - - SpawnPoints = Exts.Lazy(() => new CPos[0]) - }; - - map.PostInit(); - - return map; - } - void AssertExists(string filename) { using (var s = Container.GetContent(filename)) @@ -302,11 +261,50 @@ namespace OpenRA throw new InvalidOperationException("Required file {0} not present in this map".F(filename)); } - // Stub constructor that doesn't produce a valid map, but is - // sufficient for loading a mod to the content-install panel + /// A stub constructor that doesn't produce a valid map. Do not use. public Map() { } - // The standard constructor for most purposes + /// + /// Initializes a new map created by the editor or importer. + /// The map will not recieve a valid UID until after it has been saved and reloaded. + /// + public Map(TileSet tileset, int width, int height) + { + var size = new Size(width, height); + var tileShape = Game.ModData.Manifest.TileShape; + var tileRef = new TerrainTile(tileset.Templates.First().Key, (byte)0); + + Title = "Name your map here"; + Description = "Describe your map here"; + Author = "Your name here"; + + MapSize = new int2(size); + Tileset = tileset.Id; + Videos = new MapVideos(); + Options = new MapOptions(); + + MapResources = Exts.Lazy(() => new CellLayer(tileShape, size)); + + MapTiles = Exts.Lazy(() => + { + var ret = new CellLayer(tileShape, size); + ret.Clear(tileRef); + return ret; + }); + + MapHeight = Exts.Lazy(() => + { + var ret = new CellLayer(tileShape, size); + ret.Clear(0); + return ret; + }); + + SpawnPoints = Exts.Lazy(() => new CPos[0]); + + PostInit(); + } + + /// Initializes a map loaded from disk. public Map(string path) { Path = path; diff --git a/OpenRA.Mods.Common/UtilityCommands/LegacyMapImporter.cs b/OpenRA.Mods.Common/UtilityCommands/LegacyMapImporter.cs index 06fd2f583d..e7d1f24007 100644 --- a/OpenRA.Mods.Common/UtilityCommands/LegacyMapImporter.cs +++ b/OpenRA.Mods.Common/UtilityCommands/LegacyMapImporter.cs @@ -143,21 +143,17 @@ namespace OpenRA.Mods.Common.UtilityCommands var width = Exts.ParseIntegerInvariant(mapSection.GetValue("Width", "0")); var height = Exts.ParseIntegerInvariant(mapSection.GetValue("Height", "0")); mapSize = (legacyMapFormat == IniMapFormat.RedAlert) ? 128 : 64; - var size = new Size(mapSize, mapSize); var tileset = Truncate(mapSection.GetValue("Theater", "TEMPERAT"), 8); - map = Map.FromTileset(rules.TileSets[tileset]); - map.Title = basic.GetValue("Name", Path.GetFileNameWithoutExtension(iniFile)); - map.Author = "Westwood Studios"; - map.MapSize = new int2(mapSize, mapSize); - map.Bounds = Rectangle.FromLTRB(offsetX, offsetY, offsetX + width, offsetY + height); + map = new Map(rules.TileSets[tileset], mapSize, mapSize) + { + Title = basic.GetValue("Name", Path.GetFileNameWithoutExtension(iniFile)), + Author = "Westwood Studios" + }; - map.MapResources = Exts.Lazy(() => new CellLayer(TileShape.Rectangle, size)); - map.MapTiles = Exts.Lazy(() => new CellLayer(TileShape.Rectangle, size)); - - map.Videos = new MapVideos(); - - map.Options = new MapOptions(); + var tl = new MPos(offsetX, offsetY); + var br = new MPos(offsetX + width - 1, offsetY + height - 1); + map.SetBounds(tl, br); if (legacyMapFormat == IniMapFormat.RedAlert) { diff --git a/OpenRA.Mods.Common/Widgets/Logic/Editor/NewMapLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Editor/NewMapLogic.cs index 30bebf1718..ea9c7a2045 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Editor/NewMapLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Editor/NewMapLogic.cs @@ -51,9 +51,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic panel.Get("CREATE_BUTTON").OnClick = () => { - var tileset = modRules.TileSets[tilesetDropDown.Text]; - var map = Map.FromTileset(tileset); - int width, height; int.TryParse(widthTextField.Text, out width); int.TryParse(heightTextField.Text, out height); @@ -63,7 +60,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic width = Math.Max(2, width); height = Math.Max(2, height); - map.Resize(width + 2, height + tileset.MaxGroundHeight + 2); + var tileset = modRules.TileSets[tilesetDropDown.Text]; + var map = new Map(tileset, width + 2, height + tileset.MaxGroundHeight + 2); var tl = new MPos(1, 1); var br = new MPos(width, height + tileset.MaxGroundHeight); diff --git a/OpenRA.Mods.D2k/UtilityCommands/D2kMapImporter.cs b/OpenRA.Mods.D2k/UtilityCommands/D2kMapImporter.cs index a8a90b5cbc..2ca753a292 100644 --- a/OpenRA.Mods.D2k/UtilityCommands/D2kMapImporter.cs +++ b/OpenRA.Mods.D2k/UtilityCommands/D2kMapImporter.cs @@ -308,16 +308,16 @@ namespace OpenRA.Mods.D2k.UtilityCommands mapSize = new Size(stream.ReadUInt16(), stream.ReadUInt16()); tileSet = rules.TileSets["ARRAKIS"]; - map = Map.FromTileset(tileSet); - map.Title = Path.GetFileNameWithoutExtension(mapFile); - map.Author = "Westwood Studios"; - map.MapSize = new int2(mapSize.Width + 2 * MapCordonWidth, mapSize.Height + 2 * MapCordonWidth); - map.Bounds = new Rectangle(MapCordonWidth, MapCordonWidth, mapSize.Width, mapSize.Height); - map.MapResources = Exts.Lazy(() => new CellLayer(TileShape.Rectangle, new Size(map.MapSize.X, map.MapSize.Y))); - map.MapTiles = Exts.Lazy(() => new CellLayer(TileShape.Rectangle, new Size(map.MapSize.X, map.MapSize.Y))); + map = new Map(tileSet, mapSize.Width + 2 * MapCordonWidth, mapSize.Height + 2 * MapCordonWidth) + { + Title = Path.GetFileNameWithoutExtension(mapFile), + Author = "Westwood Studios" + }; - map.Options = new MapOptions(); + var tl = new MPos(MapCordonWidth, MapCordonWidth); + var br = new MPos(MapCordonWidth + mapSize.Width - 1, MapCordonWidth + mapSize.Height - 1); + map.SetBounds(tl, br); // Get all templates from the tileset YAML file that have at least one frame and an Image property corresponding to the requested tileset // Each frame is a tile from the Dune 2000 tileset files, with the Frame ID being the index of the tile in the original file