| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- using System;
- using System.Collections;
- using System.IO;
- using System.Linq;
- using System.Reflection;
- using System.Text;
- using System.Text.RegularExpressions;
- using TMPro;
- using UnityEngine;
- using UnityEngine.EventSystems;
- using UnityEngine.UI;
- namespace Olympus.Editor
- {
- public static class WeeklyAndPoolAudit
- {
- const BindingFlags Flags=BindingFlags.Instance|BindingFlags.NonPublic;
- static T Field<T>(OlympusGame app,string key)=>(T)typeof(OlympusGame).GetField(key,Flags).GetValue(app);
- static void Call(OlympusGame app,string method,params object[] args)=>typeof(OlympusGame).GetMethod(method,Flags).Invoke(app,args);
- static OlympusGame App(){var app=UnityEngine.Object.FindFirstObjectByType<OlympusGame>();if(!Application.isPlaying||!app||!app.IsEditorPreviewSave)throw new Exception("Use isolated Art Review save");return app;}
- static void Require(bool valid,string text){if(!valid)throw new Exception(text);}
- static SuiteView Modal(OlympusGame app)=>Field<RectTransform>(app,"modal").GetComponentInChildren<SuiteView>();
- static void OpenQuestion(OlympusGame app,Question q,bool blueberry=false)
- {
- app.ShowDesignPage("Lobby");var game=Field<MatchEngine>(app,"game");Require(game.Start(q.realm),"Cannot enter "+q.realm);
- typeof(MatchEngine).GetField("rounds",Flags).SetValue(game,new[]{q,q,q,q,q});
- if(blueberry)
- {
- int seed=Enumerable.Range(0,10000).First(s=>{var p=Rules.Pool(q.answer,new System.Random(s));return p.Count(c=>c=='U')==1&&Array.IndexOf(p,'U')>=18;});
- typeof(MatchEngine).GetField("random",Flags).SetValue(game,new System.Random(seed));
- }
- game.Tick(4);game.Tick(2);app.ArtReviewMode=true;Field<TextMeshProUGUI>(app,"toast").gameObject.SetActive(false);
- }
- static string BoardSignature(ReferenceAView v)=>string.Join("|",Enumerable.Range(0,3).Select(i=>v.leaderboardNames[i].text+":"+v.leaderboardScores[i].text));
- static ReferenceAView CompareBoard(OlympusGame app,ReferenceAView lobby)
- {
- lobby.FindButton("Leaderboard").onClick.Invoke();var popup=Modal(app);
- Require(Field<string>(app,"currentPanel")=="Weekly","lobby opens the weekly tab");
- for(int i=0;i<3;i++)
- {
- Require(lobby.leaderboardNames[i].text==popup.Text("Podium name "+i).text,"weekly name mismatch "+i);
- Require(lobby.leaderboardScores[i].text==popup.Text("Podium score "+i).text,"weekly score mismatch "+i);
- Require(lobby.leaderboardAvatars[i].sprite==popup.Image("Podium portrait "+i).sprite,"weekly avatar mismatch "+i);
- }
- popup.Button("Close").onClick.Invoke();
- return Field<ReferenceAView>(app,"referenceView");
- }
- public static string RunUi()
- {
- var app=App();var store=Field<PlayerStore>(app,"store");store.Reset();app.ShowDesignPage("Lobby");
- var lobby=CompareBoard(app,Field<ReferenceAView>(app,"referenceView"));string initial=BoardSignature(lobby);
- Call(app,"RefreshLobbyLeaderboard",true);Require(BoardSignature(lobby)==initial,"weekly data rerolled within the same week");
- store.Data.name="Weekly champion";store.Data.avatar=3;store.Data.weeklyScore=15000;Call(app,"RefreshLobbyLeaderboard",true);lobby=CompareBoard(app,lobby);
- Require(lobby.leaderboardNames[0].text==store.Data.name&&lobby.leaderboardAvatars[0].sprite.texture.name=="avatar_3","own updated weekly score and portrait did not reach lobby");
- store.Data.weeklyKey="2000-01-01";store.Data.weeklyScore=20000;Call(app,"RefreshLobbyLeaderboard",true);lobby=CompareBoard(app,lobby);
- Require(store.Data.weeklyScore==0&&BoardSignature(lobby)==initial,"week rollover did not refresh lobby and popup together");
- var cfg=Field<GameConfig>(app,"config");OpenQuestion(app,cfg.questions[0]);var game=Field<MatchEngine>(app,"game");
- game.Submit(game.Current.answer);game.Tick(1.6);var round=Field<SuiteView>(app,"suiteView");
- Require(round.GetComponentsInChildren<Button>().Length==2&&round.Button("Continue").gameObject.activeInHierarchy&&round.Button("Quit").gameObject.activeInHierarchy,"intermission must have Continue and QUIT");
- game.Tick(3600);Require(game.Phase==MatchPhase.Intermission&&game.Round==0,"standings advanced without Continue");
- round.Button("Continue").onClick.Invoke();round.Button("Continue").onClick.Invoke();Require(game.Round==1&&game.Phase==MatchPhase.Intro,"Continue did not advance exactly one round");app.ArtReviewMode=true;
- game.Tick(1.3);
- for(int n=1;n<5;n++){game.Submit(game.Current.answer);game.Tick(1.6);if(n<4){game.Continue();game.Tick(1.3);}}
- var result=Field<SuiteView>(app,"suiteView");Require(game.Phase==MatchPhase.Result&&result.GetComponentsInChildren<Button>().Length==2&&!result.Button("Continue").gameObject.activeSelf,"final result does not have exactly two actions");
- Require(result.Button("Quit").gameObject.activeInHierarchy&&result.Text("Quit label").text=="QUIT","final result is missing QUIT");
- app.ShowDesignPage("Result");Field<SuiteView>(app,"suiteView").Button("Play again").onClick.Invoke();Require(game.Phase==MatchPhase.Lobby,"PLAY AGAIN does not return to realm choice");app.ArtReviewMode=true;
- string report="PASS intermission has Continue and QUIT, waits indefinitely for Continue\nPASS Continue advances exactly once; final has PLAY AGAIN and QUIT\nPASS lobby and weekly popup match names, scores and avatars\nPASS player score/profile changes and week rollover refresh both views consistently\n";
- Directory.CreateDirectory("docs/验证");File.WriteAllText("docs/验证/轮间与周榜验收.txt",report);return report;
- }
- static void CheckHit(Button b,bool click=false)
- {
- var r=(RectTransform)b.transform;var point=RectTransformUtility.WorldToScreenPoint(null,r.TransformPoint(r.rect.center));
- Require(point.x>=0&&point.x<=Screen.width&&point.y>=0&&point.y<=Screen.height,"tile outside viewport: "+b.name);
- var data=new PointerEventData(EventSystem.current){position=point,button=PointerEventData.InputButton.Left};var hits=new System.Collections.Generic.List<RaycastResult>();EventSystem.current.RaycastAll(data,hits);
- Require(hits.Count>0&&hits[0].gameObject.GetComponentInParent<Button>()==b,"covered tile: "+b.name);
- if(click){Require(b.interactable,"disabled tile: "+b.name);ExecuteEvents.Execute(b.gameObject,data,ExecuteEvents.pointerClickHandler);}
- }
- static string InspectQuestion(OlympusGame app,Question q)
- {
- var v=Field<ReferenceAView>(app,"referenceView");var game=Field<MatchEngine>(app,"game");
- Require(v.question.sprite&&v.question.sprite.texture.name==q.id,"wrong picture bound: "+q.id);
- Require(v.letterButtons.Count(b=>b.gameObject.activeSelf)==game.Pool.Length,"candidate count differs from pool: "+q.id);
- var displayed=new StringBuilder();
- for(int i=0;i<game.Pool.Length;i++)
- {
- var b=v.letterButtons[i];var label=b.GetComponentInChildren<TextMeshProUGUI>();label.ForceMeshUpdate();
- var tileRect=((RectTransform)b.transform).rect;Require(Mathf.Abs(tileRect.width-tileRect.height)<.1f&&tileRect.width>=44,"distorted or undersized tile: "+q.id+" #"+i);
- Require(label.text==game.Pool[i].ToString()&&label.textInfo.characterCount==1&&label.textInfo.characterInfo[0].isVisible&&label.textInfo.characterInfo[0].character==game.Pool[i],"missing/wrong rendered glyph: "+q.id+" #"+i);
- CheckHit(b);displayed.Append(label.text);
- }
- Require(q.Normalized.GroupBy(c=>c).All(g=>displayed.ToString().Count(c=>c==g.Key)>=g.Count()),"displayed pool cannot spell "+q.answer);
- if(q.id=="food_05")
- {
- int u=Array.IndexOf(game.Pool,'U');Require(u>=18&&game.Pool.Count(c=>c=='U')==1,"BLUEBERRY fixture must have sole U in last row");
- CheckHit(v.letterButtons[u],true);Require(v.answerText.text=="U"&&!v.letterButtons[u].interactable,"U not selectable");CheckHit(v.FindButton("Delete"),true);
- Require(v.letterButtons[u].interactable&&Field<TileAnswerSelection>(app,"selectedAnswer").Count==0,"X did not return U");
- }
- return displayed.ToString();
- }
- static void SelectThroughPointers(OlympusGame app,Question q)
- {
- var v=Field<ReferenceAView>(app,"referenceView");var game=Field<MatchEngine>(app,"game");
- foreach(char letter in q.Normalized)
- {
- int i=Enumerable.Range(0,game.Pool.Length).First(n=>game.Pool[n]==letter&&v.letterButtons[n].interactable);CheckHit(v.letterButtons[i],true);
- }
- Require(v.answerText.text==q.Normalized,"pointer clicks assembled wrong answer: "+q.id);
- }
- public static string QuestionStatus {get;private set;}="Not started";
- public static string StartQuestions()
- {
- Require(!QuestionStatus.StartsWith("Running"),"Question audit already running");var app=App();var store=Field<PlayerStore>(app,"store");store.Reset();store.Data.coins=100000;app.ArtReviewMode=true;
- app.StartCoroutine(QuestionSequence(app));return QuestionStatus;
- }
- static IEnumerator QuestionSequence(OlympusGame app)
- {
- var cfg=Field<GameConfig>(app,"config");string error=null;var report=new StringBuilder("id,answer,length,pool_count,rendered_pool,result\n");
- var prototype=Regex.Matches(File.ReadAllText("docs/Guess_of_Olympus_UI演示.html"),@"\{a:'([^']+)',\s*k:'([^']+)',\s*d:(\d+)").Cast<Match>().ToDictionary(m=>m.Groups[2].Value,m=>m);
- string[] countryKeys={"country_t01","country_t02","country_t03","country_t04","country_t05","country_d09","country_d10","country_d08","country_d06","country_d07"};
- Directory.CreateDirectory("docs/运行截图/WeeklyAndPool");
- for(int n=0;n<cfg.questions.Length;n++)
- {
- var q=cfg.questions[n];QuestionStatus="Running "+(n+1)+" / 40: "+q.id;
- try
- {
- string key=q.realm=="country"?countryKeys[int.Parse(q.id.Substring(8))-1]:q.id;
- Require(prototype.ContainsKey(key)&&prototype[key].Groups[1].Value==q.answer&&int.Parse(prototype[key].Groups[3].Value)==q.difficulty,"prototype answer/difficulty mismatch: "+q.id);
- OpenQuestion(app,q,q.id=="food_05");
- }catch(Exception e){error=e.Message;}
- if(error!=null)break;yield return null;yield return null;
- string pool="";try{pool=InspectQuestion(app,q);}catch(Exception e){error=e.Message;}
- if(error!=null)break;
- if(q.id=="food_05"){ScreenCapture.CaptureScreenshot("docs/运行截图/WeeklyAndPool/Blueberry_U.png");yield return null;}
- try{SelectThroughPointers(app,q);}catch(Exception e){error=e.Message;}
- if(error!=null)break;
- if(q.id=="food_05"){ScreenCapture.CaptureScreenshot("docs/运行截图/WeeklyAndPool/Blueberry_Selected.png");yield return null;}
- try
- {
- CheckHit(Field<ReferenceAView>(app,"referenceView").FindButton("OK"),true);
- var game=Field<MatchEngine>(app,"game");Require(game.Phase==MatchPhase.Answer&&game.LastGain>0,"answer rejected: "+q.id);
- report.AppendLine(q.id+","+q.answer+","+q.Normalized.Length+","+pool.Length+","+pool+",PASS");
- }catch(Exception e){error=e.Message;}
- if(error!=null)break;
- }
- QuestionStatus=error==null?"PASS all 40 questions: prototype mapping, actual rendered glyphs, required repeated letters, pointer hits, submission; BLUEBERRY sole U in row 3 selectable and restored by X":"FAIL "+error;
- Directory.CreateDirectory("docs/验证");File.WriteAllText("docs/验证/全题库屏幕点选验收.csv",report.ToString());File.WriteAllText("docs/验证/全题库屏幕点选结果.txt",QuestionStatus);
- app.ShowDesignPage("Lobby");
- }
- public static string IntermissionPreview()
- {
- var app=App();OpenQuestion(app,Field<GameConfig>(app,"config").questions[0]);var game=Field<MatchEngine>(app,"game");game.Submit(game.Current.answer);game.Tick(1.6);game.Paused=true;Field<TextMeshProUGUI>(app,"toast").gameObject.SetActive(false);return "Intermission frozen for screenshot";
- }
- }
- }
|