ShopPlayAcceptance.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using System;
  2. using DevilLink2.Gameplay;
  3. using DevilLink2.Persistence;
  4. using DevilLink2.Presentation;
  5. using DevilLink2.UI;
  6. using UnityEngine;
  7. namespace DevilLink2.Editor
  8. {
  9. internal static class ShopPlayAcceptance
  10. {
  11. private static int step;
  12. private static double started;
  13. private static double remaining;
  14. private static GameSession session;
  15. public static void Reset() { step=0; session=null; }
  16. public static bool Tick(UIManager ui,BoardDemoBootstrap bootstrap,Action<bool,string> check)
  17. {
  18. if(step==0)
  19. {
  20. ui.StartScreen.StartButton.onClick.Invoke(); ui.Lobby.ShopButton.onClick.Invoke();
  21. check(ui.Shop.IsVisible && ui.CurrentPage==UIPage.Lobby,"Lobby dock opens cached Shop overlay");
  22. check(bootstrap.GetComponentsInChildren<Canvas>(true).Length==1,"Single original Canvas");
  23. check(ui.Shop.RecordsText=="NO COIN RECORDS YET","Real empty ledger");
  24. ui.Shop.RecordsButton.onClick.Invoke(); check(ui.Shop.CurrentTab==ShopTab.CoinRecords,"Records tab");
  25. ui.Shop.ItemsButton.onClick.Invoke(); check(ui.Shop.CurrentTab==ShopTab.Items,"Items tab");
  26. ui.Shop.BuyButtons[0].onClick.Invoke();
  27. check(ui.Shop.CoinsLabel.text=="COINS 7,876","Hint purchase charged existing price");
  28. check(ui.Shop.StockLabels[0].text=="OWNED 2","Hint inventory incremented");
  29. check(ui.Lobby.CoinsLabel.text=="7,876","Underlying Lobby balance refreshed");
  30. ui.Shop.CloseButton.onClick.Invoke(); ui.Lobby.CoinButton.onClick.Invoke();
  31. check(ui.Shop.IsVisible,"Top coin entry opens Shop"); ui.Shop.CloseButton.onClick.Invoke();
  32. ui.Lobby.Cards[0].Button.onClick.Invoke(); session=bootstrap.Session; ui.GameShopButton.onClick.Invoke();
  33. check(ui.Shop.IsVisible && bootstrap.Flow.State==GameFlowState.Running,"Game entry keeps flow running");
  34. remaining=bootstrap.Flow.Runtime.Timer.RemainingTime; started=Time.realtimeSinceStartupAsDouble; step++; return false;
  35. }
  36. if(step==1)
  37. {
  38. if(Time.realtimeSinceStartupAsDouble-started<.8)return false;
  39. check(bootstrap.Flow.Runtime.Timer.RemainingTime<remaining,"Actual game loop counts down with Shop open");
  40. var id=Guid.NewGuid();
  41. check(ui.Shop.TryPurchase(ItemType.Time,id)==PurchaseStatus.Success,"Time purchase through UI");
  42. check(ui.Shop.TryPurchase(ItemType.Time,id)==PurchaseStatus.DuplicateTransaction,"Replayed operation rejected");
  43. check(bootstrap.SavedPlayer.Economy.Coins==4876,"Only one Time charge");
  44. check(bootstrap.SavedPlayer.Economy.Inventory.GetCount(ItemType.Time)==1,"Time stock +1");
  45. ui.Shop.BuyButtons[1].onClick.Invoke();
  46. check(ui.Shop.FeedbackLabel.text.Contains("NOT ENOUGH"),"Insufficient funds feedback");
  47. check(bootstrap.SavedPlayer.Economy.Coins==4876,"Failed purchase preserves balance");
  48. ui.Shop.RecordsButton.onClick.Invoke();
  49. check(ui.Shop.RecordsText.IndexOf("Shop: Time")<ui.Shop.RecordsText.IndexOf("Shop: Hint"),"Newest transaction first");
  50. check(ui.Shop.SummaryLabel.text.Contains("5,000"),"Retained spending summary");
  51. check(!bootstrap.SavedPlayer.HasPendingSave,"Purchases saved successfully");
  52. using(var restored=new SavedPlayer(new LocalSaveService(new FileSaveStorage(UnityEditor.SessionState.GetString("DevilLink2.Task08A.Play.Directory","")))))
  53. { check(restored.Economy.Coins==4876 && restored.Economy.Inventory.GetCount(ItemType.Time)==1,"Disk reload restores full purchase snapshot"); }
  54. ui.Shop.CloseButton.onClick.Invoke();
  55. check(bootstrap.Session==session && ui.CurrentPage==UIPage.Gameplay && bootstrap.Flow.State==GameFlowState.Running,"Close returns to same running board");
  56. ui.OpenShop(); bootstrap.Flow.Runtime.Timer.Advance(1000);
  57. check(!ui.Shop.IsVisible && ui.Hud.Result.IsVisible,"Timeout closes Shop and exposes real Result");
  58. check(bootstrap.GetComponentsInChildren<ShopScreen>(true).Length==1,"No repeated Shop instances");
  59. bool missing=false; foreach(var component in bootstrap.GetComponentsInChildren<Component>(true))if(component==null)missing=true;
  60. check(!missing,"No missing scene component");
  61. return true;
  62. }
  63. return false;
  64. }
  65. }
  66. }