forked from OpenRA/OpenRA
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unhardcode VeteranProductionIconOverlay.
- Loading branch information
1 parent
d438508
commit 5434059
Showing
9 changed files
with
199 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
OpenRA.Mods.Common/Traits/Render/WithProductionIconOverlay.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#region Copyright & License Information | ||
/* | ||
* Copyright 2007-2022 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; | ||
using System.Linq; | ||
using OpenRA.Traits; | ||
|
||
namespace OpenRA.Mods.Common.Traits.Render | ||
{ | ||
[Desc("Displays overlays from `ProductionIconOverlayManager` with matching types when defined prerequisites are granted.")] | ||
public class WithProductionIconOverlayInfo : TraitInfo<WithProductionIconOverlay>, IRulesetLoaded | ||
{ | ||
[FieldLoader.Require] | ||
public readonly string[] Types = Array.Empty<string>(); | ||
|
||
public readonly string[] Prerequisites = Array.Empty<string>(); | ||
|
||
public virtual void RulesetLoaded(Ruleset rules, ActorInfo ai) | ||
{ | ||
foreach (var type in Types) | ||
{ | ||
if (!rules.Actors[SystemActors.Player].TraitInfos<ProductionIconOverlayManagerInfo>().Where(piom => piom.Type == type).Any()) | ||
throw new YamlException($"A 'ProductionIconOverlayManager' with type '{type}' doesn't exist."); | ||
|
||
if (ai.TraitInfos<WithProductionIconOverlayInfo>().Where(wpio => wpio != this && wpio.Types.Contains(type)).Any()) | ||
throw new YamlException($"Multiple 'WithProductionIconOverlay's with type '{type}' exist on the actor."); | ||
} | ||
} | ||
} | ||
|
||
public class WithProductionIconOverlay { } | ||
} |
49 changes: 49 additions & 0 deletions
49
OpenRA.Mods.Common/UpdateRules/Rules/20201213/UnhardcodeVeteranProductionIconOverlay.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#region Copyright & License Information | ||
/* | ||
* Copyright 2007-2022 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 UnhardcodeVeteranProductionIconOverlay : UpdateRule | ||
{ | ||
public override string Name => "VeteranProductionIconOverlay is changed to ProductionIconOverlayManager giving it more customisation."; | ||
|
||
public override string Description => "ProductionIconOverlayManager now works with the new WithProductionIconOverlay trait, instead of ProducibleWithLevel."; | ||
|
||
readonly List<string> locations = new List<string>(); | ||
|
||
public override IEnumerable<string> AfterUpdate(ModData modData) | ||
{ | ||
if (locations.Any()) | ||
yield return "Icon overlay logic has been split from ProducibleWithLevel to WithProductionIconOverlay trait.\n" + | ||
"If you have been using VeteranProductionIconOverlay trait, add WithProductionIconOverlay to following actors:\n" + | ||
UpdateUtils.FormatMessageList(locations); | ||
|
||
locations.Clear(); | ||
} | ||
|
||
public override IEnumerable<string> UpdateActorNode(ModData modData, MiniYamlNode actorNode) | ||
{ | ||
foreach (var veteranProductionIconOverlay in actorNode.ChildrenMatching("VeteranProductionIconOverlay")) | ||
{ | ||
veteranProductionIconOverlay.RenameKey("ProductionIconOverlayManager"); | ||
veteranProductionIconOverlay.AddNode(new MiniYamlNode("Type", "Veterancy")); | ||
} | ||
|
||
foreach (var producibleWithLevel in actorNode.ChildrenMatching("ProducibleWithLevel")) | ||
locations.Add($"{actorNode.Key}: {producibleWithLevel.Key} ({actorNode.Location.Filename})"); | ||
|
||
yield break; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.