PortraitTests.cs 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using NUnit.Framework;
  5. using TMPro;
  6. using UnityEngine;
  7. using UnityEngine.EventSystems;
  8. using UnityEngine.SceneManagement;
  9. using UnityEngine.TestTools;
  10. using UnityEngine.UI;
  11. namespace Fateforge.Tests
  12. {
  13. public sealed class PortraitTests
  14. {
  15. FateforgeApp app;
  16. [UnitySetUp] public IEnumerator Setup()
  17. {
  18. FateforgeApp.ValidationSession=true;
  19. yield return SceneManager.LoadSceneAsync("Assets/Fateforge/Scenes/FateforgeMain.unity");yield return null;
  20. app=Object.FindFirstObjectByType<FateforgeApp>();Assert.That(app,Is.Not.Null);app.Settings.music=false;app.Settings.sound=false;app.Settings.speed=2;
  21. Assert.That(Object.FindObjectsByType<AudioListener>(FindObjectsSortMode.None).Count(a=>a.isActiveAndEnabled),Is.EqualTo(1));
  22. }
  23. [UnityTearDown] public IEnumerator Cleanup(){FateforgeApp.ValidationSession=false;app.ShowHome();yield return null;}
  24. IEnumerator Begin(){app.PrepareRun(42);app.StartRun();yield return new WaitUntil(()=>!app.Busy);yield return null;}
  25. static IEnumerator AwaitPresentation(System.Func<bool> completed,string description,float timeout=15)
  26. {
  27. float deadline=Time.realtimeSinceStartup+timeout;
  28. while(!completed()&&Time.realtimeSinceStartup<deadline)yield return null;
  29. Assert.That(completed(),Is.True,"Presentation timed out: "+description);
  30. }
  31. static Button ButtonAt(Transform root,string name)=>root.GetComponentsInChildren<Button>(true).First(b=>b.name==name&&b.gameObject.activeInHierarchy);
  32. static void TapButtonLabel(Button button)
  33. {
  34. Canvas.ForceUpdateCanvases();
  35. var label = button.GetComponentInChildren<TMP_Text>().rectTransform;
  36. var events = EventSystem.current;
  37. var pointer = new PointerEventData(events){
  38. position = RectTransformUtility.WorldToScreenPoint(null, label.TransformPoint(label.rect.center))
  39. };
  40. var hits = new List<RaycastResult>();
  41. events.RaycastAll(pointer, hits);
  42. Assert.That(hits, Is.Not.Empty, "No UI hit at " + button.name + " label " + pointer.position);
  43. var pressed = ExecuteEvents.ExecuteHierarchy(hits[0].gameObject, pointer, ExecuteEvents.pointerDownHandler);
  44. Assert.That(pressed, Is.EqualTo(button.gameObject));
  45. ExecuteEvents.Execute(pressed, pointer, ExecuteEvents.pointerUpHandler);
  46. ExecuteEvents.Execute(pressed, pointer, ExecuteEvents.pointerClickHandler);
  47. }
  48. IEnumerator TapModalButton(string name)
  49. {
  50. // Let the newly opened panel participate in the next UI raycast.
  51. yield return null;
  52. TapButtonLabel(ButtonAt(app.view.modalBody, name));
  53. }
  54. [UnityTest] public IEnumerator EveryHomeButtonOpensItsScreenImmediatelyAfterLaunch()
  55. {
  56. var buttons = new[] {app.view.normalRun, app.view.homeSettings, app.view.homeHelp,
  57. app.view.leaderboard, app.view.endlessRun};
  58. bool replacingNormal = app.Saves.Current.hasRun && !app.Saves.Current.run.endless;
  59. string[] titles = {"Normal Mode", "Settings", "Help", "Leaderboard",
  60. replacingNormal ? "Start Endless Mode?" : "Endless Mode"};
  61. for (int i = 0; i < buttons.Length; i++)
  62. {
  63. TapButtonLabel(buttons[i]);
  64. Assert.That(app.view.modal.gameObject.activeInHierarchy, Is.True, buttons[i].name);
  65. Assert.That(app.view.modalTitle.text, Is.EqualTo(titles[i]), buttons[i].name);
  66. app.ShowHome();
  67. yield return null;
  68. }
  69. }
  70. [UnityTest] public IEnumerator HiddenLeverAndSegmentedSettingsPreserveGameState()
  71. {
  72. app.ShowHome();app.view.homeSettings.onClick.Invoke();yield return null;
  73. Assert.That(app.view.home.gameObject.activeInHierarchy,Is.True,"Settings must preserve the menu behind the dimmer.");
  74. Assert.That(app.view.modal.GetComponent<Image>().color.a,Is.InRange(.3f,.85f));
  75. var eventData=new PointerEventData(EventSystem.current){position=RectTransformUtility.WorldToScreenPoint(null,app.view.normalRun.transform.position)};var hits=new List<RaycastResult>();EventSystem.current.RaycastAll(eventData,hits);
  76. Assert.That(hits.Count,Is.GreaterThan(0));Assert.That(hits[0].gameObject.transform.IsChildOf(app.view.modal)||hits[0].gameObject==app.view.modal.gameObject,"The settings dialog must consume underlying menu clicks.");
  77. ButtonAt(app.view.modalBody,"Music_0").onClick.Invoke();yield return null;Assert.That(app.Settings.music,Is.True);
  78. ButtonAt(app.view.modalBody,"Music_1").onClick.Invoke();yield return null;Assert.That(app.Settings.music,Is.False);
  79. ButtonAt(app.view.modalBody,"AnimationSpeed_0").onClick.Invoke();yield return null;Assert.That(app.Settings.speed,Is.EqualTo(1));
  80. ButtonAt(app.view.modalBody,"AnimationSpeed_1").onClick.Invoke();yield return null;Assert.That(app.Settings.speed,Is.EqualTo(2));
  81. ButtonAt(app.view.modalBody,"Resume").onClick.Invoke();Assert.That(app.view.home.gameObject.activeSelf,Is.True);
  82. app.ShowHelp(0);yield return null;Assert.That(app.view.home.gameObject.activeInHierarchy,Is.True);app.view.modalClose.onClick.Invoke();Assert.That(app.view.modal.gameObject.activeSelf,Is.False);
  83. yield return Begin();Assert.That(app.view.collectLever.lever.gameObject.activeInHierarchy,Is.False);
  84. foreach(var card in app.view.board.GetComponentsInChildren<CardView>()){var symbol=app.Game.Board.cells.First(c=>c.id==card.CardId).symbol;Assert.That(card.symbol.sprite,Is.SameAs(app.view.art.Sprite(symbol)));}
  85. app.view.collect.onClick.Invoke();Assert.That(app.Game.State.stage,Is.EqualTo(Stage.Settlement));int round=app.Game.Board.round;app.view.collect.onClick.Invoke();Assert.That(app.Game.Board.round,Is.EqualTo(round));yield return new WaitUntil(()=>!app.Busy);
  86. }
  87. [UnityTest] public IEnumerator CarnivalGlyphsRenderInBattleAndMarket()
  88. {
  89. yield return Begin();
  90. var cards=app.view.board.GetComponentsInChildren<CardView>();
  91. Assert.That(cards.Length,Is.EqualTo(12));
  92. foreach(var card in cards){Assert.That(card.outline,Is.Not.Null);card.outline.enabled=true;card.outline.color=Color.yellow;}
  93. Canvas.ForceUpdateCanvases();yield return null;
  94. foreach(var glyph in app.view.GetComponentsInChildren<UiGlyph>(true)){
  95. Assert.That(glyph.GetComponent<CanvasRenderer>(),Is.Not.Null,glyph.name);
  96. if(glyph.gameObject.activeInHierarchy&&glyph.enabled){var mesh=glyph.canvasRenderer.GetMesh();Assert.That(mesh.vertexCount,Is.GreaterThan(0),glyph.name);Object.Destroy(mesh);}
  97. }
  98. app.Game.OpenShop();app.Render();yield return null;Canvas.ForceUpdateCanvases();
  99. var prices=app.view.market.GetComponentsInChildren<Image>().Where(g=>g.sprite==app.view.theme.coinSprite && g.name=="PriceCoin").ToArray();
  100. Assert.That(prices.Length,Is.GreaterThan(0));
  101. foreach(var price in prices)Assert.That(price.GetComponent<CanvasRenderer>(),Is.Not.Null,price.name);
  102. }
  103. [UnityTest] public IEnumerator HomeLoadoutAndAllHelpEntriesAreAvailable()
  104. {
  105. app.PrepareRun(42);yield return null;Assert.That(app.view.home.gameObject.activeSelf,Is.False,"Loadout must show only the game beneath the modal.");Assert.That(app.view.play.gameObject.activeSelf,Is.True);Assert.That(app.view.modalTitle.text,Is.EqualTo("Forge Your Fate"));Assert.That(app.Game.State.stage,Is.EqualTo(Stage.Ready));Assert.That(app.Saves.Current.hasRun);app.ShowHelp(0);yield return null;
  106. Assert.That(app.view.modalBody.GetComponentsInChildren<Button>().Count(b=>b.name.StartsWith("HelpTab_")),Is.EqualTo(2));
  107. foreach(var id in Fateforge.Game.StartingTricks)
  108. Assert.That(app.view.modalBody.Find("GuideList/Viewport/Content/SkillDescription_"+id).GetComponent<TMP_Text>().text,Is.EqualTo(app.view.art.Description(id)));
  109. app.ShowHelp(1);yield return null;Assert.That(app.view.modalBody.GetComponentsInChildren<Image>().Count(i=>i.name=="Icon"),Is.EqualTo(46));Assert.That(app.view.art.Catalog.Count(c=>c.category=="tickets"),Is.EqualTo(46));
  110. }
  111. [UnityTest] public IEnumerator ReelsStopAndPreviewDoesNotBlockDiscardOrCollection()
  112. {
  113. yield return Begin();Assert.That(app.StoppedReels,Is.EqualTo(4));Assert.That(app.VisibleCardCount,Is.EqualTo(12));Assert.That(app.Game.Board.stock.Count,Is.EqualTo(21));ButtonAt(app.view.tricks,"Trick_discard").onClick.Invoke();yield return null;var card=app.view.board.GetComponentsInChildren<CardView>().First(c=>app.Game.CanDiscard(app.Game.Board.cells.FindIndex(x=>x.id==c.CardId)));card.Click(card.CardId,false);yield return null;Assert.That(app.Game.Board.discardUsed,Is.EqualTo(1));Assert.That(card.DiscardFlash);
  114. Assert.That(card.transform.Find("SelectedCard").gameObject.activeSelf);
  115. Assert.That(app.Busy,Is.False);app.Primary();Assert.That(app.Game.State.stage,Is.EqualTo(Stage.Settlement));Assert.That(app.Game.Board.operation,Is.Empty);yield return new WaitUntil(()=>!app.Busy);Assert.That(app.Game.State.stage,Is.EqualTo(Stage.Battle));Assert.That(app.Game.Board.round,Is.EqualTo(2));
  116. }
  117. [UnityTest] public IEnumerator TooltipDismissalConsumesTapAndModalBlocksBattle()
  118. {
  119. yield return Begin();app.view.deck.onClick.Invoke();yield return null;Assert.That(app.view.quickLayer.gameObject.activeSelf);int round=app.Game.Board.round;var eventData=new PointerEventData(EventSystem.current){position=RectTransformUtility.WorldToScreenPoint(null,app.view.collect.transform.position)};var hits=new List<RaycastResult>();EventSystem.current.RaycastAll(eventData,hits);Assert.That(hits.Count,Is.GreaterThan(0));Assert.That(hits[0].gameObject.transform.IsChildOf(app.view.quickLayer)||hits[0].gameObject==app.view.quickLayer.gameObject);ExecuteEvents.ExecuteHierarchy(hits[0].gameObject,eventData,ExecuteEvents.pointerClickHandler);Assert.That(app.Game.Board.round,Is.EqualTo(round));Assert.That(app.view.quickLayer.gameObject.activeSelf,Is.False);app.view.help.onClick.Invoke();app.Primary();Assert.That(app.Game.State.stage,Is.EqualTo(Stage.Battle));yield return null;
  120. }
  121. [UnityTest] public IEnumerator RewardedSlotCanUnlockBeforeCoinSlotAndSurvivesContinue()
  122. {
  123. yield return Begin();app.Game.OpenShop();app.Save();app.Render();yield return null;ButtonAt(app.view.market.Find("MarketSlot_4"),"Buy").onClick.Invoke();Assert.That(app.Busy);Assert.That(app.view.modalTitle.text,Is.EqualTo("Ad Simulation"));ButtonAt(app.view.modalBody,"CompleteAd").onClick.Invoke();yield return null;Assert.That(app.Game.State.adSlot);Assert.That(app.Game.State.coinSlot,Is.False);int coins=app.Game.State.coins;((SimulatedAdService)app.Ads).RepeatLastReward();Assert.That(app.Game.State.coins,Is.EqualTo(coins));app.ShowHome();app.Continue();yield return null;Assert.That(app.Game.State.adSlot);Assert.That(app.Game.State.stage,Is.EqualTo(Stage.Shop));
  124. }
  125. [UnityTest] public IEnumerator MarketAdWaitCanBeCancelledAndRetriedWhenReady()
  126. {
  127. yield return Begin();
  128. app.Game.OpenShop();
  129. app.Render();
  130. yield return null;
  131. var ads = (SimulatedAdService)app.Ads;
  132. ads.Available = false;
  133. var watch = ButtonAt(app.view.market.Find("MarketSlot_4"), "Buy");
  134. TapButtonLabel(watch);
  135. yield return TapModalButton("CancelAdWait");
  136. ads.Available = true;
  137. yield return new WaitForSecondsRealtime(.35f);
  138. Assert.That(ads.Pending, Is.Null);
  139. Assert.That(app.view.modal.gameObject.activeSelf, Is.False);
  140. Assert.That(app.Game.State.adSlot, Is.False);
  141. ads.Available = false;
  142. TapButtonLabel(watch);
  143. yield return AwaitPresentation(() => app.view.modalBody.Find("RetryAd"), "market ad timeout");
  144. yield return TapModalButton("RetryAd");
  145. Assert.That(ButtonAt(app.view.modalBody, "CancelAdWait"), Is.Not.Null);
  146. ads.Available = true;
  147. yield return AwaitPresentation(() => ads.Pending != null, "delayed ad readiness");
  148. Assert.That(ads.Pending.purpose, Is.EqualTo(AdPurpose.ShopSlot));
  149. yield return TapModalButton("FailAd");
  150. Assert.That(app.Game.State.adSlot, Is.False);
  151. yield return TapModalButton("RetryAd");
  152. yield return TapModalButton("CompleteAd");
  153. Assert.That(app.Game.State.adSlot, Is.True);
  154. Assert.That(app.Busy, Is.False);
  155. }
  156. [UnityTest] public IEnumerator CancellingAnEndlessAdWaitRestoresEndRunChoice()
  157. {
  158. yield return Begin();
  159. app.Game.State.endless = true;
  160. app.Game.State.stage = Stage.ReviveChoice;
  161. app.Render();
  162. ((SimulatedAdService)app.Ads).Available = false;
  163. yield return TapModalButton("WatchAd");
  164. yield return TapModalButton("CancelAdWait");
  165. Assert.That(app.Game.State.reviveUsed, Is.False);
  166. yield return TapModalButton("EndRun");
  167. Assert.That(app.Game.State.stage, Is.EqualTo(Stage.Failed));
  168. yield return null;
  169. }
  170. [UnityTest] public IEnumerator CloudConflictDialogUsesOneCompleteRecordFromHome()
  171. {
  172. app.PrepareRun(42);app.ShowHome();var cloud=(SimulatedCloudService)app.Cloud;cloud.SeedConflict(app.Saves.Current);app.ShowSimulation();ButtonAt(app.view.modalBody,"Sync").onClick.Invoke();yield return null;Assert.That(app.view.modalTitle.text,Is.EqualTo("Choose Your Progress"));ButtonAt(app.view.modalBody,"KeepCloud").onClick.Invoke();yield return null;Assert.That(app.Saves.Current.run.coins,Is.EqualTo(16));Assert.That(app.Game.State.coins,Is.EqualTo(16));
  173. }
  174. [UnityTest] public IEnumerator ScatterDoubleTapWorksAndTicketTooltipStaysInSafeArea()
  175. {
  176. yield return Begin();var cell=app.Game.Board.cells.First(c=>c.symbol=="clown");int id=cell.id;var card=app.view.board.GetComponentsInChildren<CardView>().First(c=>c.CardId==id);card.Click(id,false);Assert.That(app.view.quickLayer.gameObject.activeSelf,Is.False);card.Click(id,true);yield return null;Assert.That(app.Game.Board.cells.Any(c=>c.id==id),Is.False);ButtonAt(app.view.tickets,"Ticket_0").onClick.Invoke();yield return null;var r=app.view.quickPanel;Assert.That(-r.anchoredPosition.y+r.rect.height,Is.LessThanOrEqualTo(app.view.safeArea.rect.height));
  177. }
  178. [UnityTest] public IEnumerator NormalModeOffersContinueOrNewGameFromHome()
  179. {
  180. // Start with an empty slot in the validation profile.
  181. app.PrepareRun(42);
  182. app.Game.State.stage = Stage.Failed;
  183. app.Save();
  184. app.ShowHome();
  185. yield return null;
  186. Assert.That(app.Saves.Current.hasRun, Is.False);
  187. Assert.That(app.view.home.Find("Buttons/Continue"), Is.Null);
  188. var normal = ButtonAt(app.view.home, "NormalMode");
  189. Assert.That(normal.GetComponentInChildren<TMP_Text>().text, Is.EqualTo("Normal Mode"));
  190. TapButtonLabel(normal);
  191. Assert.That(app.view.modalTitle.text, Is.EqualTo("Normal Mode"));
  192. Assert.That(ButtonAt(app.view.modalBody, "Continue").interactable, Is.False);
  193. ButtonAt(app.view.modalBody, "NewGame").onClick.Invoke();
  194. Assert.That(app.Game.State.endless, Is.False);
  195. Assert.That(app.Game.State.stage, Is.EqualTo(Stage.Ready));
  196. string runId = app.Game.State.id;
  197. app.Game.OpenShop();
  198. app.Game.State.coins = 31;
  199. app.Save();
  200. app.ShowHome();
  201. yield return null;
  202. TapButtonLabel(normal);
  203. app.view.modalClose.onClick.Invoke();
  204. Assert.That(app.Saves.Current.run.id, Is.EqualTo(runId));
  205. yield return null;
  206. TapButtonLabel(normal);
  207. yield return null;
  208. TapButtonLabel(ButtonAt(app.view.modalBody, "Continue"));
  209. Assert.That(app.Game.State.id, Is.EqualTo(runId));
  210. Assert.That(app.Game.State.stage, Is.EqualTo(Stage.Shop));
  211. Assert.That(app.Game.State.coins, Is.EqualTo(31));
  212. app.ShowHome();
  213. yield return null;
  214. TapButtonLabel(normal);
  215. yield return null;
  216. TapButtonLabel(ButtonAt(app.view.modalBody, "NewGame"));
  217. Assert.That(app.Game.State.id, Is.Not.EqualTo(runId));
  218. Assert.That(app.Game.State.endless, Is.False);
  219. Assert.That(app.Game.State.level, Is.EqualTo(1));
  220. Assert.That(app.Game.State.stage, Is.EqualTo(Stage.Ready));
  221. }
  222. [UnityTest] public IEnumerator HomeStartsEndlessAtOneAndShowsTheBestOnlyAfterEndingTheRun()
  223. {
  224. app.Settings.speed = 20;
  225. app.PrepareRun(42);
  226. string normalRun = app.Game.State.id;
  227. app.ShowHome();
  228. var endless = ButtonAt(app.view.home, "EndlessMode");
  229. Assert.That(endless.GetComponentInChildren<TMP_Text>().text, Is.EqualTo("Endless Mode"));
  230. Assert.That(app.view.leaderboard.GetComponentInChildren<TMP_Text>().text, Is.EqualTo("Leaderboard"));
  231. var saveStatus = app.view.saveStatus.text;
  232. TapButtonLabel(app.view.leaderboard);
  233. Assert.That(app.view.modalTitle.text, Is.EqualTo("Leaderboard"));
  234. Assert.That(app.view.saveStatus.text, Is.EqualTo(saveStatus));
  235. yield return null;
  236. TapButtonLabel(ButtonAt(app.view.modalBody, "Dismiss"));
  237. yield return null;
  238. TapButtonLabel(endless);
  239. Assert.That(app.view.modalTitle.text, Is.EqualTo("Start Endless Mode?"));
  240. Assert.That(app.view.saveStatus.text, Is.EqualTo(saveStatus));
  241. ButtonAt(app.view.modalBody, "Cancel").onClick.Invoke();
  242. Assert.That(app.Saves.Current.run.id, Is.EqualTo(normalRun));
  243. endless.onClick.Invoke();
  244. ButtonAt(app.view.modalBody, "Confirm").onClick.Invoke();
  245. Assert.That(app.Game.State.endless, Is.True);
  246. Assert.That(app.Game.State.level, Is.EqualTo(1));
  247. Assert.That(app.Game.TotalScore, Is.Zero);
  248. Assert.That(app.Game.State.id, Is.Not.EqualTo(normalRun));
  249. Assert.That(app.view.modalTitle.text, Is.EqualTo("Endless Mode"));
  250. string runId = app.Game.State.id;
  251. app.ShowHome();
  252. yield return null;
  253. TapButtonLabel(app.view.normalRun);
  254. Assert.That(ButtonAt(app.view.modalBody, "Continue").interactable, Is.False);
  255. Assert.That(app.view.modalBody.Find("Description").GetComponent<TMP_Text>().text, Does.Contain("Endless Mode"));
  256. app.view.modalClose.onClick.Invoke();
  257. yield return null;
  258. TapButtonLabel(endless);
  259. ButtonAt(app.view.modalBody, "Continue").onClick.Invoke();
  260. Assert.That(app.Game.State.id, Is.EqualTo(runId));
  261. ButtonAt(app.view.modalBody, "Start").onClick.Invoke();
  262. yield return AwaitPresentation(() => !app.Busy, "first endless deal");
  263. var directory = System.IO.Path.Combine(FateforgeApp.SaveDirectory, "Validation");
  264. app.Game.State.leaderboardPlayer = runId;
  265. app.Game.Board.score = 50;
  266. app.Save();
  267. Assert.That(new EndlessRecords(directory).Pending(runId), Is.Zero);
  268. app.Game.State.tickets.Clear();
  269. app.Game.State.battleSpins = 1;
  270. app.Game.State.target = long.MaxValue;
  271. app.Primary();
  272. yield return AwaitPresentation(() => !app.Busy, "revive choice");
  273. Assert.That(app.Game.State.stage, Is.EqualTo(Stage.ReviveChoice));
  274. Assert.That(app.view.modalBody.Find("PersonalBest"), Is.Null);
  275. Assert.That(new EndlessRecords(directory).Pending(runId), Is.Zero);
  276. ButtonAt(app.view.modalBody, "EndRun").onClick.Invoke();
  277. yield return AwaitPresentation(() => app.view.modalBody.Find("PersonalBest") != null, "endless results");
  278. var records = new EndlessRecords(directory);
  279. long best = records.Best(runId);
  280. Assert.That(best, Is.EqualTo(app.Game.TotalScore));
  281. Assert.That(records.Pending(runId), Is.EqualTo(best));
  282. Assert.That(app.view.modalBody.Find("FinalScore").GetComponent<TMP_Text>().text, Is.EqualTo(English.Number(app.Game.TotalScore)));
  283. Assert.That(app.view.modalBody.Find("PersonalBest").GetComponent<TMP_Text>().text, Does.EndWith(English.Number(best)));
  284. ButtonAt(app.view.modalBody, "ReturnHome").onClick.Invoke();
  285. Assert.That(app.Saves.Current.hasRun, Is.False);
  286. yield return null;
  287. Assert.That(app.view.home.GetComponentsInChildren<TMP_Text>().Any(t => t.text.ToLowerInvariant().Contains("best")), Is.False);
  288. TapButtonLabel(endless);
  289. Assert.That(app.view.modalTitle.text, Is.EqualTo("Endless Mode"));
  290. Assert.That(app.Game.State.id, Is.Not.EqualTo(runId));
  291. Assert.That(app.Game.State.level, Is.EqualTo(1));
  292. Assert.That(app.Game.TotalScore, Is.Zero);
  293. }
  294. [UnityTest] public IEnumerator TwelveLevelUiRouteReachesEndWithoutDuplicateRewards()
  295. {
  296. yield return Begin();app.Settings.speed=20;
  297. for(int level=1;level<=12;level++){
  298. Assert.That(app.view.level.text, Is.EqualTo($"LEVEL · {level:00} / 12"));
  299. Assert.That(app.Game.State.level,Is.EqualTo(level));app.Game.State.reprieved=true;app.Game.Board.score=app.Game.State.target;app.Primary();yield return new WaitUntil(()=>!app.Busy);Assert.That(app.Game.State.stage,Is.EqualTo(Stage.Victory));Assert.That(app.Game.State.history.Count,Is.EqualTo(level));app.Primary();yield return null;
  300. if(app.Game.State.stage==Stage.Reward){ButtonAt(app.view.market,"Reward_0").onClick.Invoke();app.Primary();yield return new WaitForSecondsRealtime(.32f);}
  301. if(app.Game.State.stage==Stage.Upgrade)app.Primary();yield return null;
  302. if(app.Game.State.stage==Stage.Shop)app.Primary();yield return null;
  303. yield return null;
  304. if(app.Game.State.stage==Stage.Map)ButtonAt(app.view.modalBody,"NextFloor").onClick.Invoke();
  305. yield return new WaitUntil(()=>!app.Busy);yield return null;
  306. }
  307. Assert.That(app.Game.State.stage,Is.EqualTo(Stage.EndlessChoice));Assert.That(app.Saves.Current.hasRun,Is.True);Assert.That(app.view.modalTitle.text,Is.EqualTo("Fate, Forged."));
  308. var runId=app.Game.State.id;
  309. long total=app.Game.TotalScore;
  310. app.ShowHome();app.Continue();
  311. ButtonAt(app.view.modalBody,"ContinueEndless").onClick.Invoke();
  312. yield return AwaitPresentation(()=>!app.Busy,"Entering endless");
  313. Assert.That(app.Game.State.level,Is.EqualTo(13));
  314. Assert.That(app.Game.State.id,Is.EqualTo(runId));Assert.That(app.Game.TotalScore,Is.EqualTo(total));
  315. app.Game.State.tickets.Clear();app.Game.State.battleSpins=1;app.Game.State.target=long.MaxValue;
  316. app.Primary();yield return AwaitPresentation(()=>!app.Busy,"Revive prompt");
  317. Assert.That(app.Game.State.stage,Is.EqualTo(Stage.ReviveChoice));
  318. ButtonAt(app.view.modalBody,"WatchAd").onClick.Invoke();
  319. ButtonAt(app.view.modalBody,"NoFill").onClick.Invoke();
  320. Assert.That(app.Game.State.reviveUsed,Is.False);
  321. ButtonAt(app.view.modalBody,"WatchAd").onClick.Invoke();
  322. ButtonAt(app.view.modalBody,"CompleteAd").onClick.Invoke();
  323. yield return AwaitPresentation(()=>!app.Busy,"Reward deal");
  324. Assert.That(app.Game.State.reviveUsed);
  325. app.ShowHome();app.Continue();app.Primary();
  326. yield return AwaitPresentation(()=>app.Game.State.stage==Stage.Failed,"Second exhaustion");
  327. yield return AwaitPresentation(()=>!app.Busy,"Game over");
  328. Assert.That(app.Saves.Current.hasRun,Is.False);
  329. ButtonAt(app.view.modalBody,"PlayAgain").onClick.Invoke();
  330. Assert.That(app.Game.State.endless,Is.True);
  331. Assert.That(app.Game.TotalScore,Is.Zero);
  332. }
  333. [UnityTest] public IEnumerator PaidBurnNeedsConfirmationAndCanResumeSelection()
  334. {
  335. yield return Begin();app.Game.OpenShop();app.Game.State.coins=10;app.Game.BeginBurn();app.Save();app.Render();yield return null;Assert.That(app.Game.State.coins,Is.EqualTo(7));int id=app.Game.State.purchase.candidates[0];ButtonAt(app.view.market,"Candidate_"+id).onClick.Invoke();yield return null;app.Primary();Assert.That(app.view.marketTitle.text,Is.EqualTo("Burn This Card?"));Assert.That(app.Game.State.cards.Count,Is.EqualTo(33));ButtonAt(app.view.dock,"ChoiceBack").onClick.Invoke();app.ShowHome();app.Continue();yield return null;Assert.That(app.Game.State.purchase.selected,Is.EqualTo(id));app.Primary();yield return new WaitForSecondsRealtime(.32f);app.Primary();yield return null;Assert.That(app.Game.State.cards.Count,Is.EqualTo(32));Assert.That(app.Game.State.coins,Is.EqualTo(7));
  336. }
  337. [UnityTest] public IEnumerator OpenDrawerSurvivesJackpotAndShowsTheRunDeck()
  338. {
  339. yield return Begin(); app.Settings.speed=10;
  340. app.Game.Board.score=app.Game.State.target;
  341. app.Primary(); app.view.deck.onClick.Invoke();
  342. Assert.That(app.view.quickTitle.text,Does.StartWith("Draw pile"));
  343. yield return AwaitPresentation(()=>app.Game.State.stage==Stage.Victory && !app.Busy,"Jackpot");
  344. Assert.That(app.view.deck.gameObject.activeInHierarchy);
  345. Assert.That(app.view.quickLayer.gameObject.activeInHierarchy);
  346. Assert.That(app.view.quickTitle.text,Is.EqualTo("Run deck · "+app.Game.State.cards.Count));
  347. app.view.quickClose.onClick.Invoke(); app.Primary();
  348. Assert.That(app.Game.State.stage,Is.EqualTo(Stage.Shop));
  349. }
  350. [UnityTest] public IEnumerator TicketUseAndFailureFinishTheirPresentationsOnce()
  351. {
  352. yield return Begin();
  353. for(int i=1;i>=0;i--)
  354. {
  355. int before=app.Game.State.tickets.Count;
  356. ButtonAt(app.view.tickets,"Ticket_"+i).onClick.Invoke();
  357. var use=ButtonAt(app.view.quickBody,"Use");use.onClick.Invoke();use.onClick.Invoke();
  358. Assert.That(app.MotionPhase,Is.EqualTo("ticket"));
  359. Assert.That(app.Game.State.tickets.Count,Is.EqualTo(before-1));
  360. Assert.That(app.view.GetComponentsInChildren<TornTicket>().Length,Is.EqualTo(2));
  361. yield return AwaitPresentation(()=>!app.Busy,"ticket tear");
  362. }
  363. app.Game.State.stage=Stage.Failed;app.Render();app.Render();
  364. Assert.That(app.MotionPhase,Is.EqualTo("game-over"));Assert.That(app.view.modal.gameObject.activeSelf,Is.False);
  365. Assert.That(app.view.board.gameObject.activeInHierarchy);
  366. yield return AwaitPresentation(()=>app.view.modal.gameObject.activeSelf,"defeat dialog");
  367. app.Render();Assert.That(app.Busy,Is.False);Assert.That(app.view.modalTitle.text,Is.EqualTo("Game Over"));
  368. Assert.That(app.view.modalBody.Find("ClosingArtwork").GetComponent<Image>().sprite,Is.Not.Null);
  369. Assert.That(app.view.modalPanel.rect.width,Is.EqualTo(Mathf.Min(664,app.view.safeArea.rect.width-48)).Within(.01f));
  370. Assert.That(app.view.modalBody.Find("ClosingArtwork/TopRule"),Is.Null);
  371. Assert.That(app.view.modalBody.Find("ClosingArtwork/BottomRule"),Is.Null);
  372. Assert.That(app.view.modalBody.Find("FinalScore").GetComponent<TMP_Text>().text,Is.EqualTo(English.Number(app.Game.Board.score)));
  373. }
  374. [UnityTest] public IEnumerator LastCollectResolvesMagnetsAndScoreBeforeShowingPassiveTicket()
  375. {
  376. yield return Begin();
  377. var g=app.Game;
  378. g.State.target=long.MaxValue;g.Board.round=g.State.battleSpins;
  379. g.State.tickets=new List<Item>{Fateforge.Game.FindItem("regain_denergie"),Fateforge.Game.FindItem("free_spin")};
  380. var magnet=g.MakeMagnet("encens");magnet.charge=1;g.State.magnets.Add(magnet);
  381. app.Render();yield return null;
  382. var label=app.view.collect.GetComponentInChildren<TMP_Text>();
  383. app.Primary();Assert.That(label.text,Does.EndWith("1"));
  384. var layer=app.view.play.Find("PresentationEffects");
  385. yield return AwaitPresentation(()=>layer.Find("MagnetActivation"),"magnet name above the slot");
  386. Assert.That(layer.Find("MagnetActivation/Lettering").GetComponent<TMP_Text>().text,Does.Contain("+200"));
  387. Assert.That(g.State.tickets.Count,Is.EqualTo(2));
  388. yield return AwaitPresentation(()=>app.MotionPhase=="transfer" && app.view.score.GetComponent<RollingCounter>().IsRolling,"SCORE rolling");
  389. Assert.That(app.view.theme.scoreTick && app.view.theme.scoreImpact);
  390. Assert.That(label.text,Does.EndWith("1"));
  391. yield return AwaitPresentation(()=>app.MotionPhase=="ticket","passive ticket after score transfer");
  392. Assert.That(app.DisplayedScore,Is.EqualTo(g.Board.score).Within(.01));
  393. Assert.That(g.State.tickets.Single().id,Is.EqualTo("regain_denergie"));
  394. Assert.That(label.text,Does.EndWith("1"));Assert.That(app.Busy);
  395. app.Primary();
  396. yield return AwaitPresentation(()=>!app.Busy,"replacement deal");
  397. Assert.That(label.text,Does.EndWith("1"));
  398. }
  399. [UnityTest] public IEnumerator ScatterExpansionSlidesTheNewColumnAndPausesInPlace()
  400. {
  401. yield return Begin();
  402. var g=app.Game;int width=g.Board.width;
  403. for(int i=0;i<g.Board.cells.Count;i++)g.Board.cells[i].symbol=i<4?"clown":"citron";
  404. foreach(var card in g.Board.stock)card.symbol="cloche";
  405. app.Render();yield return null;
  406. var first=app.view.board.GetComponentsInChildren<CardView>().First(c=>c.CardId==g.Board.cells[0].id);
  407. first.Click(first.CardId,true);
  408. Assert.That(g.Board.width,Is.EqualTo(width+1));
  409. Assert.That(app.MotionPhase,Is.EqualTo("expansion"));Assert.That(app.Busy);
  410. int added=g.Board.cells[width].id;
  411. CardView entering=null;
  412. yield return AwaitPresentation(()=>{
  413. entering=app.view.board.GetComponentsInChildren<CardView>().FirstOrDefault(c=>c.CardId==added);
  414. return entering && entering.Rect.anchoredPosition.x>entering.Target.x+4;
  415. },"new reel sliding in");
  416. app.ShowHelp(0);yield return null;
  417. Vector2 paused=entering.Rect.anchoredPosition;
  418. yield return new WaitForSecondsRealtime(.12f);
  419. Assert.That(entering.Rect.anchoredPosition,Is.EqualTo(paused));
  420. app.view.modalClose.onClick.Invoke();yield return AwaitPresentation(()=>!app.Busy,"expanded deal");
  421. Assert.That(entering.Rect.anchoredPosition,Is.EqualTo(entering.Target));
  422. }
  423. [UnityTest] public IEnumerator BossPortraitLandsBelowTheRackAndOpensItsDescription()
  424. {
  425. yield return Begin();var g=app.Game;
  426. g.State.level=2;g.State.bosses[3]="flambeuse";g.OpenShop();app.Render();
  427. float start=app.Clock;
  428. app.Primary();
  429. yield return AwaitPresentation(()=>app.MotionPhase=="boss-flight","boss flight");
  430. float frameTolerance=.10f+2*Time.unscaledDeltaTime*app.Settings.speed;
  431. Assert.That(app.Clock-start,Is.EqualTo(3f).Within(frameTolerance));
  432. var dock=app.view.cabinet.Find("BossBadge") as RectTransform;
  433. Assert.That(dock.gameObject.activeSelf,Is.False);
  434. yield return AwaitPresentation(()=>dock.gameObject.activeInHierarchy,"portrait dock");
  435. var rack=app.view.magnetRack;
  436. Assert.That(dock.TransformPoint(dock.rect.center).x,Is.LessThan(rack.TransformPoint(rack.rect.center).x));
  437. Assert.That(dock.TransformPoint(new Vector2(0,dock.rect.yMax)).y,Is.LessThan(rack.TransformPoint(new Vector2(0,rack.rect.yMin)).y));
  438. dock.GetComponent<Button>().onClick.Invoke();
  439. Assert.That(app.view.quickTitle.text,Is.EqualTo(app.view.art.Name(g.Boss)));
  440. Assert.That(app.view.quickBody.Find("Description").GetComponent<TMP_Text>().text,Is.EqualTo(app.view.art.Description(g.Boss)));
  441. app.view.quickClose.onClick.Invoke();app.ShowHome();app.Continue();
  442. Assert.That(dock.gameObject.activeInHierarchy);
  443. }
  444. [UnityTest] public IEnumerator MarketResellsOwnedTicketsAndMagnetsExactlyOnceAndProtectsSkills()
  445. {
  446. yield return Begin();
  447. var g=app.Game;g.OpenShop();
  448. var magnet=g.MakeMagnet("eventail");g.State.magnets.Add(magnet);
  449. var ticket=g.State.tickets[0];int balance=g.State.coins;
  450. app.Render();yield return null;
  451. ButtonAt(app.view.dock,"Sell").onClick.Invoke();yield return null;
  452. ButtonAt(app.view.tricks,"Trick_swap").onClick.Invoke();
  453. Assert.That(app.view.quickBody.GetComponentsInChildren<Button>().Any(b=>b.name=="Sell"),Is.False);
  454. app.view.quickClose.onClick.Invoke();
  455. foreach(var pair in new[]{(app.view.magnetRack,"Magnet_0",magnet),(app.view.tickets,"Ticket_0",ticket)})
  456. {
  457. ButtonAt(pair.Item1,pair.Item2).onClick.Invoke();
  458. var confirm=ButtonAt(app.view.quickBody,"Sell");
  459. confirm.onClick.Invoke();confirm.onClick.Invoke();yield return null;
  460. balance+=Fateforge.Game.SalePrice(pair.Item3);
  461. Assert.That(g.State.coins,Is.EqualTo(balance));
  462. }
  463. app.ShowHome();app.Continue();
  464. Assert.That(app.Game.State.coins,Is.EqualTo(balance));
  465. Assert.That(app.Game.State.magnets.Any(m=>m.id==magnet.id),Is.False);
  466. Assert.That(app.Game.State.tricks.Count,Is.EqualTo(2));
  467. }
  468. [UnityTest] public IEnumerator SwapOnlyHighlightsTheChosenCardAndClearsOnCollect()
  469. {
  470. yield return Begin();
  471. var g=app.Game;var deck=app.view.board.GetComponentsInChildren<CardView>();
  472. var first=deck.First(c=>c.CardId==g.Board.cells[0].id);
  473. var near=deck.First(c=>c.CardId==g.Board.cells[1].id);
  474. var far=deck.First(c=>c.CardId==g.Board.cells[3].id);
  475. var normalMaterial=near.symbol.material;
  476. var normalColor=near.symbol.color;
  477. var normalValue=near.value.color;
  478. ButtonAt(app.view.tricks,"Trick_swap").onClick.Invoke();yield return null;
  479. var orb=app.view.tricks.Find("Trick_swap/Activated");Assert.That(orb.gameObject.activeSelf);
  480. first.Click(first.CardId,false);yield return null;
  481. Assert.That(first.transform.Find("SelectedCard").gameObject.activeSelf);
  482. foreach(var other in new[]{near,far}){
  483. Assert.That(other.symbol.material,Is.SameAs(normalMaterial));
  484. Assert.That(other.symbol.color,Is.EqualTo(normalColor));
  485. Assert.That(other.value.color,Is.EqualTo(normalValue));
  486. Assert.That(other.transform.Find("SelectedCard"),Is.Null);
  487. }
  488. app.Primary();yield return null;
  489. Assert.That(first.transform.Find("SelectedCard").gameObject.activeSelf,Is.False);
  490. Assert.That(orb.gameObject.activeSelf,Is.False);
  491. Assert.That(near.symbol.material,Is.SameAs(normalMaterial));
  492. }
  493. [UnityTest] public IEnumerator MarketServicesAndPaidChoicesUseTheConsole()
  494. {
  495. yield return Begin();app.Game.OpenShop();app.Game.State.coins=30;app.Render();yield return null;
  496. Assert.That(ButtonAt(app.view.dock,"Sell").interactable);
  497. Assert.That(app.view.tricks.GetComponentsInChildren<Button>().Length,Is.EqualTo(2));
  498. Assert.That(app.view.coins.fontSizeMax,Is.GreaterThanOrEqualTo(38));
  499. foreach(int family in new[]{-1,1})
  500. {
  501. app.Game.State.shop.special[0]=new Item{kind="elixir",symbol="citron",family=family,amount=.2,price=3};
  502. app.Render();yield return null;
  503. var offer=app.view.market.Find("SpecialSlot_0").GetComponent<OfferView>();
  504. if(family<0)Assert.That(offer.charge.sprite,Is.SameAs(app.view.art.Sprite("citron")));
  505. else Assert.That(offer.GetComponentsInChildren<UiGlyph>().Any(g=>g.name=="ElixirDirection" && g.shape==UiGlyph.Shape.Vertical));
  506. }
  507. var locked=app.view.market.Find("MarketSlot_3").GetComponent<OfferView>();
  508. Assert.That(locked.icon.sprite,Is.SameAs(app.view.theme.unlockSprite));
  509. locked.buy.onClick.Invoke();yield return null;Assert.That(app.Game.State.coinSlot);
  510. var refresh=app.view.market.Find("Refresh").GetComponent<OfferView>();
  511. Assert.That(refresh.icon.sprite,Is.SameAs(app.view.theme.rerollSprite));
  512. refresh.buy.onClick.Invoke();yield return null;Assert.That(app.Game.State.shop.rerolls,Is.EqualTo(1));
  513. ButtonAt(app.view.market.Find("SpecialSlot_1"),"Buy").onClick.Invoke();yield return null;
  514. int paid=app.Game.State.coins;
  515. Assert.That(app.view.collect.interactable,Is.False);
  516. ButtonAt(app.view.market,"Choose_1").onClick.Invoke();
  517. ButtonAt(app.view.dock,"ChoiceBack").onClick.Invoke();
  518. Assert.That(app.view.marketTitle.text,Is.EqualTo(EnglishCopy.SkipThisPurchase));
  519. ButtonAt(app.view.dock,"ChoiceBack").onClick.Invoke();
  520. Assert.That(app.view.collect.interactable);
  521. app.Primary();app.Primary();Assert.That(app.Game.State.stage,Is.EqualTo(Stage.Shop));
  522. Assert.That(app.Game.State.coins,Is.EqualTo(paid));
  523. yield return new WaitForSecondsRealtime(.32f);
  524. app.Game.State.shop.shelf[0]=Fateforge.Game.FindItem("super_carte");app.Render();yield return null;
  525. ButtonAt(app.view.market.Find("MarketSlot_0"),"Buy").onClick.Invoke();yield return null;
  526. int id=app.Game.State.purchase.candidates[0];
  527. ButtonAt(app.view.market,"Candidate_"+id).onClick.Invoke();app.Primary();
  528. Assert.That(app.Game.State.cards.First(c=>c.id==id).sticker,Is.EqualTo("super_carte"));
  529. }
  530. [UnityTest] public IEnumerator SkippingPaidElixirsKeepsPaymentAndShopOffers()
  531. {
  532. yield return Begin();app.Game.OpenShop();app.Game.State.coins=20;app.Render();yield return null;
  533. ButtonAt(app.view.market.Find("SpecialSlot_1"),"Buy").onClick.Invoke();
  534. int paid=app.Game.State.coins;
  535. string[] choices=app.Game.State.purchase.choices.Select(c=>c.id).ToArray();
  536. app.ShowHome();app.Continue();yield return null;
  537. Assert.That(app.Game.State.purchase.choices.Select(c=>c.id),Is.EqualTo(choices));
  538. ButtonAt(app.view.dock,"ChoiceBack").onClick.Invoke();
  539. app.Primary();app.Primary();
  540. Assert.That(app.Game.State.stage,Is.EqualTo(Stage.Shop));
  541. Assert.That(app.Game.State.coins,Is.EqualTo(paid));Assert.That(app.Game.State.shop.special[1].sold);
  542. }
  543. [UnityTest] public IEnumerator EndlessLevelRollsTheExactTotalAfterScoreIncludingOnResume()
  544. {
  545. app.PrepareRun(42, endless:true);
  546. Assert.That(app.view.level.text, Is.EqualTo("Total Score: 0"));
  547. app.Settings.speed = 4;
  548. app.StartRun();
  549. yield return AwaitPresentation(() => !app.Busy, "first endless deal");
  550. var game = app.Game;
  551. for (int i = 0; i < game.Board.cells.Count; i++) game.Board.cells[i].symbol = Game.Reference[i];
  552. long gain = game.PlanSettlement().total;
  553. Assert.That(gain, Is.GreaterThan(0));
  554. const long finalTotal = long.MaxValue - 2; // Not exactly representable as a double.
  555. game.State.clearedScore = finalTotal - gain;
  556. game.State.target = long.MaxValue;
  557. string before = "Total Score: " + English.Number(game.TotalScore);
  558. string after = "Total Score: " + English.Number(finalTotal);
  559. app.Render();
  560. Assert.That(app.view.level.text, Is.EqualTo(before));
  561. app.Primary();
  562. var score = app.view.score.GetComponent<RollingCounter>();
  563. var total = app.view.level.GetComponent<RollingCounter>();
  564. for (int pass = 0; pass < 2; pass++)
  565. {
  566. Assert.That(app.Game.TotalScore, Is.EqualTo(finalTotal));
  567. Assert.That(app.view.level.text, Is.EqualTo(before));
  568. yield return AwaitPresentation(() => score.IsRolling, "level score roll");
  569. while (score.IsRolling)
  570. {
  571. Assert.That(total.IsRolling, Is.False);
  572. Assert.That(app.view.level.text, Is.EqualTo(before));
  573. yield return null;
  574. }
  575. yield return AwaitPresentation(() => total.IsRolling, "run total roll");
  576. Assert.That(app.view.score.text, Is.EqualTo(English.Number(gain)));
  577. Assert.That(app.view.level.text, Is.EqualTo(after));
  578. var fixedGlyphs = app.view.level.transform.Find("CounterPunctuation").GetComponentsInChildren<TMP_Text>();
  579. Assert.That(string.Concat(fixedGlyphs.Select(glyph => glyph.text)), Does.StartWith("Total Score: "));
  580. Assert.That(app.view.level.isTextTruncated, Is.False);
  581. Assert.That(app.view.level.textInfo.lineCount, Is.EqualTo(1));
  582. if (pass == 0)
  583. {
  584. app.ShowHome();
  585. Assert.That(total.IsRolling, Is.False);
  586. app.Continue();
  587. }
  588. }
  589. yield return AwaitPresentation(() => !app.Busy, "next endless round");
  590. Assert.That(total.IsRolling, Is.False);
  591. Assert.That(app.Game.Board.round, Is.EqualTo(2));
  592. Assert.That(app.view.level.text, Is.EqualTo(after));
  593. }
  594. [UnityTest] public IEnumerator SettlementMotionPausesAndTransfersCommittedBossScoreOnlyOnce()
  595. {
  596. yield return Begin();
  597. // The reprieve changes the committed score independently of the formula total.
  598. app.Game.State.bosses[app.Game.State.level]="flambeuse";app.Game.State.target=100;app.Game.Board.score=80;app.Render();
  599. Assert.That(app.Game.PlanSettlement().total,Is.GreaterThan(20));
  600. app.Primary();long committed=app.Game.Board.score;int coins=app.Game.State.coins;
  601. Assert.That(committed,Is.EqualTo(50));Assert.That(app.DisplayedScore,Is.EqualTo(80).Within(.01));Assert.That(app.Busy,Is.True);
  602. app.Primary();app.view.collect.onClick.Invoke();
  603. Assert.That(app.Game.Board.score,Is.EqualTo(committed));Assert.That(app.Game.State.coins,Is.EqualTo(coins));
  604. yield return new WaitForSecondsRealtime(.08f);app.ShowHelp(0);yield return null;
  605. string phase=app.MotionPhase;double score=app.DisplayedScore,total=app.DisplayedPreviewTotal;
  606. yield return new WaitForSecondsRealtime(.18f);
  607. Assert.That(app.MotionPhase,Is.EqualTo(phase));Assert.That(app.DisplayedScore,Is.EqualTo(score).Within(.01));Assert.That(app.DisplayedPreviewTotal,Is.EqualTo(total).Within(.01));
  608. app.view.modalClose.onClick.Invoke();yield return AwaitPresentation(()=>!app.Busy,"paused settlement and next deal");
  609. Assert.That(app.Game.Board.score,Is.EqualTo(committed));Assert.That(app.DisplayedScore,Is.EqualTo(committed).Within(.01));Assert.That(app.Game.Board.round,Is.EqualTo(2));Assert.That(app.Game.State.coins,Is.EqualTo(coins));
  610. }
  611. [UnityTest] public IEnumerator DiscardInterruptsMatchPreviewWithoutStaleGroupsOrNumbers()
  612. {
  613. yield return Begin();var original=app.Game.Preview();Assert.That(original.matches.Count,Is.GreaterThan(0));int index=original.matches[0].cells[0],id=app.Game.Board.cells[index].id;
  614. ButtonAt(app.view.tricks,"Trick_discard").onClick.Invoke();
  615. var card=app.view.board.GetComponentsInChildren<CardView>().First(c=>c.CardId==id);card.Click(id,false);yield return null;
  616. Assert.That(app.Game.Board.cells.Any(c=>c.id==id),Is.False);Assert.That(app.Busy,Is.False,"Preview must not lock another board action.");
  617. var current=app.Game.Preview();
  618. yield return AwaitPresentation(()=>app.PresentationGroupCount==current.matches.Count&&System.Math.Abs(app.DisplayedPreviewTotal-current.preview)<.01,"fresh preview after discard");
  619. yield return new WaitForSecondsRealtime(.15f);
  620. Assert.That(app.PresentationGroupCount,Is.EqualTo(current.matches.Count));Assert.That(app.DisplayedPreviewTotal,Is.EqualTo(current.preview).Within(.01));
  621. long before=app.Game.Board.score,expected=app.Game.PlanSettlement().total;
  622. app.Primary();Assert.That(app.Game.Board.operation,Is.Empty);long committed=app.Game.Board.score;Assert.That(committed,Is.EqualTo(before+expected));
  623. app.Primary();yield return AwaitPresentation(()=>!app.Busy,"collection after preview interruption");
  624. Assert.That(app.Game.Board.score,Is.EqualTo(committed));Assert.That(app.DisplayedScore,Is.EqualTo(committed).Within(.01));
  625. }
  626. [UnityTest] public IEnumerator RollingScoreClipsDigitsAboveCommaAndRestoresLabelAfterFinishOrCancel()
  627. {
  628. yield return Begin();var label=app.view.score;var counter=RollingCounter.Attach(label);Color original=label.color;
  629. counter.Begin(0,2363,false);counter.Sample(.2f);
  630. var digits=(RectTransform)label.transform.Find("RollingDigits");var punctuation=label.transform.Find("CounterPunctuation");
  631. Assert.That(counter.IsRolling,Is.True);Assert.That(label.color.a,Is.Zero);Assert.That(punctuation.parent,Is.EqualTo(label.transform));
  632. Assert.That(digits.GetComponentsInChildren<TMP_Text>().All(t=>t.text.Length==1&&char.IsDigit(t.text[0])),Is.True,"Only moving digits belong inside the numeric mask.");
  633. var comma=punctuation.GetComponentsInChildren<TMP_Text>().Single(t=>t.text==",");Vector2 commaPosition=comma.rectTransform.anchoredPosition;
  634. var commaInfo=label.textInfo.characterInfo.First(c=>c.character==',');var commaMetrics=commaInfo.textElement.glyph.metrics;
  635. float commaBottom=commaInfo.baseLine+(commaMetrics.horizontalBearingY-commaMetrics.height)*commaInfo.scale;
  636. float clipBottom=digits.rect.yMin+digits.GetComponent<RectMask2D>().padding.y;
  637. Assert.That(clipBottom,Is.GreaterThan(commaBottom+1),"A comma descender must not let rolling digits descend onto the score frame.");
  638. var moving=digits.GetComponentsInChildren<TMP_Text>().First();Vector2 digitPosition=moving.rectTransform.anchoredPosition;
  639. counter.Sample(.61f);
  640. Assert.That(comma.rectTransform.anchoredPosition,Is.EqualTo(commaPosition));Assert.That(comma.text,Is.EqualTo(","));
  641. Assert.That(moving.rectTransform.anchoredPosition,Is.Not.EqualTo(digitPosition));
  642. counter.Finish();Assert.That(counter.IsRolling,Is.False);Assert.That(label.text,Is.EqualTo("2,363"));Assert.That(label.color,Is.EqualTo(original));
  643. Assert.That(digits.gameObject.activeSelf,Is.False);Assert.That(punctuation.gameObject.activeSelf,Is.False);
  644. counter.Begin(2363,-2363,false);counter.Sample(.4f);
  645. Assert.That(punctuation.GetComponentsInChildren<TMP_Text>().Select(t=>t.text),Is.EquivalentTo(new[]{"-",","}));
  646. counter.Cancel(17);Assert.That(counter.IsRolling,Is.False);Assert.That(label.text,Is.EqualTo("17"));Assert.That(label.color,Is.EqualTo(original));
  647. Assert.That(digits.gameObject.activeSelf,Is.False);Assert.That(punctuation.gameObject.activeSelf,Is.False);
  648. Assert.That(label.GetComponentsInChildren<TMP_Text>().Length,Is.EqualTo(1),"Cancel must leave only the restored original label visible.");
  649. }
  650. [UnityTest] public IEnumerator ReloadingSettlementReplaysMotionWithoutRepeatingScoreOrRewards()
  651. {
  652. yield return Begin();
  653. int startingCoins = app.Game.State.coins;
  654. var goldMagnet = app.Game.MakeMagnet("ticket_or");
  655. goldMagnet.charge = 1;
  656. app.Game.State.magnets.Add(goldMagnet);
  657. foreach (var card in app.Game.State.cards) card.sticker = "carte_doree";
  658. app.Game.State.target=1;app.Primary();
  659. Assert.That(app.Game.State.stage,Is.EqualTo(Stage.Settlement));long committed=app.Game.Board.score;int coins=app.Game.State.coins,history=app.Game.State.history.Count;string runId=app.Game.State.id;
  660. Assert.That(coins, Is.GreaterThan(startingCoins + app.Game.State.reward.Total));
  661. Assert.That(app.view.coins.text, Is.EqualTo(English.Number(startingCoins)));
  662. Assert.That(history,Is.EqualTo(1));app.Save();
  663. yield return SceneManager.LoadSceneAsync("Assets/Fateforge/Scenes/FateforgeMain.unity");yield return null;
  664. app=Object.FindFirstObjectByType<FateforgeApp>();app.Settings.music=false;app.Settings.sound=false;app.Settings.speed=2;
  665. Assert.That(app.Saves.Current.run.id,Is.EqualTo(runId));Assert.That(app.Saves.Current.run.stage,Is.EqualTo(Stage.Settlement));Assert.That(app.Saves.Current.run.board.score,Is.EqualTo(committed));
  666. app.Continue();app.Primary();
  667. var counter = app.view.coins.GetComponent<RollingCounter>();
  668. yield return AwaitPresentation(() => app.Game.State.stage == Stage.Victory, "Jackpot reveal");
  669. for (int replay = 0; replay < 2; replay++)
  670. {
  671. Assert.That(counter.IsRolling, Is.False);
  672. Assert.That(app.view.coins.text, Is.EqualTo(English.Number(startingCoins)));
  673. yield return AwaitPresentation(() => counter.IsRolling, "purse starts rolling");
  674. var lastAmount = app.view.market.Find("RewardRow_2/Amount");
  675. Assert.That(lastAmount.localScale, Is.EqualTo(Vector3.one));
  676. Assert.That(lastAmount.Find("Count").GetComponent<TMP_Text>().text, Is.EqualTo(English.Number(app.Game.State.reward.excess)));
  677. app.Primary();
  678. Assert.That(app.Game.State.stage, Is.EqualTo(Stage.Victory));
  679. if (replay == 0)
  680. {
  681. app.ShowHome();
  682. app.Continue();
  683. }
  684. }
  685. yield return AwaitPresentation(()=>!app.Busy,"resumed payout");
  686. Assert.That(counter.IsRolling, Is.False);
  687. Assert.That(app.view.coins.text, Is.EqualTo(English.Number(coins)));
  688. Assert.That(app.Game.State.stage,Is.EqualTo(Stage.Victory));Assert.That(app.Game.Board.score,Is.EqualTo(committed));Assert.That(app.DisplayedScore,Is.EqualTo(committed).Within(.01));Assert.That(app.Game.State.coins,Is.EqualTo(coins));Assert.That(app.Game.State.history.Count,Is.EqualTo(history));
  689. }
  690. }
  691. }