some fileformats cleanup
This commit is contained in:
@@ -73,5 +73,10 @@ namespace OpenRA
|
|||||||
yield return line;
|
yield return line;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool HasAttribute<T>(this MemberInfo mi)
|
||||||
|
{
|
||||||
|
return mi.GetCustomAttributes(typeof(T), true).Length != 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,15 +37,11 @@ namespace OpenRA.FileFormats
|
|||||||
throw new NotImplementedException( "FieldLoader: Missing field `{0}` on `{1}`".F( s, f.Name ) );
|
throw new NotImplementedException( "FieldLoader: Missing field `{0}` on `{1}`".F( s, f.Name ) );
|
||||||
};
|
};
|
||||||
|
|
||||||
public static void Load(object self, IniSection ini)
|
public static void Load(object self, MiniYaml my) { Load(self, my.Nodes); }
|
||||||
{
|
|
||||||
foreach (var x in ini)
|
|
||||||
LoadField(self, x.Key, x.Value);
|
|
||||||
}
|
|
||||||
|
|
||||||
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("-"))
|
if (!x.Key.StartsWith("-"))
|
||||||
LoadField(self, x.Key, x.Value.Value);
|
LoadField(self, x.Key, x.Value.Value);
|
||||||
}
|
}
|
||||||
@@ -62,7 +58,7 @@ namespace OpenRA.FileFormats
|
|||||||
foreach (var field in fields)
|
foreach (var field in fields)
|
||||||
{
|
{
|
||||||
if (!my.ContainsKey(field)) continue;
|
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 TopLeft;
|
||||||
public int2 BottomRight;
|
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<ushort, byte>[,] MapTiles;
|
||||||
public TileReference<byte, byte>[,] MapResources;
|
public TileReference<byte, byte>[,] MapResources;
|
||||||
|
|
||||||
@@ -74,6 +72,7 @@ namespace OpenRA.FileFormats
|
|||||||
public int Height { get { return BottomRight.Y - TopLeft.Y; } }
|
public int Height { get { return BottomRight.Y - TopLeft.Y; } }
|
||||||
public string Theater { get { return Tileset; } }
|
public string Theater { get { return Tileset; } }
|
||||||
public IEnumerable<int2> SpawnPoints { get { return Waypoints.Select(kv => kv.Value); } }
|
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>() {
|
static List<string> SimpleFields = new List<string>() {
|
||||||
"Selectable", "MapFormat", "Title", "Description", "Author", "PlayerCount", "Tileset", "MapSize", "TopLeft", "BottomRight"
|
"Selectable", "MapFormat", "Title", "Description", "Author", "PlayerCount", "Tileset", "MapSize", "TopLeft", "BottomRight"
|
||||||
@@ -170,7 +169,7 @@ namespace OpenRA.FileFormats
|
|||||||
{
|
{
|
||||||
MapFormat = 2;
|
MapFormat = 2;
|
||||||
|
|
||||||
Dictionary<string, MiniYaml> root = new Dictionary<string, MiniYaml>();
|
var root = new Dictionary<string, MiniYaml>();
|
||||||
foreach (var field in SimpleFields)
|
foreach (var field in SimpleFields)
|
||||||
{
|
{
|
||||||
FieldInfo f = this.GetType().GetField(field);
|
FieldInfo f = this.GetType().GetField(field);
|
||||||
@@ -178,19 +177,20 @@ namespace OpenRA.FileFormats
|
|||||||
root.Add(field, new MiniYaml(FieldSaver.FormatValue(this, f), null));
|
root.Add(field, new MiniYaml(FieldSaver.FormatValue(this, f), null));
|
||||||
}
|
}
|
||||||
|
|
||||||
Dictionary<string, MiniYaml> playerYaml = new Dictionary<string, MiniYaml>();
|
root.Add("Players",
|
||||||
foreach(var p in Players)
|
new MiniYaml(null, Players.ToDictionary(
|
||||||
playerYaml.Add("PlayerReference@{0}".F(p.Key), FieldSaver.Save(p.Value));
|
p => "PlayerReference@{0}".F(p.Key),
|
||||||
root.Add("Players",new MiniYaml(null, playerYaml));
|
p => FieldSaver.Save(p.Value))));
|
||||||
|
|
||||||
Dictionary<string, MiniYaml> actorYaml = new Dictionary<string, MiniYaml>();
|
root.Add("Actors",
|
||||||
foreach(var p in Actors)
|
new MiniYaml(null, Actors.ToDictionary(
|
||||||
actorYaml.Add("ActorReference@{0}".F(p.Key), FieldSaver.Save(p.Value));
|
a => "ActorReference@{0}".F(a.Key),
|
||||||
root.Add("Actors",new MiniYaml(null, actorYaml));
|
a => FieldSaver.Save(a.Value))));
|
||||||
|
|
||||||
root.Add("Waypoints", MiniYaml.FromDictionary<string, int2>(Waypoints));
|
root.Add("Waypoints", MiniYaml.FromDictionary<string, int2>(Waypoints));
|
||||||
root.Add("Smudges", MiniYaml.FromList<SmudgeReference>(Smudges));
|
root.Add("Smudges", MiniYaml.FromList<SmudgeReference>(Smudges));
|
||||||
root.Add("Rules", new MiniYaml(null, Rules));
|
root.Add("Rules", new MiniYaml(null, Rules));
|
||||||
|
|
||||||
SaveBinaryData(Path.Combine(filepath, "map.bin"));
|
SaveBinaryData(Path.Combine(filepath, "map.bin"));
|
||||||
root.WriteToFile(Path.Combine(filepath, "map.yaml"));
|
root.WriteToFile(Path.Combine(filepath, "map.yaml"));
|
||||||
SaveUid(Path.Combine(filepath, "map.uid"));
|
SaveUid(Path.Combine(filepath, "map.uid"));
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ using System.Collections.Generic;
|
|||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace OpenRA.FileFormats
|
namespace OpenRA.FileFormats
|
||||||
{
|
{
|
||||||
@@ -33,10 +34,7 @@ namespace OpenRA.FileFormats
|
|||||||
public bool IsWater = false;
|
public bool IsWater = false;
|
||||||
public Color Color;
|
public Color Color;
|
||||||
|
|
||||||
public TerrainTypeInfo(MiniYaml my)
|
public TerrainTypeInfo(MiniYaml my) { FieldLoader.Load(this, my); }
|
||||||
{
|
|
||||||
FieldLoader.Load(this, my);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class TileTemplate
|
public class TileTemplate
|
||||||
@@ -49,10 +47,10 @@ namespace OpenRA.FileFormats
|
|||||||
|
|
||||||
static List<string> fields = new List<string>() {"Id", "Image", "Size", "PickAny"};
|
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);
|
FieldLoader.LoadFields(this, my.Nodes, fields);
|
||||||
foreach (var tt in my["Tiles"].Nodes)
|
foreach (var tt in my.Nodes["Tiles"].Nodes)
|
||||||
Tiles.Add(byte.Parse(tt.Key), tt.Value.Value);
|
Tiles.Add(byte.Parse(tt.Key), tt.Value.Value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -75,18 +73,12 @@ namespace OpenRA.FileFormats
|
|||||||
FieldLoader.Load(this, yaml["General"]);
|
FieldLoader.Load(this, yaml["General"]);
|
||||||
|
|
||||||
// TerrainTypes
|
// TerrainTypes
|
||||||
foreach (var tt in yaml["Terrain"].Nodes)
|
Terrain = yaml["Terrain"].Nodes.Values
|
||||||
{
|
.Select(y => new TerrainTypeInfo(y)).ToDictionary(t => t.Type);
|
||||||
var t = new TerrainTypeInfo(tt.Value);
|
|
||||||
Terrain.Add(t.Type, t);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Templates
|
// Templates
|
||||||
foreach (var tt in yaml["Templates"].Nodes)
|
Templates = yaml["Templates"].Nodes.Values
|
||||||
{
|
.Select(y => new TileTemplate(y)).ToDictionary(t => t.Id);
|
||||||
var t = new TileTemplate(tt.Value.Nodes);
|
|
||||||
Templates.Add(t.Id, t);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void LoadTiles()
|
public void LoadTiles()
|
||||||
|
|||||||
@@ -139,10 +139,5 @@ namespace OpenRA
|
|||||||
return p.Index * 0x567;
|
return p.Index * 0x567;
|
||||||
return 0;
|
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}`."
|
EmitError("{0}.{1}.{2}: Missing {3} `{4}`."
|
||||||
.F(actorInfo.Name, traitInfo.GetType().Name, fieldInfo.Name, type, v));
|
.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