Simplify editor/importer map creation.
This commit is contained in:
@@ -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<TerrainTile>(tileShape, size);
|
||||
ret.Clear(tileRef);
|
||||
return ret;
|
||||
});
|
||||
|
||||
var makeMapHeight = Exts.Lazy(() =>
|
||||
{
|
||||
var ret = new CellLayer<byte>(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<ResourceTile>(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
|
||||
/// <summary>A stub constructor that doesn't produce a valid map. Do not use.</summary>
|
||||
public Map() { }
|
||||
|
||||
// The standard constructor for most purposes
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
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<ResourceTile>(tileShape, size));
|
||||
|
||||
MapTiles = Exts.Lazy(() =>
|
||||
{
|
||||
var ret = new CellLayer<TerrainTile>(tileShape, size);
|
||||
ret.Clear(tileRef);
|
||||
return ret;
|
||||
});
|
||||
|
||||
MapHeight = Exts.Lazy(() =>
|
||||
{
|
||||
var ret = new CellLayer<byte>(tileShape, size);
|
||||
ret.Clear(0);
|
||||
return ret;
|
||||
});
|
||||
|
||||
SpawnPoints = Exts.Lazy(() => new CPos[0]);
|
||||
|
||||
PostInit();
|
||||
}
|
||||
|
||||
/// <summary>Initializes a map loaded from disk.</summary>
|
||||
public Map(string path)
|
||||
{
|
||||
Path = path;
|
||||
|
||||
@@ -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<ResourceTile>(TileShape.Rectangle, size));
|
||||
map.MapTiles = Exts.Lazy(() => new CellLayer<TerrainTile>(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)
|
||||
{
|
||||
|
||||
@@ -51,9 +51,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
|
||||
panel.Get<ButtonWidget>("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);
|
||||
|
||||
@@ -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<ResourceTile>(TileShape.Rectangle, new Size(map.MapSize.X, map.MapSize.Y)));
|
||||
map.MapTiles = Exts.Lazy(() => new CellLayer<TerrainTile>(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
|
||||
|
||||
Reference in New Issue
Block a user