From 331b854e4edccb1c17245dbb206979a252dead11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Sat, 4 Apr 2020 13:31:01 +0200 Subject: [PATCH] Add a lint check for production bar types. --- .../Traits/Render/ProductionBar.cs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/OpenRA.Mods.Common/Traits/Render/ProductionBar.cs b/OpenRA.Mods.Common/Traits/Render/ProductionBar.cs index 565fae2c0e..73a9e5f0f1 100644 --- a/OpenRA.Mods.Common/Traits/Render/ProductionBar.cs +++ b/OpenRA.Mods.Common/Traits/Render/ProductionBar.cs @@ -16,7 +16,7 @@ using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits.Render { [Desc("Visualizes the remaining build time of actor produced here.")] - class ProductionBarInfo : ConditionalTraitInfo, Requires + class ProductionBarInfo : ConditionalTraitInfo, Requires, IRulesetLoaded { [FieldLoader.Require] [Desc("Production queue type, for actors with multiple queues.")] @@ -24,6 +24,21 @@ namespace OpenRA.Mods.Common.Traits.Render public readonly Color Color = Color.SkyBlue; + public override void RulesetLoaded(Ruleset rules, ActorInfo ai) + { + // Per-actor queue + var queue = ai.TraitInfos().FirstOrDefault(q => ProductionType == q.Type); + + // No queues available - check for classic production queues + if (queue == null) + queue = rules.Actors["player"].TraitInfos().FirstOrDefault(q => ProductionType == q.Type); + + if (queue == null) + throw new YamlException("Can't find a queue with ProductionType '{0}'".F(ProductionType)); + + base.RulesetLoaded(rules, ai); + } + public override object Create(ActorInitializer init) { return new ProductionBar(init.Self, this); } }