removed FieldLoader.LoadFields
This commit is contained in:
@@ -15,6 +15,7 @@ using System.Linq;
|
||||
|
||||
namespace OpenRA.FileFormats
|
||||
{
|
||||
[FieldLoader.Foo( "Selectable", "Title", "Description", "Author", "PlayerCount", "Tileset", "TopLeft", "BottomRight" )]
|
||||
public class MapStub
|
||||
{
|
||||
public readonly IFolder Package;
|
||||
@@ -28,6 +29,8 @@ namespace OpenRA.FileFormats
|
||||
public string Author;
|
||||
public int PlayerCount;
|
||||
public string Tileset;
|
||||
|
||||
[FieldLoader.LoadUsing( "LoadWaypoints" )]
|
||||
public Dictionary<string, int2> Waypoints = new Dictionary<string, int2>();
|
||||
public IEnumerable<int2> SpawnPoints { get { return Waypoints.Select(kv => kv.Value); } }
|
||||
|
||||
@@ -36,24 +39,24 @@ namespace OpenRA.FileFormats
|
||||
public int Width { get { return BottomRight.X - TopLeft.X; } }
|
||||
public int Height { get { return BottomRight.Y - TopLeft.Y; } }
|
||||
|
||||
static List<string> Fields = new List<string>() {
|
||||
"Selectable", "Title", "Description", "Author", "PlayerCount", "Tileset", "TopLeft", "BottomRight"
|
||||
};
|
||||
|
||||
public MapStub(IFolder package)
|
||||
{
|
||||
Package = package;
|
||||
var yaml = MiniYaml.DictFromStream(Package.GetContent("map.yaml"));
|
||||
FieldLoader.LoadFields(this, yaml, Fields);
|
||||
var yaml = MiniYaml.FromStream(Package.GetContent("map.yaml"));
|
||||
FieldLoader.Load( this, new MiniYaml( null, yaml ) );
|
||||
|
||||
// Waypoints
|
||||
foreach (var wp in yaml["Waypoints"].NodesDict)
|
||||
{
|
||||
string[] loc = wp.Value.Value.Split(',');
|
||||
Waypoints.Add(wp.Key, new int2(int.Parse(loc[0]), int.Parse(loc[1])));
|
||||
}
|
||||
|
||||
Uid = Package.GetContent("map.uid").ReadAllText();
|
||||
}
|
||||
|
||||
static object LoadWaypoints( MiniYaml y )
|
||||
{
|
||||
var ret = new Dictionary<string, int2>();
|
||||
foreach( var wp in y.NodesDict[ "Waypoints" ].NodesDict )
|
||||
{
|
||||
string[] loc = wp.Value.Value.Split( ',' );
|
||||
ret.Add( wp.Key, new int2( int.Parse( loc[ 0 ] ), int.Parse( loc[ 1 ] ) ) );
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,30 +29,34 @@ namespace OpenRA.FileFormats
|
||||
public MiniYaml Save() { return FieldSaver.Save(this); }
|
||||
}
|
||||
|
||||
[FieldLoader.Foo("Id", "Image", "Size", "PickAny")]
|
||||
public class TileTemplate
|
||||
{
|
||||
public ushort Id;
|
||||
public string Image;
|
||||
public int2 Size;
|
||||
public bool PickAny;
|
||||
|
||||
[FieldLoader.LoadUsing( "LoadTiles" )]
|
||||
public Dictionary<byte, string> Tiles = new Dictionary<byte, string>();
|
||||
|
||||
static List<string> fields = new List<string>() {"Id", "Image", "Size", "PickAny"};
|
||||
|
||||
public TileTemplate() {}
|
||||
public TileTemplate(MiniYaml my)
|
||||
{
|
||||
FieldLoader.LoadFields(this, my.NodesDict, fields);
|
||||
FieldLoader.Load( this, my );
|
||||
}
|
||||
|
||||
Tiles = my.NodesDict["Tiles"].NodesDict.ToDictionary(
|
||||
static object LoadTiles( MiniYaml y )
|
||||
{
|
||||
return y.NodesDict["Tiles"].NodesDict.ToDictionary(
|
||||
t => byte.Parse(t.Key),
|
||||
t => t.Value.Value);
|
||||
t => t.Value.Value );
|
||||
}
|
||||
|
||||
public MiniYaml Save()
|
||||
{
|
||||
var root = new List<MiniYamlNode>();
|
||||
foreach (var field in fields)
|
||||
foreach (var field in new string[] {"Id", "Image", "Size", "PickAny"})
|
||||
{
|
||||
FieldInfo f = this.GetType().GetField(field);
|
||||
if (f.GetValue(this) == null) continue;
|
||||
|
||||
Reference in New Issue
Block a user