Skip to content

Commit

Permalink
Automate update rule.
Browse files Browse the repository at this point in the history
  • Loading branch information
PunkPun committed Dec 4, 2023
1 parent ad833a6 commit dd7441e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,40 +10,55 @@
#endregion

using System.Collections.Generic;
using System.Linq;

namespace OpenRA.Mods.Common.UpdateRules.Rules
{
public class ReplaceCloakPalette : UpdateRule
public class ReplaceCloakPalette : UpdateRule, IBeforeUpdateActors
{
public override string Name => "Change default Cloak style from Palette to Alpha.";

public override string Description =>
"Cloak has gained several new rendering modes\n" +
"and its default behaviour has changed from using a palette to native alpha.";

readonly List<string> locations = new();

public override IEnumerable<string> AfterUpdate(ModData modData)
readonly List<(string, string)> actorsWithDefault = new();
IEnumerable<string> IBeforeUpdateActors.BeforeUpdateActors(ModData modData, List<MiniYamlNodeBuilder> resolvedActors)
{
if (locations.Count > 0)
yield return "Cloak no longer defaults to replacing the actor's palette.\n" +
"If you wish to keep the previous behavior you wish to change the\n" +
"Cloak definitions on the following actor definitions:\n" +
UpdateUtils.FormatMessageList(locations);
foreach (var actor in resolvedActors)
foreach (var cloak in actor.ChildrenMatching("Cloak"))
if (cloak.LastChildMatching("Palette", false) == null)
actorsWithDefault.Add((actor.Key, cloak.Key));

locations.Clear();
yield break;
}

public override IEnumerable<string> UpdateActorNode(ModData modData, MiniYamlNodeBuilder actorNode)
{
foreach (var cloak in actorNode.ChildrenMatching("Cloak"))
{
cloak.RemoveNodes("Palette");
cloak.RemoveNodes("IsPlayerPalette");
locations.Add($"{actorNode.Key} ({actorNode.Location.Filename})");
}
if (actorsWithDefault.Any(pair => pair.Item1 == actorNode.Key && pair.Item2 == cloak.Key))
{
cloak.AddNode("CloakedPalette", "cloak");
cloak.AddNode("CloakStyle", "Palette");
yield break;
}

yield break;
var palette = cloak.LastChildMatching("Palette", false);
if (palette != null)
{
if (string.IsNullOrEmpty(palette.Value.Value))
{
cloak.RemoveNode(palette);
cloak.AddNode("CloakStyle", "None");
}
else
{
palette.RenameKey("CloakedPalette");
cloak.AddNode("CloakStyle", "Palette");
}
}
}
}
}
}
2 changes: 1 addition & 1 deletion OpenRA.Mods.Common/UpdateRules/UpdatePath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ public sealed class UpdatePath
new ExtractResourceStorageFromHarvester(),
new ReplacePaletteModifiers(),
new RemoveConyardChronoReturnAnimation(),
new ReplaceCloakPalette(),

// Execute these rules last to avoid premature yaml merge crashes.
new ReplaceCloakPalette(),
new AbstractDocking(),
}),
};
Expand Down

0 comments on commit dd7441e

Please sign in to comment.