Move SupportPowerDecisions to a single parent node.

This is required before we can force all trait
properties to match a TraitInfo-defined field.
This commit is contained in:
Paul Chote
2018-06-14 15:37:15 +00:00
committed by reaperrr
parent f82674cfef
commit cce9b06a40
8 changed files with 559 additions and 490 deletions

View File

@@ -0,0 +1,56 @@
#region Copyright & License Information
/*
* Copyright 2007-2018 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version. For more
* information, see COPYING.
*/
#endregion
using System.Collections.Generic;
using System.Linq;
namespace OpenRA.Mods.Common.UpdateRules.Rules
{
public class MoveHackyAISupportPowerDecisions : UpdateRule
{
public override string Name { get { return "Move HackyAI SupportPowerDecisions to a trait property"; } }
public override string Description
{
get
{
return "The SupportPowerDefinitions on HackyAI are moved from top-level trait properties\n" +
"to children of a single SupportPowerDecisions property.";
}
}
public override IEnumerable<string> UpdateActorNode(ModData modData, MiniYamlNode actorNode)
{
foreach (var hackyAINode in actorNode.ChildrenMatching("HackyAI"))
{
var children = hackyAINode.ChildrenMatching("SupportPowerDecision");
if (!children.Any())
continue;
var parent = hackyAINode.LastChildMatching("SupportPowerDecisions");
if (parent == null)
{
parent = new MiniYamlNode("SupportPowerDecisions", "");
hackyAINode.AddNode(parent);
}
foreach (var child in children.ToList())
{
var split = child.Key.Split('@');
child.Key = split.Length > 1 ? split[1] : "Default";
parent.AddNode(child);
hackyAINode.RemoveNode(child);
}
}
yield break;
}
}
}

View File

@@ -54,6 +54,7 @@ namespace OpenRA.Mods.Common.UpdateRules
new DefineOwnerLostAction(),
new RenameEmitInfantryOnSell(),
new SplitRepairDecoration(),
new MoveHackyAISupportPowerDecisions(),
})
};