Add some more useful extensions to UpdateUtils
In many situations, these will save up to 3-4 lines, because quite often this will be enough to avoid curly brackets, "if"s or one-by-on renamings.
This commit is contained in:
@@ -273,6 +273,19 @@ namespace OpenRA.Mods.Common.UpdateRules
|
||||
node.Value.Nodes.Remove(toRemove);
|
||||
}
|
||||
|
||||
public static void MoveNode(this MiniYamlNode node, MiniYamlNode fromNode, MiniYamlNode toNode)
|
||||
{
|
||||
toNode.Value.Nodes.Add(node);
|
||||
fromNode.Value.Nodes.Remove(node);
|
||||
}
|
||||
|
||||
public static void MoveAndRenameNode(this MiniYamlNode node,
|
||||
MiniYamlNode fromNode, MiniYamlNode toNode, string newKey, bool preserveSuffix = true, bool includeRemovals = true)
|
||||
{
|
||||
node.RenameKey(newKey, preserveSuffix, includeRemovals);
|
||||
node.MoveNode(fromNode, toNode);
|
||||
}
|
||||
|
||||
/// <summary>Removes children with keys equal to [match] or [match]@[arbitrary suffix]</summary>
|
||||
public static int RemoveNodes(this MiniYamlNode node, string match, bool ignoreSuffix = true, bool includeRemovals = true)
|
||||
{
|
||||
@@ -307,5 +320,12 @@ namespace OpenRA.Mods.Common.UpdateRules
|
||||
{
|
||||
return node.ChildrenMatching(match, includeRemovals).LastOrDefault();
|
||||
}
|
||||
|
||||
public static void RenameChildrenMatching(this MiniYamlNode node, string match, string newKey, bool preserveSuffix = true, bool includeRemovals = true)
|
||||
{
|
||||
var matching = node.ChildrenMatching(match);
|
||||
foreach (var m in matching)
|
||||
m.RenameKey(newKey, preserveSuffix, includeRemovals);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user