make yaml into a list, rather than a dict
This commit is contained in:
@@ -45,7 +45,7 @@ namespace OpenRA.FileFormats
|
||||
foreach( var init in InitDict )
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace OpenRA
|
||||
|
||||
public ActorInfo( string name, MiniYaml node, Dictionary<string, MiniYaml> allUnits )
|
||||
{
|
||||
var mergedNode = MergeWithParent( node, allUnits ).Nodes;
|
||||
var mergedNode = MergeWithParent( node, allUnits ).NodesDict;
|
||||
|
||||
Name = name;
|
||||
foreach( var t in mergedNode )
|
||||
@@ -34,7 +34,7 @@ namespace OpenRA
|
||||
static MiniYaml GetParent( MiniYaml node, Dictionary<string, MiniYaml> allUnits )
|
||||
{
|
||||
MiniYaml inherits;
|
||||
node.Nodes.TryGetValue( "Inherits", out inherits );
|
||||
node.NodesDict.TryGetValue( "Inherits", out inherits );
|
||||
if( inherits == null || string.IsNullOrEmpty( inherits.Value ) )
|
||||
return null;
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace OpenRA
|
||||
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));
|
||||
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>();
|
||||
foreach (var file in m.TileSets)
|
||||
@@ -45,10 +45,11 @@ namespace OpenRA
|
||||
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);
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,7 +109,7 @@ namespace OpenRA.GameRules
|
||||
if (File.Exists(SettingsFile))
|
||||
{
|
||||
System.Console.WriteLine("Loading settings file {0}",SettingsFile);
|
||||
var yaml = MiniYaml.FromFile(SettingsFile);
|
||||
var yaml = MiniYaml.DictFromFile(SettingsFile);
|
||||
|
||||
foreach (var kv in Sections)
|
||||
if (yaml.ContainsKey(kv.Key))
|
||||
@@ -128,9 +128,9 @@ namespace OpenRA.GameRules
|
||||
|
||||
public void Save()
|
||||
{
|
||||
Dictionary<string, MiniYaml> root = new Dictionary<string, MiniYaml>();
|
||||
foreach (var kv in Sections)
|
||||
root.Add(kv.Key, SectionYaml(kv.Value));
|
||||
var root = new List<MiniYamlNode>();
|
||||
foreach( var kv in Sections )
|
||||
root.Add( new MiniYamlNode( kv.Key, SectionYaml( kv.Value ) ) );
|
||||
|
||||
root.WriteToFile(SettingsFile);
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace OpenRA.GameRules
|
||||
public readonly string DefaultVariant = ".aud" ;
|
||||
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 ))
|
||||
: new Dictionary<string, string[]>();
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace OpenRA.GameRules
|
||||
|
||||
public VoiceInfo( MiniYaml y )
|
||||
{
|
||||
FieldLoader.LoadFields(this, y.Nodes, new string[] { "DisableVariants" });
|
||||
FieldLoader.LoadFields(this, y.NodesDict, new string[] { "DisableVariants" });
|
||||
Variants = Load(y, "Variants");
|
||||
Voices = Load(y, "Voices");
|
||||
|
||||
|
||||
@@ -86,19 +86,19 @@ namespace OpenRA.GameRules
|
||||
|
||||
public WeaponInfo(string name, MiniYaml content)
|
||||
{
|
||||
foreach (var kv in content.Nodes)
|
||||
foreach (var kv in content.NodesDict)
|
||||
{
|
||||
var key = kv.Key.Split('@')[0];
|
||||
switch (key)
|
||||
{
|
||||
case "Range": FieldLoader.LoadField(this, "Range", content.Nodes["Range"].Value); break;
|
||||
case "ROF": FieldLoader.LoadField(this, "ROF", content.Nodes["ROF"].Value); break;
|
||||
case "Report": FieldLoader.LoadField(this, "Report", content.Nodes["Report"].Value); break;
|
||||
case "Burst": FieldLoader.LoadField(this, "Burst", content.Nodes["Burst"].Value); break;
|
||||
case "Charges": FieldLoader.LoadField(this, "Charges", content.Nodes["Charges"].Value); break;
|
||||
case "ValidTargets": FieldLoader.LoadField(this, "ValidTargets", content.Nodes["ValidTargets"].Value); break;
|
||||
case "Underwater": FieldLoader.LoadField(this, "Underwater", content.Nodes["Underwater"].Value); break;
|
||||
case "BurstDelay": FieldLoader.LoadField(this, "BurstDelay", content.Nodes["BurstDelay"].Value); break;
|
||||
case "Range": FieldLoader.LoadField(this, "Range", content.NodesDict["Range"].Value); break;
|
||||
case "ROF": FieldLoader.LoadField(this, "ROF", content.NodesDict["ROF"].Value); break;
|
||||
case "Report": FieldLoader.LoadField(this, "Report", content.NodesDict["Report"].Value); break;
|
||||
case "Burst": FieldLoader.LoadField(this, "Burst", content.NodesDict["Burst"].Value); break;
|
||||
case "Charges": FieldLoader.LoadField(this, "Charges", content.NodesDict["Charges"].Value); break;
|
||||
case "ValidTargets": FieldLoader.LoadField(this, "ValidTargets", content.NodesDict["ValidTargets"].Value); break;
|
||||
case "Underwater": FieldLoader.LoadField(this, "Underwater", content.NodesDict["Underwater"].Value); break;
|
||||
case "BurstDelay": FieldLoader.LoadField(this, "BurstDelay", content.NodesDict["BurstDelay"].Value); break;
|
||||
|
||||
case "Warhead":
|
||||
{
|
||||
|
||||
@@ -39,11 +39,11 @@ namespace OpenRA
|
||||
public Dictionary<string, int2> Waypoints = new Dictionary<string, int2>();
|
||||
|
||||
// Rules overrides
|
||||
public Dictionary<string, MiniYaml> Rules = new Dictionary<string, MiniYaml>();
|
||||
public Dictionary<string, MiniYaml> Weapons = new Dictionary<string, MiniYaml>();
|
||||
public Dictionary<string, MiniYaml> Voices = new Dictionary<string, MiniYaml>();
|
||||
public Dictionary<string, MiniYaml> Music = new Dictionary<string, MiniYaml>();
|
||||
public Dictionary<string, MiniYaml> Terrain = new Dictionary<string, MiniYaml>();
|
||||
public List<MiniYamlNode> Rules = new List<MiniYamlNode>();
|
||||
public List<MiniYamlNode> Weapons = new List<MiniYamlNode>();
|
||||
public List<MiniYamlNode> Voices = new List<MiniYamlNode>();
|
||||
public List<MiniYamlNode> Music = new List<MiniYamlNode>();
|
||||
public List<MiniYamlNode> Terrain = new List<MiniYamlNode>();
|
||||
|
||||
// Binary map data
|
||||
public byte TileFormat = 1;
|
||||
@@ -99,13 +99,13 @@ namespace OpenRA
|
||||
public Map(IFolder package)
|
||||
{
|
||||
Package = package;
|
||||
var yaml = MiniYaml.FromStream(Package.GetContent("map.yaml"));
|
||||
var yaml = MiniYaml.DictFromStream(Package.GetContent("map.yaml"));
|
||||
|
||||
// 'Simple' metadata
|
||||
FieldLoader.LoadFields(this, yaml, SimpleFields);
|
||||
|
||||
// Waypoints
|
||||
foreach (var wp in yaml["Waypoints"].Nodes)
|
||||
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])));
|
||||
@@ -124,7 +124,7 @@ namespace OpenRA
|
||||
Players.Add("Neutral", new PlayerReference("Neutral", "allies", true, true));
|
||||
|
||||
int actors = 0;
|
||||
foreach (var kv in yaml["Actors"].Nodes)
|
||||
foreach (var kv in yaml["Actors"].NodesDict)
|
||||
{
|
||||
string[] vals = kv.Value.Value.Split(' ');
|
||||
string[] loc = vals[2].Split(',');
|
||||
@@ -138,13 +138,13 @@ namespace OpenRA
|
||||
|
||||
case 2:
|
||||
{
|
||||
foreach (var kv in yaml["Players"].Nodes)
|
||||
foreach (var kv in yaml["Players"].NodesDict)
|
||||
{
|
||||
var player = new PlayerReference(kv.Value);
|
||||
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);
|
||||
Actors.Add(oldActorReference.Id, new ActorReference(oldActorReference.Type)
|
||||
@@ -157,14 +157,14 @@ namespace OpenRA
|
||||
|
||||
case 3:
|
||||
{
|
||||
foreach (var kv in yaml["Players"].Nodes)
|
||||
foreach (var kv in yaml["Players"].NodesDict)
|
||||
{
|
||||
var player = new PlayerReference(kv.Value);
|
||||
Players.Add(player.Name, player);
|
||||
}
|
||||
|
||||
foreach (var kv in yaml["Actors"].Nodes)
|
||||
Actors.Add(kv.Key, new ActorReference(kv.Value.Value, kv.Value.Nodes));
|
||||
foreach (var kv in yaml["Actors"].NodesDict)
|
||||
Actors.Add(kv.Key, new ActorReference(kv.Value.Value, kv.Value.NodesDict));
|
||||
} break;
|
||||
|
||||
default:
|
||||
@@ -188,7 +188,7 @@ namespace OpenRA
|
||||
}
|
||||
|
||||
// Smudges
|
||||
foreach (var kv in yaml["Smudges"].Nodes)
|
||||
foreach (var kv in yaml["Smudges"].NodesDict)
|
||||
{
|
||||
string[] vals = kv.Key.Split(' ');
|
||||
string[] loc = vals[1].Split(',');
|
||||
@@ -207,27 +207,27 @@ namespace OpenRA
|
||||
{
|
||||
MapFormat = 3;
|
||||
|
||||
var root = new Dictionary<string, MiniYaml>();
|
||||
var root = new List<MiniYamlNode>();
|
||||
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));
|
||||
root.Add( new MiniYamlNode( field, FieldSaver.FormatValue( this, f ) ) );
|
||||
}
|
||||
|
||||
root.Add("Players",
|
||||
new MiniYaml(null, Players.ToDictionary(
|
||||
p => "PlayerReference@{0}".F(p.Key),
|
||||
p => FieldSaver.Save(p.Value))));
|
||||
root.Add( new MiniYamlNode( "Players", null,
|
||||
Players.Select( p => new MiniYamlNode(
|
||||
"PlayerReference@{0}".F( p.Key ),
|
||||
FieldSaver.Save( p.Value ) ) ).ToList() ) );
|
||||
|
||||
root.Add("Actors",
|
||||
new MiniYaml( null, Actors.ToDictionary(
|
||||
x => x.Key,
|
||||
x => x.Value.Save() ) ) );
|
||||
root.Add( new MiniYamlNode( "Actors", null,
|
||||
Actors.Select( x => new MiniYamlNode(
|
||||
x.Key,
|
||||
x.Value.Save() ) ).ToList() ) );
|
||||
|
||||
root.Add("Waypoints", MiniYaml.FromDictionary<string, int2>(Waypoints));
|
||||
root.Add("Smudges", MiniYaml.FromList<SmudgeReference>(Smudges));
|
||||
root.Add("Rules", new MiniYaml(null, Rules));
|
||||
root.Add( new MiniYamlNode( "Waypoints", MiniYaml.FromDictionary<string, int2>( Waypoints ) ) );
|
||||
root.Add( new MiniYamlNode( "Smudges", MiniYaml.FromList<SmudgeReference>( Smudges ) ) );
|
||||
root.Add( new MiniYamlNode( "Rules", null, Rules ) );
|
||||
|
||||
SaveBinaryData(Path.Combine(filepath, "map.bin"));
|
||||
root.WriteToFile(Path.Combine(filepath, "map.yaml"));
|
||||
|
||||
@@ -61,15 +61,15 @@ namespace OpenRA.Network
|
||||
|
||||
public string Serialize()
|
||||
{
|
||||
var clientData = new Dictionary<string, MiniYaml>();
|
||||
var clientData = new List<MiniYamlNode>();
|
||||
|
||||
foreach (var client in Clients)
|
||||
clientData["Client@{0}".F(client.Index)] = FieldSaver.Save(client);
|
||||
foreach( var client in Clients )
|
||||
clientData.Add( new MiniYamlNode( "Client@{0}".F( client.Index ), FieldSaver.Save( client ) ) );
|
||||
|
||||
foreach (var slot in Slots)
|
||||
clientData["Slot@{0}".F(slot.Index)] = FieldSaver.Save(slot);
|
||||
foreach( var slot in Slots )
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace OpenRA
|
||||
{
|
||||
class WidgetLoader
|
||||
{
|
||||
public static Widget LoadWidget(KeyValuePair<string, MiniYaml> node)
|
||||
public static Widget LoadWidget(MiniYamlNode node)
|
||||
{
|
||||
var widget = NewWidget(node.Key);
|
||||
foreach (var child in node.Value.Nodes)
|
||||
|
||||
Reference in New Issue
Block a user