using System.Collections; using System.Collections.Generic; using NUnit.Framework; using TKS.OutGame; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.SceneManagement; using UnityEngine.TestTools; using UnityEngine.UI; namespace TKS.Tests { /// /// 연무장 첫 페이지 = 성 안 풍경 허브(PD 2026-11-18) — 장소 · 이름표 · 유닛 · 앞 층 수 = 표(Resources/UI/Yeonmu) · 글자 = 글자 표 키 · /// 캔버스 층(배경 Static · 유닛 Frame · 이름표 Event + 레이캐스터 · 스크롤 내용 Frame) · 좌우 스크롤 범위 · 장소 누름 → 모드 페이지 · 뒤로 = 허브 · 다시 뒤로 = 로비. /// 기대값은 표에서 읽는다(C45) · 장소 → 모드 연결 기대 = 개발 요청서 §0 + 컨텐츠 모드 4종(2026-11-18 · 성문 = 맹장 토벌전 · 탑 · 마구간·훈련장 = 보급전 · 비무대 = 투기장 · 집현전 = 연의 전기 · 군막 = 잠김). /// public class ArenaHubTests { [TearDown] public void TearDown() { SaveStore.UseMemory(false); } static void AssertRate(Transform t, UiRate rate, string what) { var c = t.GetComponent(); Assert.IsNotNull(c, what + ": 캔버스 없음"); Assert.IsFalse(c.overrideSorting, what + ": overrideSorting 끔"); var tag = c.GetComponent(); Assert.IsNotNull(tag, what + ": 등급 표시 없음"); Assert.AreEqual(rate, tag.rate, what + ": 등급"); } /// 요청서 §0 장소 → 모드(표 open 값) 기대 페이지 · −1 = 팝업(준비 중 · 잠김). static int ExpectedPage(string open) { switch (open) { case "tower": return 1; case "supply": return 2; case "league": return 3; case "raid": return 4; case "scenario": return ArenaScreen.ScenarioPage; } return -1; } [UnityTest] public IEnumerator Hub_Table_Layers_Scroll_SpotsOpenModes_BackToHub() { WorldProgress.Reset(); SaveStore.UseMemory(true); SceneManager.LoadScene("Battle"); yield return null; yield return null; var og = OutGameRoot.Instance; Assert.IsNotNull(og); og.ShowLobby(); og.Arena.SetPage(0); og.Show(og.Arena); yield return null; yield return null; var hub = og.Arena.Hub; Assert.IsNotNull(hub, "허브 표(Resources/UI/Yeonmu/yeonmu_hub) 없음"); Assert.IsTrue(og.Arena.HubVisible, "첫 페이지 = 허브"); // ① 표 = 화면: 이름표(f_tag 가 있는 장소) · 유닛(발 자리가 있는 표 줄) · 앞 층(json 수) int tagged = 0, actors = 0; foreach (var s in hub.Spots) if (s.hasTag && s.nameKey.Length > 0) tagged++; foreach (var a in hub.Actors) { var s = hub.SpotOf(a.spot); if (s != null && a.slot < s.feet.Count) actors++; } Assert.Greater(tagged, 0); Assert.AreEqual(tagged, hub.TagCount, "이름표 수"); Assert.AreEqual(actors, hub.ActorCount, "유닛 수(그림이 없는 유닛 있음)"); Assert.Greater(hub.LayerRows, 0, "앞 층 json"); Assert.AreEqual(hub.LayerRows, hub.LayerCount, "앞 층 그림"); // ② 글자 = 글자 표(키가 그대로 보이지 않음 · 값 자리 {n} 이 남지 않음) foreach (var s in hub.Spots) { if (!s.hasTag || s.nameKey.Length == 0) continue; Assert.IsTrue(UiText.Has(s.nameKey) && UiText.Has(s.statusKey), s.id + ": 글자 표 키"); Assert.AreEqual(UiText.T(s.nameKey), hub.NameOf(s.id), s.id + " 이름"); Assert.IsFalse(hub.StatusOf(s.id).Contains("{"), s.id + " 상태 줄 값 자리: " + hub.StatusOf(s.id)); Assert.AreEqual(UiText.F(s.statusKey, hub.Args(s)), hub.StatusOf(s.id), s.id + " 상태 줄"); } // 실제 값 자리: 탑 = 최고 층 · 투기장 = 남은/최대(arena.entries_per_day + 산 입장) · 맹장 토벌전 최대 = 메인 + 서브 기록 도전 var save = og.Session.Save; var tower = FindOpen(hub, "tower"); if (tower != null) Assert.AreEqual(save.arena.towerFloor.ToString(), hub.Args(tower)[0], "탑 상태 = 최고 층"); var ring = FindOpen(hub, "league"); if (ring != null) { var ra = hub.Args(ring); Assert.AreEqual(LeagueRules.Left(og.Session.Db, save, og.Session.Now).ToString(), ra[0], "투기장 상태 = 남은 입장"); Assert.AreEqual((ContentTables.Int("arena", "entries_per_day") + save.league.bought).ToString(), ra[1], "투기장 상태 = 하루 최대"); } var gateS = FindOpen(hub, "raid"); if (gateS != null) Assert.AreEqual((RaidData.EntryLimit(RaidData.Main) + RaidData.EntryLimit(RaidData.Sub)).ToString(), hub.Args(gateS)[1], "맹장 토벌전 상태 = 하루 최대"); // ③ 캔버스 층(P41) AssertRate(og.Arena.Rt, UiRate.Event, "연무장 화면"); AssertRate(hub.Content, UiRate.Frame, "허브 스크롤 내용"); AssertRate(hub.Art, UiRate.Static, "허브 배경"); AssertRate(hub.Scene, UiRate.Frame, "허브 유닛 층"); AssertRate(hub.Tags, UiRate.Event, "허브 이름표 층"); Assert.IsNotNull(hub.Tags.GetComponent(), "이름표 층 레이캐스터"); Assert.IsNull(hub.Scene.GetComponent(), "유닛 층 = 누름 없음"); Assert.Less(hub.Art.GetSiblingIndex(), hub.Scene.GetSiblingIndex(), "배경 → 유닛"); Assert.Less(hub.Scene.GetSiblingIndex(), hub.Tags.GetSiblingIndex(), "유닛 → 이름표"); foreach (var fa in hub.Content.GetComponentsInChildren(true)) Assert.AreEqual(UiRate.Frame, fa.GetComponentInParent(true).GetComponent().rate, "유닛 대기 = Frame 층: " + fa.name); Assert.Greater(hub.Content.GetComponentsInChildren(true).Length, 0, "대기 숨 유닛 없음"); // ④ 좌우 스크롤: 그림 폭 × 배율 > 화면 폭 · 양끝까지 가도 그림이 화면을 덮음 · 세로는 그대로 var view = hub.View.rect; float z = hub.Fitter.Zoom; Assert.Greater(z, 0f); float half = (hub.Fitter.canvasSize.x * z - view.width) * 0.5f; Assert.Greater(half, 1f, "좌우 스크롤 여유"); float y0 = hub.Content.anchoredPosition.y; hub.Scroll.horizontalNormalizedPosition = 0f; Assert.AreEqual(half, hub.Content.anchoredPosition.x, 1f, "왼쪽 끝"); hub.Scroll.horizontalNormalizedPosition = 1f; Assert.AreEqual(-half, hub.Content.anchoredPosition.x, 1f, "오른쪽 끝"); Assert.AreEqual(y0, hub.Content.anchoredPosition.y, 0.01f, "세로 고정"); hub.Fitter.Fit(true); // ⑤ 이름표 위 누름 = 이름표 층(성문 · 화면 안쪽) var gate = FindOpen(hub, "raid"); Assert.IsNotNull(gate, "성문(raid) 장소"); var trt = hub.TagOf(gate.id); var plq = (RectTransform)trt.Find("Plaque"); var screen = RectTransformUtility.WorldToScreenPoint(og.Cam, plq.TransformPoint(plq.rect.center)); var hits = new List(); EventSystem.current.RaycastAll(new PointerEventData(EventSystem.current) { position = screen }, hits); Assert.Greater(hits.Count, 0, "이름표 위 레이캐스트 없음"); Assert.IsTrue(hits[0].gameObject.transform.IsChildOf(trt), "이름표 위 첫 결과 = 이름표: " + hits[0].gameObject.name); // ⑥ 장소 누름 → 모드 페이지 / 팝업 · 뒤로 = 허브 int checkedN = 0; foreach (var s in hub.Spots) { if (s.open.Length == 0) continue; hub.Press(s.id); yield return null; int want = ExpectedPage(s.open); if (want > 0) { Assert.AreEqual(want, og.Arena.Page, s.id + " → 모드 페이지"); Assert.IsFalse(og.Arena.HubVisible, s.id + ": 모드 페이지에서 허브 숨김"); } else { Assert.IsTrue(og.ModalVisible, s.id + " → 안내 팝업"); Assert.AreEqual(0, og.Arena.Page); } og.Back(); yield return null; Assert.IsFalse(og.ModalVisible); Assert.AreEqual(og.Arena, og.Current, s.id + ": 뒤로 = 연무장"); Assert.AreEqual(0, og.Arena.Page, s.id + ": 뒤로 = 허브"); Assert.IsTrue(og.Arena.HubVisible, s.id + ": 허브 다시 보임"); checkedN++; } Assert.AreEqual(7, checkedN, "연결된 장소 7곳(요청서 §0)"); og.Back(); yield return null; Assert.IsTrue(og.LobbyVisible, "허브 뒤로 = 로비"); } /// /// 연무장 연출(PD 2026-11-18 · 표 yeonmu_scene · ArenaHubFx) — 표 줄 수 = 묶인 연출 수 · 층(전부 Frame · 누름 없음 · 배경 → 환경 뒤 → 유닛 → 연출 → 환경 앞 → 구름 → 이름표) · /// 대련·궁병 유닛은 대기 프레임 재생을 연출이 맡음 · 4 초 동안 대련 그림이 바뀌고 화살이 날거나 꽂히고 불똥·건초가 원화 프레임을 잡는다. /// [UnityTest] public IEnumerator Hub_Fx_TableBound_Layers_Animate() { WorldProgress.Reset(); SaveStore.UseMemory(true); SceneManager.LoadScene("Battle"); yield return null; yield return null; var og = OutGameRoot.Instance; og.ShowLobby(); og.Arena.SetPage(0); og.Show(og.Arena); yield return null; var hub = og.Arena.Hub; Assert.IsNotNull(hub); var fx = hub.Fx; Assert.IsNotNull(fx, "연출 표(허브 표 scene) 없음"); // ① 표 = 묶인 연출(유닛이 있는 줄만 · 대련 = 같은 i_n 두 줄이 한 쌍) var rows = LobbyScene.Load(hub.S("scene")); int duelRows = 0, shoot = 0, zzz = 0, trig = 0, cloud = 0; foreach (var r in rows) { bool bound = string.IsNullOrEmpty(r.spot) || hub.ActorRt(r.spot, r.slot) != null; if (!bound) continue; if (r.kind == "duel") duelRows++; else if (r.kind == "shoot") shoot++; else if (r.kind == "zzz") zzz++; else if (r.kind == "spark" || r.kind == "drop") trig++; else if (r.kind == "cloud") cloud++; } Assert.AreEqual(duelRows / 2, fx.DuelCount, "대련 쌍"); Assert.AreEqual(shoot, fx.ShooterCount, "궁병"); Assert.AreEqual(zzz, fx.SleeperCount, "조는 병사"); Assert.AreEqual(trig, fx.TriggerCount, "불똥·건초"); Assert.AreEqual(cloud, fx.CloudCount, "구름"); Assert.Greater(fx.DuelCount + fx.ShooterCount + fx.SleeperCount + fx.TriggerCount, 0, "유닛 연출 0"); // ② 층(P41) · 순서 var layers = new[] { fx.AmbBack, fx.Layer, fx.AmbFront, fx.Clouds }; foreach (var l in layers) { Assert.IsNotNull(l, "연출 층 없음"); AssertRate(l, UiRate.Frame, "연출 층 " + l.name); Assert.IsNull(l.GetComponent(), l.name + " = 누름 없음"); foreach (var g in l.GetComponentsInChildren(true)) Assert.IsFalse(g.raycastTarget, l.name + " 그래픽 누름: " + g.name); } var order = new[] { hub.Art, fx.AmbBack, hub.Scene, fx.Layer, fx.AmbFront, fx.Clouds, hub.Tags }; for (int i = 1; i < order.Length; i++) Assert.Less(order[i - 1].GetSiblingIndex(), order[i].GetSiblingIndex(), order[i - 1].name + " → " + order[i].name); // ③ 대련·궁병 = 연출이 프레임을 맡음(대기 프레임 재생기 뗌) foreach (var r in rows) { if (r.kind != "duel" && r.kind != "shoot") continue; var rt = hub.ActorRt(r.spot, r.slot); if (rt != null) Assert.IsNull(rt.GetComponent(), r.spot + ":" + r.slot + " 대기 재생기 남음"); } // ④ 4 초 동안 움직임 var duelImg = hub.ActorRt("ring", 0) != null ? hub.ActorRt("ring", 0).GetComponent() : null; var seen = new HashSet(); bool arrow = false; float end = Time.realtimeSinceStartup + 4f; while (Time.realtimeSinceStartup < end) { if (duelImg != null) seen.Add(duelImg.sprite); arrow |= fx.ArrowsFlying + fx.ArrowsStuck > 0; yield return null; } if (fx.DuelCount > 0) Assert.GreaterOrEqual(seen.Count, 3, "대련 그림(대기 · 자세 · 타격)이 바뀌지 않음"); if (fx.ShooterCount > 0) Assert.IsTrue(arrow, "화살이 날거나 꽂힌 적 없음"); if (fx.TriggerCount > 0) Assert.Greater(fx.Fired, 0, "불똥·건초가 원화 프레임을 잡지 못함"); og.Back(); yield return null; } static ArenaHub.Spot FindOpen(ArenaHub hub, string open) { foreach (var s in hub.Spots) if (s.open == open) return s; return null; } } }