| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714 |
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using NUnit.Framework;
- using TMPro;
- using UnityEngine;
- using UnityEngine.EventSystems;
- using UnityEngine.SceneManagement;
- using UnityEngine.TestTools;
- using UnityEngine.UI;
- namespace Fateforge.Tests
- {
- public sealed class PortraitTests
- {
- FateforgeApp app;
- [UnitySetUp] public IEnumerator Setup()
- {
- FateforgeApp.ValidationSession=true;
- yield return SceneManager.LoadSceneAsync("Assets/Fateforge/Scenes/FateforgeMain.unity");yield return null;
- app=Object.FindFirstObjectByType<FateforgeApp>();Assert.That(app,Is.Not.Null);app.Settings.music=false;app.Settings.sound=false;app.Settings.speed=2;
- Assert.That(Object.FindObjectsByType<AudioListener>(FindObjectsSortMode.None).Count(a=>a.isActiveAndEnabled),Is.EqualTo(1));
- }
- [UnityTearDown] public IEnumerator Cleanup(){FateforgeApp.ValidationSession=false;app.ShowHome();yield return null;}
- IEnumerator Begin(){app.PrepareRun(42);app.StartRun();yield return new WaitUntil(()=>!app.Busy);yield return null;}
- static IEnumerator AwaitPresentation(System.Func<bool> completed,string description,float timeout=15)
- {
- float deadline=Time.realtimeSinceStartup+timeout;
- while(!completed()&&Time.realtimeSinceStartup<deadline)yield return null;
- Assert.That(completed(),Is.True,"Presentation timed out: "+description);
- }
- static Button ButtonAt(Transform root,string name)=>root.GetComponentsInChildren<Button>(true).First(b=>b.name==name&&b.gameObject.activeInHierarchy);
- static void TapButtonLabel(Button button)
- {
- Canvas.ForceUpdateCanvases();
- var label = button.GetComponentInChildren<TMP_Text>().rectTransform;
- var events = EventSystem.current;
- var pointer = new PointerEventData(events){
- position = RectTransformUtility.WorldToScreenPoint(null, label.TransformPoint(label.rect.center))
- };
- var hits = new List<RaycastResult>();
- events.RaycastAll(pointer, hits);
- Assert.That(hits, Is.Not.Empty, "No UI hit at " + button.name + " label " + pointer.position);
- var pressed = ExecuteEvents.ExecuteHierarchy(hits[0].gameObject, pointer, ExecuteEvents.pointerDownHandler);
- Assert.That(pressed, Is.EqualTo(button.gameObject));
- ExecuteEvents.Execute(pressed, pointer, ExecuteEvents.pointerUpHandler);
- ExecuteEvents.Execute(pressed, pointer, ExecuteEvents.pointerClickHandler);
- }
- IEnumerator TapModalButton(string name)
- {
- // Let the newly opened panel participate in the next UI raycast.
- yield return null;
- TapButtonLabel(ButtonAt(app.view.modalBody, name));
- }
- [UnityTest] public IEnumerator EveryHomeButtonOpensItsScreenImmediatelyAfterLaunch()
- {
- var buttons = new[] {app.view.normalRun, app.view.homeSettings, app.view.homeHelp,
- app.view.leaderboard, app.view.endlessRun};
- bool replacingNormal = app.Saves.Current.hasRun && !app.Saves.Current.run.endless;
- string[] titles = {"Normal Mode", "Settings", "Help", "Leaderboard",
- replacingNormal ? "Start Endless Mode?" : "Endless Mode"};
- for (int i = 0; i < buttons.Length; i++)
- {
- TapButtonLabel(buttons[i]);
- Assert.That(app.view.modal.gameObject.activeInHierarchy, Is.True, buttons[i].name);
- Assert.That(app.view.modalTitle.text, Is.EqualTo(titles[i]), buttons[i].name);
- app.ShowHome();
- yield return null;
- }
- }
- [UnityTest] public IEnumerator HiddenLeverAndSegmentedSettingsPreserveGameState()
- {
- app.ShowHome();app.view.homeSettings.onClick.Invoke();yield return null;
- Assert.That(app.view.home.gameObject.activeInHierarchy,Is.True,"Settings must preserve the menu behind the dimmer.");
- Assert.That(app.view.modal.GetComponent<Image>().color.a,Is.InRange(.3f,.85f));
- 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);
- 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.");
- ButtonAt(app.view.modalBody,"Music_0").onClick.Invoke();yield return null;Assert.That(app.Settings.music,Is.True);
- ButtonAt(app.view.modalBody,"Music_1").onClick.Invoke();yield return null;Assert.That(app.Settings.music,Is.False);
- ButtonAt(app.view.modalBody,"AnimationSpeed_0").onClick.Invoke();yield return null;Assert.That(app.Settings.speed,Is.EqualTo(1));
- ButtonAt(app.view.modalBody,"AnimationSpeed_1").onClick.Invoke();yield return null;Assert.That(app.Settings.speed,Is.EqualTo(2));
- ButtonAt(app.view.modalBody,"Resume").onClick.Invoke();Assert.That(app.view.home.gameObject.activeSelf,Is.True);
- 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);
- yield return Begin();Assert.That(app.view.collectLever.lever.gameObject.activeInHierarchy,Is.False);
- 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)));}
- 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);
- }
- [UnityTest] public IEnumerator CarnivalGlyphsRenderInBattleAndMarket()
- {
- yield return Begin();
- var cards=app.view.board.GetComponentsInChildren<CardView>();
- Assert.That(cards.Length,Is.EqualTo(12));
- foreach(var card in cards){Assert.That(card.outline,Is.Not.Null);card.outline.enabled=true;card.outline.color=Color.yellow;}
- Canvas.ForceUpdateCanvases();yield return null;
- foreach(var glyph in app.view.GetComponentsInChildren<UiGlyph>(true)){
- Assert.That(glyph.GetComponent<CanvasRenderer>(),Is.Not.Null,glyph.name);
- if(glyph.gameObject.activeInHierarchy&&glyph.enabled){var mesh=glyph.canvasRenderer.GetMesh();Assert.That(mesh.vertexCount,Is.GreaterThan(0),glyph.name);Object.Destroy(mesh);}
- }
- app.Game.OpenShop();app.Render();yield return null;Canvas.ForceUpdateCanvases();
- var prices=app.view.market.GetComponentsInChildren<Image>().Where(g=>g.sprite==app.view.theme.coinSprite && g.name=="PriceCoin").ToArray();
- Assert.That(prices.Length,Is.GreaterThan(0));
- foreach(var price in prices)Assert.That(price.GetComponent<CanvasRenderer>(),Is.Not.Null,price.name);
- }
- [UnityTest] public IEnumerator HomeLoadoutAndAllHelpEntriesAreAvailable()
- {
- 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;
- Assert.That(app.view.modalBody.GetComponentsInChildren<Button>().Count(b=>b.name.StartsWith("HelpTab_")),Is.EqualTo(2));
- foreach(var id in Fateforge.Game.StartingTricks)
- Assert.That(app.view.modalBody.Find("GuideList/Viewport/Content/SkillDescription_"+id).GetComponent<TMP_Text>().text,Is.EqualTo(app.view.art.Description(id)));
- 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));
- }
- [UnityTest] public IEnumerator ReelsStopAndPreviewDoesNotBlockDiscardOrCollection()
- {
- 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);
- Assert.That(card.transform.Find("SelectedCard").gameObject.activeSelf);
- 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));
- }
- [UnityTest] public IEnumerator TooltipDismissalConsumesTapAndModalBlocksBattle()
- {
- 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;
- }
- [UnityTest] public IEnumerator RewardedSlotCanUnlockBeforeCoinSlotAndSurvivesContinue()
- {
- 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));
- }
- [UnityTest] public IEnumerator MarketAdWaitCanBeCancelledAndRetriedWhenReady()
- {
- yield return Begin();
- app.Game.OpenShop();
- app.Render();
- yield return null;
- var ads = (SimulatedAdService)app.Ads;
- ads.Available = false;
- var watch = ButtonAt(app.view.market.Find("MarketSlot_4"), "Buy");
- TapButtonLabel(watch);
- yield return TapModalButton("CancelAdWait");
- ads.Available = true;
- yield return new WaitForSecondsRealtime(.35f);
- Assert.That(ads.Pending, Is.Null);
- Assert.That(app.view.modal.gameObject.activeSelf, Is.False);
- Assert.That(app.Game.State.adSlot, Is.False);
- ads.Available = false;
- TapButtonLabel(watch);
- yield return AwaitPresentation(() => app.view.modalBody.Find("RetryAd"), "market ad timeout");
- yield return TapModalButton("RetryAd");
- Assert.That(ButtonAt(app.view.modalBody, "CancelAdWait"), Is.Not.Null);
- ads.Available = true;
- yield return AwaitPresentation(() => ads.Pending != null, "delayed ad readiness");
- Assert.That(ads.Pending.purpose, Is.EqualTo(AdPurpose.ShopSlot));
- yield return TapModalButton("FailAd");
- Assert.That(app.Game.State.adSlot, Is.False);
- yield return TapModalButton("RetryAd");
- yield return TapModalButton("CompleteAd");
- Assert.That(app.Game.State.adSlot, Is.True);
- Assert.That(app.Busy, Is.False);
- }
- [UnityTest] public IEnumerator CancellingAnEndlessAdWaitRestoresEndRunChoice()
- {
- yield return Begin();
- app.Game.State.endless = true;
- app.Game.State.stage = Stage.ReviveChoice;
- app.Render();
- ((SimulatedAdService)app.Ads).Available = false;
- yield return TapModalButton("WatchAd");
- yield return TapModalButton("CancelAdWait");
- Assert.That(app.Game.State.reviveUsed, Is.False);
- yield return TapModalButton("EndRun");
- Assert.That(app.Game.State.stage, Is.EqualTo(Stage.Failed));
- yield return null;
- }
- [UnityTest] public IEnumerator CloudConflictDialogUsesOneCompleteRecordFromHome()
- {
- 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));
- }
- [UnityTest] public IEnumerator ScatterDoubleTapWorksAndTicketTooltipStaysInSafeArea()
- {
- 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));
- }
- [UnityTest] public IEnumerator NormalModeOffersContinueOrNewGameFromHome()
- {
- // Start with an empty slot in the validation profile.
- app.PrepareRun(42);
- app.Game.State.stage = Stage.Failed;
- app.Save();
- app.ShowHome();
- yield return null;
- Assert.That(app.Saves.Current.hasRun, Is.False);
- Assert.That(app.view.home.Find("Buttons/Continue"), Is.Null);
- var normal = ButtonAt(app.view.home, "NormalMode");
- Assert.That(normal.GetComponentInChildren<TMP_Text>().text, Is.EqualTo("Normal Mode"));
- TapButtonLabel(normal);
- Assert.That(app.view.modalTitle.text, Is.EqualTo("Normal Mode"));
- Assert.That(ButtonAt(app.view.modalBody, "Continue").interactable, Is.False);
- ButtonAt(app.view.modalBody, "NewGame").onClick.Invoke();
- Assert.That(app.Game.State.endless, Is.False);
- Assert.That(app.Game.State.stage, Is.EqualTo(Stage.Ready));
- string runId = app.Game.State.id;
- app.Game.OpenShop();
- app.Game.State.coins = 31;
- app.Save();
- app.ShowHome();
- yield return null;
- TapButtonLabel(normal);
- app.view.modalClose.onClick.Invoke();
- Assert.That(app.Saves.Current.run.id, Is.EqualTo(runId));
- yield return null;
- TapButtonLabel(normal);
- yield return null;
- TapButtonLabel(ButtonAt(app.view.modalBody, "Continue"));
- Assert.That(app.Game.State.id, Is.EqualTo(runId));
- Assert.That(app.Game.State.stage, Is.EqualTo(Stage.Shop));
- Assert.That(app.Game.State.coins, Is.EqualTo(31));
- app.ShowHome();
- yield return null;
- TapButtonLabel(normal);
- yield return null;
- TapButtonLabel(ButtonAt(app.view.modalBody, "NewGame"));
- Assert.That(app.Game.State.id, Is.Not.EqualTo(runId));
- Assert.That(app.Game.State.endless, Is.False);
- Assert.That(app.Game.State.level, Is.EqualTo(1));
- Assert.That(app.Game.State.stage, Is.EqualTo(Stage.Ready));
- }
- [UnityTest] public IEnumerator HomeStartsEndlessAtOneAndShowsTheBestOnlyAfterEndingTheRun()
- {
- app.Settings.speed = 20;
- app.PrepareRun(42);
- string normalRun = app.Game.State.id;
- app.ShowHome();
- var endless = ButtonAt(app.view.home, "EndlessMode");
- Assert.That(endless.GetComponentInChildren<TMP_Text>().text, Is.EqualTo("Endless Mode"));
- Assert.That(app.view.leaderboard.GetComponentInChildren<TMP_Text>().text, Is.EqualTo("Leaderboard"));
- var saveStatus = app.view.saveStatus.text;
- TapButtonLabel(app.view.leaderboard);
- Assert.That(app.view.modalTitle.text, Is.EqualTo("Leaderboard"));
- Assert.That(app.view.saveStatus.text, Is.EqualTo(saveStatus));
- yield return null;
- TapButtonLabel(ButtonAt(app.view.modalBody, "Dismiss"));
- yield return null;
- TapButtonLabel(endless);
- Assert.That(app.view.modalTitle.text, Is.EqualTo("Start Endless Mode?"));
- Assert.That(app.view.saveStatus.text, Is.EqualTo(saveStatus));
- ButtonAt(app.view.modalBody, "Cancel").onClick.Invoke();
- Assert.That(app.Saves.Current.run.id, Is.EqualTo(normalRun));
- endless.onClick.Invoke();
- ButtonAt(app.view.modalBody, "Confirm").onClick.Invoke();
- Assert.That(app.Game.State.endless, Is.True);
- Assert.That(app.Game.State.level, Is.EqualTo(1));
- Assert.That(app.Game.TotalScore, Is.Zero);
- Assert.That(app.Game.State.id, Is.Not.EqualTo(normalRun));
- Assert.That(app.view.modalTitle.text, Is.EqualTo("Endless Mode"));
- string runId = app.Game.State.id;
- app.ShowHome();
- yield return null;
- TapButtonLabel(app.view.normalRun);
- Assert.That(ButtonAt(app.view.modalBody, "Continue").interactable, Is.False);
- Assert.That(app.view.modalBody.Find("Description").GetComponent<TMP_Text>().text, Does.Contain("Endless Mode"));
- app.view.modalClose.onClick.Invoke();
- yield return null;
- TapButtonLabel(endless);
- ButtonAt(app.view.modalBody, "Continue").onClick.Invoke();
- Assert.That(app.Game.State.id, Is.EqualTo(runId));
- ButtonAt(app.view.modalBody, "Start").onClick.Invoke();
- yield return AwaitPresentation(() => !app.Busy, "first endless deal");
- var directory = System.IO.Path.Combine(FateforgeApp.SaveDirectory, "Validation");
- app.Game.State.leaderboardPlayer = runId;
- app.Game.Board.score = 50;
- app.Save();
- Assert.That(new EndlessRecords(directory).Pending(runId), Is.Zero);
- app.Game.State.tickets.Clear();
- app.Game.State.battleSpins = 1;
- app.Game.State.target = long.MaxValue;
- app.Primary();
- yield return AwaitPresentation(() => !app.Busy, "revive choice");
- Assert.That(app.Game.State.stage, Is.EqualTo(Stage.ReviveChoice));
- Assert.That(app.view.modalBody.Find("PersonalBest"), Is.Null);
- Assert.That(new EndlessRecords(directory).Pending(runId), Is.Zero);
- ButtonAt(app.view.modalBody, "EndRun").onClick.Invoke();
- yield return AwaitPresentation(() => app.view.modalBody.Find("PersonalBest") != null, "endless results");
- var records = new EndlessRecords(directory);
- long best = records.Best(runId);
- Assert.That(best, Is.EqualTo(app.Game.TotalScore));
- Assert.That(records.Pending(runId), Is.EqualTo(best));
- Assert.That(app.view.modalBody.Find("FinalScore").GetComponent<TMP_Text>().text, Is.EqualTo(English.Number(app.Game.TotalScore)));
- Assert.That(app.view.modalBody.Find("PersonalBest").GetComponent<TMP_Text>().text, Does.EndWith(English.Number(best)));
- ButtonAt(app.view.modalBody, "ReturnHome").onClick.Invoke();
- Assert.That(app.Saves.Current.hasRun, Is.False);
- yield return null;
- Assert.That(app.view.home.GetComponentsInChildren<TMP_Text>().Any(t => t.text.ToLowerInvariant().Contains("best")), Is.False);
- TapButtonLabel(endless);
- Assert.That(app.view.modalTitle.text, Is.EqualTo("Endless Mode"));
- Assert.That(app.Game.State.id, Is.Not.EqualTo(runId));
- Assert.That(app.Game.State.level, Is.EqualTo(1));
- Assert.That(app.Game.TotalScore, Is.Zero);
- }
- [UnityTest] public IEnumerator TwelveLevelUiRouteReachesEndWithoutDuplicateRewards()
- {
- yield return Begin();app.Settings.speed=20;
- for(int level=1;level<=12;level++){
- Assert.That(app.view.level.text, Is.EqualTo($"LEVEL · {level:00} / 12"));
- 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;
- if(app.Game.State.stage==Stage.Reward){ButtonAt(app.view.market,"Reward_0").onClick.Invoke();app.Primary();yield return new WaitForSecondsRealtime(.32f);}
- if(app.Game.State.stage==Stage.Upgrade)app.Primary();yield return null;
- if(app.Game.State.stage==Stage.Shop)app.Primary();yield return null;
- yield return null;
- if(app.Game.State.stage==Stage.Map)ButtonAt(app.view.modalBody,"NextFloor").onClick.Invoke();
- yield return new WaitUntil(()=>!app.Busy);yield return null;
- }
- 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."));
- var runId=app.Game.State.id;
- long total=app.Game.TotalScore;
- app.ShowHome();app.Continue();
- ButtonAt(app.view.modalBody,"ContinueEndless").onClick.Invoke();
- yield return AwaitPresentation(()=>!app.Busy,"Entering endless");
- Assert.That(app.Game.State.level,Is.EqualTo(13));
- Assert.That(app.Game.State.id,Is.EqualTo(runId));Assert.That(app.Game.TotalScore,Is.EqualTo(total));
- app.Game.State.tickets.Clear();app.Game.State.battleSpins=1;app.Game.State.target=long.MaxValue;
- app.Primary();yield return AwaitPresentation(()=>!app.Busy,"Revive prompt");
- Assert.That(app.Game.State.stage,Is.EqualTo(Stage.ReviveChoice));
- ButtonAt(app.view.modalBody,"WatchAd").onClick.Invoke();
- ButtonAt(app.view.modalBody,"NoFill").onClick.Invoke();
- Assert.That(app.Game.State.reviveUsed,Is.False);
- ButtonAt(app.view.modalBody,"WatchAd").onClick.Invoke();
- ButtonAt(app.view.modalBody,"CompleteAd").onClick.Invoke();
- yield return AwaitPresentation(()=>!app.Busy,"Reward deal");
- Assert.That(app.Game.State.reviveUsed);
- app.ShowHome();app.Continue();app.Primary();
- yield return AwaitPresentation(()=>app.Game.State.stage==Stage.Failed,"Second exhaustion");
- yield return AwaitPresentation(()=>!app.Busy,"Game over");
- Assert.That(app.Saves.Current.hasRun,Is.False);
- ButtonAt(app.view.modalBody,"PlayAgain").onClick.Invoke();
- Assert.That(app.Game.State.endless,Is.True);
- Assert.That(app.Game.TotalScore,Is.Zero);
- }
- [UnityTest] public IEnumerator PaidBurnNeedsConfirmationAndCanResumeSelection()
- {
- 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));
- }
- [UnityTest] public IEnumerator OpenDrawerSurvivesJackpotAndShowsTheRunDeck()
- {
- yield return Begin(); app.Settings.speed=10;
- app.Game.Board.score=app.Game.State.target;
- app.Primary(); app.view.deck.onClick.Invoke();
- Assert.That(app.view.quickTitle.text,Does.StartWith("Draw pile"));
- yield return AwaitPresentation(()=>app.Game.State.stage==Stage.Victory && !app.Busy,"Jackpot");
- Assert.That(app.view.deck.gameObject.activeInHierarchy);
- Assert.That(app.view.quickLayer.gameObject.activeInHierarchy);
- Assert.That(app.view.quickTitle.text,Is.EqualTo("Run deck · "+app.Game.State.cards.Count));
- app.view.quickClose.onClick.Invoke(); app.Primary();
- Assert.That(app.Game.State.stage,Is.EqualTo(Stage.Shop));
- }
- [UnityTest] public IEnumerator TicketUseAndFailureFinishTheirPresentationsOnce()
- {
- yield return Begin();
- for(int i=1;i>=0;i--)
- {
- int before=app.Game.State.tickets.Count;
- ButtonAt(app.view.tickets,"Ticket_"+i).onClick.Invoke();
- var use=ButtonAt(app.view.quickBody,"Use");use.onClick.Invoke();use.onClick.Invoke();
- Assert.That(app.MotionPhase,Is.EqualTo("ticket"));
- Assert.That(app.Game.State.tickets.Count,Is.EqualTo(before-1));
- Assert.That(app.view.GetComponentsInChildren<TornTicket>().Length,Is.EqualTo(2));
- yield return AwaitPresentation(()=>!app.Busy,"ticket tear");
- }
- app.Game.State.stage=Stage.Failed;app.Render();app.Render();
- Assert.That(app.MotionPhase,Is.EqualTo("game-over"));Assert.That(app.view.modal.gameObject.activeSelf,Is.False);
- Assert.That(app.view.board.gameObject.activeInHierarchy);
- yield return AwaitPresentation(()=>app.view.modal.gameObject.activeSelf,"defeat dialog");
- app.Render();Assert.That(app.Busy,Is.False);Assert.That(app.view.modalTitle.text,Is.EqualTo("Game Over"));
- Assert.That(app.view.modalBody.Find("ClosingArtwork").GetComponent<Image>().sprite,Is.Not.Null);
- Assert.That(app.view.modalPanel.rect.width,Is.EqualTo(Mathf.Min(664,app.view.safeArea.rect.width-48)).Within(.01f));
- Assert.That(app.view.modalBody.Find("ClosingArtwork/TopRule"),Is.Null);
- Assert.That(app.view.modalBody.Find("ClosingArtwork/BottomRule"),Is.Null);
- Assert.That(app.view.modalBody.Find("FinalScore").GetComponent<TMP_Text>().text,Is.EqualTo(English.Number(app.Game.Board.score)));
- }
- [UnityTest] public IEnumerator LastCollectResolvesMagnetsAndScoreBeforeShowingPassiveTicket()
- {
- yield return Begin();
- var g=app.Game;
- g.State.target=long.MaxValue;g.Board.round=g.State.battleSpins;
- g.State.tickets=new List<Item>{Fateforge.Game.FindItem("regain_denergie"),Fateforge.Game.FindItem("free_spin")};
- var magnet=g.MakeMagnet("encens");magnet.charge=1;g.State.magnets.Add(magnet);
- app.Render();yield return null;
- var label=app.view.collect.GetComponentInChildren<TMP_Text>();
- app.Primary();Assert.That(label.text,Does.EndWith("1"));
- var layer=app.view.play.Find("PresentationEffects");
- yield return AwaitPresentation(()=>layer.Find("MagnetActivation"),"magnet name above the slot");
- Assert.That(layer.Find("MagnetActivation/Lettering").GetComponent<TMP_Text>().text,Does.Contain("+200"));
- Assert.That(g.State.tickets.Count,Is.EqualTo(2));
- yield return AwaitPresentation(()=>app.MotionPhase=="transfer" && app.view.score.GetComponent<RollingCounter>().IsRolling,"SCORE rolling");
- Assert.That(app.view.theme.scoreTick && app.view.theme.scoreImpact);
- Assert.That(label.text,Does.EndWith("1"));
- yield return AwaitPresentation(()=>app.MotionPhase=="ticket","passive ticket after score transfer");
- Assert.That(app.DisplayedScore,Is.EqualTo(g.Board.score).Within(.01));
- Assert.That(g.State.tickets.Single().id,Is.EqualTo("regain_denergie"));
- Assert.That(label.text,Does.EndWith("1"));Assert.That(app.Busy);
- app.Primary();
- yield return AwaitPresentation(()=>!app.Busy,"replacement deal");
- Assert.That(label.text,Does.EndWith("1"));
- }
- [UnityTest] public IEnumerator ScatterExpansionSlidesTheNewColumnAndPausesInPlace()
- {
- yield return Begin();
- var g=app.Game;int width=g.Board.width;
- for(int i=0;i<g.Board.cells.Count;i++)g.Board.cells[i].symbol=i<4?"clown":"citron";
- foreach(var card in g.Board.stock)card.symbol="cloche";
- app.Render();yield return null;
- var first=app.view.board.GetComponentsInChildren<CardView>().First(c=>c.CardId==g.Board.cells[0].id);
- first.Click(first.CardId,true);
- Assert.That(g.Board.width,Is.EqualTo(width+1));
- Assert.That(app.MotionPhase,Is.EqualTo("expansion"));Assert.That(app.Busy);
- int added=g.Board.cells[width].id;
- CardView entering=null;
- yield return AwaitPresentation(()=>{
- entering=app.view.board.GetComponentsInChildren<CardView>().FirstOrDefault(c=>c.CardId==added);
- return entering && entering.Rect.anchoredPosition.x>entering.Target.x+4;
- },"new reel sliding in");
- app.ShowHelp(0);yield return null;
- Vector2 paused=entering.Rect.anchoredPosition;
- yield return new WaitForSecondsRealtime(.12f);
- Assert.That(entering.Rect.anchoredPosition,Is.EqualTo(paused));
- app.view.modalClose.onClick.Invoke();yield return AwaitPresentation(()=>!app.Busy,"expanded deal");
- Assert.That(entering.Rect.anchoredPosition,Is.EqualTo(entering.Target));
- }
- [UnityTest] public IEnumerator BossPortraitLandsBelowTheRackAndOpensItsDescription()
- {
- yield return Begin();var g=app.Game;
- g.State.level=2;g.State.bosses[3]="flambeuse";g.OpenShop();app.Render();
- float start=app.Clock;
- app.Primary();
- yield return AwaitPresentation(()=>app.MotionPhase=="boss-flight","boss flight");
- float frameTolerance=.10f+2*Time.unscaledDeltaTime*app.Settings.speed;
- Assert.That(app.Clock-start,Is.EqualTo(3f).Within(frameTolerance));
- var dock=app.view.cabinet.Find("BossBadge") as RectTransform;
- Assert.That(dock.gameObject.activeSelf,Is.False);
- yield return AwaitPresentation(()=>dock.gameObject.activeInHierarchy,"portrait dock");
- var rack=app.view.magnetRack;
- Assert.That(dock.TransformPoint(dock.rect.center).x,Is.LessThan(rack.TransformPoint(rack.rect.center).x));
- Assert.That(dock.TransformPoint(new Vector2(0,dock.rect.yMax)).y,Is.LessThan(rack.TransformPoint(new Vector2(0,rack.rect.yMin)).y));
- dock.GetComponent<Button>().onClick.Invoke();
- Assert.That(app.view.quickTitle.text,Is.EqualTo(app.view.art.Name(g.Boss)));
- Assert.That(app.view.quickBody.Find("Description").GetComponent<TMP_Text>().text,Is.EqualTo(app.view.art.Description(g.Boss)));
- app.view.quickClose.onClick.Invoke();app.ShowHome();app.Continue();
- Assert.That(dock.gameObject.activeInHierarchy);
- }
- [UnityTest] public IEnumerator MarketResellsOwnedTicketsAndMagnetsExactlyOnceAndProtectsSkills()
- {
- yield return Begin();
- var g=app.Game;g.OpenShop();
- var magnet=g.MakeMagnet("eventail");g.State.magnets.Add(magnet);
- var ticket=g.State.tickets[0];int balance=g.State.coins;
- app.Render();yield return null;
- ButtonAt(app.view.dock,"Sell").onClick.Invoke();yield return null;
- ButtonAt(app.view.tricks,"Trick_swap").onClick.Invoke();
- Assert.That(app.view.quickBody.GetComponentsInChildren<Button>().Any(b=>b.name=="Sell"),Is.False);
- app.view.quickClose.onClick.Invoke();
- foreach(var pair in new[]{(app.view.magnetRack,"Magnet_0",magnet),(app.view.tickets,"Ticket_0",ticket)})
- {
- ButtonAt(pair.Item1,pair.Item2).onClick.Invoke();
- var confirm=ButtonAt(app.view.quickBody,"Sell");
- confirm.onClick.Invoke();confirm.onClick.Invoke();yield return null;
- balance+=Fateforge.Game.SalePrice(pair.Item3);
- Assert.That(g.State.coins,Is.EqualTo(balance));
- }
- app.ShowHome();app.Continue();
- Assert.That(app.Game.State.coins,Is.EqualTo(balance));
- Assert.That(app.Game.State.magnets.Any(m=>m.id==magnet.id),Is.False);
- Assert.That(app.Game.State.tricks.Count,Is.EqualTo(2));
- }
- [UnityTest] public IEnumerator SwapOnlyHighlightsTheChosenCardAndClearsOnCollect()
- {
- yield return Begin();
- var g=app.Game;var deck=app.view.board.GetComponentsInChildren<CardView>();
- var first=deck.First(c=>c.CardId==g.Board.cells[0].id);
- var near=deck.First(c=>c.CardId==g.Board.cells[1].id);
- var far=deck.First(c=>c.CardId==g.Board.cells[3].id);
- var normalMaterial=near.symbol.material;
- var normalColor=near.symbol.color;
- var normalValue=near.value.color;
- ButtonAt(app.view.tricks,"Trick_swap").onClick.Invoke();yield return null;
- var orb=app.view.tricks.Find("Trick_swap/Activated");Assert.That(orb.gameObject.activeSelf);
- first.Click(first.CardId,false);yield return null;
- Assert.That(first.transform.Find("SelectedCard").gameObject.activeSelf);
- foreach(var other in new[]{near,far}){
- Assert.That(other.symbol.material,Is.SameAs(normalMaterial));
- Assert.That(other.symbol.color,Is.EqualTo(normalColor));
- Assert.That(other.value.color,Is.EqualTo(normalValue));
- Assert.That(other.transform.Find("SelectedCard"),Is.Null);
- }
- app.Primary();yield return null;
- Assert.That(first.transform.Find("SelectedCard").gameObject.activeSelf,Is.False);
- Assert.That(orb.gameObject.activeSelf,Is.False);
- Assert.That(near.symbol.material,Is.SameAs(normalMaterial));
- }
- [UnityTest] public IEnumerator MarketServicesAndPaidChoicesUseTheConsole()
- {
- yield return Begin();app.Game.OpenShop();app.Game.State.coins=30;app.Render();yield return null;
- Assert.That(ButtonAt(app.view.dock,"Sell").interactable);
- Assert.That(app.view.tricks.GetComponentsInChildren<Button>().Length,Is.EqualTo(2));
- Assert.That(app.view.coins.fontSizeMax,Is.GreaterThanOrEqualTo(38));
- foreach(int family in new[]{-1,1})
- {
- app.Game.State.shop.special[0]=new Item{kind="elixir",symbol="citron",family=family,amount=.2,price=3};
- app.Render();yield return null;
- var offer=app.view.market.Find("SpecialSlot_0").GetComponent<OfferView>();
- if(family<0)Assert.That(offer.charge.sprite,Is.SameAs(app.view.art.Sprite("citron")));
- else Assert.That(offer.GetComponentsInChildren<UiGlyph>().Any(g=>g.name=="ElixirDirection" && g.shape==UiGlyph.Shape.Vertical));
- }
- var locked=app.view.market.Find("MarketSlot_3").GetComponent<OfferView>();
- Assert.That(locked.icon.sprite,Is.SameAs(app.view.theme.unlockSprite));
- locked.buy.onClick.Invoke();yield return null;Assert.That(app.Game.State.coinSlot);
- var refresh=app.view.market.Find("Refresh").GetComponent<OfferView>();
- Assert.That(refresh.icon.sprite,Is.SameAs(app.view.theme.rerollSprite));
- refresh.buy.onClick.Invoke();yield return null;Assert.That(app.Game.State.shop.rerolls,Is.EqualTo(1));
- ButtonAt(app.view.market.Find("SpecialSlot_1"),"Buy").onClick.Invoke();yield return null;
- int paid=app.Game.State.coins;
- Assert.That(app.view.collect.interactable,Is.False);
- ButtonAt(app.view.market,"Choose_1").onClick.Invoke();
- ButtonAt(app.view.dock,"ChoiceBack").onClick.Invoke();
- Assert.That(app.view.marketTitle.text,Is.EqualTo(EnglishCopy.SkipThisPurchase));
- ButtonAt(app.view.dock,"ChoiceBack").onClick.Invoke();
- Assert.That(app.view.collect.interactable);
- app.Primary();app.Primary();Assert.That(app.Game.State.stage,Is.EqualTo(Stage.Shop));
- Assert.That(app.Game.State.coins,Is.EqualTo(paid));
- yield return new WaitForSecondsRealtime(.32f);
- app.Game.State.shop.shelf[0]=Fateforge.Game.FindItem("super_carte");app.Render();yield return null;
- ButtonAt(app.view.market.Find("MarketSlot_0"),"Buy").onClick.Invoke();yield return null;
- int id=app.Game.State.purchase.candidates[0];
- ButtonAt(app.view.market,"Candidate_"+id).onClick.Invoke();app.Primary();
- Assert.That(app.Game.State.cards.First(c=>c.id==id).sticker,Is.EqualTo("super_carte"));
- }
- [UnityTest] public IEnumerator SkippingPaidElixirsKeepsPaymentAndShopOffers()
- {
- yield return Begin();app.Game.OpenShop();app.Game.State.coins=20;app.Render();yield return null;
- ButtonAt(app.view.market.Find("SpecialSlot_1"),"Buy").onClick.Invoke();
- int paid=app.Game.State.coins;
- string[] choices=app.Game.State.purchase.choices.Select(c=>c.id).ToArray();
- app.ShowHome();app.Continue();yield return null;
- Assert.That(app.Game.State.purchase.choices.Select(c=>c.id),Is.EqualTo(choices));
- ButtonAt(app.view.dock,"ChoiceBack").onClick.Invoke();
- app.Primary();app.Primary();
- Assert.That(app.Game.State.stage,Is.EqualTo(Stage.Shop));
- Assert.That(app.Game.State.coins,Is.EqualTo(paid));Assert.That(app.Game.State.shop.special[1].sold);
- }
- [UnityTest] public IEnumerator EndlessLevelRollsTheExactTotalAfterScoreIncludingOnResume()
- {
- app.PrepareRun(42, endless:true);
- Assert.That(app.view.level.text, Is.EqualTo("Total Score: 0"));
- app.Settings.speed = 4;
- app.StartRun();
- yield return AwaitPresentation(() => !app.Busy, "first endless deal");
- var game = app.Game;
- for (int i = 0; i < game.Board.cells.Count; i++) game.Board.cells[i].symbol = Game.Reference[i];
- long gain = game.PlanSettlement().total;
- Assert.That(gain, Is.GreaterThan(0));
- const long finalTotal = long.MaxValue - 2; // Not exactly representable as a double.
- game.State.clearedScore = finalTotal - gain;
- game.State.target = long.MaxValue;
- string before = "Total Score: " + English.Number(game.TotalScore);
- string after = "Total Score: " + English.Number(finalTotal);
- app.Render();
- Assert.That(app.view.level.text, Is.EqualTo(before));
- app.Primary();
- var score = app.view.score.GetComponent<RollingCounter>();
- var total = app.view.level.GetComponent<RollingCounter>();
- for (int pass = 0; pass < 2; pass++)
- {
- Assert.That(app.Game.TotalScore, Is.EqualTo(finalTotal));
- Assert.That(app.view.level.text, Is.EqualTo(before));
- yield return AwaitPresentation(() => score.IsRolling, "level score roll");
- while (score.IsRolling)
- {
- Assert.That(total.IsRolling, Is.False);
- Assert.That(app.view.level.text, Is.EqualTo(before));
- yield return null;
- }
- yield return AwaitPresentation(() => total.IsRolling, "run total roll");
- Assert.That(app.view.score.text, Is.EqualTo(English.Number(gain)));
- Assert.That(app.view.level.text, Is.EqualTo(after));
- var fixedGlyphs = app.view.level.transform.Find("CounterPunctuation").GetComponentsInChildren<TMP_Text>();
- Assert.That(string.Concat(fixedGlyphs.Select(glyph => glyph.text)), Does.StartWith("Total Score: "));
- Assert.That(app.view.level.isTextTruncated, Is.False);
- Assert.That(app.view.level.textInfo.lineCount, Is.EqualTo(1));
- if (pass == 0)
- {
- app.ShowHome();
- Assert.That(total.IsRolling, Is.False);
- app.Continue();
- }
- }
- yield return AwaitPresentation(() => !app.Busy, "next endless round");
- Assert.That(total.IsRolling, Is.False);
- Assert.That(app.Game.Board.round, Is.EqualTo(2));
- Assert.That(app.view.level.text, Is.EqualTo(after));
- }
- [UnityTest] public IEnumerator SettlementMotionPausesAndTransfersCommittedBossScoreOnlyOnce()
- {
- yield return Begin();
- // The reprieve changes the committed score independently of the formula total.
- app.Game.State.bosses[app.Game.State.level]="flambeuse";app.Game.State.target=100;app.Game.Board.score=80;app.Render();
- Assert.That(app.Game.PlanSettlement().total,Is.GreaterThan(20));
- app.Primary();long committed=app.Game.Board.score;int coins=app.Game.State.coins;
- Assert.That(committed,Is.EqualTo(50));Assert.That(app.DisplayedScore,Is.EqualTo(80).Within(.01));Assert.That(app.Busy,Is.True);
- app.Primary();app.view.collect.onClick.Invoke();
- Assert.That(app.Game.Board.score,Is.EqualTo(committed));Assert.That(app.Game.State.coins,Is.EqualTo(coins));
- yield return new WaitForSecondsRealtime(.08f);app.ShowHelp(0);yield return null;
- string phase=app.MotionPhase;double score=app.DisplayedScore,total=app.DisplayedPreviewTotal;
- yield return new WaitForSecondsRealtime(.18f);
- 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));
- app.view.modalClose.onClick.Invoke();yield return AwaitPresentation(()=>!app.Busy,"paused settlement and next deal");
- 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));
- }
- [UnityTest] public IEnumerator DiscardInterruptsMatchPreviewWithoutStaleGroupsOrNumbers()
- {
- 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;
- ButtonAt(app.view.tricks,"Trick_discard").onClick.Invoke();
- var card=app.view.board.GetComponentsInChildren<CardView>().First(c=>c.CardId==id);card.Click(id,false);yield return null;
- 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.");
- var current=app.Game.Preview();
- yield return AwaitPresentation(()=>app.PresentationGroupCount==current.matches.Count&&System.Math.Abs(app.DisplayedPreviewTotal-current.preview)<.01,"fresh preview after discard");
- yield return new WaitForSecondsRealtime(.15f);
- Assert.That(app.PresentationGroupCount,Is.EqualTo(current.matches.Count));Assert.That(app.DisplayedPreviewTotal,Is.EqualTo(current.preview).Within(.01));
- long before=app.Game.Board.score,expected=app.Game.PlanSettlement().total;
- app.Primary();Assert.That(app.Game.Board.operation,Is.Empty);long committed=app.Game.Board.score;Assert.That(committed,Is.EqualTo(before+expected));
- app.Primary();yield return AwaitPresentation(()=>!app.Busy,"collection after preview interruption");
- Assert.That(app.Game.Board.score,Is.EqualTo(committed));Assert.That(app.DisplayedScore,Is.EqualTo(committed).Within(.01));
- }
- [UnityTest] public IEnumerator RollingScoreClipsDigitsAboveCommaAndRestoresLabelAfterFinishOrCancel()
- {
- yield return Begin();var label=app.view.score;var counter=RollingCounter.Attach(label);Color original=label.color;
- counter.Begin(0,2363,false);counter.Sample(.2f);
- var digits=(RectTransform)label.transform.Find("RollingDigits");var punctuation=label.transform.Find("CounterPunctuation");
- Assert.That(counter.IsRolling,Is.True);Assert.That(label.color.a,Is.Zero);Assert.That(punctuation.parent,Is.EqualTo(label.transform));
- 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.");
- var comma=punctuation.GetComponentsInChildren<TMP_Text>().Single(t=>t.text==",");Vector2 commaPosition=comma.rectTransform.anchoredPosition;
- var commaInfo=label.textInfo.characterInfo.First(c=>c.character==',');var commaMetrics=commaInfo.textElement.glyph.metrics;
- float commaBottom=commaInfo.baseLine+(commaMetrics.horizontalBearingY-commaMetrics.height)*commaInfo.scale;
- float clipBottom=digits.rect.yMin+digits.GetComponent<RectMask2D>().padding.y;
- Assert.That(clipBottom,Is.GreaterThan(commaBottom+1),"A comma descender must not let rolling digits descend onto the score frame.");
- var moving=digits.GetComponentsInChildren<TMP_Text>().First();Vector2 digitPosition=moving.rectTransform.anchoredPosition;
- counter.Sample(.61f);
- Assert.That(comma.rectTransform.anchoredPosition,Is.EqualTo(commaPosition));Assert.That(comma.text,Is.EqualTo(","));
- Assert.That(moving.rectTransform.anchoredPosition,Is.Not.EqualTo(digitPosition));
- counter.Finish();Assert.That(counter.IsRolling,Is.False);Assert.That(label.text,Is.EqualTo("2,363"));Assert.That(label.color,Is.EqualTo(original));
- Assert.That(digits.gameObject.activeSelf,Is.False);Assert.That(punctuation.gameObject.activeSelf,Is.False);
- counter.Begin(2363,-2363,false);counter.Sample(.4f);
- Assert.That(punctuation.GetComponentsInChildren<TMP_Text>().Select(t=>t.text),Is.EquivalentTo(new[]{"-",","}));
- counter.Cancel(17);Assert.That(counter.IsRolling,Is.False);Assert.That(label.text,Is.EqualTo("17"));Assert.That(label.color,Is.EqualTo(original));
- Assert.That(digits.gameObject.activeSelf,Is.False);Assert.That(punctuation.gameObject.activeSelf,Is.False);
- Assert.That(label.GetComponentsInChildren<TMP_Text>().Length,Is.EqualTo(1),"Cancel must leave only the restored original label visible.");
- }
- [UnityTest] public IEnumerator ReloadingSettlementReplaysMotionWithoutRepeatingScoreOrRewards()
- {
- yield return Begin();
- int startingCoins = app.Game.State.coins;
- var goldMagnet = app.Game.MakeMagnet("ticket_or");
- goldMagnet.charge = 1;
- app.Game.State.magnets.Add(goldMagnet);
- foreach (var card in app.Game.State.cards) card.sticker = "carte_doree";
- app.Game.State.target=1;app.Primary();
- 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;
- Assert.That(coins, Is.GreaterThan(startingCoins + app.Game.State.reward.Total));
- Assert.That(app.view.coins.text, Is.EqualTo(English.Number(startingCoins)));
- Assert.That(history,Is.EqualTo(1));app.Save();
- yield return SceneManager.LoadSceneAsync("Assets/Fateforge/Scenes/FateforgeMain.unity");yield return null;
- app=Object.FindFirstObjectByType<FateforgeApp>();app.Settings.music=false;app.Settings.sound=false;app.Settings.speed=2;
- 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));
- app.Continue();app.Primary();
- var counter = app.view.coins.GetComponent<RollingCounter>();
- yield return AwaitPresentation(() => app.Game.State.stage == Stage.Victory, "Jackpot reveal");
- for (int replay = 0; replay < 2; replay++)
- {
- Assert.That(counter.IsRolling, Is.False);
- Assert.That(app.view.coins.text, Is.EqualTo(English.Number(startingCoins)));
- yield return AwaitPresentation(() => counter.IsRolling, "purse starts rolling");
- var lastAmount = app.view.market.Find("RewardRow_2/Amount");
- Assert.That(lastAmount.localScale, Is.EqualTo(Vector3.one));
- Assert.That(lastAmount.Find("Count").GetComponent<TMP_Text>().text, Is.EqualTo(English.Number(app.Game.State.reward.excess)));
- app.Primary();
- Assert.That(app.Game.State.stage, Is.EqualTo(Stage.Victory));
- if (replay == 0)
- {
- app.ShowHome();
- app.Continue();
- }
- }
- yield return AwaitPresentation(()=>!app.Busy,"resumed payout");
- Assert.That(counter.IsRolling, Is.False);
- Assert.That(app.view.coins.text, Is.EqualTo(English.Number(coins)));
- 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));
- }
- }
- }
|