HUDPlayAcceptance.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. using System;
  2. using System.Globalization;
  3. using System.Linq;
  4. using DevilLink2.Core;
  5. using DevilLink2.Gameplay;
  6. using DevilLink2.Presentation;
  7. using DevilLink2.UI;
  8. using UnityEditor;
  9. using UnityEngine;
  10. using UnityEngine.UI;
  11. namespace DevilLink2.Editor
  12. {
  13. public static class HUDPlayAcceptance
  14. {
  15. private const string Prefix="DevilLink2.Task08B.Accept.";
  16. public static void Reset() { SessionState.SetInt(Prefix+"Step",0); }
  17. private static void Advance(int step) { SessionState.SetInt(Prefix+"Step",step); }
  18. public static bool Tick(UIManager ui,BoardDemoBootstrap bootstrap,Action<bool,string> check)
  19. {
  20. int step=SessionState.GetInt(Prefix+"Step",0); var hud=ui.Hud;
  21. if(step==0)
  22. {
  23. check(ui.CurrentPage==UIPage.Start && bootstrap.Session==null,"Actual Main starts at Start without eager session");
  24. ui.StartScreen.StartButton.onClick.Invoke(); ui.Lobby.Cards[0].Button.onClick.Invoke(); Advance(1); return false;
  25. }
  26. var flow=bootstrap.Flow; var runtime=flow.Runtime; var view=bootstrap.GetComponentInChildren<BoardView>(true);
  27. if(SessionState.GetBool("DevilLink2.UI11B.Capture",false) && (step==2 || step==3 || step==5 || step==60)) {
  28. string key="DevilLink2.UI11B.Shot"+step;
  29. if(!SessionState.GetBool(key,false)) {
  30. float start=SessionState.GetFloat(key+"Wait",0);
  31. if(start==0){SessionState.SetFloat(key+"Wait",(float)EditorApplication.timeSinceStartup);return false;}
  32. if(EditorApplication.timeSinceStartup-start<.4)return false;
  33. var shot=ScreenCapture.CaptureScreenshotAsTexture();
  34. try{System.IO.Directory.CreateDirectory("Temp/DevilLink2Task11B2B");System.IO.File.WriteAllBytes("Temp/DevilLink2Task11B2B/Gameplay_"+step+".png",shot.EncodeToPNG());}
  35. finally{UnityEngine.Object.Destroy(shot);}SessionState.SetBool(key,true);
  36. }
  37. }
  38. if(step==1)
  39. {
  40. check(runtime.Session.Definition.Level==20 && runtime.Session.Mode==GameMode.Classic,"Classic level 20 from loaded progress");
  41. check(hud.ModeLabel.text.Contains("LEVEL 20") && hud.TimerLabel.text==HudFormatting.Time(true,runtime.Timer.RemainingTime),"HUD mode level and timer binding");
  42. hud.ItemButtons[2].onClick.Invoke(); check(runtime.Timer.TimeBarMax>runtime.Timer.InitialTime,"Time item expands real bar maximum");
  43. runtime.Timer.Advance(Math.Max(0,runtime.Timer.RemainingTime-10)); hud.Refresh(); check(hud.IsLowTime,"Low-time warning at ten seconds");
  44. hud.ItemButtons[2].onClick.Invoke(); check(!hud.IsLowTime && runtime.Timer.RemainingTime>15,"Time item clears warning without changing initial time");
  45. check(runtime.Timer.InitialTime==180 && flow.Economy.Inventory.GetCount(ItemType.Time)==1,"Real Time stock decremented exactly twice");
  46. int before=runtime.Session.Board.RemainingTileCount; hud.ItemButtons[0].onClick.Invoke();
  47. check(view.BoardRoot.GetComponentsInChildren<TileView>().Count(t=>t.IsHinted)==2 && runtime.Session.Board.RemainingTileCount==before,"Hint highlights pair without removal");
  48. SessionState.SetFloat(Prefix+"Wait",(float)EditorApplication.timeSinceStartup); Advance(2); return false;
  49. }
  50. if(step==2)
  51. {
  52. if(EditorApplication.timeSinceStartup-SessionState.GetFloat(Prefix+"Wait",0)<1.7)return false;
  53. check(!view.BoardRoot.GetComponentsInChildren<TileView>().Any(t=>t.IsHinted),"Hint expires after approximately 1.6 seconds");
  54. int count=runtime.Session.Board.RemainingTileCount; hud.ItemButtons[1].onClick.Invoke();
  55. check(runtime.Session.Board.RemainingTileCount==count && new BoardMoveFinder().TryFindMove(runtime.Session.Board,out _),"Manual shuffle conserves board and leaves legal pair");
  56. new BoardMoveFinder().TryFindMove(runtime.Session.Board,out var pair); flow.Click(pair.First.Row,pair.First.Column); flow.Click(pair.Second.Row,pair.Second.Column); hud.Refresh();
  57. check(runtime.Score.TotalScore==100 && hud.ScoreLabel.text.Contains("100"),"Real match updates score and combo");
  58. check(hud.ItemButtons.All(b=>!b.interactable),"Animation lock disables all items");
  59. hud.PauseButton.onClick.Invoke(); check(flow.State==GameFlowState.Paused && hud.Pause.IsVisible,"Pause opens modal and stops flow");
  60. SessionState.SetFloat(Prefix+"Remaining",(float)runtime.Timer.RemainingTime); SessionState.SetString(Prefix+"Session",runtime.Session.Id.ToString());
  61. SessionState.SetFloat(Prefix+"Wait",(float)EditorApplication.timeSinceStartup); Advance(3); return false;
  62. }
  63. if(step==3)
  64. {
  65. if(EditorApplication.timeSinceStartup-SessionState.GetFloat(Prefix+"Wait",0)<4.2)return false;
  66. hud.Refresh(); check(runtime.Timer.RemainingTime==SessionState.GetFloat(Prefix+"Remaining",0),"Paused timer remains fixed");
  67. check(!runtime.Score.IsInCombo,"Combo real-time window expires while paused");
  68. hud.Pause.ResumeButton.onClick.Invoke(); check(flow.State==GameFlowState.Running && runtime.Session.Id.ToString()==SessionState.GetString(Prefix+"Session","") && runtime.Score.TotalScore==100,"Resume retains session board and score");
  69. hud.PauseButton.onClick.Invoke(); hud.Pause.RestartButton.onClick.Invoke();
  70. check(flow.Runtime.Session.Id.ToString()!=SessionState.GetString(Prefix+"Session","") && flow.Runtime.Score.TotalScore==0 && hud.BoundSessionId==flow.Runtime.Session.Id,"Restart creates clean session and rebinds HUD");
  71. Advance(4); return false;
  72. }
  73. if(step==4)
  74. {
  75. if(flow.State==GameFlowState.Running)
  76. {
  77. if(runtime.Interaction.IsLocked)return false;
  78. check(new BoardMoveFinder().TryFindMove(runtime.Session.Board,out var pair),"A legal pair exists during full-board playthrough");
  79. flow.Click(pair.First.Row,pair.First.Column); flow.Click(pair.Second.Row,pair.Second.Column); return false;
  80. }
  81. check(flow.State==GameFlowState.Victory && hud.Result.IsVisible && ReferenceEquals(hud.Result.Data,flow.Result),"Full real board clear shows immutable Victory result");
  82. check(hud.Result.ScoreLabel.text.Contains(flow.Result.FinalScore.ToString("N0",CultureInfo.InvariantCulture)),"Result displays final score snapshot");
  83. check(flow.Economy.Coins==14876 && flow.Economy.SpinTickets==8,"Victory rewards granted once by existing settlement");
  84. check(hud.Result.NextButton.GetComponentInChildren<Text>(true).text=="REPLAY LEVEL 20","Level 20 offers replay");
  85. check(flow.Click(0,0)==DevilLink2.Interaction.TileClickResult.Ignored,"Victory blocks board input");
  86. Advance(5); return false;
  87. }
  88. if(step==5)
  89. {
  90. var old=runtime.Session.Id; hud.Result.NextButton.onClick.Invoke(); var fresh=flow.Runtime.Session.Id; hud.Result.NextButton.onClick.Invoke();
  91. check(fresh!=old && flow.Runtime.Session.Id==fresh && flow.Runtime.Session.Definition.Level==20,"Replay creates one level 20 session without level 21");
  92. check(flow.Economy.Coins==14876 && flow.Economy.SpinTickets==8 && !hud.Result.IsVisible,"Replay does not award again or retain stale result");
  93. hud.PauseButton.onClick.Invoke(); hud.Pause.LobbyButton.onClick.Invoke(); check(ui.CurrentPage==UIPage.Lobby,"Pause Back to Lobby returns through existing flow");
  94. ui.Lobby.Cards[1].Button.onClick.Invoke(); Advance(6); return false;
  95. }
  96. if(step==6)
  97. {
  98. check(runtime.Session.Mode==GameMode.TimeAttack,"Time Attack starts from Lobby");
  99. // Exercise the real expiration callback without waiting the full 120 seconds.
  100. runtime.Timer.Advance(runtime.Timer.RemainingTime); hud.Refresh();
  101. check(flow.State==GameFlowState.Defeat && hud.Result.IsVisible && hud.Result.Data.Outcome==GameOutcome.Defeat,"Real timer expiration shows Defeat result");
  102. check(!hud.Result.NextButton.gameObject.activeSelf && !hud.Result.RewardsLabel.gameObject.activeSelf,"Defeat hides Next and clear rewards");
  103. check(flow.Economy.Coins==14876 && flow.Economy.SpinTickets==8,"Defeat adds no economic rewards");
  104. Advance(60);return false;
  105. }
  106. if(step==60) {
  107. hud.Result.RetryButton.onClick.Invoke(); check(flow.State==GameFlowState.Running && flow.Runtime.Session.Definition.Level==1 && flow.Runtime.Score.TotalScore==0,"Defeat Retry recreates same level");
  108. hud.PauseButton.onClick.Invoke(); hud.Pause.LobbyButton.onClick.Invoke(); ui.Lobby.Cards[2].Button.onClick.Invoke(); Advance(7); return false;
  109. }
  110. if(step==7)
  111. {
  112. check(runtime.Session.Mode==GameMode.Zen && hud.TimerLabel.text==HudFormatting.Time(false,0),"Zen displays infinity");
  113. check(!hud.ItemButtons[2].interactable && !runtime.Timer.HasTimer,"Zen disables Time item");
  114. check(bootstrap.GetComponentsInChildren<Canvas>(true).Length==1 && ui.Gameplay.GetComponentsInChildren<PauseScreen>(true).Length==1 && ui.Gameplay.GetComponentsInChildren<ResultScreen>(true).Length==1,"One Canvas and cached modal instances");
  115. int missing=0; foreach(var t in bootstrap.GetComponentsInChildren<Transform>(true))missing+=GameObjectUtility.GetMonoBehavioursWithMissingScriptCount(t.gameObject);
  116. check(missing==0,"No Missing Script in Main runtime hierarchy");
  117. hud.PauseButton.onClick.Invoke(); hud.Pause.LobbyButton.onClick.Invoke(); check(ui.CurrentPage==UIPage.Lobby,"Final return to Lobby"); return true;
  118. }
  119. return false;
  120. }
  121. }
  122. }