fix bug 609 -- removing traits that arent on an actor is an error.

This commit is contained in:
Chris Forbes
2011-04-05 21:26:32 +12:00
parent 576e9b90f6
commit 55c609ee16
2 changed files with 61 additions and 22 deletions

View File

@@ -22,14 +22,30 @@ namespace OpenRA
public readonly TypeDictionary Traits = new TypeDictionary();
public ActorInfo( string name, MiniYaml node, Dictionary<string, MiniYaml> allUnits )
{
var mergedNode = MergeWithParent( node, allUnits ).NodesDict;
Name = name;
foreach( var t in mergedNode )
if( t.Key != "Inherits" && !t.Key.StartsWith("-") )
Traits.Add( LoadTraitInfo( t.Key.Split('@')[0], t.Value ) );
}
{
try
{
var mergedNode = MergeWithParent(node, allUnits).NodesDict;
Name = name;
foreach (var t in mergedNode)
if (t.Key != "Inherits" && !t.Key.StartsWith("-"))
Traits.Add(LoadTraitInfo(t.Key.Split('@')[0], t.Value));
}
catch (YamlException e)
{
throw new YamlException("Actor type {0}: {1}".F(name, e.Message));
}
}
static IEnumerable<MiniYaml> GetInheritanceChain(MiniYaml node, Dictionary<string, MiniYaml> allUnits)
{
while (node != null)
{
yield return node;
node = GetParent(node, allUnits);
}
}
static MiniYaml GetParent( MiniYaml node, Dictionary<string, MiniYaml> allUnits )
{
@@ -49,9 +65,15 @@ namespace OpenRA
static MiniYaml MergeWithParent( MiniYaml node, Dictionary<string, MiniYaml> allUnits )
{
var parent = GetParent( node, allUnits );
if( parent != null )
return MiniYaml.Merge( node, MergeWithParent( parent, allUnits ) );
var parent = GetParent( node, allUnits );
if (parent != null)
{
var result = MiniYaml.Merge(node, MergeWithParent(parent, allUnits));
// strip the '-'
result.Nodes.RemoveAll(a => a.Key.StartsWith("-"));
return result;
}
return node;
}