TileArtValidation.cs 4.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using System.IO;
  2. using UnityEditor;
  3. using UnityEditor.TestTools.TestRunner.Api;
  4. using UnityEngine;
  5. namespace DevilLink2.Editor
  6. {
  7. /// <summary>Read-only asset previews and test execution; never saves scenes or prefabs.</summary>
  8. public sealed class TileArtValidation : EditorWindow
  9. {
  10. private static TestRunnerApi runner;
  11. private static string reportFolder = "Temp/DevilLink2Task10E3";
  12. private readonly string[] names = { "Imp", "Trident", "Potion", "Piggy", "Ring", "Candle", "Star", "A", "Q", "J", "Ten", "Nine" };
  13. [MenuItem("Tools/Devil Link 2/Preview Tile Art 64 and 48")]
  14. public static void Preview()
  15. {
  16. var window = GetWindow<TileArtValidation>("Tile Art 09B");
  17. window.minSize = new Vector2(840, 410);
  18. }
  19. private void OnGUI()
  20. {
  21. EditorGUILayout.LabelField("Tile artwork at 64 x 64 and 48 x 48", EditorStyles.boldLabel);
  22. EditorGUILayout.LabelField("Original PNGs, aspect preserved. Inset matches TileView (2px per side).");
  23. for (int i = 0; i < names.Length; i++)
  24. {
  25. float x = 18 + (i % 6) * 130;
  26. float y = (i / 6) * 180;
  27. GUI.Label(new Rect(x, 48 + y, 94, 22), names[i]);
  28. var sprite = AssetDatabase.LoadAssetAtPath<Sprite>("Assets/DevilLink2/Sprites/Tiles/" + names[i] + ".png");
  29. foreach (int size in new[] { 64, 48 })
  30. {
  31. var rect = new Rect(x, y + (size == 64 ? 76 : 150), size, size);
  32. EditorGUI.DrawRect(rect, new Color32(55, 56, 77, 255));
  33. EditorGUI.DrawRect(new Rect(rect.x + 1, rect.y + 1, size - 2, size - 2), new Color32(24, 24, 40, 255));
  34. if (sprite) GUI.DrawTexture(new Rect(rect.x + 2, rect.y + 2, size - 4, size - 4), sprite.texture, ScaleMode.ScaleToFit, true);
  35. else GUI.Label(rect, "Not imported");
  36. }
  37. }
  38. }
  39. [MenuItem("Tools/Devil Link 2/Validate Tile Art")]
  40. [MenuItem("Tools/Devil Link 2/Validate Board Visuals")]
  41. [MenuItem("Tools/Devil Link 2/Validate Interaction Visuals")]
  42. [MenuItem("Tools/Devil Link 2/Validate Score Combo Visuals")]
  43. [MenuItem("Tools/Devil Link 2/Validate UI Transitions")]
  44. [MenuItem("Tools/Devil Link 2/Validate Audio Integration")]
  45. [MenuItem("Tools/Devil Link 2/Validate Audio Mix Calibration")]
  46. public static void Validate() { RunTests("Temp/DevilLink2Task10E3"); }
  47. [MenuItem("Tools/Devil Link 2/Validate Lobby Visual Integration")]
  48. public static void ValidateLobby() { RunTests("Temp/DevilLink2Task11A2"); }
  49. private static void RunTests(string folder)
  50. {
  51. if (EditorApplication.isCompiling || EditorApplication.isUpdating || EditorApplication.isPlayingOrWillChangePlaymode || runner)
  52. { Debug.LogWarning("[DevilLink2.Task10E3] Requires an idle EditMode editor."); return; }
  53. reportFolder = folder;
  54. runner = CreateInstance<TestRunnerApi>(); runner.RegisterCallbacks(new Results());
  55. runner.Execute(new ExecutionSettings(new Filter { testMode = TestMode.EditMode,
  56. assemblyNames = new[] { "DevilLink2.Core.Tests", "DevilLink2.Presentation.Tests", "DevilLink2.Interaction.Tests",
  57. "DevilLink2.Gameplay.Tests", "DevilLink2.Persistence.Tests", "DevilLink2.UI.Tests" } }));
  58. }
  59. private sealed class Results : ICallbacks
  60. {
  61. public void RunStarted(ITestAdaptor test) { }
  62. public void TestStarted(ITestAdaptor test) { }
  63. public void TestFinished(ITestResultAdaptor result)
  64. { if (result.TestStatus == TestStatus.Failed) Debug.LogError("[DevilLink2.Task10E3] " + result.FullName + " " + result.Message); }
  65. public void RunFinished(ITestResultAdaptor result)
  66. {
  67. Directory.CreateDirectory(reportFolder);
  68. TestRunnerApi.SaveResultToFile(result, Path.Combine(reportFolder, "UnityResults.xml"));
  69. Debug.Log($"[DevilLink2.Task10E3] passed={result.PassCount} failed={result.FailCount} skipped={result.SkipCount}");
  70. runner.UnregisterCallbacks(this); DestroyImmediate(runner); runner = null;
  71. }
  72. }
  73. }
  74. }