Automate update rule.
This commit is contained in:
@@ -10,10 +10,11 @@
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace OpenRA.Mods.Common.UpdateRules.Rules
|
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 Name => "Change default Cloak style from Palette to Alpha.";
|
||||||
|
|
||||||
@@ -21,29 +22,43 @@ namespace OpenRA.Mods.Common.UpdateRules.Rules
|
|||||||
"Cloak has gained several new rendering modes\n" +
|
"Cloak has gained several new rendering modes\n" +
|
||||||
"and its default behaviour has changed from using a palette to native alpha.";
|
"and its default behaviour has changed from using a palette to native alpha.";
|
||||||
|
|
||||||
readonly List<string> locations = new();
|
readonly List<(string, string)> actorsWithDefault = new();
|
||||||
|
IEnumerable<string> IBeforeUpdateActors.BeforeUpdateActors(ModData modData, List<MiniYamlNodeBuilder> resolvedActors)
|
||||||
public override IEnumerable<string> AfterUpdate(ModData modData)
|
|
||||||
{
|
{
|
||||||
if (locations.Count > 0)
|
foreach (var actor in resolvedActors)
|
||||||
yield return "Cloak no longer defaults to replacing the actor's palette.\n" +
|
foreach (var cloak in actor.ChildrenMatching("Cloak"))
|
||||||
"If you wish to keep the previous behavior you wish to change the\n" +
|
if (cloak.LastChildMatching("Palette", false) == null)
|
||||||
"Cloak definitions on the following actor definitions:\n" +
|
actorsWithDefault.Add((actor.Key, cloak.Key));
|
||||||
UpdateUtils.FormatMessageList(locations);
|
|
||||||
|
|
||||||
locations.Clear();
|
yield break;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override IEnumerable<string> UpdateActorNode(ModData modData, MiniYamlNodeBuilder actorNode)
|
public override IEnumerable<string> UpdateActorNode(ModData modData, MiniYamlNodeBuilder actorNode)
|
||||||
{
|
{
|
||||||
foreach (var cloak in actorNode.ChildrenMatching("Cloak"))
|
foreach (var cloak in actorNode.ChildrenMatching("Cloak"))
|
||||||
{
|
{
|
||||||
cloak.RemoveNodes("Palette");
|
if (actorsWithDefault.Any(pair => pair.Item1 == actorNode.Key && pair.Item2 == cloak.Key))
|
||||||
cloak.RemoveNodes("IsPlayerPalette");
|
{
|
||||||
locations.Add($"{actorNode.Key} ({actorNode.Location.Filename})");
|
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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -85,9 +85,9 @@ namespace OpenRA.Mods.Common.UpdateRules
|
|||||||
new ExtractResourceStorageFromHarvester(),
|
new ExtractResourceStorageFromHarvester(),
|
||||||
new ReplacePaletteModifiers(),
|
new ReplacePaletteModifiers(),
|
||||||
new RemoveConyardChronoReturnAnimation(),
|
new RemoveConyardChronoReturnAnimation(),
|
||||||
new ReplaceCloakPalette(),
|
|
||||||
|
|
||||||
// Execute these rules last to avoid premature yaml merge crashes.
|
// Execute these rules last to avoid premature yaml merge crashes.
|
||||||
|
new ReplaceCloakPalette(),
|
||||||
new AbstractDocking(),
|
new AbstractDocking(),
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user