| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- using System;
- using System.IO;
- using System.Linq;
- using System.Reflection;
- using TMPro;
- using UnityEditor;
- using UnityEngine;
- using UnityEngine.EventSystems;
- using UnityEngine.UI;
- namespace Olympus.Editor
- {
- public static class ManualContinueAudit
- {
- const BindingFlags Flags=BindingFlags.Instance|BindingFlags.NonPublic;
- const string Report="docs/验证/手动继续与退出验收.txt";
- static T Field<T>(OlympusGame app,string name)=>(T)typeof(OlympusGame).GetField(name,Flags).GetValue(app);
- static void Require(bool valid,string message){if(!valid)throw new Exception(message);}
- static OlympusGame Prepare()
- {
- var app=UnityEngine.Object.FindFirstObjectByType<OlympusGame>();
- Require(Application.isPlaying&&app&&app.IsEditorPreviewSave,"Use isolated Art Review save");
- Field<PlayerStore>(app,"store").Reset();app.ShowDesignPage("Lobby");
- var q=Field<GameConfig>(app,"config").questions.First(x=>x.answer=="SPIRITED AWAY");var game=Field<MatchEngine>(app,"game");
- Require(game.Start(q.realm),"Entry failed");typeof(MatchEngine).GetField("rounds",Flags).SetValue(game,new[]{q,q,q,q,q});
- game.Tick(4);game.Tick(2);app.ArtReviewMode=true;Field<TextMeshProUGUI>(app,"toast").gameObject.SetActive(false);return app;
- }
- static void CheckFeedback(ReferenceAView v,bool visible)
- {
- Require(v.feedbackPanel.gameObject.activeInHierarchy==visible,"feedback visibility mismatch");
- if(!visible)return;
- Require(v.feedbackPanel.color.a>0&&v.feedbackPanel.color.a<1&&!v.feedbackPanel.raycastTarget&&!v.clue.raycastTarget,"feedback must be translucent and nonblocking");
- Canvas.ForceUpdateCanvases();v.clue.ForceMeshUpdate();Require(!v.clue.isTextOverflowing&&v.clue.textInfo.characterCount>0,"feedback text is clipped");
- }
- static void CompleteRound(OlympusGame app)
- {
- var game=Field<MatchEngine>(app,"game");TileAnswerAudit.SelectAnswer(app,game.Current.answer);Field<ReferenceAView>(app,"referenceView").FindButton("OK").onClick.Invoke();game.Tick(1.6);
- }
- public static string Run()
- {
- var app=Prepare();var game=Field<MatchEngine>(app,"game");var trial=Field<ReferenceAView>(app,"referenceView");CheckFeedback(trial,false);
- trial.itemButtons[0].onClick.Invoke();CheckFeedback(trial,true);Require(trial.clue.text.Contains("LETTERS"),"hint text absent");
- TileAnswerAudit.SelectAnswer(app,game.Current.answer);trial.FindButton("OK").onClick.Invoke();CheckFeedback(trial,true);Require(trial.clue.text.Contains("SPIRITED AWAY")&&trial.clue.text.Contains("points"),"long answer feedback absent");
- game.Tick(1.6);var round=Field<SuiteView>(app,"suiteView");
- Require(round.GetComponentsInChildren<Button>().Length==2&&round.Button("Continue").gameObject.activeSelf&&round.Button("Quit").gameObject.activeSelf,"intermission actions mismatch");
- int score=game.Score;var ai=game.Rivals.Select(x=>x.score).ToArray();game.Tick(3600);
- Require(game.Phase==MatchPhase.Intermission&&game.Round==0&&game.Score==score&&ai.SequenceEqual(game.Rivals.Select(x=>x.score)),"intermission changed while waiting");
- round.Button("Continue").onClick.Invoke();round.Button("Continue").onClick.Invoke();app.ArtReviewMode=true;
- Require(game.Phase==MatchPhase.Intro&&game.Round==1,"Continue skipped a round");game.Tick(1.3);CheckFeedback(Field<ReferenceAView>(app,"referenceView"),false);
- for(int n=1;n<5;n++){CompleteRound(app);if(n<4){Field<SuiteView>(app,"suiteView").Button("Continue").onClick.Invoke();app.ArtReviewMode=true;game.Tick(1.3);}}
- var result=Field<SuiteView>(app,"suiteView");Require(game.Phase==MatchPhase.Result&&result.GetComponentsInChildren<Button>().Length==2&&result.Button("Quit").gameObject.activeSelf&&!result.Button("Continue").gameObject.activeSelf,"result actions mismatch");
- result.Button("Play again").onClick.Invoke();Require(game.Phase==MatchPhase.Lobby,"PLAY AGAIN navigation failed");
- app.ShowDesignPage("Result");Field<SuiteView>(app,"suiteView").Button("Quit").onClick.Invoke();Require(Field<string>(app,"currentScreen")=="Lobby"&&EditorApplication.isPlaying,"design preview QUIT must also return to lobby");
- foreach(string outcome in new[]{"timeout","skip"}){FeedbackPreview(outcome);app=UnityEngine.Object.FindFirstObjectByType<OlympusGame>();trial=Field<ReferenceAView>(app,"referenceView");CheckFeedback(trial,true);Require(trial.clue.text.Contains(outcome=="timeout"?"Time's up":"Skipped"),"outcome absent");}
- string report="PASS intermission has CONTINUE and QUIT; no transition or AI scoring after 3600 seconds\nPASS Continue advances one round, double click guarded; fifth round has PLAY AGAIN and QUIT\nPASS feedback background translucent, nonblocking and hidden when empty; hint/correct/timeout/skip text fits\nPASS new round clears feedback; PLAY AGAIN returns to realm selection\n";
- Directory.CreateDirectory("docs/验证");File.WriteAllText(Report,report);app.ShowDesignPage("Lobby");return report;
- }
- public static string FeedbackPreview(string outcome="correct")
- {
- var app=Prepare();var game=Field<MatchEngine>(app,"game");
- if(outcome=="timeout")game.Tick(game.TimeLeft);else if(outcome=="skip")game.Use(Item.Skip);else if(outcome=="hint")game.Use(Item.Hint);else game.Submit(game.Current.answer);
- typeof(OlympusGame).GetMethod("RefreshTrial",Flags).Invoke(app,null);
- Field<TextMeshProUGUI>(app,"toast").gameObject.SetActive(false);return "Feedback preview: "+outcome;
- }
- public static string ClickQuit(bool final)
- {
- var app=Prepare();var game=Field<MatchEngine>(app,"game");CompleteRound(app);
- if(final)for(int i=1;i<5;i++){Field<SuiteView>(app,"suiteView").Button("Continue").onClick.Invoke();app.ArtReviewMode=true;game.Tick(1.3);CompleteRound(app);}
- SessionState.SetString("OlympusQuitAuditData",JsonUtility.ToJson(Field<PlayerStore>(app,"store").Data));SessionState.SetString("OlympusQuitAuditPhase",final?"Result":"Intermission");
- app.StartCoroutine(ClickQuitAfterRender(app));return "QUIT audit waiting for UI layout before pointer click";
- }
- static System.Collections.IEnumerator ClickQuitAfterRender(OlympusGame app)
- {
- yield return null;yield return null;
- var quit=Field<SuiteView>(app,"suiteView").Button("Quit");Canvas.ForceUpdateCanvases();var rect=(RectTransform)quit.transform;
- var data=new PointerEventData(EventSystem.current){position=RectTransformUtility.WorldToScreenPoint(null,rect.TransformPoint(rect.rect.center)),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>()==quit,"QUIT is covered");
- ExecuteEvents.Execute(quit.gameObject,data,ExecuteEvents.pointerClickHandler);quit.onClick.Invoke();
- var game=Field<MatchEngine>(app,"game");Require(EditorApplication.isPlaying&&Field<bool>(app,"started")&&game.Phase==MatchPhase.Lobby&&!game.Paused&&Field<string>(app,"currentScreen")=="Lobby","QUIT did not return to a running lobby");
- }
- public static string VerifyQuit()
- {
- Require(EditorApplication.isPlaying,"QUIT must keep Play Mode running");
- string phase=SessionState.GetString("OlympusQuitAuditPhase","");Require(phase.Length>0,"No pending QUIT audit");
- var app=UnityEngine.Object.FindFirstObjectByType<OlympusGame>();Require(app&&app.IsEditorPreviewSave,"Use isolated Art Review save");
- var game=Field<MatchEngine>(app,"game");Require(game.Phase==MatchPhase.Lobby&&Field<string>(app,"currentScreen")=="Lobby","QUIT did not show the lobby");
- var data=JsonUtility.FromJson<PlayerData>(File.ReadAllText("Library/olympus-preview-save.json"));
- Require(JsonUtility.ToJson(data)==SessionState.GetString("OlympusQuitAuditData",""),"saved progress changed or lost during QUIT");
- game.Tick(100);Require(game.Phase==MatchPhase.Lobby&&JsonUtility.ToJson(Field<PlayerStore>(app,"store").Data)==JsonUtility.ToJson(data),"quit allowed a delayed transition or settlement");
- Field<ReferenceAView>(app,"referenceView").realmButtons[0].onClick.Invoke();game.Tick(4);game.Tick(2);app.ArtReviewMode=true;
- Require(game.Phase==MatchPhase.Playing&&Field<bool>(app,"started")&&!game.Paused,"cannot start a new match after QUIT");double time=game.TimeLeft;game.Tick(1);Require(game.TimeLeft<time,"new match timer is stopped");app.ShowDesignPage("Lobby");
- string result="PASS "+phase+" QUIT pointer click returns to Lobby and keeps Play Mode running; duplicate click guarded; save preserved; no delayed settlement; new match and timer work\n";File.AppendAllText(Report,result);SessionState.EraseString("OlympusQuitAuditPhase");return result;
- }
- }
- }
|