Add a HasChild helper command

This commit is contained in:
Gustas
2025-04-05 17:32:09 +03:00
committed by Gustas Kažukauskas
parent a2a7b30727
commit 58088ecabe
3 changed files with 9 additions and 2 deletions

View File

@@ -45,7 +45,7 @@ namespace OpenRA.Mods.Common.UpdateRules.Rules
harvesters[actorNode.Key] = harvesterNode.ChildrenMatching("DeliveryBuildings", includeRemovals: false)
.FirstOrDefault()?.NodeValue<HashSet<string>>() ?? [];
if (actorNode.ChildrenMatching("Refinery", includeRemovals: false).Any())
if (actorNode.HasChild("Refinery"))
refineries.Add(actorNode.Key.ToLowerInvariant());
}

View File

@@ -27,7 +27,7 @@ namespace OpenRA.Mods.Common.UpdateRules.Rules
{
foreach (var actor in resolvedActors)
foreach (var cloak in actor.ChildrenMatching("Cloak"))
if (cloak.LastChildMatching("Palette", false) == null)
if (cloak.HasChild("Palette"))
actorsWithDefault.Add((actor.Key, cloak.Key));
yield break;

View File

@@ -471,6 +471,13 @@ namespace OpenRA.Mods.Common.UpdateRules
return node.Value.Nodes.Where(n => n.KeyMatches(match, ignoreSuffix, includeRemovals));
}
/// <summary>Returns true if node exists and is not being removed.</summary>
public static bool HasChild(
this MiniYamlNodeBuilder node, string match, bool ignoreSuffix = true)
{
return ChildrenMatching(node, match, ignoreSuffix).LastOrDefault()?.IsRemoval() == false;
}
/// <summary>Returns children whose keys contain 'match' (optionally in the suffix).</summary>
public static IEnumerable<MiniYamlNodeBuilder> ChildrenContaining(
this MiniYamlNodeBuilder node, string match, bool ignoreSuffix = true, bool includeRemovals = true)