76 lines
5.3 KiB
C#
76 lines
5.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using HotUpdate.Gameplay;
|
|
using HotUpdate.UI;
|
|
using TMPro;
|
|
using UnityEditor;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.UI;
|
|
|
|
public static class VerifyRoster
|
|
{
|
|
static PrototypeFlow Flow => UnityEngine.Object.FindObjectOfType<PrototypeFlow>();
|
|
static void Check(bool value, string message) { if (!value) throw new Exception(message); }
|
|
static T Get<T>(string name) => (T)typeof(PrototypeFlow).GetField(name, System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(Flow);
|
|
static void Set(string name, object value) => typeof(PrototypeFlow).GetField(name, System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).SetValue(Flow, value);
|
|
static async Task Until(Func<bool> condition, int seconds = 20)
|
|
{ var end = DateTime.UtcNow.AddSeconds(seconds); while (!condition()) { Check(DateTime.UtcNow < end, "Roster timed out: " + Flow?.Page); await Task.Delay(100); } await Task.Delay(120); }
|
|
static Button Button(string name) => UnityEngine.Object.FindObjectsOfType<Button>().Single(b => b.name == "Btn_" + name && b.gameObject.activeInHierarchy);
|
|
static Button Any(string name) => UnityEngine.Object.FindObjectsOfType<Button>(true).Single(b => b.name == "Btn_" + name);
|
|
static void Click(string name)
|
|
{
|
|
var b = Button(name); Check(b.interactable, "Disabled " + name); Canvas.ForceUpdateCanvases();
|
|
var rect = b.GetComponent<RectTransform>();
|
|
var pointer = new PointerEventData(EventSystem.current) { position = RectTransformUtility.WorldToScreenPoint(null, rect.TransformPoint(rect.rect.center)), button = PointerEventData.InputButton.Left };
|
|
var hits = new List<RaycastResult>(); EventSystem.current.RaycastAll(pointer, hits);
|
|
Check(hits.Count > 0 && ExecuteEvents.GetEventHandler<IPointerClickHandler>(hits[0].gameObject) == b.gameObject, "Blocked " + name);
|
|
ExecuteEvents.Execute(b.gameObject, pointer, ExecuteEvents.pointerClickHandler);
|
|
}
|
|
static async Task Capture(string name)
|
|
{
|
|
await Task.Delay(180);
|
|
var type = AppDomain.CurrentDomain.GetAssemblies().Select(a => a.GetType("Unity.Pipeline.Editor.Commands.Capture.CaptureCommands")).First(t => t != null);
|
|
type.GetMethod("CaptureGameView", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static).Invoke(null, new object[] { 1080, 1920, null, "Screenshots/roster_" + name + ".png", false, 0, "screen" });
|
|
}
|
|
static void Ok() => UiManager.Instance.Get(ConfirmDialogView.PrefabName).GetComponent<ConfirmDialogView>().Hide();
|
|
|
|
public static async Task<string> Pages()
|
|
{
|
|
await Until(() => Flow?.Game != null && !Flow.IsBusy);
|
|
Ok(); Flow.Handle("Home"); await Until(() => Flow.Page == "Home");
|
|
Check(Flow.Game.State.stages.Length == 10 && Flow.Game.State.clearedStages.Length == 20, "Server save not widened to 10/20");
|
|
|
|
Click("Adventure"); await Until(() => Flow.Page == "UI_PrototypeStages");
|
|
Check(Any("Stage1").gameObject.activeInHierarchy && !Any("Stage11").gameObject.activeInHierarchy, "Chapter one rows not isolated");
|
|
await Capture("stages_ch1");
|
|
Click("StageTab1"); await Task.Delay(200); Canvas.ForceUpdateCanvases();
|
|
Check(Any("Stage11").gameObject.activeInHierarchy && !Any("Stage1").gameObject.activeInHierarchy, "Chapter two rows not isolated");
|
|
Check(UnityEngine.Object.FindObjectsOfType<TextMeshProUGUI>().Single(t => t.name == "Txt_StageName11").text.Contains("2-1"), "Chapter two label wrong");
|
|
await Capture("stages_ch2");
|
|
Flow.Handle("Home"); await Until(() => Flow.Page == "Home");
|
|
|
|
Click("NavPets"); await Until(() => Flow.Page == "UI_PrototypePets");
|
|
int petRows = UnityEngine.Object.FindObjectsOfType<Button>().Count(b => b.name.StartsWith("Btn_Pet", StringComparison.Ordinal) && b.gameObject.activeInHierarchy);
|
|
Check(petRows == 10, "Expected ten partner rows, found " + petRows);
|
|
Check(UnityEngine.Object.FindObjectsOfType<TextMeshProUGUI>().Single(t => t.name == "Txt_PetName9").text.Contains("潮汐鲸"), "Tenth partner missing");
|
|
await Capture("pets");
|
|
Flow.Handle("Home"); await Until(() => Flow.Page == "Home");
|
|
|
|
Click("NavPinball"); await Until(() => Flow.Page == "UI_PrototypePinball"); Click("Capture"); await Until(() => Flow.Page == "UI_PrototypeCapture");
|
|
int oddsRows = UnityEngine.Object.FindObjectsOfType<TextMeshProUGUI>().Count(t => t.name.StartsWith("Txt_CaptureOdds", StringComparison.Ordinal));
|
|
Check(oddsRows == 10, "Expected ten capture rows, found " + oddsRows);
|
|
await Capture("capture");
|
|
Flow.Handle("Home"); await Until(() => Flow.Page == "Home");
|
|
|
|
Click("Rewards"); await Until(() => Flow.Page == "UI_PrototypeChest");
|
|
int choices = UnityEngine.Object.FindObjectsOfType<Button>(true).Count(b => b.name.StartsWith("Btn_ChestChoice", StringComparison.Ordinal));
|
|
Check(choices == 10, "Expected ten chest choices, found " + choices);
|
|
await Capture("chest");
|
|
Flow.Handle("Home"); await Until(() => Flow.Page == "Home");
|
|
return "PASS ten-partner pets/capture/chest pages and two chapter tabs over twenty stages.";
|
|
}
|
|
}
|