Add a lint check for production bar types.

This commit is contained in:
Matthias Mailänder
2020-04-04 13:31:01 +02:00
committed by reaperrr
parent 274bc9cbba
commit 331b854e4e

View File

@@ -16,7 +16,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits.Render namespace OpenRA.Mods.Common.Traits.Render
{ {
[Desc("Visualizes the remaining build time of actor produced here.")] [Desc("Visualizes the remaining build time of actor produced here.")]
class ProductionBarInfo : ConditionalTraitInfo, Requires<ProductionInfo> class ProductionBarInfo : ConditionalTraitInfo, Requires<ProductionInfo>, IRulesetLoaded
{ {
[FieldLoader.Require] [FieldLoader.Require]
[Desc("Production queue type, for actors with multiple queues.")] [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 readonly Color Color = Color.SkyBlue;
public override void RulesetLoaded(Ruleset rules, ActorInfo ai)
{
// Per-actor queue
var queue = ai.TraitInfos<ProductionQueueInfo>().FirstOrDefault(q => ProductionType == q.Type);
// No queues available - check for classic production queues
if (queue == null)
queue = rules.Actors["player"].TraitInfos<ProductionQueueInfo>().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); } public override object Create(ActorInitializer init) { return new ProductionBar(init.Self, this); }
} }