From 1f69a0f6ed9b248a430f7a59f5294511da10adb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Wed, 8 Jul 2015 17:06:24 +0200 Subject: [PATCH] make projectile sprite sequences lint testable --- OpenRA.Mods.Common/Lint/CheckSequences.cs | 43 +++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/OpenRA.Mods.Common/Lint/CheckSequences.cs b/OpenRA.Mods.Common/Lint/CheckSequences.cs index 05c3108092..284959f624 100644 --- a/OpenRA.Mods.Common/Lint/CheckSequences.cs +++ b/OpenRA.Mods.Common/Lint/CheckSequences.cs @@ -12,6 +12,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Reflection; +using OpenRA.GameRules; using OpenRA.Mods.Common.Traits; using OpenRA.Traits; @@ -89,6 +90,48 @@ namespace OpenRA.Mods.Common.Lint } } } + + foreach (var weaponInfo in map.Rules.Weapons) + { + var projectileInfo = weaponInfo.Value.Projectile; + if (projectileInfo == null) + continue; + + var fields = projectileInfo.GetType().GetFields(); + foreach (var field in fields) + { + if (field.HasAttribute()) + { + var sequences = LintExts.GetFieldValues(projectileInfo, field, emitError); + foreach (var sequence in sequences) + { + if (string.IsNullOrEmpty(sequence)) + continue; + + var sequenceReference = field.GetCustomAttributes(true).FirstOrDefault(); + if (sequenceReference != null && !string.IsNullOrEmpty(sequenceReference.ImageReference)) + { + var imageField = fields.FirstOrDefault(f => f.Name == sequenceReference.ImageReference); + if (imageField != null) + { + foreach (var imageOverride in LintExts.GetFieldValues(projectileInfo, imageField, emitError)) + { + if (!string.IsNullOrEmpty(imageOverride)) + { + var definitions = sequenceDefinitions.FirstOrDefault(n => n.Key == imageOverride.ToLowerInvariant()); + if (definitions == null) + emitWarning("Can't find sequence definition for projectile image {0} at weapon {1}.".F(imageOverride, weaponInfo.Key)); + else if (!definitions.Value.Nodes.Any(n => n.Key == sequence)) + emitWarning("Projectile sprite image {0} from weapon {1} does not define sequence {2} from field {3} of {4}" + .F(imageOverride, weaponInfo.Key, sequence, field.Name, projectileInfo)); + } + } + } + } + } + } + } + } } }