make yaml into a list, rather than a dict

This commit is contained in:
Bob
2010-08-26 21:59:43 +12:00
committed by Chris Forbes
parent bce52e989f
commit 2f92b873e8
15 changed files with 176 additions and 141 deletions

View File

@@ -30,7 +30,7 @@ namespace OpenRA.FileFormats
public static void Load( object self, MiniYaml my ) public static void Load( object self, MiniYaml my )
{ {
foreach( var x in my.Nodes ) foreach( var x in my.NodesDict )
if (!x.Key.StartsWith("-")) if (!x.Key.StartsWith("-"))
LoadField(self, x.Key, x.Value.Value); LoadField(self, x.Key, x.Value.Value);
@@ -154,7 +154,7 @@ namespace OpenRA.FileFormats
{ {
public static MiniYaml Save(object o) public static MiniYaml Save(object o)
{ {
var dict = new Dictionary<string, MiniYaml>(); var nodes = new List<MiniYamlNode>();
string root = null; string root = null;
foreach( var f in o.GetType().GetFields( BindingFlags.Public | BindingFlags.Instance ) ) foreach( var f in o.GetType().GetFields( BindingFlags.Public | BindingFlags.Instance ) )
@@ -162,10 +162,10 @@ namespace OpenRA.FileFormats
if( f.HasAttribute<FieldFromYamlKeyAttribute>() ) if( f.HasAttribute<FieldFromYamlKeyAttribute>() )
root = FormatValue( o, f ); root = FormatValue( o, f );
else else
dict.Add( f.Name, new MiniYaml( FormatValue( o, f ) ) ); nodes.Add( new MiniYamlNode( f.Name, FormatValue( o, f ) ) );
} }
return new MiniYaml( root, dict ); return new MiniYaml( root, nodes );
} }
public static MiniYaml SaveDifferences(object o, object from) public static MiniYaml SaveDifferences(object o, object from)
@@ -175,10 +175,10 @@ namespace OpenRA.FileFormats
var fields = o.GetType().GetFields(BindingFlags.Public | BindingFlags.Instance) var fields = o.GetType().GetFields(BindingFlags.Public | BindingFlags.Instance)
.Where(f => FormatValue(o,f) != FormatValue(from,f)); .Where(f => FormatValue(o,f) != FormatValue(from,f));
return new MiniYaml(null, fields.ToDictionary( return new MiniYaml( null, fields.Select( f => new MiniYamlNode(
f => f.Name, f.Name,
f => new MiniYaml(FormatValue(o, f)))); FormatValue( o, f ) ) ).ToList() );
} }
public static string FormatValue(object o, FieldInfo f) public static string FormatValue(object o, FieldInfo f)

View File

@@ -43,13 +43,17 @@ namespace OpenRA.FileFormats
Movies = YamlList(yaml, "Movies"); Movies = YamlList(yaml, "Movies");
TileSets = YamlList(yaml, "TileSets"); TileSets = YamlList(yaml, "TileSets");
ShellmapUid = yaml["ShellmapUid"].Value; ShellmapUid = yaml.First( x => x.Key == "ShellmapUid" ).Value.Value;
LoadScreen = yaml["LoadScreen"].Value; LoadScreen = yaml.First( x => x.Key == "LoadScreen" ).Value.Value;
} }
static string[] YamlList(Dictionary<string, MiniYaml> ys, string key) static string[] YamlList(List<MiniYamlNode> ys, string key)
{ {
return ys.ContainsKey(key) ? ys[key].Nodes.Keys.ToArray() : new string[] { }; var y = ys.FirstOrDefault( x => x.Key == key );
if( y == null )
return new string[ 0 ];
return y.Value.NodesDict.Keys.ToArray();
} }
} }
} }

View File

@@ -43,11 +43,11 @@ namespace OpenRA.FileFormats
public MapStub(IFolder package) public MapStub(IFolder package)
{ {
Package = package; Package = package;
var yaml = MiniYaml.FromStream(Package.GetContent("map.yaml")); var yaml = MiniYaml.DictFromStream(Package.GetContent("map.yaml"));
FieldLoader.LoadFields(this, yaml, Fields); FieldLoader.LoadFields(this, yaml, Fields);
// Waypoints // Waypoints
foreach (var wp in yaml["Waypoints"].Nodes) foreach (var wp in yaml["Waypoints"].NodesDict)
{ {
string[] loc = wp.Value.Value.Split(','); string[] loc = wp.Value.Value.Split(',');
Waypoints.Add(wp.Key, new int2(int.Parse(loc[0]), int.Parse(loc[1]))); Waypoints.Add(wp.Key, new int2(int.Parse(loc[0]), int.Parse(loc[1])));

View File

@@ -42,27 +42,25 @@ namespace OpenRA.FileFormats
public TileTemplate() {} public TileTemplate() {}
public TileTemplate(MiniYaml my) public TileTemplate(MiniYaml my)
{ {
FieldLoader.LoadFields(this, my.Nodes, fields); FieldLoader.LoadFields(this, my.NodesDict, fields);
Tiles = my.Nodes["Tiles"].Nodes.ToDictionary( Tiles = my.NodesDict["Tiles"].NodesDict.ToDictionary(
t => byte.Parse(t.Key), t => byte.Parse(t.Key),
t => t.Value.Value); t => t.Value.Value);
} }
public MiniYaml Save() public MiniYaml Save()
{ {
var root = new Dictionary<string, MiniYaml>(); var root = new List<MiniYamlNode>();
foreach (var field in fields) foreach (var field in fields)
{ {
FieldInfo f = this.GetType().GetField(field); FieldInfo f = this.GetType().GetField(field);
if (f.GetValue(this) == null) continue; if (f.GetValue(this) == null) continue;
root.Add(field, new MiniYaml(FieldSaver.FormatValue(this, f), null)); root.Add( new MiniYamlNode( field, FieldSaver.FormatValue( this, f ) ) );
} }
root.Add("Tiles", root.Add( new MiniYamlNode( "Tiles", null,
new MiniYaml(null, Tiles.ToDictionary( Tiles.Select( x => new MiniYamlNode( x.Key.ToString(), x.Value ) ).ToList() ) );
p => p.Key.ToString(),
p => new MiniYaml(p.Value))));
return new MiniYaml(null, root); return new MiniYaml(null, root);
} }
@@ -82,17 +80,17 @@ namespace OpenRA.FileFormats
public TileSet() {} public TileSet() {}
public TileSet( string filepath ) public TileSet( string filepath )
{ {
var yaml = MiniYaml.FromFile(filepath); var yaml = MiniYaml.FromFile(filepath).ToDictionary( x => x.Key, x => x.Value );
// General info // General info
FieldLoader.Load(this, yaml["General"]); FieldLoader.Load(this, yaml["General"]);
// TerrainTypes // TerrainTypes
Terrain = yaml["Terrain"].Nodes.Values Terrain = yaml["Terrain"].NodesDict.Values
.Select(y => new TerrainTypeInfo(y)).ToDictionary(t => t.Type); .Select(y => new TerrainTypeInfo(y)).ToDictionary(t => t.Type);
// Templates // Templates
Templates = yaml["Templates"].Nodes.Values Templates = yaml["Templates"].NodesDict.Values
.Select(y => new TileTemplate(y)).ToDictionary(t => t.Id); .Select(y => new TileTemplate(y)).ToDictionary(t => t.Id);
} }
@@ -108,32 +106,32 @@ namespace OpenRA.FileFormats
public void Save(string filepath) public void Save(string filepath)
{ {
var root = new Dictionary<string, MiniYaml>(); var root = new List<MiniYamlNode>();
foreach (var field in fields) foreach (var field in fields)
{ {
FieldInfo f = this.GetType().GetField(field); FieldInfo f = this.GetType().GetField(field);
if (f.GetValue(this) == null) continue; if (f.GetValue(this) == null) continue;
root.Add(field, new MiniYaml(FieldSaver.FormatValue(this, f), null)); root.Add( new MiniYamlNode( field, FieldSaver.FormatValue( this, f ) ) );
} }
var gen = new Dictionary<string, MiniYaml>(); var gen = new List<MiniYamlNode>();
foreach (var field in fields) foreach (var field in fields)
{ {
FieldInfo f = this.GetType().GetField(field); FieldInfo f = this.GetType().GetField(field);
if (f.GetValue(this) == null) continue; if (f.GetValue(this) == null) continue;
gen.Add(field, new MiniYaml(FieldSaver.FormatValue(this, f), null)); gen.Add( new MiniYamlNode( field, FieldSaver.FormatValue( this, f ) ) );
} }
root.Add("General", new MiniYaml(null, gen)); root.Add( new MiniYamlNode( "General", null, gen ) );
root.Add("Terrain", root.Add( new MiniYamlNode( "Terrain", null,
new MiniYaml(null, Terrain.ToDictionary( Terrain.Select( t => new MiniYamlNode(
t => "TerrainType@{0}".F(t.Value.Type), "TerrainType@{0}".F( t.Value.Type ),
t => t.Value.Save()))); t.Value.Save() ) ).ToList() ) );
root.Add("Templates", root.Add( new MiniYamlNode( "Templates", null,
new MiniYaml(null, Templates.ToDictionary( Templates.Select( t => new MiniYamlNode(
t => "Template@{0}".F(t.Value.Id), "Template@{0}".F( t.Value.Id ),
t => t.Value.Save()))); t.Value.Save() ) ).ToList() ) );
root.WriteToFile(filepath); root.WriteToFile(filepath);
} }

View File

@@ -15,35 +15,58 @@ using System.Linq;
namespace OpenRA.FileFormats namespace OpenRA.FileFormats
{ {
using MiniYamlNodes = Dictionary<string, MiniYaml>; using MiniYamlNodes = List<MiniYamlNode>;
public class MiniYamlNode
{
public string Key;
public MiniYaml Value;
public MiniYamlNode( string k, MiniYaml v )
{
Key = k;
Value = v;
}
public MiniYamlNode( string k, string v )
: this( k, new MiniYaml( v, null ) )
{
}
public MiniYamlNode( string k, string v, List<MiniYamlNode> n )
: this( k, new MiniYaml( v, n ) )
{
}
}
public class MiniYaml public class MiniYaml
{ {
public string Value; public string Value;
public Dictionary<string, MiniYaml> Nodes = new Dictionary<string,MiniYaml>(); public List<MiniYamlNode> Nodes;
public MiniYaml( string value ) : this( value, new Dictionary<string, MiniYaml>() ) { } public Dictionary<string, MiniYaml> NodesDict { get { return Nodes.ToDictionary( x => x.Key, x => x.Value ); } }
public MiniYaml( string value, Dictionary<string, MiniYaml> nodes ) public MiniYaml( string value ) : this( value, null ) { }
public MiniYaml( string value, List<MiniYamlNode> nodes )
{ {
Value = value; Value = value;
Nodes = nodes; Nodes = nodes ?? new List<MiniYamlNode>();
}
public static MiniYaml FromDictionary<K, V>( Dictionary<K, V> dict )
{
return new MiniYaml( null, dict.Select( x => new MiniYamlNode( x.Key.ToString(), new MiniYaml( x.Value.ToString() ) ) ).ToList() );
}
public static MiniYaml FromList<T>( List<T> list )
{
return new MiniYaml( null, list.Select( x => new MiniYamlNode( x.ToString(), new MiniYaml( null ) ) ).ToList() );
} }
public static MiniYaml FromDictionary<K,V>(Dictionary<K,V>dict) static List<MiniYamlNode> FromLines(string[] lines)
{ {
return new MiniYaml( null, dict.ToDictionary( x=>x.Key.ToString(), x=>new MiniYaml(x.Value.ToString()))); var levels = new List<List<MiniYamlNode>>();
} levels.Add(new List<MiniYamlNode>());
public static MiniYaml FromList<T>(List<T>list)
{
return new MiniYaml( null, list.ToDictionary( x=>x.ToString(), x=>new MiniYaml(null)));
}
static Dictionary<string, MiniYaml> FromLines(string[] lines)
{
var levels = new List<Dictionary<string, MiniYaml>>();
levels.Add(new Dictionary<string, MiniYaml>());
foreach (var line in lines) foreach (var line in lines)
{ {
@@ -58,27 +81,27 @@ namespace OpenRA.FileFormats
levels.RemoveAt(levels.Count - 1); levels.RemoveAt(levels.Count - 1);
var colon = t.IndexOf(':'); var colon = t.IndexOf(':');
var d = new Dictionary<string, MiniYaml>(); var d = new List<MiniYamlNode>();
try try
{ {
if (colon == -1) if( colon == -1 )
levels[level].Add(t.Trim(), new MiniYaml(null, d)); levels[ level ].Add( new MiniYamlNode( t.Trim(), new MiniYaml( null, d ) ) );
else else
{ {
var value = t.Substring(colon + 1).Trim(); var value = t.Substring( colon + 1 ).Trim();
if (value.Length == 0) if( value.Length == 0 )
value = null; value = null;
levels[level].Add(t.Substring(0, colon).Trim(), new MiniYaml(value, d)); levels[ level ].Add( new MiniYamlNode( t.Substring( 0, colon ).Trim(), new MiniYaml( value, d ) ) );
} }
} }
catch (ArgumentException) { throw new InvalidDataException("Duplicate Identifier:`{0}`".F(t)); } catch (ArgumentException) { throw new InvalidDataException("Duplicate Identifier:`{0}`".F(t)); }
levels.Add(d); levels.Add(d);
} }
return levels[0]; return levels[ 0 ];
} }
public static Dictionary<string, MiniYaml> FromFileInPackage( string path ) public static List<MiniYamlNode> FromFileInPackage( string path )
{ {
StreamReader reader = new StreamReader( FileSystem.Open(path) ); StreamReader reader = new StreamReader( FileSystem.Open(path) );
List<string> lines = new List<string>(); List<string> lines = new List<string>();
@@ -89,52 +112,61 @@ namespace OpenRA.FileFormats
return FromLines(lines.ToArray()); return FromLines(lines.ToArray());
} }
public static Dictionary<string, MiniYaml> FromFile( string path ) public static Dictionary<string, MiniYaml> DictFromFile( string path )
{
return FromFile( path ).ToDictionary( x => x.Key, x => x.Value );
}
public static Dictionary<string, MiniYaml> DictFromStream( Stream stream )
{
return FromStream( stream ).ToDictionary( x => x.Key, x => x.Value );
}
public static List<MiniYamlNode> FromFile( string path )
{ {
return FromLines(File.ReadAllLines( path )); return FromLines(File.ReadAllLines( path ));
} }
public static Dictionary<string, MiniYaml> FromStream(Stream s) public static List<MiniYamlNode> FromStream(Stream s)
{ {
using (var reader = new StreamReader(s)) using (var reader = new StreamReader(s))
return FromString(reader.ReadToEnd()); return FromString(reader.ReadToEnd());
} }
public static Dictionary<string, MiniYaml> FromString(string text) public static List<MiniYamlNode> FromString(string text)
{ {
return FromLines(text.Split(new[] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries)); return FromLines(text.Split(new[] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries));
} }
public static Dictionary<string, MiniYaml> Merge( Dictionary<string, MiniYaml> a, Dictionary<string, MiniYaml> b ) public static List<MiniYamlNode> Merge( List<MiniYamlNode> a, List<MiniYamlNode> b )
{ {
if( a.Count == 0 ) if( a.Count == 0 )
return b; return b;
if( b.Count == 0 ) if( b.Count == 0 )
return a; return a;
var ret = new Dictionary<string, MiniYaml>(); var ret = new List<MiniYamlNode>();
var keys = a.Keys.Union( b.Keys ).ToList(); var aDict = a.ToDictionary( x => x.Key, x => x.Value );
var bDict = b.ToDictionary( x => x.Key, x => x.Value );
var keys = aDict.Keys.Union( bDict.Keys ).ToList();
var noInherit = keys.Where( x => x.Length > 0 && x[ 0 ] == '-' ).Select( x => x.Substring( 1 ) ).ToList(); var noInherit = keys.Where( x => x.Length > 0 && x[ 0 ] == '-' ).Select( x => x.Substring( 1 ) ).ToList();
foreach( var key in keys ) foreach( var key in keys )
{ {
MiniYaml aa, bb; MiniYaml aa, bb;
a.TryGetValue( key, out aa ); aDict.TryGetValue( key, out aa );
b.TryGetValue( key, out bb ); bDict.TryGetValue( key, out bb );
// if( key.Length > 0 && key[ 0 ] == '-' )
// continue;
// else
if( noInherit.Contains( key ) ) if( noInherit.Contains( key ) )
{ {
if( aa != null ) if( aa != null )
ret.Add( key, aa ); ret.Add( new MiniYamlNode( key, aa ) );
} }
else else
ret.Add( key, Merge( aa, bb ) ); ret.Add( new MiniYamlNode( key, Merge( aa, bb ) ) );
} }
return ret; return ret;

View File

@@ -45,7 +45,7 @@ namespace OpenRA.FileFormats
foreach( var init in InitDict ) foreach( var init in InitDict )
{ {
var initName = init.GetType().Name; var initName = init.GetType().Name;
ret.Nodes.Add( initName.Substring( 0, initName.Length - 4 ), FieldSaver.Save( init ) ); ret.NodesDict.Add( initName.Substring( 0, initName.Length - 4 ), FieldSaver.Save( init ) );
} }
return ret; return ret;
} }

View File

@@ -23,7 +23,7 @@ namespace OpenRA
public ActorInfo( string name, MiniYaml node, Dictionary<string, MiniYaml> allUnits ) public ActorInfo( string name, MiniYaml node, Dictionary<string, MiniYaml> allUnits )
{ {
var mergedNode = MergeWithParent( node, allUnits ).Nodes; var mergedNode = MergeWithParent( node, allUnits ).NodesDict;
Name = name; Name = name;
foreach( var t in mergedNode ) foreach( var t in mergedNode )
@@ -34,7 +34,7 @@ namespace OpenRA
static MiniYaml GetParent( MiniYaml node, Dictionary<string, MiniYaml> allUnits ) static MiniYaml GetParent( MiniYaml node, Dictionary<string, MiniYaml> allUnits )
{ {
MiniYaml inherits; MiniYaml inherits;
node.Nodes.TryGetValue( "Inherits", out inherits ); node.NodesDict.TryGetValue( "Inherits", out inherits );
if( inherits == null || string.IsNullOrEmpty( inherits.Value ) ) if( inherits == null || string.IsNullOrEmpty( inherits.Value ) )
return null; return null;

View File

@@ -33,7 +33,7 @@ namespace OpenRA
Weapons = LoadYamlRules(m.Weapons, map.Weapons, (k, _) => new WeaponInfo(k.Key.ToLowerInvariant(), k.Value)); Weapons = LoadYamlRules(m.Weapons, map.Weapons, (k, _) => new WeaponInfo(k.Key.ToLowerInvariant(), k.Value));
Voices = LoadYamlRules(m.Voices, map.Voices, (k, _) => new VoiceInfo(k.Value)); Voices = LoadYamlRules(m.Voices, map.Voices, (k, _) => new VoiceInfo(k.Value));
Music = LoadYamlRules(m.Music, map.Music, (k, _) => new MusicInfo(k.Key, k.Value)); Music = LoadYamlRules(m.Music, map.Music, (k, _) => new MusicInfo(k.Key, k.Value));
Movies = LoadYamlRules(m.Movies, new Dictionary<string,MiniYaml>(), (k, v) => k.Value.Value); Movies = LoadYamlRules(m.Movies, new List<MiniYamlNode>(), (k, v) => k.Value.Value);
TileSets = new Dictionary<string, TileSet>(); TileSets = new Dictionary<string, TileSet>();
foreach (var file in m.TileSets) foreach (var file in m.TileSets)
@@ -45,10 +45,11 @@ namespace OpenRA
TechTree = new TechTree(); TechTree = new TechTree();
} }
static Dictionary<string, T> LoadYamlRules<T>(string[] files, Dictionary<string,MiniYaml>dict, Func<KeyValuePair<string, MiniYaml>, Dictionary<string, MiniYaml>, T> f) static Dictionary<string, T> LoadYamlRules<T>(string[] files, List<MiniYamlNode> dict, Func<MiniYamlNode, Dictionary<string, MiniYaml>, T> f)
{ {
var y = files.Select(a => MiniYaml.FromFile(a)).Aggregate(dict,MiniYaml.Merge); var y = files.Select(a => MiniYaml.FromFile(a)).Aggregate(dict,MiniYaml.Merge);
return y.ToDictionary(kv => kv.Key.ToLowerInvariant(), kv => f(kv, y)); var yy = y.ToDictionary( x => x.Key, x => x.Value );
return y.ToDictionary(kv => kv.Key.ToLowerInvariant(), kv => f(kv, yy));
} }
} }
} }

View File

@@ -109,7 +109,7 @@ namespace OpenRA.GameRules
if (File.Exists(SettingsFile)) if (File.Exists(SettingsFile))
{ {
System.Console.WriteLine("Loading settings file {0}",SettingsFile); System.Console.WriteLine("Loading settings file {0}",SettingsFile);
var yaml = MiniYaml.FromFile(SettingsFile); var yaml = MiniYaml.DictFromFile(SettingsFile);
foreach (var kv in Sections) foreach (var kv in Sections)
if (yaml.ContainsKey(kv.Key)) if (yaml.ContainsKey(kv.Key))
@@ -128,9 +128,9 @@ namespace OpenRA.GameRules
public void Save() public void Save()
{ {
Dictionary<string, MiniYaml> root = new Dictionary<string, MiniYaml>(); var root = new List<MiniYamlNode>();
foreach (var kv in Sections) foreach( var kv in Sections )
root.Add(kv.Key, SectionYaml(kv.Value)); root.Add( new MiniYamlNode( kv.Key, SectionYaml( kv.Value ) ) );
root.WriteToFile(SettingsFile); root.WriteToFile(SettingsFile);
} }

View File

@@ -22,7 +22,7 @@ namespace OpenRA.GameRules
public readonly string DefaultVariant = ".aud" ; public readonly string DefaultVariant = ".aud" ;
public readonly string[] DisableVariants = { }; public readonly string[] DisableVariants = { };
Func<MiniYaml, string, Dictionary<string, string[]>> Load = (y,name) => (y.Nodes.ContainsKey(name))? y.Nodes[name].Nodes.ToDictionary(a => a.Key, Func<MiniYaml, string, Dictionary<string, string[]>> Load = (y,name) => (y.NodesDict.ContainsKey(name))? y.NodesDict[name].NodesDict.ToDictionary(a => a.Key,
a => (string[])FieldLoader.GetValue( "(value)", typeof(string[]), a.Value.Value )) a => (string[])FieldLoader.GetValue( "(value)", typeof(string[]), a.Value.Value ))
: new Dictionary<string, string[]>(); : new Dictionary<string, string[]>();
@@ -30,7 +30,7 @@ namespace OpenRA.GameRules
public VoiceInfo( MiniYaml y ) public VoiceInfo( MiniYaml y )
{ {
FieldLoader.LoadFields(this, y.Nodes, new string[] { "DisableVariants" }); FieldLoader.LoadFields(this, y.NodesDict, new string[] { "DisableVariants" });
Variants = Load(y, "Variants"); Variants = Load(y, "Variants");
Voices = Load(y, "Voices"); Voices = Load(y, "Voices");

View File

@@ -86,19 +86,19 @@ namespace OpenRA.GameRules
public WeaponInfo(string name, MiniYaml content) public WeaponInfo(string name, MiniYaml content)
{ {
foreach (var kv in content.Nodes) foreach (var kv in content.NodesDict)
{ {
var key = kv.Key.Split('@')[0]; var key = kv.Key.Split('@')[0];
switch (key) switch (key)
{ {
case "Range": FieldLoader.LoadField(this, "Range", content.Nodes["Range"].Value); break; case "Range": FieldLoader.LoadField(this, "Range", content.NodesDict["Range"].Value); break;
case "ROF": FieldLoader.LoadField(this, "ROF", content.Nodes["ROF"].Value); break; case "ROF": FieldLoader.LoadField(this, "ROF", content.NodesDict["ROF"].Value); break;
case "Report": FieldLoader.LoadField(this, "Report", content.Nodes["Report"].Value); break; case "Report": FieldLoader.LoadField(this, "Report", content.NodesDict["Report"].Value); break;
case "Burst": FieldLoader.LoadField(this, "Burst", content.Nodes["Burst"].Value); break; case "Burst": FieldLoader.LoadField(this, "Burst", content.NodesDict["Burst"].Value); break;
case "Charges": FieldLoader.LoadField(this, "Charges", content.Nodes["Charges"].Value); break; case "Charges": FieldLoader.LoadField(this, "Charges", content.NodesDict["Charges"].Value); break;
case "ValidTargets": FieldLoader.LoadField(this, "ValidTargets", content.Nodes["ValidTargets"].Value); break; case "ValidTargets": FieldLoader.LoadField(this, "ValidTargets", content.NodesDict["ValidTargets"].Value); break;
case "Underwater": FieldLoader.LoadField(this, "Underwater", content.Nodes["Underwater"].Value); break; case "Underwater": FieldLoader.LoadField(this, "Underwater", content.NodesDict["Underwater"].Value); break;
case "BurstDelay": FieldLoader.LoadField(this, "BurstDelay", content.Nodes["BurstDelay"].Value); break; case "BurstDelay": FieldLoader.LoadField(this, "BurstDelay", content.NodesDict["BurstDelay"].Value); break;
case "Warhead": case "Warhead":
{ {

View File

@@ -39,11 +39,11 @@ namespace OpenRA
public Dictionary<string, int2> Waypoints = new Dictionary<string, int2>(); public Dictionary<string, int2> Waypoints = new Dictionary<string, int2>();
// Rules overrides // Rules overrides
public Dictionary<string, MiniYaml> Rules = new Dictionary<string, MiniYaml>(); public List<MiniYamlNode> Rules = new List<MiniYamlNode>();
public Dictionary<string, MiniYaml> Weapons = new Dictionary<string, MiniYaml>(); public List<MiniYamlNode> Weapons = new List<MiniYamlNode>();
public Dictionary<string, MiniYaml> Voices = new Dictionary<string, MiniYaml>(); public List<MiniYamlNode> Voices = new List<MiniYamlNode>();
public Dictionary<string, MiniYaml> Music = new Dictionary<string, MiniYaml>(); public List<MiniYamlNode> Music = new List<MiniYamlNode>();
public Dictionary<string, MiniYaml> Terrain = new Dictionary<string, MiniYaml>(); public List<MiniYamlNode> Terrain = new List<MiniYamlNode>();
// Binary map data // Binary map data
public byte TileFormat = 1; public byte TileFormat = 1;
@@ -99,13 +99,13 @@ namespace OpenRA
public Map(IFolder package) public Map(IFolder package)
{ {
Package = package; Package = package;
var yaml = MiniYaml.FromStream(Package.GetContent("map.yaml")); var yaml = MiniYaml.DictFromStream(Package.GetContent("map.yaml"));
// 'Simple' metadata // 'Simple' metadata
FieldLoader.LoadFields(this, yaml, SimpleFields); FieldLoader.LoadFields(this, yaml, SimpleFields);
// Waypoints // Waypoints
foreach (var wp in yaml["Waypoints"].Nodes) foreach (var wp in yaml["Waypoints"].NodesDict)
{ {
string[] loc = wp.Value.Value.Split(','); string[] loc = wp.Value.Value.Split(',');
Waypoints.Add(wp.Key, new int2(int.Parse(loc[0]), int.Parse(loc[1]))); Waypoints.Add(wp.Key, new int2(int.Parse(loc[0]), int.Parse(loc[1])));
@@ -124,7 +124,7 @@ namespace OpenRA
Players.Add("Neutral", new PlayerReference("Neutral", "allies", true, true)); Players.Add("Neutral", new PlayerReference("Neutral", "allies", true, true));
int actors = 0; int actors = 0;
foreach (var kv in yaml["Actors"].Nodes) foreach (var kv in yaml["Actors"].NodesDict)
{ {
string[] vals = kv.Value.Value.Split(' '); string[] vals = kv.Value.Value.Split(' ');
string[] loc = vals[2].Split(','); string[] loc = vals[2].Split(',');
@@ -138,13 +138,13 @@ namespace OpenRA
case 2: case 2:
{ {
foreach (var kv in yaml["Players"].Nodes) foreach (var kv in yaml["Players"].NodesDict)
{ {
var player = new PlayerReference(kv.Value); var player = new PlayerReference(kv.Value);
Players.Add(player.Name, player); Players.Add(player.Name, player);
} }
foreach (var kv in yaml["Actors"].Nodes) foreach (var kv in yaml["Actors"].NodesDict)
{ {
var oldActorReference = FieldLoader.Load<Format2ActorReference>(kv.Value); var oldActorReference = FieldLoader.Load<Format2ActorReference>(kv.Value);
Actors.Add(oldActorReference.Id, new ActorReference(oldActorReference.Type) Actors.Add(oldActorReference.Id, new ActorReference(oldActorReference.Type)
@@ -157,14 +157,14 @@ namespace OpenRA
case 3: case 3:
{ {
foreach (var kv in yaml["Players"].Nodes) foreach (var kv in yaml["Players"].NodesDict)
{ {
var player = new PlayerReference(kv.Value); var player = new PlayerReference(kv.Value);
Players.Add(player.Name, player); Players.Add(player.Name, player);
} }
foreach (var kv in yaml["Actors"].Nodes) foreach (var kv in yaml["Actors"].NodesDict)
Actors.Add(kv.Key, new ActorReference(kv.Value.Value, kv.Value.Nodes)); Actors.Add(kv.Key, new ActorReference(kv.Value.Value, kv.Value.NodesDict));
} break; } break;
default: default:
@@ -188,7 +188,7 @@ namespace OpenRA
} }
// Smudges // Smudges
foreach (var kv in yaml["Smudges"].Nodes) foreach (var kv in yaml["Smudges"].NodesDict)
{ {
string[] vals = kv.Key.Split(' '); string[] vals = kv.Key.Split(' ');
string[] loc = vals[1].Split(','); string[] loc = vals[1].Split(',');
@@ -207,27 +207,27 @@ namespace OpenRA
{ {
MapFormat = 3; MapFormat = 3;
var root = new Dictionary<string, MiniYaml>(); var root = new List<MiniYamlNode>();
foreach (var field in SimpleFields) foreach (var field in SimpleFields)
{ {
FieldInfo f = this.GetType().GetField(field); FieldInfo f = this.GetType().GetField(field);
if (f.GetValue(this) == null) continue; if (f.GetValue(this) == null) continue;
root.Add(field, new MiniYaml(FieldSaver.FormatValue(this, f), null)); root.Add( new MiniYamlNode( field, FieldSaver.FormatValue( this, f ) ) );
} }
root.Add("Players", root.Add( new MiniYamlNode( "Players", null,
new MiniYaml(null, Players.ToDictionary( Players.Select( p => new MiniYamlNode(
p => "PlayerReference@{0}".F(p.Key), "PlayerReference@{0}".F( p.Key ),
p => FieldSaver.Save(p.Value)))); FieldSaver.Save( p.Value ) ) ).ToList() ) );
root.Add("Actors", root.Add( new MiniYamlNode( "Actors", null,
new MiniYaml( null, Actors.ToDictionary( Actors.Select( x => new MiniYamlNode(
x => x.Key, x.Key,
x => x.Value.Save() ) ) ); x.Value.Save() ) ).ToList() ) );
root.Add("Waypoints", MiniYaml.FromDictionary<string, int2>(Waypoints)); root.Add( new MiniYamlNode( "Waypoints", MiniYaml.FromDictionary<string, int2>( Waypoints ) ) );
root.Add("Smudges", MiniYaml.FromList<SmudgeReference>(Smudges)); root.Add( new MiniYamlNode( "Smudges", MiniYaml.FromList<SmudgeReference>( Smudges ) ) );
root.Add("Rules", new MiniYaml(null, Rules)); root.Add( new MiniYamlNode( "Rules", 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"));

View File

@@ -61,15 +61,15 @@ namespace OpenRA.Network
public string Serialize() public string Serialize()
{ {
var clientData = new Dictionary<string, MiniYaml>(); var clientData = new List<MiniYamlNode>();
foreach (var client in Clients) foreach( var client in Clients )
clientData["Client@{0}".F(client.Index)] = FieldSaver.Save(client); clientData.Add( new MiniYamlNode( "Client@{0}".F( client.Index ), FieldSaver.Save( client ) ) );
foreach (var slot in Slots) foreach( var slot in Slots )
clientData["Slot@{0}".F(slot.Index)] = FieldSaver.Save(slot); clientData.Add( new MiniYamlNode( "Slot@{0}".F( slot.Index ), FieldSaver.Save( slot ) ) );
clientData["GlobalSettings"] = FieldSaver.Save(GlobalSettings); clientData.Add( new MiniYamlNode( "GlobalSettings", FieldSaver.Save( GlobalSettings ) ) );
return clientData.WriteToString(); return clientData.WriteToString();
} }

View File

@@ -16,7 +16,7 @@ namespace OpenRA
{ {
class WidgetLoader class WidgetLoader
{ {
public static Widget LoadWidget(KeyValuePair<string, MiniYaml> node) public static Widget LoadWidget(MiniYamlNode node)
{ {
var widget = NewWidget(node.Key); var widget = NewWidget(node.Key);
foreach (var child in node.Value.Nodes) foreach (var child in node.Value.Nodes)

View File

@@ -33,7 +33,7 @@ namespace RALint
static int Main(string[] args) static int Main(string[] args)
{ {
try //try
{ {
// bind some nonfatal error handling into FieldLoader, so we don't just *explode*. // bind some nonfatal error handling into FieldLoader, so we don't just *explode*.
ObjectCreator.MissingTypeAction = s => EmitError("Missing Type: {0}".F(s)); ObjectCreator.MissingTypeAction = s => EmitError("Missing Type: {0}".F(s));
@@ -61,11 +61,11 @@ namespace RALint
return 0; return 0;
} }
catch (Exception e) //catch (Exception e)
{ //{
Console.WriteLine("Failed with exception: {0}".F(e)); // Console.WriteLine("Failed with exception: {0}".F(e));
return 1; // return 1;
} //}
} }
static void CheckTrait(ActorInfo actorInfo, ITraitInfo traitInfo) static void CheckTrait(ActorInfo actorInfo, ITraitInfo traitInfo)