| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- using System;
- using System.IO;
- using System.Linq;
- using System.Reflection;
- using System.Text;
- using TMPro;
- using UnityEngine;
- using UnityEngine.EventSystems;
- using UnityEngine.UI;
- namespace Olympus.Editor
- {
- public static class TileAnswerAudit
- {
- 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 Refresh(OlympusGame app)=>typeof(OlympusGame).GetMethod("RefreshTrial",Flags).Invoke(app,null);
- static TileAnswerSelection Selection(OlympusGame app)=>Field<TileAnswerSelection>(app,"selectedAnswer");
- public static void SelectAnswer(OlympusGame app,string value)
- {
- var v=Field<ReferenceAView>(app,"referenceView");
- while(Selection(app).Count>0)
- {
- if(!v.FindButton("Delete").interactable)throw new Exception("Delete disabled during answer selection");
- v.FindButton("Delete").onClick.Invoke();
- }
- var game=Field<MatchEngine>(app,"game");
- foreach(char letter in Rules.Normalize(value))
- {
- int index=Enumerable.Range(0,game.Pool.Length).First(i=>game.Pool[i]==letter&&v.letterButtons[i].interactable);
- v.letterButtons[index].onClick.Invoke();
- }
- if(Selection(app).Value!=Rules.Normalize(value))throw new Exception("Tile clicks produced the wrong answer");
- }
- static void CheckHit(Button button)
- {
- var data=new PointerEventData(EventSystem.current){position=RectTransformUtility.WorldToScreenPoint(null,((RectTransform)button.transform).TransformPoint(((RectTransform)button.transform).rect.center))};
- var hits=new System.Collections.Generic.List<RaycastResult>();EventSystem.current.RaycastAll(data,hits);
- if(hits.Count==0||hits[0].gameObject.GetComponentInParent<Button>()!=button)throw new Exception("Button covered: "+button.name);
- }
- // Run after the newly opened page has rendered and registered its graphics.
- public static string PointerTargets()
- {
- var v=UnityEngine.Object.FindFirstObjectByType<ReferenceAView>();
- if(!v||!v.trial)throw new Exception("Open the trial page and let it render first.");
- foreach(var b in v.letterButtons.Where(b=>b.gameObject.activeSelf))CheckHit(b);
- CheckHit(v.FindButton("Delete"));CheckHit(v.FindButton("OK"));
- string report="PASS all "+v.letterButtons.Count(b=>b.gameObject.activeSelf)+" candidates, X and OK receive pointer hits\n";
- File.AppendAllText("docs/验证/候选字母交互验收.txt",report);return report;
- }
- public static string Run()
- {
- var app=UnityEngine.Object.FindFirstObjectByType<OlympusGame>();
- if(!Application.isPlaying||!app||!app.IsEditorPreviewSave)throw new Exception("Use isolated Art Review save.");
- var report=new StringBuilder();Action<bool,string> check=(ok,label)=>{if(!ok)throw new Exception("FAIL "+label);report.AppendLine("PASS "+label);};
- var game=Field<MatchEngine>(app,"game");var store=Field<PlayerStore>(app,"store");var config=Field<GameConfig>(app,"config");
- app.ShowPreview("Lobby");store.Reset();store.Data.letterPool=false;
- game.Start("olympus");var q=config.questions.First(x=>x.Normalized=="POSEIDON");
- typeof(MatchEngine).GetField("rounds",Flags).SetValue(game,new[]{q,q,q,q,q});game.Tick(4);game.Tick(2);app.ArtReviewMode=true;
- var v=Field<ReferenceAView>(app,"referenceView");var selection=Selection(app);
- check(v.GetComponentsInChildren<TMP_InputField>(true).Length==0,"answer has no editable input or keyboard entry");
- check(v.letterButtons.Count(b=>b.gameObject.activeSelf)==game.Pool.Length,"all candidates visible despite old letterPool=false setting");
- check(!v.FindButton("Delete").interactable&&!v.FindButton("OK").interactable,"empty answer disables X and OK");
- double time=game.TimeLeft;v.FindButton("OK").onClick.Invoke();v.FindButton("Delete").onClick.Invoke();check(game.TimeLeft==time&&selection.Count==0,"empty submit/delete have no effect or time penalty");
- int[] repeated=Enumerable.Range(0,game.Pool.Length).Where(i=>game.Pool[i]=='O').Take(2).ToArray();
- v.letterButtons[repeated[1]].onClick.Invoke();v.letterButtons[repeated[1]].onClick.Invoke();
- check(selection.Value=="O"&&!v.letterButtons[repeated[1]].interactable&&v.letterButtons[repeated[0]].interactable,"same physical tile cannot be selected twice; matching tile stays available");
- v.letterButtons[repeated[0]].onClick.Invoke();check(selection.Value=="OO","duplicate letters use separate candidate tiles");
- v.FindButton("Delete").onClick.Invoke();check(selection.Value=="O"&&v.letterButtons[repeated[0]].interactable&&!v.letterButtons[repeated[1]].interactable,"X restores exactly the last selected tile");
- v.FindButton("OK").onClick.Invoke();check(game.TimeLeft==time-2&&selection.Value=="O","wrong answer costs two seconds and stays editable");
- v.itemButtons[0].onClick.Invoke();check(selection.Value=="O"&&!v.letterButtons[repeated[1]].interactable,"hint preserves selected tile identities");
- game.Paused=true;Refresh(app);time=game.TimeLeft;v.letterButtons[repeated[0]].onClick.Invoke();v.FindButton("Delete").onClick.Invoke();v.FindButton("OK").onClick.Invoke();
- check(selection.Value=="O"&&game.TimeLeft==time&&v.letterButtons.Where(b=>b.gameObject.activeSelf).All(b=>!b.interactable),"pause blocks candidate, delete and submit actions");
- game.Paused=false;Refresh(app);SelectAnswer(app,q.answer);
- v.FindButton("OK").onClick.Invoke();int score=game.Score;v.FindButton("OK").onClick.Invoke();v.FindButton("Delete").onClick.Invoke();
- check(game.Phase==MatchPhase.Answer&&game.Score==score&&selection.Value==q.Normalized,"correct answer locks controls and duplicate submission");
- game.Tick(1.6);game.Continue();game.Tick(1.3);check(Selection(app).Count==0&&Field<ReferenceAView>(app,"referenceView").letterButtons.Where(b=>b.gameObject.activeSelf).All(b=>b.interactable),"next question clears answer and restores every tile");
- SelectAnswer(app,"P");game.Start("olympus",true);game.Tick(4);game.Tick(2);check(Selection(app).Count==0,"restart starts with an empty selection");
- // Every shipped question is solved through native buttons, including multiword and repeated-letter answers.
- foreach(var question in config.questions)
- {
- app.ShowPreview("Lobby");store.Reset();game.Start(question.realm);
- typeof(MatchEngine).GetField("rounds",Flags).SetValue(game,new[]{question,question,question,question,question});game.Tick(4);game.Tick(2);
- SelectAnswer(app,question.answer);Field<ReferenceAView>(app,"referenceView").FindButton("OK").onClick.Invoke();
- if(game.Phase!=MatchPhase.Answer||game.LastGain<=0)throw new Exception("Cannot solve through tiles: "+question.id);
- }
- check(true,"all 40 questions submit successfully using only candidate buttons");
- app.ShowDesignPage("Settings");var settings=app.GetComponentsInChildren<SuiteView>().First(x=>x.screen=="Settings");
- check(!settings.Button("Toggle 4").interactable&&settings.Text("Toggle state 4").text=="ON","settings cannot hide candidates");
- Directory.CreateDirectory("docs/验证");File.WriteAllText("docs/验证/候选字母交互验收.txt",report.ToString());return report.ToString();
- }
- }
- }
|