| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- using System;using System.IO;using System.Linq;using System.Reflection;using System.Collections.Generic;using DevilLink2.UI;using DevilLink2.Gameplay;using DevilLink2.Core;using DevilLink2.Persistence;using DevilLink2.Presentation;using UnityEditor;using UnityEngine;using UnityEngine.UI;
- namespace DevilLink2.Editor {
- internal static class Task12Acceptance {
- const BindingFlags F=BindingFlags.Instance|BindingFlags.Static|BindingFlags.Public|BindingFlags.NonPublic;
- static int cell,phase;static double wait,soak;static long firstMemory;static int firstObjects;static EditorWindow game,sim;static object group;static int originalIndex,customIndex=-1;static bool prepared;
- static readonly int[] W={360,360,390,412,430,480},H={640,800,844,915,932,1040};
- static readonly string[] Pages={"Start","Lobby","Gameplay","Pause","Victory","Defeat","Shop","Daily","Wheel","Profile","Settings","Help"};
- static readonly List<string> rows=new List<string>();
- static SavedPlayer Player(UIManager ui)=>(SavedPlayer)typeof(UIManager).GetField("player",F).GetValue(ui);
- static Type GV=>typeof(UnityEditor.Editor).Assembly.GetType("UnityEditor.GameView");
- static object Get(object o,string name)=>o.GetType().GetProperty(name,F).GetValue(o,null);
- static void Set(object o,string name,object value)=>o.GetType().GetProperty(name,F).SetValue(o,value,null);
- static void Call(object o,string name,params object[] args)=>o.GetType().GetMethod(name,F).Invoke(o,args);
- public static void Reset(){cell=phase=0;wait=soak=0;prepared=false;rows.Clear();customIndex=-1;}
- static void Resize(int index){
- var st=Type.GetType("UnityEditor.DeviceSimulation.SimulatorWindow, UnityEditor.DeviceSimulatorModule");
- if(index<6){foreach(var v in Resources.FindObjectsOfTypeAll(st).Cast<EditorWindow>())v.Close();
- if(!game){game=EditorWindow.GetWindow(GV);originalIndex=(int)Get(game,"selectedSizeIndex");var t=typeof(UnityEditor.Editor).Assembly.GetType("UnityEditor.GameViewSizes");var sizes=t.BaseType.GetProperty("instance",F).GetValue(null,null);group=Get(sizes,"currentGroup");}
- var sizeType=typeof(UnityEditor.Editor).Assembly.GetType("UnityEditor.GameViewSize");var kind=Enum.Parse(typeof(UnityEditor.Editor).Assembly.GetType("UnityEditor.GameViewSizeType"),"FixedResolution");
- if(customIndex<0){customIndex=(int)group.GetType().GetMethod("GetTotalCount").Invoke(group,null);var size=Activator.CreateInstance(sizeType,F,null,new object[]{kind,W[index],H[index],"DL2Task12"},null);Call(group,"AddCustomSize",size);}
- var item=group.GetType().GetMethod("GetGameViewSize").Invoke(group,new object[]{customIndex});Set(item,"width",W[index]);Set(item,"height",H[index]);Set(game,"selectedSizeIndex",customIndex);game.Focus();game.Repaint();
- }else{
- sim=EditorWindow.GetWindow(st);var main=Get(sim,"main");var devices=(Array)Get(main,"devices");int chosen=-1;
- for(int i=0;i<devices.Length;i++){var raw=JsonUtility.ToJson(devices.GetValue(i));if(raw.Contains(index==6?"iOS Notch Device (1170x2532)":"Punch Hole Center (1440x3088)")){chosen=i;break;}}
- if(chosen<0)throw new Exception("Requested Simulator profile unavailable");Set(main,"deviceIndex",chosen);sim.Focus();sim.Repaint();
- }
- }
- public static void Restore(){if(sim)sim.Close();if(game){Set(game,"selectedSizeIndex",originalIndex);if(group!=null&&customIndex>=0)Call(group,"RemoveCustomSize",customIndex);game.Repaint();}customIndex=-1;}
- static void Clear(UIManager ui){var flow=UnityEngine.Object.FindFirstObjectByType<BoardDemoBootstrap>().Flow;int max=flow.Runtime.Session.Board.RemainingTileCount/2;for(int i=0;i<max;i++){if(!new BoardMoveFinder().TryFindMove(flow.Runtime.Session.Board,out var pair))throw new Exception("No pair after automatic recovery");flow.Click(pair.First.Row,pair.First.Column);flow.Click(pair.Second.Row,pair.Second.Column);flow.Runtime.Interaction.Advance(.24);}if(flow.State!=GameFlowState.Victory)throw new Exception("Clear did not settle Victory");}
- static void Show(UIManager ui,BoardDemoBootstrap b,int page){
- if(page==0){ui.ShowLobby();ui.Lobby.SetVisible(false);ui.StartScreen.SetVisible(true);}
- if(page==1)ui.ShowLobby();
- if(page==2){ui.SelectMode(GameMode.Classic);}
- if(page==3)ui.Hud.PauseButton.onClick.Invoke();
- if(page==4){ui.Hud.Pause.ResumeButton.onClick.Invoke();Clear(ui);}
- if(page==5){ui.Hud.Result.RetryButton.onClick.Invoke();b.Flow.Runtime.Timer.Advance(10000);}
- if(page==6){ui.Hud.Result.LobbyButton.onClick.Invoke();ui.OpenShop();}
- if(page==7){ui.CloseShop();ui.OpenDaily();}
- if(page==8){ui.CloseDaily();ui.OpenWheel();}
- if(page==9){ui.CloseWheel();ui.OpenProfile();}
- if(page==10){ui.CloseProfile();ui.OpenSettings();}
- if(page==11){ui.CloseSettings();ui.OpenHelp();}
- }
- static void CheckLayout(UIManager ui,BoardDemoBootstrap b,int size,int page,Action<bool,string> check){
- if(size<6)check(Screen.width==W[size]&&Screen.height==H[size],"Actual resolution "+W[size]+"x"+H[size]);
- var adapter=b.GetComponentInChildren<SafeAreaAdapter>();var r=(RectTransform)adapter.transform;
- check(Vector2.Distance(r.anchorMin,new Vector2(Screen.safeArea.xMin/Screen.width,Screen.safeArea.yMin/Screen.height))<.001f,"Actual SafeArea minimum anchors");
- check(Vector2.Distance(r.anchorMax,new Vector2(Screen.safeArea.xMax/Screen.width,Screen.safeArea.yMax/Screen.height))<.001f,"Actual SafeArea maximum anchors");
- if(page>=2&&page<=5){var v=b.GetComponentInChildren<BoardView>(true);var rect=(RectTransform)v.transform;check(Vector2.Distance(rect.rect.size,GameplayStageView.BoardArea)<.01f&&rect.anchoredPosition==new Vector2(6,-226),"Responsive Gameplay board region");}
- int buttons=0;foreach(var bt in ui.transform.parent.GetComponentsInChildren<Button>(false)){
- if(bt.GetComponentInParent<ScrollRect>())continue;
- var cg=bt.GetComponentsInParent<CanvasGroup>();if(cg.Any(g=>g.alpha<.95f))continue;
- var corners=new Vector3[4];((RectTransform)bt.transform).GetWorldCorners(corners);foreach(var c in corners){var p=RectTransformUtility.WorldToScreenPoint(null,c);if(p.x<Screen.safeArea.xMin-2||p.x>Screen.safeArea.xMax+2||p.y<Screen.safeArea.yMin-2||p.y>Screen.safeArea.yMax+2)throw new Exception("Button beyond SafeArea: "+bt.name+" "+p);}buttons++;
- }
- var shot=ScreenCapture.CaptureScreenshotAsTexture();try{Directory.CreateDirectory("Temp/DevilLink2Task12/Shots");File.WriteAllBytes("Temp/DevilLink2Task12/Shots/"+size+"_"+Pages[page]+".png",shot.EncodeToPNG());}finally{UnityEngine.Object.Destroy(shot);}
- rows.Add(JsonUtility.ToJson(new Row{size=size,page=Pages[page],width=Screen.width,height=Screen.height,safe=Screen.safeArea.ToString(),buttons=buttons}));File.WriteAllLines("Temp/DevilLink2Task12/Layout.jsonl",rows);
- foreach(var scroll in ui.GetComponentsInChildren<ScrollRect>(false)){scroll.verticalNormalizedPosition=0;Canvas.ForceUpdateCanvases();scroll.verticalNormalizedPosition=1;}
- }
- [Serializable]class Row{public int size,width,height,buttons;public string page,safe;}
- public static bool Tick(UIManager ui,BoardDemoBootstrap b,Action<bool,string> check){
- if(SessionState.GetBool("DL2Task12.Reopen",false)){
- var p=Player(ui);check(p.Profile.Nickname=="Task12Hero"&&p.Profile.Avatar=="moon","Actual scene restart restores profile");
- check(p.Economy.Coins.ToString()==SessionState.GetString("DL2Task12.Coins",""),"Actual restart restores economy");check(p.Economy.SpinTickets.ToString()==SessionState.GetString("DL2Task12.Tickets",""),"Actual restart restores tickets");
- foreach(GameMode m in Enum.GetValues(typeof(GameMode)))check(p.Progress.GetHighestCleared(m)==20,"Restart progress "+m);
- var audio=DevilLink2.Presentation.AudioManager.Instance;check(audio.MusicEnabled&&audio.SfxEnabled&&Mathf.Approximately(audio.MusicVolume,.3f)&&Mathf.Approximately(audio.SfxVolume,.5f),"Audio settings reset by existing runtime-only lifecycle (not persisted)");
- check(p.Economy.Inventory.GetCount(ItemType.Hint)==SessionState.GetInt("DL2Task12.Hint",-1)&&p.Economy.Inventory.GetCount(ItemType.Shuffle)==SessionState.GetInt("DL2Task12.Shuffle",-1)&&p.Economy.Inventory.GetCount(ItemType.Time)==SessionState.GetInt("DL2Task12.Time",-1),"Actual restart inventory preserved");
- check(b.GetComponentsInChildren<AudioSource>(true).Length==8,"Scene restart recreates one bounded audio pool");
- check(b.Session==null,"No unfinished board restored");return true;
- }
- if(cell<96){int size=cell/12,page=cell%12;
- if(!prepared){if(page==0){ui.ShowLobby();Resize(size);}Show(ui,b,page);wait=EditorApplication.timeSinceStartup+.5;prepared=true;return false;}
- if(EditorApplication.timeSinceStartup<wait)return false;CheckLayout(ui,b,size,page,check);if(page==11)ui.CloseHelp();cell++;prepared=false;return false;
- }
- if(phase==0){
- Restore();ui.ShowLobby();
- foreach(GameMode m in Enum.GetValues(typeof(GameMode))){ui.SelectMode(m);check(b.Session.Definition.Level==20,"Mode20 "+m);if(m==GameMode.TimeAttack)check(b.Session.Board.RemainingTileCount==48&&b.Flow.Runtime.Timer.InitialTime==44,"TimeAttack20 parameters");if(m==GameMode.Zen)check(!b.Flow.Runtime.Timer.HasTimer,"Zen no timer");Clear(ui);long coins=Player(ui).Economy.Coins;long reward=b.Flow.Result.CoinReward;ui.Hud.Result.NextButton.onClick.Invoke();Clear(ui);check(Player(ui).Economy.Coins==coins+reward,"Repeated20 full reward "+m);ui.Hud.Result.LobbyButton.onClick.Invoke();}
- var p=Player(ui);p.UpdateProfile("Task12Hero","moon");p.Shop.TryBuy(ItemType.Hint,Guid.NewGuid());p.CheckIn.TryClaimDailyReward(Guid.NewGuid());p.Wheel.TrySpin(Guid.NewGuid());var before=p.CaptureSnapshot();
- using(var again=new SavedPlayer(new LocalSaveService(new FileSaveStorage(SessionState.GetString("DevilLink2.Task08A.Play.Directory",""))))){var after=again.CaptureSnapshot();check(before.Coins==after.Coins&&before.SpinTickets==after.SpinTickets&&before.HintCount==after.HintCount&&before.ShuffleCount==after.ShuffleCount&&before.TimeCount==after.TimeCount,"Economy inventory disk roundtrip");check(before.LastCheckInDateUtc==after.LastCheckInDateUtc&&before.LastFreeSpinDateUtc==after.LastFreeSpinDateUtc&&before.RewardOperations.Count==after.RewardOperations.Count,"Daily wheel disk roundtrip");}
- SessionState.SetString("DL2Task12.Coins",p.Economy.Coins.ToString());SessionState.SetString("DL2Task12.Tickets",p.Economy.SpinTickets.ToString());
- ui.OpenSettings();ui.Settings.SetMusicVolume(.13f);ui.Settings.SetSfxVolume(.27f);ui.Settings.ToggleMusic();ui.Settings.ToggleSfx();ui.CloseSettings();
- soak=EditorApplication.timeSinceStartup;firstMemory=GC.GetTotalMemory(true);firstObjects=UnityEngine.Object.FindObjectsByType<Transform>(FindObjectsInactive.Include,FindObjectsSortMode.None).Length;phase=1;
- }
- if(phase==1){
- ui.OpenSettings();ui.CloseSettings();ui.OpenHelp();ui.CloseHelp();
- if(EditorApplication.timeSinceStartup-soak<180)return false;
- int now=UnityEngine.Object.FindObjectsByType<Transform>(FindObjectsInactive.Include,FindObjectsSortMode.None).Length;long memory=GC.GetTotalMemory(true);
- File.WriteAllText("Temp/DevilLink2Task12/Soak.json", "{\"seconds\":180,\"objectsBefore\":"+firstObjects+",\"objectsAfter\":"+now+",\"managedBefore\":"+firstMemory+",\"managedAfter\":"+memory+"}");check(now<=firstObjects+4,"Three minute modal churn has bounded objects");return true;
- }
- return false;
- }
- }
- }
|