Guard province action animation sprites (#7224)

This commit is contained in:
2026-06-14 13:06:50 -07:00
committed by GitHub
parent 5da05a58b2
commit 65a97388c9
2 changed files with 75 additions and 0 deletions
@@ -0,0 +1,64 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using eagle;
using NUnit.Framework;
using UnityEditor.SceneManagement;
using UnityEngine;
using UnityEngine.SceneManagement;
namespace eagle0.Tests {
[TestFixture]
public class ProvinceActionAnimatorSpriteTests {
private const string EagleScenePath = "Assets/Scenes/Eagle.unity";
[Test]
public void EagleSceneProvinceActionAnimatorHasVisualSpritesAssigned() {
var scene = EditorSceneManager.OpenScene(EagleScenePath, OpenSceneMode.Single);
var animator = FindSceneComponent<ProvinceActionAnimator>(scene);
var violations = new List<string>();
foreach (var field in PublicInstanceFields()) {
if (field.FieldType == typeof(Sprite)) {
if (field.GetValue(animator) == null) {
violations.Add($"{field.Name} must be assigned.");
}
} else if (field.FieldType == typeof(Sprite[])) {
var sprites = (Sprite[])field.GetValue(animator);
if (sprites == null || sprites.Length == 0) {
violations.Add($"{field.Name} must contain at least one sprite.");
continue;
}
for (var i = 0; i < sprites.Length; i++) {
if (sprites[i] == null) {
violations.Add($"{field.Name}[{i}] must be assigned.");
}
}
}
}
Assert.IsEmpty(
violations,
"Eagle action animation sprites should stay assigned so URP visual QA covers real effects:\n" +
string.Join("\n", violations));
}
private static IEnumerable<FieldInfo> PublicInstanceFields() {
return typeof(ProvinceActionAnimator)
.GetFields(BindingFlags.Instance | BindingFlags.Public)
.Where(field => field.FieldType == typeof(Sprite) ||
field.FieldType == typeof(Sprite[]))
.OrderBy(field => field.Name, StringComparer.Ordinal);
}
private static T FindSceneComponent<T>(Scene scene)
where T : Component {
var component = Resources.FindObjectsOfTypeAll<T>().FirstOrDefault(
item => item.gameObject.scene == scene);
Assert.NotNull(component, $"{scene.path} must contain {typeof(T).Name}.");
return component;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d6061174edd34718ab7e71ea8a08ffe5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: