using System.Collections; using System.Collections.Generic; using NUnit.Framework; using UnityEngine; using UnityEngine.TestTools; namespace TKS.Tests { /// /// 맵 경계 기본 사양(PD 2026-11-26 「새로운 맵이 추가될 때도 항상 같은 규칙 — 맵 추가 시 맵 경계선 충돌을 자연스럽게 적용하는 것을 기본 사양」): /// ① 전투에 쓰는 모든 바닥 그림(출정 기본 · 출정 테마 · 연의 편 바닥)에 걷는 땅 줄(Resources/Board/board_bounds.csv walk)이 있다 — 새 그림만 넣고 경계를 안 그리면 여기서 실패 /// ② 기본 맵에서 아래 목책 너머 자리는 걷는 땅 안으로 보정되고 ③ 아래로 굴린 원은 목책 경계(BoardWall)에 막혀 위로 튕기는 면을 얻는다. /// public class MapBoundsTests { static BalanceConfig Config { get { return Resources.Load("BalanceConfig"); } } [Test] public void EveryBattleFloor_HasWalkableBounds() { var used = new SortedSet(); if (!string.IsNullOrEmpty(Config.boardArt)) used.Add(Config.boardArt); var errors = new List(); var themes = Resources.Load("Board/bg_theme_files"); if (themes != null) foreach (var r in StageTable.ReadCsv(themes.text, "bg_theme_files.csv", errors)) { string f; if (r.TryGetValue("s_file", out f) && Resources.Load("Board/" + f) != null) used.Add(f); // 납품된 테마 그림만 } ScenarioProps.Reload(); foreach (var r in ScenarioProps.All) if (r.id == "_bg") used.Add(r.art); MapBounds.Reload(); var missing = new List(); foreach (var f in used) if (!MapBounds.HasWalk(f)) missing.Add(f); Assert.IsEmpty(errors, "표 읽기 오류"); Assert.IsEmpty(MapBounds.Errors, "board_bounds.csv 오류"); Assert.IsEmpty(missing, "걷는 땅(board_bounds.csv walk) 없는 바닥 그림 — 새 맵은 Tools/map_bounds.py 로 경계 · 가림층을 넣는다: " + string.Join(", ", missing)); } [UnityTest] public IEnumerator DefaultBoard_ClampsInsideAndBouncesAtPalisade() { var go = new GameObject("BoundsTestBoard"); try { var board = go.AddComponent(); board.Build(Config.boardSize, Config.boardArt); yield return null; Assert.IsNotNull(board.Bounds, "기본 맵에 경계 없음"); Assert.IsNotNull(board.Bounds.Walk, "기본 맵에 걷는 땅 없음"); const float r = 0.5f; var beyond = new Vector2(0f, board.Rect.yMin + 0.1f); // 아래 목책 너머(전장 안 · 걷는 땅 밖) Vector2 c = board.ClampInside(beyond, r); Assert.IsTrue(board.Bounds.Walkable(c), "보정한 자리가 걷는 땅 밖: " + c); Assert.AreEqual(c, board.ClampInside(c, r), "보정한 자리를 다시 보정하면 그대로여야 함"); Assert.Greater(c.y, beyond.y, "아래 목책 너머 자리는 위(전장 안쪽)로 올라와야 함"); Physics2D.SyncTransforms(); RaycastHit2D wall = default(RaycastHit2D); foreach (var h in Physics2D.CircleCastAll(c + Vector2.up * 3f, r * 0.9f, Vector2.down, 10f)) if (h.collider.GetComponent() != null && (wall.collider == null || h.distance < wall.distance)) wall = h; Assert.IsNotNull(wall.collider, "아래로 굴린 원이 목책 경계에 닿지 않음"); Assert.Greater(wall.normal.y, 0.7f, "목책 경계 면 방향이 위(튕겨 올라옴)가 아님: " + wall.normal); } finally { Object.Destroy(go); } } } }