using System; using System.Globalization; using System.Linq; using DevilLink2.Core; using DevilLink2.Gameplay; using DevilLink2.Presentation; using DevilLink2.UI; using UnityEditor; using UnityEngine; using UnityEngine.UI; namespace DevilLink2.Editor { public static class HUDPlayAcceptance { private const string Prefix="DevilLink2.Task08B.Accept."; public static void Reset() { SessionState.SetInt(Prefix+"Step",0); } private static void Advance(int step) { SessionState.SetInt(Prefix+"Step",step); } public static bool Tick(UIManager ui,BoardDemoBootstrap bootstrap,Action check) { int step=SessionState.GetInt(Prefix+"Step",0); var hud=ui.Hud; if(step==0) { check(ui.CurrentPage==UIPage.Start && bootstrap.Session==null,"Actual Main starts at Start without eager session"); ui.StartScreen.StartButton.onClick.Invoke(); ui.Lobby.Cards[0].Button.onClick.Invoke(); Advance(1); return false; } var flow=bootstrap.Flow; var runtime=flow.Runtime; var view=bootstrap.GetComponentInChildren(true); if(SessionState.GetBool("DevilLink2.UI11B.Capture",false) && (step==2 || step==3 || step==5 || step==60)) { string key="DevilLink2.UI11B.Shot"+step; if(!SessionState.GetBool(key,false)) { float start=SessionState.GetFloat(key+"Wait",0); if(start==0){SessionState.SetFloat(key+"Wait",(float)EditorApplication.timeSinceStartup);return false;} if(EditorApplication.timeSinceStartup-start<.4)return false; var shot=ScreenCapture.CaptureScreenshotAsTexture(); try{System.IO.Directory.CreateDirectory("Temp/DevilLink2Task11B2B");System.IO.File.WriteAllBytes("Temp/DevilLink2Task11B2B/Gameplay_"+step+".png",shot.EncodeToPNG());} finally{UnityEngine.Object.Destroy(shot);}SessionState.SetBool(key,true); } } if(step==1) { check(runtime.Session.Definition.Level==20 && runtime.Session.Mode==GameMode.Classic,"Classic level 20 from loaded progress"); check(hud.ModeLabel.text.Contains("LEVEL 20") && hud.TimerLabel.text==HudFormatting.Time(true,runtime.Timer.RemainingTime),"HUD mode level and timer binding"); hud.ItemButtons[2].onClick.Invoke(); check(runtime.Timer.TimeBarMax>runtime.Timer.InitialTime,"Time item expands real bar maximum"); runtime.Timer.Advance(Math.Max(0,runtime.Timer.RemainingTime-10)); hud.Refresh(); check(hud.IsLowTime,"Low-time warning at ten seconds"); hud.ItemButtons[2].onClick.Invoke(); check(!hud.IsLowTime && runtime.Timer.RemainingTime>15,"Time item clears warning without changing initial time"); check(runtime.Timer.InitialTime==180 && flow.Economy.Inventory.GetCount(ItemType.Time)==1,"Real Time stock decremented exactly twice"); int before=runtime.Session.Board.RemainingTileCount; hud.ItemButtons[0].onClick.Invoke(); check(view.BoardRoot.GetComponentsInChildren().Count(t=>t.IsHinted)==2 && runtime.Session.Board.RemainingTileCount==before,"Hint highlights pair without removal"); SessionState.SetFloat(Prefix+"Wait",(float)EditorApplication.timeSinceStartup); Advance(2); return false; } if(step==2) { if(EditorApplication.timeSinceStartup-SessionState.GetFloat(Prefix+"Wait",0)<1.7)return false; check(!view.BoardRoot.GetComponentsInChildren().Any(t=>t.IsHinted),"Hint expires after approximately 1.6 seconds"); int count=runtime.Session.Board.RemainingTileCount; hud.ItemButtons[1].onClick.Invoke(); check(runtime.Session.Board.RemainingTileCount==count && new BoardMoveFinder().TryFindMove(runtime.Session.Board,out _),"Manual shuffle conserves board and leaves legal pair"); 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(); check(runtime.Score.TotalScore==100 && hud.ScoreLabel.text.Contains("100"),"Real match updates score and combo"); check(hud.ItemButtons.All(b=>!b.interactable),"Animation lock disables all items"); hud.PauseButton.onClick.Invoke(); check(flow.State==GameFlowState.Paused && hud.Pause.IsVisible,"Pause opens modal and stops flow"); SessionState.SetFloat(Prefix+"Remaining",(float)runtime.Timer.RemainingTime); SessionState.SetString(Prefix+"Session",runtime.Session.Id.ToString()); SessionState.SetFloat(Prefix+"Wait",(float)EditorApplication.timeSinceStartup); Advance(3); return false; } if(step==3) { if(EditorApplication.timeSinceStartup-SessionState.GetFloat(Prefix+"Wait",0)<4.2)return false; hud.Refresh(); check(runtime.Timer.RemainingTime==SessionState.GetFloat(Prefix+"Remaining",0),"Paused timer remains fixed"); check(!runtime.Score.IsInCombo,"Combo real-time window expires while paused"); 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"); hud.PauseButton.onClick.Invoke(); hud.Pause.RestartButton.onClick.Invoke(); 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"); Advance(4); return false; } if(step==4) { if(flow.State==GameFlowState.Running) { if(runtime.Interaction.IsLocked)return false; check(new BoardMoveFinder().TryFindMove(runtime.Session.Board,out var pair),"A legal pair exists during full-board playthrough"); flow.Click(pair.First.Row,pair.First.Column); flow.Click(pair.Second.Row,pair.Second.Column); return false; } check(flow.State==GameFlowState.Victory && hud.Result.IsVisible && ReferenceEquals(hud.Result.Data,flow.Result),"Full real board clear shows immutable Victory result"); check(hud.Result.ScoreLabel.text.Contains(flow.Result.FinalScore.ToString("N0",CultureInfo.InvariantCulture)),"Result displays final score snapshot"); check(flow.Economy.Coins==14876 && flow.Economy.SpinTickets==8,"Victory rewards granted once by existing settlement"); check(hud.Result.NextButton.GetComponentInChildren(true).text=="REPLAY LEVEL 20","Level 20 offers replay"); check(flow.Click(0,0)==DevilLink2.Interaction.TileClickResult.Ignored,"Victory blocks board input"); Advance(5); return false; } if(step==5) { var old=runtime.Session.Id; hud.Result.NextButton.onClick.Invoke(); var fresh=flow.Runtime.Session.Id; hud.Result.NextButton.onClick.Invoke(); check(fresh!=old && flow.Runtime.Session.Id==fresh && flow.Runtime.Session.Definition.Level==20,"Replay creates one level 20 session without level 21"); check(flow.Economy.Coins==14876 && flow.Economy.SpinTickets==8 && !hud.Result.IsVisible,"Replay does not award again or retain stale result"); hud.PauseButton.onClick.Invoke(); hud.Pause.LobbyButton.onClick.Invoke(); check(ui.CurrentPage==UIPage.Lobby,"Pause Back to Lobby returns through existing flow"); ui.Lobby.Cards[1].Button.onClick.Invoke(); Advance(6); return false; } if(step==6) { check(runtime.Session.Mode==GameMode.TimeAttack,"Time Attack starts from Lobby"); // Exercise the real expiration callback without waiting the full 120 seconds. runtime.Timer.Advance(runtime.Timer.RemainingTime); hud.Refresh(); check(flow.State==GameFlowState.Defeat && hud.Result.IsVisible && hud.Result.Data.Outcome==GameOutcome.Defeat,"Real timer expiration shows Defeat result"); check(!hud.Result.NextButton.gameObject.activeSelf && !hud.Result.RewardsLabel.gameObject.activeSelf,"Defeat hides Next and clear rewards"); check(flow.Economy.Coins==14876 && flow.Economy.SpinTickets==8,"Defeat adds no economic rewards"); Advance(60);return false; } if(step==60) { 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"); hud.PauseButton.onClick.Invoke(); hud.Pause.LobbyButton.onClick.Invoke(); ui.Lobby.Cards[2].Button.onClick.Invoke(); Advance(7); return false; } if(step==7) { check(runtime.Session.Mode==GameMode.Zen && hud.TimerLabel.text==HudFormatting.Time(false,0),"Zen displays infinity"); check(!hud.ItemButtons[2].interactable && !runtime.Timer.HasTimer,"Zen disables Time item"); check(bootstrap.GetComponentsInChildren(true).Length==1 && ui.Gameplay.GetComponentsInChildren(true).Length==1 && ui.Gameplay.GetComponentsInChildren(true).Length==1,"One Canvas and cached modal instances"); int missing=0; foreach(var t in bootstrap.GetComponentsInChildren(true))missing+=GameObjectUtility.GetMonoBehavioursWithMissingScriptCount(t.gameObject); check(missing==0,"No Missing Script in Main runtime hierarchy"); hud.PauseButton.onClick.Invoke(); hud.Pause.LobbyButton.onClick.Invoke(); check(ui.CurrentPage==UIPage.Lobby,"Final return to Lobby"); return true; } return false; } } }