ManualContinueAudit.cs 9.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. using System;
  2. using System.IO;
  3. using System.Linq;
  4. using System.Reflection;
  5. using TMPro;
  6. using UnityEditor;
  7. using UnityEngine;
  8. using UnityEngine.EventSystems;
  9. using UnityEngine.UI;
  10. namespace Olympus.Editor
  11. {
  12. public static class ManualContinueAudit
  13. {
  14. const BindingFlags Flags=BindingFlags.Instance|BindingFlags.NonPublic;
  15. const string Report="docs/验证/手动继续与退出验收.txt";
  16. static T Field<T>(OlympusGame app,string name)=>(T)typeof(OlympusGame).GetField(name,Flags).GetValue(app);
  17. static void Require(bool valid,string message){if(!valid)throw new Exception(message);}
  18. static OlympusGame Prepare()
  19. {
  20. var app=UnityEngine.Object.FindFirstObjectByType<OlympusGame>();
  21. Require(Application.isPlaying&&app&&app.IsEditorPreviewSave,"Use isolated Art Review save");
  22. Field<PlayerStore>(app,"store").Reset();app.ShowDesignPage("Lobby");
  23. var q=Field<GameConfig>(app,"config").questions.First(x=>x.answer=="SPIRITED AWAY");var game=Field<MatchEngine>(app,"game");
  24. Require(game.Start(q.realm),"Entry failed");typeof(MatchEngine).GetField("rounds",Flags).SetValue(game,new[]{q,q,q,q,q});
  25. game.Tick(4);game.Tick(2);app.ArtReviewMode=true;Field<TextMeshProUGUI>(app,"toast").gameObject.SetActive(false);return app;
  26. }
  27. static void CheckFeedback(ReferenceAView v,bool visible)
  28. {
  29. Require(v.feedbackPanel.gameObject.activeInHierarchy==visible,"feedback visibility mismatch");
  30. if(!visible)return;
  31. Require(v.feedbackPanel.color.a>0&&v.feedbackPanel.color.a<1&&!v.feedbackPanel.raycastTarget&&!v.clue.raycastTarget,"feedback must be translucent and nonblocking");
  32. Canvas.ForceUpdateCanvases();v.clue.ForceMeshUpdate();Require(!v.clue.isTextOverflowing&&v.clue.textInfo.characterCount>0,"feedback text is clipped");
  33. }
  34. static void CompleteRound(OlympusGame app)
  35. {
  36. var game=Field<MatchEngine>(app,"game");TileAnswerAudit.SelectAnswer(app,game.Current.answer);Field<ReferenceAView>(app,"referenceView").FindButton("OK").onClick.Invoke();game.Tick(1.6);
  37. }
  38. public static string Run()
  39. {
  40. var app=Prepare();var game=Field<MatchEngine>(app,"game");var trial=Field<ReferenceAView>(app,"referenceView");CheckFeedback(trial,false);
  41. trial.itemButtons[0].onClick.Invoke();CheckFeedback(trial,true);Require(trial.clue.text.Contains("LETTERS"),"hint text absent");
  42. 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");
  43. game.Tick(1.6);var round=Field<SuiteView>(app,"suiteView");
  44. Require(round.GetComponentsInChildren<Button>().Length==2&&round.Button("Continue").gameObject.activeSelf&&round.Button("Quit").gameObject.activeSelf,"intermission actions mismatch");
  45. int score=game.Score;var ai=game.Rivals.Select(x=>x.score).ToArray();game.Tick(3600);
  46. Require(game.Phase==MatchPhase.Intermission&&game.Round==0&&game.Score==score&&ai.SequenceEqual(game.Rivals.Select(x=>x.score)),"intermission changed while waiting");
  47. round.Button("Continue").onClick.Invoke();round.Button("Continue").onClick.Invoke();app.ArtReviewMode=true;
  48. Require(game.Phase==MatchPhase.Intro&&game.Round==1,"Continue skipped a round");game.Tick(1.3);CheckFeedback(Field<ReferenceAView>(app,"referenceView"),false);
  49. 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);}}
  50. 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");
  51. result.Button("Play again").onClick.Invoke();Require(game.Phase==MatchPhase.Lobby,"PLAY AGAIN navigation failed");
  52. 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");
  53. 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");}
  54. 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";
  55. Directory.CreateDirectory("docs/验证");File.WriteAllText(Report,report);app.ShowDesignPage("Lobby");return report;
  56. }
  57. public static string FeedbackPreview(string outcome="correct")
  58. {
  59. var app=Prepare();var game=Field<MatchEngine>(app,"game");
  60. 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);
  61. typeof(OlympusGame).GetMethod("RefreshTrial",Flags).Invoke(app,null);
  62. Field<TextMeshProUGUI>(app,"toast").gameObject.SetActive(false);return "Feedback preview: "+outcome;
  63. }
  64. public static string ClickQuit(bool final)
  65. {
  66. var app=Prepare();var game=Field<MatchEngine>(app,"game");CompleteRound(app);
  67. 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);}
  68. SessionState.SetString("OlympusQuitAuditData",JsonUtility.ToJson(Field<PlayerStore>(app,"store").Data));SessionState.SetString("OlympusQuitAuditPhase",final?"Result":"Intermission");
  69. app.StartCoroutine(ClickQuitAfterRender(app));return "QUIT audit waiting for UI layout before pointer click";
  70. }
  71. static System.Collections.IEnumerator ClickQuitAfterRender(OlympusGame app)
  72. {
  73. yield return null;yield return null;
  74. var quit=Field<SuiteView>(app,"suiteView").Button("Quit");Canvas.ForceUpdateCanvases();var rect=(RectTransform)quit.transform;
  75. var data=new PointerEventData(EventSystem.current){position=RectTransformUtility.WorldToScreenPoint(null,rect.TransformPoint(rect.rect.center)),button=PointerEventData.InputButton.Left};
  76. 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");
  77. ExecuteEvents.Execute(quit.gameObject,data,ExecuteEvents.pointerClickHandler);quit.onClick.Invoke();
  78. 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");
  79. }
  80. public static string VerifyQuit()
  81. {
  82. Require(EditorApplication.isPlaying,"QUIT must keep Play Mode running");
  83. string phase=SessionState.GetString("OlympusQuitAuditPhase","");Require(phase.Length>0,"No pending QUIT audit");
  84. var app=UnityEngine.Object.FindFirstObjectByType<OlympusGame>();Require(app&&app.IsEditorPreviewSave,"Use isolated Art Review save");
  85. var game=Field<MatchEngine>(app,"game");Require(game.Phase==MatchPhase.Lobby&&Field<string>(app,"currentScreen")=="Lobby","QUIT did not show the lobby");
  86. var data=JsonUtility.FromJson<PlayerData>(File.ReadAllText("Library/olympus-preview-save.json"));
  87. Require(JsonUtility.ToJson(data)==SessionState.GetString("OlympusQuitAuditData",""),"saved progress changed or lost during QUIT");
  88. 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");
  89. Field<ReferenceAView>(app,"referenceView").realmButtons[0].onClick.Invoke();game.Tick(4);game.Tick(2);app.ArtReviewMode=true;
  90. 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");
  91. 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;
  92. }
  93. }
  94. }