some fileformats cleanup

This commit is contained in:
Chris Forbes
2010-07-16 17:48:29 +12:00
parent ebec75be0e
commit 9bbb2f78de
6 changed files with 52 additions and 69 deletions

View File

@@ -61,8 +61,6 @@ namespace OpenRA.FileFormats
public int2 TopLeft;
public int2 BottomRight;
public Rectangle Bounds { get { return Rectangle.FromLTRB(TopLeft.X, TopLeft.Y, BottomRight.X, BottomRight.Y); } }
public TileReference<ushort, byte>[,] MapTiles;
public TileReference<byte, byte>[,] MapResources;
@@ -74,31 +72,32 @@ namespace OpenRA.FileFormats
public int Height { get { return BottomRight.Y - TopLeft.Y; } }
public string Theater { get { return Tileset; } }
public IEnumerable<int2> SpawnPoints { get { return Waypoints.Select(kv => kv.Value); } }
public Rectangle Bounds { get { return Rectangle.FromLTRB(TopLeft.X, TopLeft.Y, BottomRight.X, BottomRight.Y); } }
static List<string> SimpleFields = new List<string>() {
"Selectable", "MapFormat", "Title", "Description", "Author", "PlayerCount", "Tileset", "MapSize", "TopLeft", "BottomRight"
};
public Map()
{
MapSize = new int2(1, 1);
MapResources = new TileReference<byte, byte>[1, 1];
public Map()
{
MapSize = new int2(1, 1);
MapResources = new TileReference<byte, byte>[1, 1];
MapTiles = new TileReference<ushort, byte>[1, 1]
{ { new TileReference<ushort, byte> {
type = (ushort)0xffffu,
image = (byte)0xffu,
index = (byte)0xffu } } };
PlayerCount = 0;
TopLeft = new int2(0,0);
BottomRight = new int2(0,0);
Tileset = "TEMPERAT";
Players.Add("Neutral", new PlayerReference("Neutral", "neutral", "allies", true, true));
Title = "Name your map here";
Description = "Describe your map here";
Author = "Your name here";
index = (byte)0xffu } } };
PlayerCount = 0;
TopLeft = new int2(0, 0);
BottomRight = new int2(0, 0);
Tileset = "TEMPERAT";
Players.Add("Neutral", new PlayerReference("Neutral", "neutral", "allies", true, true));
Title = "Name your map here";
Description = "Describe your map here";
Author = "Your name here";
}
public Map(IFolder package)
@@ -170,27 +169,28 @@ namespace OpenRA.FileFormats
{
MapFormat = 2;
Dictionary<string, MiniYaml> root = new Dictionary<string, MiniYaml>();
var root = new Dictionary<string, MiniYaml>();
foreach (var field in SimpleFields)
{
FieldInfo f = this.GetType().GetField(field);
if (f.GetValue(this) == null) continue;
root.Add(field, new MiniYaml(FieldSaver.FormatValue(this, f), null));
}
Dictionary<string, MiniYaml> playerYaml = new Dictionary<string, MiniYaml>();
foreach(var p in Players)
playerYaml.Add("PlayerReference@{0}".F(p.Key), FieldSaver.Save(p.Value));
root.Add("Players",new MiniYaml(null, playerYaml));
Dictionary<string, MiniYaml> actorYaml = new Dictionary<string, MiniYaml>();
foreach(var p in Actors)
actorYaml.Add("ActorReference@{0}".F(p.Key), FieldSaver.Save(p.Value));
root.Add("Actors",new MiniYaml(null, actorYaml));
}
root.Add("Players",
new MiniYaml(null, Players.ToDictionary(
p => "PlayerReference@{0}".F(p.Key),
p => FieldSaver.Save(p.Value))));
root.Add("Actors",
new MiniYaml(null, Actors.ToDictionary(
a => "ActorReference@{0}".F(a.Key),
a => FieldSaver.Save(a.Value))));
root.Add("Waypoints", MiniYaml.FromDictionary<string, int2>(Waypoints));
root.Add("Smudges", MiniYaml.FromList<SmudgeReference>(Smudges));
root.Add("Rules", new MiniYaml(null, Rules));
SaveBinaryData(Path.Combine(filepath, "map.bin"));
root.WriteToFile(Path.Combine(filepath, "map.yaml"));
SaveUid(Path.Combine(filepath, "map.uid"));