| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- using System;
- using System.Collections.Generic;
- using System.IO;
- using DevilLink2.Gameplay;
- using DevilLink2.Persistence;
- using DevilLink2.Presentation;
- using DevilLink2.UI;
- using UnityEditor;
- using UnityEngine;
- using UnityEngine.SceneManagement;
- using Object = UnityEngine.Object;
- namespace DevilLink2.Editor
- {
- /// <summary>Actual Main scene Play Mode acceptance, entirely through structured code.
- /// No scene is saved. The test profile always lives under Temp, never persistentDataPath.</summary>
- [InitializeOnLoad]
- public static class UIPlayModeValidation
- {
- private const string Prefix = "DevilLink2.Task08A.Play.";
- private static string ReportPath => SessionState.GetString(Prefix + "Scenario", "08A") == "12" ? "Temp/DevilLink2Task12/PlayModeResults.json" : SessionState.GetString(Prefix + "Scenario", "08A") == "11C" ? "Temp/DevilLink2Task11C/PlayModeResults.json" : SessionState.GetString(Prefix + "Scenario", "08A") == "11A2" ? "Temp/DevilLink2Task11A2/PlayModeResults.json" : SessionState.GetString(Prefix + "Scenario", "08A") == "08C6" ? "Temp/DevilLink2Task08C6/PlayModeResults.json" : SessionState.GetString(Prefix + "Scenario", "08A") == "08C5" ? "Temp/DevilLink2Task08C5/PlayModeResults.json" : SessionState.GetString(Prefix + "Scenario", "08A") == "08C4" ? "Temp/DevilLink2Task08C4/PlayModeResults.json" : SessionState.GetString(Prefix + "Scenario", "08A") == "08C3" ? "Temp/DevilLink2Task08C3/PlayModeResults.json" : SessionState.GetString(Prefix + "Scenario", "08A") == "08C2" ? "Temp/DevilLink2Task08C2/PlayModeResults.json" : SessionState.GetString(Prefix + "Scenario", "08A") == "08C1" ? "Temp/DevilLink2Task08C1/PlayModeResults.json" : SessionState.GetString(Prefix + "Scenario", "08A") == "08B" ? "Temp/DevilLink2Task08B/PlayModeResults.json" : "Temp/DevilLink2Task08A/PlayModeResults.json";
- private sealed class FixedUtc : IUtcClock
- { public DateTimeOffset UtcNow => new DateTimeOffset(2026,11,3,12,0,0,TimeSpan.Zero); }
- [Serializable] private sealed class Report
- { public bool Passed; public string Scene; public string Checks; public string Error; }
- static UIPlayModeValidation()
- {
- EditorApplication.update += Tick;
- EditorApplication.playModeStateChanged += Changed;
- InstallOverride();
- }
- [InitializeOnEnterPlayMode]
- private static void BeforePlay(EnterPlayModeOptions options) { InstallOverride(); }
- private static void InstallOverride()
- {
- if (!SessionState.GetBool(MainUIInstaller.ValidationSessionKey, false)) return;
- string path = SessionState.GetString(Prefix + "Directory", "");
- MainUIInstaller.PlayerLoaderOverride = () => new SavedPlayer(new LocalSaveService(new FileSaveStorage(path)), new FixedUtc());
- }
- [MenuItem("Tools/Devil Link 2/Validate Start Lobby Play Mode")]
- public static void Run() { RunScenario("08A"); }
- [MenuItem("Tools/Devil Link 2/Validate Game HUD Pause Result Play Mode")]
- public static void RunGameHUD() { RunScenario("08B"); }
- [MenuItem("Tools/Devil Link 2/Validate Shop Play Mode")]
- public static void RunShop() { RunScenario("08C1"); }
- [MenuItem("Tools/Devil Link 2/Validate Daily Check-in Play Mode")]
- public static void RunDaily() { RunScenario("08C2"); }
- [MenuItem("Tools/Devil Link 2/Validate Lucky Wheel Play Mode")]
- public static void RunWheel() { RunScenario("08C3"); }
- [MenuItem("Tools/Devil Link 2/Validate Profile Play Mode")]
- public static void RunProfile(){RunScenario("08C4");}
- [MenuItem("Tools/Devil Link 2/Validate Settings Play Mode")]
- public static void RunSettings(){RunScenario("08C5");}
- [MenuItem("Tools/Devil Link 2/Validate Help Play Mode")]
- public static void RunHelp(){RunScenario("08C6");}
- [MenuItem("Tools/Devil Link 2/Validate Lobby Visual Play Mode")]
- public static void RunLobbyVisuals(){RunScenario("11A2");}
- [MenuItem("Tools/Devil Link 2/Validate Functional Screens Play Mode")]
- public static void RunFunctional(){RunScenario("11C");}
- [MenuItem("Tools/Devil Link 2/Validate Task 12 Runtime Matrix")]
- public static void RunTask12(){Task12Acceptance.Reset();RunScenario("12");}
- private static void RunScenario(string scenario)
- {
- var scene = SceneManager.GetActiveScene();
- if (EditorApplication.isPlayingOrWillChangePlaymode || EditorApplication.isCompiling || scene.isDirty || scene.path != "Assets/DevilLink2/Scenes/Main.unity")
- throw new InvalidOperationException("Requires the saved Main scene in idle EditMode. No scenes will be opened or saved.");
- SessionState.SetString(Prefix + "Scenario", scenario);
- string path = Path.GetFullPath(Path.Combine("Temp/DevilLink2Task" + scenario + "/PlayProfiles", Guid.NewGuid().ToString("N")));
- if(scenario=="12" && SessionState.GetBool("DL2Task12.Reopen",false))path=SessionState.GetString("DL2Task12.Profile",path);
- else new LocalSaveService(new FileSaveStorage(path)).Save(new SaveData {
- Coins = 9876, SpinTickets = 7, ClassicProgress = scenario == "12" ? 19 : scenario == "08B" ? 19 : 2, TimeAttackProgress = scenario == "12" ? 19 : scenario == "08B" ? 0 : 3, ZenProgress = scenario == "12" ? 19 : scenario == "08B" ? 0 : 19,
- HintCount = scenario == "08B" ? 2 : 1, ShuffleCount = scenario == "08B" ? 2 : 1, TimeCount = scenario == "08B" ? 3 : 0
- });
- if(scenario=="12")SessionState.SetString("DL2Task12.Profile",path);
- SessionState.SetString(Prefix + "Directory", path); SessionState.SetInt(Prefix + "Step", 0);
- SessionState.SetString(Prefix + "Checks", ""); SessionState.SetFloat(Prefix + "Start", (float)EditorApplication.timeSinceStartup);
- SessionState.SetBool(MainUIInstaller.ValidationSessionKey, true); InstallOverride();
- WheelPlayAcceptance.Reset(); HUDPlayAcceptance.Reset(); ShopPlayAcceptance.Reset();
- EditorApplication.isPlaying = true;
- }
- private static void Check(bool condition, string name)
- {
- if (!condition) throw new InvalidOperationException(name);
- SessionState.SetString(Prefix + "Checks", SessionState.GetString(Prefix + "Checks", "") + name + "\n");
- }
- private static void Tick()
- {
- if (!SessionState.GetBool(MainUIInstaller.ValidationSessionKey, false) || !EditorApplication.isPlaying || EditorApplication.isPaused) return;
- try
- {
- if (EditorApplication.timeSinceStartup - SessionState.GetFloat(Prefix + "Start", 0) > (SessionState.GetString(Prefix+"Scenario","")=="12"?600:180)) throw new TimeoutException("UI startup did not finish within the acceptance timeout.");
- var manager = Object.FindFirstObjectByType<UIManager>();
- if (!manager || !manager.IsInitialized || manager.transform.localScale.x <= 0) return;
- var bootstrap = Object.FindFirstObjectByType<BoardDemoBootstrap>();
- if (SessionState.GetString(Prefix + "Scenario", "08A") == "12")
- {if(Task12Acceptance.Tick(manager,bootstrap,Check))Finish(true,null);return;}
- if (SessionState.GetString(Prefix + "Scenario", "08A") == "11C")
- {if(FunctionalScreensAcceptance.Tick(manager,bootstrap,Check))Finish(true,null);return;}
- if (SessionState.GetString(Prefix + "Scenario", "08A") == "11A2")
- {if(LobbyArtPlayAcceptance.Tick(manager,bootstrap,Check))Finish(true,null);return;}
- if (SessionState.GetString(Prefix + "Scenario", "08A") == "08C6")
- {if(HelpPlayAcceptance.Tick(manager,bootstrap,Check))Finish(true,null);return;}
- if (SessionState.GetString(Prefix + "Scenario", "08A") == "08C5")
- {if(SettingsPlayAcceptance.Tick(manager,bootstrap,Check))Finish(true,null);return;}
- if (SessionState.GetString(Prefix + "Scenario", "08A") == "08C4")
- {if(ProfilePlayAcceptance.Tick(manager,bootstrap,Check))Finish(true,null);return;}
- if (SessionState.GetString(Prefix + "Scenario", "08A") == "08C3")
- { if (WheelPlayAcceptance.Tick(manager, bootstrap, Check)) Finish(true, null); return; }
- if (SessionState.GetString(Prefix + "Scenario", "08A") == "08C2")
- { if (DailyPlayAcceptance.Tick(manager, bootstrap, Check)) Finish(true, null); return; }
- if (SessionState.GetString(Prefix + "Scenario", "08A") == "08C1")
- { if (ShopPlayAcceptance.Tick(manager, bootstrap, Check)) Finish(true, null); return; }
- if (SessionState.GetString(Prefix + "Scenario", "08A") == "08B")
- { if (HUDPlayAcceptance.Tick(manager, bootstrap, Check)) Finish(true, null); return; }
- int step = SessionState.GetInt(Prefix + "Step", 0);
- if (step == 0)
- {
- Check(SceneManager.GetActiveScene().path == "Assets/DevilLink2/Scenes/Main.unity", "Actual Main scene running");
- Check(manager.CurrentPage == UIPage.Start && bootstrap.Session == null, "Start is first; no eager GameSession");
- Check(bootstrap.GetComponentsInChildren<Canvas>(true).Length == 1, "Single existing Canvas reused");
- manager.StartScreen.StartButton.onClick.Invoke(); manager.StartScreen.StartButton.onClick.Invoke();
- Check(manager.CurrentPage == UIPage.Lobby, "Repeated Start enters one Lobby");
- Check(manager.Lobby.CoinsLabel.text == "9,876" && manager.Lobby.TicketsLabel.text == "7", "Loaded economy displayed");
- }
- else if (step <= 6)
- {
- int index = (step - 1) / 2;
- if (step % 2 == 1)
- {
- manager.Lobby.Cards[index].Button.onClick.Invoke();
- var session = bootstrap.Session; var mode = (GameMode)index; int level = index == 0 ? 3 : index == 1 ? 4 : 20;
- var expected = LevelCatalog.Get(mode, level);
- Check(manager.CurrentPage == UIPage.Gameplay && session.Mode == mode && session.Definition.Level == level, mode + " independent next level");
- Check(session.Board.Columns == expected.Columns && session.Board.Rows == expected.Rows && session.Board.RemainingTileCount == expected.Columns * expected.Rows, mode + " real board dimensions");
- Check(bootstrap.Flow.Runtime.Timer.InitialTime == expected.TimeLimitSeconds && bootstrap.Flow.Runtime.Timer.HasTimer == expected.HasTimer, mode + " timer parameters");
- Check(manager.GameTitle.text.Contains("LEVEL " + level), mode + " title");
- var id = session.Id; manager.Lobby.Cards[index].Button.onClick.Invoke();
- Check(bootstrap.Session.Id == id, mode + " hidden/duplicate input ignored");
- }
- else
- {
- manager.LobbyButton.onClick.Invoke();
- Check(manager.CurrentPage == UIPage.Lobby && bootstrap.Flow.State == GameFlowState.Abandoned, "Return to Lobby abandons run");
- }
- }
- else { Finish(true, null); return; }
- SessionState.SetInt(Prefix + "Step", step + 1);
- }
- catch (Exception error) { Finish(false, error.ToString()); }
- }
- private static void Finish(bool passed, string error)
- {
- Directory.CreateDirectory(Path.GetDirectoryName(ReportPath));
- File.WriteAllText(ReportPath, JsonUtility.ToJson(new Report { Passed = passed, Scene = SceneManager.GetActiveScene().path,
- Checks = SessionState.GetString(Prefix + "Checks", ""), Error = error }, true));
- if(SessionState.GetString(Prefix+"Scenario","")=="12")Task12Acceptance.Restore();
- SessionState.SetBool(MainUIInstaller.ValidationSessionKey, false); MainUIInstaller.PlayerLoaderOverride = null;
- if (passed) Debug.Log("[DevilLink2.UI] PLAY MODE ACCEPTANCE PASSED: " + ReportPath);
- else Debug.LogError("[DevilLink2.UI] PLAY MODE ACCEPTANCE FAILED: " + error);
- if (EditorApplication.isPlaying) EditorApplication.isPlaying = false;
- }
- private static void Changed(PlayModeStateChange state)
- {
- if (state == PlayModeStateChange.EnteredPlayMode) InstallOverride();
- if (state == PlayModeStateChange.ExitingPlayMode && SessionState.GetBool(MainUIInstaller.ValidationSessionKey, false))
- Finish(false, "Play Mode was stopped before acceptance finished.");
- }
- }
- }
|