some fileformats cleanup
This commit is contained in:
@@ -73,5 +73,10 @@ namespace OpenRA
|
||||
yield return line;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool HasAttribute<T>(this MemberInfo mi)
|
||||
{
|
||||
return mi.GetCustomAttributes(typeof(T), true).Length != 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,17 +37,13 @@ namespace OpenRA.FileFormats
|
||||
throw new NotImplementedException( "FieldLoader: Missing field `{0}` on `{1}`".F( s, f.Name ) );
|
||||
};
|
||||
|
||||
public static void Load(object self, IniSection ini)
|
||||
{
|
||||
foreach (var x in ini)
|
||||
LoadField(self, x.Key, x.Value);
|
||||
}
|
||||
public static void Load(object self, MiniYaml my) { Load(self, my.Nodes); }
|
||||
|
||||
public static void Load(object self, MiniYaml my)
|
||||
public static void Load(object self, Dictionary<string, MiniYaml> my)
|
||||
{
|
||||
foreach (var x in my.Nodes)
|
||||
foreach (var x in my)
|
||||
if (!x.Key.StartsWith("-"))
|
||||
LoadField( self, x.Key, x.Value.Value );
|
||||
LoadField(self, x.Key, x.Value.Value);
|
||||
}
|
||||
|
||||
public static T Load<T>(MiniYaml y) where T : new()
|
||||
@@ -62,7 +58,7 @@ namespace OpenRA.FileFormats
|
||||
foreach (var field in fields)
|
||||
{
|
||||
if (!my.ContainsKey(field)) continue;
|
||||
FieldLoader.LoadField(self,field,my[field].Value);
|
||||
LoadField(self,field,my[field].Value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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,6 +72,7 @@ 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"
|
||||
@@ -90,8 +89,8 @@ namespace OpenRA.FileFormats
|
||||
index = (byte)0xffu } } };
|
||||
|
||||
PlayerCount = 0;
|
||||
TopLeft = new int2(0,0);
|
||||
BottomRight = new int2(0,0);
|
||||
TopLeft = new int2(0, 0);
|
||||
BottomRight = new int2(0, 0);
|
||||
|
||||
Tileset = "TEMPERAT";
|
||||
Players.Add("Neutral", new PlayerReference("Neutral", "neutral", "allies", true, true));
|
||||
@@ -170,7 +169,7 @@ 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);
|
||||
@@ -178,19 +177,20 @@ namespace OpenRA.FileFormats
|
||||
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));
|
||||
root.Add("Players",
|
||||
new MiniYaml(null, Players.ToDictionary(
|
||||
p => "PlayerReference@{0}".F(p.Key),
|
||||
p => FieldSaver.Save(p.Value))));
|
||||
|
||||
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("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"));
|
||||
|
||||
@@ -22,6 +22,7 @@ using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
|
||||
namespace OpenRA.FileFormats
|
||||
{
|
||||
@@ -33,10 +34,7 @@ namespace OpenRA.FileFormats
|
||||
public bool IsWater = false;
|
||||
public Color Color;
|
||||
|
||||
public TerrainTypeInfo(MiniYaml my)
|
||||
{
|
||||
FieldLoader.Load(this, my);
|
||||
}
|
||||
public TerrainTypeInfo(MiniYaml my) { FieldLoader.Load(this, my); }
|
||||
}
|
||||
|
||||
public class TileTemplate
|
||||
@@ -49,10 +47,10 @@ namespace OpenRA.FileFormats
|
||||
|
||||
static List<string> fields = new List<string>() {"Id", "Image", "Size", "PickAny"};
|
||||
|
||||
public TileTemplate(Dictionary<string,MiniYaml> my)
|
||||
public TileTemplate(MiniYaml my)
|
||||
{
|
||||
FieldLoader.LoadFields(this, my, fields);
|
||||
foreach (var tt in my["Tiles"].Nodes)
|
||||
FieldLoader.LoadFields(this, my.Nodes, fields);
|
||||
foreach (var tt in my.Nodes["Tiles"].Nodes)
|
||||
Tiles.Add(byte.Parse(tt.Key), tt.Value.Value);
|
||||
}
|
||||
}
|
||||
@@ -75,18 +73,12 @@ namespace OpenRA.FileFormats
|
||||
FieldLoader.Load(this, yaml["General"]);
|
||||
|
||||
// TerrainTypes
|
||||
foreach (var tt in yaml["Terrain"].Nodes)
|
||||
{
|
||||
var t = new TerrainTypeInfo(tt.Value);
|
||||
Terrain.Add(t.Type, t);
|
||||
}
|
||||
Terrain = yaml["Terrain"].Nodes.Values
|
||||
.Select(y => new TerrainTypeInfo(y)).ToDictionary(t => t.Type);
|
||||
|
||||
// Templates
|
||||
foreach (var tt in yaml["Templates"].Nodes)
|
||||
{
|
||||
var t = new TileTemplate(tt.Value.Nodes);
|
||||
Templates.Add(t.Id, t);
|
||||
}
|
||||
Templates = yaml["Templates"].Nodes.Values
|
||||
.Select(y => new TileTemplate(y)).ToDictionary(t => t.Id);
|
||||
}
|
||||
|
||||
public void LoadTiles()
|
||||
|
||||
@@ -139,10 +139,5 @@ namespace OpenRA
|
||||
return p.Index * 0x567;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static bool HasAttribute<T>( this MemberInfo mi )
|
||||
{
|
||||
return mi.GetCustomAttributes(typeof(T), true).Length != 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,10 +95,5 @@ namespace RALint
|
||||
EmitError("{0}.{1}.{2}: Missing {3} `{4}`."
|
||||
.F(actorInfo.Name, traitInfo.GetType().Name, fieldInfo.Name, type, v));
|
||||
}
|
||||
|
||||
static bool HasAttribute<T>(this MemberInfo mi)
|
||||
{
|
||||
return mi.GetCustomAttributes(typeof(T), true).Length != 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user