268 lines
14 KiB
C#
268 lines
14 KiB
C#
|
|
using System;
|
|||
|
|
using System.Collections;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.IO;
|
|||
|
|
using NUnit.Framework;
|
|||
|
|
using TKS.OutGame;
|
|||
|
|
using UnityEngine;
|
|||
|
|
using UnityEngine.SceneManagement;
|
|||
|
|
using UnityEngine.TestTools;
|
|||
|
|
using UnityEngine.UI;
|
|||
|
|
|
|||
|
|
namespace TKS.Tests
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// 외형(코스튬 · 2026-11-20 개발요청_코스튬 §4) — 착용 · 벗기 · 저장 · 다른 영웅과 공용 보유 · 미보유 미리보기 → 적용 막힘 · 외형 칸 잠김 · 기준점 대체(관우 외) ·
|
|||
|
|
/// 세이브 다시 불러오기 · 창 흐름 · 전투 레이어. 기대값은 표에서 읽는다(C45).
|
|||
|
|
/// </summary>
|
|||
|
|
public class CostumeTests
|
|||
|
|
{
|
|||
|
|
static readonly DateTime T0 = new DateTime(2026, 11, 18, 3, 0, 0, DateTimeKind.Utc);
|
|||
|
|
|
|||
|
|
static OutGameData Db
|
|||
|
|
{
|
|||
|
|
get { return OutGameData.Default; }
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
[TearDown]
|
|||
|
|
public void TearDown()
|
|||
|
|
{
|
|||
|
|
SaveStore.UseMemory(false);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
static CostumeDb.Item First(string slot)
|
|||
|
|
{
|
|||
|
|
foreach (var it in Db.Costume.items)
|
|||
|
|
if (it.slot == slot) return it;
|
|||
|
|
return null;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
[Test]
|
|||
|
|
public void Tables_Import_SlotsItemsAnchors_SkinLocked()
|
|||
|
|
{
|
|||
|
|
var dir = Path.Combine(Application.dataPath, OutGameTables.Folder);
|
|||
|
|
var texts = new string[OutGameTables.Files.Length];
|
|||
|
|
for (int i = 0; i < texts.Length; i++) texts[i] = File.ReadAllText(Path.Combine(dir, OutGameTables.Files[i]), System.Text.Encoding.UTF8);
|
|||
|
|
var r = OutGameTables.Parse(texts);
|
|||
|
|
Assert.AreEqual(0, r.errors.Count, string.Join("\n", r.errors.ToArray()));
|
|||
|
|
Assert.AreEqual(r.data.Costume.items.Count, Db.Costume.items.Count, "꾸미기 = 자산(TKS/Import Costume)");
|
|||
|
|
Assert.AreEqual(r.data.Costume.slots.Count, Db.Costume.slots.Count);
|
|||
|
|
var skin = Db.Costume.SlotOf("skin");
|
|||
|
|
Assert.IsNotNull(skin);
|
|||
|
|
Assert.IsFalse(skin.open, "외형 = 잠김(추후)");
|
|||
|
|
foreach (var it in Db.Costume.items) Assert.IsNotNull(CostumeRules.Art(it), it.id + " 그림");
|
|||
|
|
Assert.Greater(Db.Costume.frames.Count, 0, "유닛 알파 경계");
|
|||
|
|
OutGameTables.Destroy(r);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
[Test]
|
|||
|
|
public void Wear_Unwear_SharedOwnership_UnownedPreviewBlocked_SkinBad_Reload()
|
|||
|
|
{
|
|||
|
|
var cdb = Db.Costume;
|
|||
|
|
var d = HeroRules.NewSave(Db, 5, T0);
|
|||
|
|
var heroes = new List<HeroState>(d.heroes);
|
|||
|
|
Assert.GreaterOrEqual(heroes.Count, 2);
|
|||
|
|
var face = First("face");
|
|||
|
|
var head = First("head");
|
|||
|
|
Assert.IsTrue(CostumeRules.Grant(cdb, d, face.id));
|
|||
|
|
Assert.IsTrue(d.costumeNew, "새 꾸미기 = 빨간 점");
|
|||
|
|
Assert.IsTrue(CostumeRules.Grant(cdb, d, head.id));
|
|||
|
|
Assert.IsFalse(CostumeRules.Grant(cdb, d, face.id), "이미 보유");
|
|||
|
|
// 착용 · 두 영웅이 같은 꾸미기(계정 공용)
|
|||
|
|
var map = new Dictionary<string, string> { { "face", face.id }, { "head", head.id } };
|
|||
|
|
Assert.IsNull(CostumeRules.Apply(cdb, d, heroes[0], map));
|
|||
|
|
Assert.IsNull(CostumeRules.Apply(cdb, d, heroes[1], new Dictionary<string, string> { { "face", face.id } }));
|
|||
|
|
Assert.AreEqual(face.id, CostumeRules.Worn(cdb, heroes[0])["face"]);
|
|||
|
|
Assert.AreEqual(face.id, CostumeRules.Worn(cdb, heroes[1])["face"], "같은 꾸미기를 여러 영웅이");
|
|||
|
|
// 미보유 미리보기 = 적용 막힘(바뀌지 않음)
|
|||
|
|
CostumeDb.Item unowned = null;
|
|||
|
|
foreach (var it in cdb.items)
|
|||
|
|
if (!CostumeRules.Owns(d, it.id) && it.slot == "face") unowned = it;
|
|||
|
|
Assert.IsNotNull(unowned);
|
|||
|
|
var pv = new Dictionary<string, string>(CostumeRules.Worn(cdb, heroes[0]));
|
|||
|
|
pv["face"] = unowned.id;
|
|||
|
|
Assert.AreEqual("unowned", CostumeRules.Apply(cdb, d, heroes[0], pv), "미보유 = 적용 안 됨");
|
|||
|
|
Assert.AreEqual(face.id, CostumeRules.Worn(cdb, heroes[0])["face"], "그대로");
|
|||
|
|
// 외형 칸 = 잠김
|
|||
|
|
Assert.AreEqual("bad", CostumeRules.CanApply(cdb, d, new Dictionary<string, string> { { "skin", face.id } }));
|
|||
|
|
// 벗기
|
|||
|
|
Assert.IsNull(CostumeRules.Apply(cdb, d, heroes[0], new Dictionary<string, string> { { "face", "" }, { "head", head.id } }));
|
|||
|
|
Assert.IsFalse(CostumeRules.Worn(cdb, heroes[0]).ContainsKey("face"), "벗기");
|
|||
|
|
Assert.AreEqual(head.id, CostumeRules.Worn(cdb, heroes[0])["head"]);
|
|||
|
|
// 세이브 다시 불러오기
|
|||
|
|
var back = JsonUtility.FromJson<SaveData>(JsonUtility.ToJson(d));
|
|||
|
|
HeroRules.Sanitize(Db, back, 5);
|
|||
|
|
Assert.AreEqual(d.costumes.Count, back.costumes.Count, "보유 유지");
|
|||
|
|
Assert.AreEqual(head.id, CostumeRules.Worn(cdb, back.Hero(heroes[0].id))["head"], "착용 유지");
|
|||
|
|
Assert.AreEqual(face.id, CostumeRules.Worn(cdb, back.Hero(heroes[1].id))["face"]);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
[Test]
|
|||
|
|
public void Anchor_Table_Fallback_FrameShift_BackHidesFace()
|
|||
|
|
{
|
|||
|
|
var cdb = Db.Costume;
|
|||
|
|
var face = cdb.SlotOf("face");
|
|||
|
|
var headSlot = cdb.SlotOf("head");
|
|||
|
|
var weapon = cdb.SlotOf("weapon");
|
|||
|
|
// 표 기준점(관우)
|
|||
|
|
var a = cdb.anchors[0];
|
|||
|
|
var h = Db.Heroes.Get(a.unit);
|
|||
|
|
var baseF = cdb.FrameOf(h.art, "front_idle", 0);
|
|||
|
|
Assert.IsNotNull(baseF, a.unit + " 경계");
|
|||
|
|
var sl = cdb.SlotOf(a.anchor) ?? face;
|
|||
|
|
foreach (var s in cdb.slots)
|
|||
|
|
if (s.anchor == a.anchor) sl = s;
|
|||
|
|
var p = CostumeRules.Resolve(cdb, a.unit, h.art, sl, "front_idle", 0);
|
|||
|
|
Assert.IsTrue(p.show);
|
|||
|
|
Assert.AreEqual(a.x * baseF.w, p.x, 0.01f, "x = f_x × 그림 폭");
|
|||
|
|
Assert.AreEqual(a.y * baseF.h, p.y, 0.01f, "y = f_y × 그림 높이");
|
|||
|
|
Assert.AreEqual(baseF.w * a.scale, p.width, 0.01f, "폭 = 그림 폭 × f_scale");
|
|||
|
|
// 다른 프레임 = 윗선 이동만큼
|
|||
|
|
CostumeDb.Frame other = null;
|
|||
|
|
foreach (var f in cdb.frames)
|
|||
|
|
if (f.art == h.art && f.top != baseF.top && !f.clip.StartsWith("back")) { other = f; break; }
|
|||
|
|
if (other != null)
|
|||
|
|
{
|
|||
|
|
var q = CostumeRules.Resolve(cdb, a.unit, h.art, sl, other.clip, other.index);
|
|||
|
|
Assert.AreEqual(p.y + (other.top - baseF.top), q.y, 0.01f, "윗선 이동만큼 따라감");
|
|||
|
|
}
|
|||
|
|
// 뒷모습 = 얼굴 숨김
|
|||
|
|
Assert.IsFalse(CostumeRules.Resolve(cdb, a.unit, h.art, face, "back_idle", 0).show, "뒷모습 얼굴 숨김");
|
|||
|
|
// 대체(표에 줄이 없는 영웅) = 머리 위 중앙 · 얼굴 위에서 38 % · 무기 숨김
|
|||
|
|
HeroDb.Hero o = null;
|
|||
|
|
foreach (var x in Db.Heroes.heroes)
|
|||
|
|
if (!x.isSoldier && cdb.AnchorOf(x.id, "head") == null && cdb.FrameOf(x.art, "front_idle", 0) != null) { o = x; break; }
|
|||
|
|
Assert.IsNotNull(o, "기준점 표에 없는 영웅");
|
|||
|
|
var of = cdb.FrameOf(o.art, "front_idle", 0);
|
|||
|
|
var ph = CostumeRules.Resolve(cdb, o.id, o.art, headSlot, "front_idle", 0);
|
|||
|
|
Assert.IsTrue(ph.show);
|
|||
|
|
Assert.AreEqual((of.left + of.right) * 0.5f, ph.x, 0.01f, "머리 = 위 중앙");
|
|||
|
|
Assert.AreEqual(of.top, ph.y, 0.01f);
|
|||
|
|
var pf = CostumeRules.Resolve(cdb, o.id, o.art, face, "front_idle", 0);
|
|||
|
|
Assert.AreEqual(of.top + (of.bottom - of.top) * 0.38f, pf.y, 0.01f, "얼굴 = 위에서 38 %");
|
|||
|
|
Assert.IsFalse(CostumeRules.Resolve(cdb, o.id, o.art, weapon, "front_idle", 0).show, "무기 기준점 없음 = 숨김");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
static IEnumerator Boot()
|
|||
|
|
{
|
|||
|
|
WorldProgress.Reset();
|
|||
|
|
SaveStore.UseMemory(true);
|
|||
|
|
SceneManager.LoadScene("Battle");
|
|||
|
|
yield return null;
|
|||
|
|
yield return null;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
static Button Find(OutGameRoot og, string name)
|
|||
|
|
{
|
|||
|
|
foreach (var b in og.TopRoot.GetComponentsInChildren<Button>(true))
|
|||
|
|
if (b.name == name) return b;
|
|||
|
|
return null;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
static string Guanyu(OutGameSession s)
|
|||
|
|
{
|
|||
|
|
var h = s.Def("guanyu");
|
|||
|
|
return h != null && s.Save.Hero(h.id) != null ? h.id : s.Owned(false)[0].id;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
[UnityTest]
|
|||
|
|
public IEnumerator Window_Flow_Preview_Detail_Apply_RedDot_BattleLayer()
|
|||
|
|
{
|
|||
|
|
yield return Boot();
|
|||
|
|
var og = OutGameRoot.Instance;
|
|||
|
|
var s = og.Session;
|
|||
|
|
var cdb = s.Db.Costume;
|
|||
|
|
string id = Guanyu(s);
|
|||
|
|
Assert.AreEqual(1, s.CostumeGrant(false), "하나씩 지급");
|
|||
|
|
Assert.IsTrue(s.Save.costumeNew);
|
|||
|
|
og.ShowHero(id);
|
|||
|
|
yield return null;
|
|||
|
|
og.HeroDetail.OnMenu(3);
|
|||
|
|
Assert.AreEqual("costume", CostumeWindow.Last, "외형 버튼 = 외형 창");
|
|||
|
|
Assert.IsFalse(s.Save.costumeNew, "열면 빨간 점 끔");
|
|||
|
|
// 미보유 칸 = 미리 입힘 → 두 번 = 상세 창 · 적용 = 막힘
|
|||
|
|
CostumeDb.Item unowned = null;
|
|||
|
|
foreach (var it in cdb.items)
|
|||
|
|
if (!CostumeRules.Owns(s.Save, it.id) && it.slot == cdb.slots[0].slot) { unowned = it; break; }
|
|||
|
|
Find(og, "Item_" + unowned.id).onClick.Invoke();
|
|||
|
|
Assert.AreEqual(unowned.id, CostumeWindow.Preview[unowned.slot], "미보유 미리보기");
|
|||
|
|
Find(og, "Apply").onClick.Invoke();
|
|||
|
|
Assert.AreEqual(0, CostumeRules.Worn(cdb, s.Save.Hero(id)).Count, "미보유 = 저장 안 됨");
|
|||
|
|
Find(og, "Item_" + unowned.id).onClick.Invoke();
|
|||
|
|
Assert.AreEqual("detail", CostumeWindow.Last, "두 번 = 상세 창");
|
|||
|
|
Find(og, "DetailClose").onClick.Invoke();
|
|||
|
|
Assert.AreEqual("costume", CostumeWindow.Last, "닫기 = 외형 창(미리보기 그대로)");
|
|||
|
|
Assert.AreEqual(unowned.id, CostumeWindow.Preview[unowned.slot]);
|
|||
|
|
// 잠긴 외형 칸 = 고르지 못함
|
|||
|
|
var skin = Find(og, "Slot_skin");
|
|||
|
|
if (skin != null) skin.onClick.Invoke();
|
|||
|
|
Assert.AreEqual("costume", CostumeWindow.Last);
|
|||
|
|
// 전부 지급 → 보유 = 적용 · 저장
|
|||
|
|
s.CostumeGrant(true);
|
|||
|
|
CostumeWindow.Open(og, id);
|
|||
|
|
foreach (var sl in CostumeRules.DrawOrder(cdb))
|
|||
|
|
{
|
|||
|
|
Find(og, "Slot_" + sl.slot).onClick.Invoke();
|
|||
|
|
Find(og, "Item_" + First(sl.slot).id).onClick.Invoke();
|
|||
|
|
}
|
|||
|
|
Find(og, "Apply").onClick.Invoke();
|
|||
|
|
Assert.AreEqual(CostumeRules.DrawOrder(cdb).Count, CostumeRules.Worn(cdb, s.Save.Hero(id)).Count, "적용 = 저장");
|
|||
|
|
og.CloseModal();
|
|||
|
|
// 전투 = 그 영웅 레이어
|
|||
|
|
var bm = BattleManager.Instance;
|
|||
|
|
int idx = 0;
|
|||
|
|
for (int i = 0; i < bm.Config.stages.Length; i++)
|
|||
|
|
if (bm.Config.stages[i].chapter == 1 && bm.Config.stages[i].stage == 1) idx = i;
|
|||
|
|
bm.LineupProvider = () => new List<LineupEntry>(s.BuildLineup().FindAll(e => e.id == id));
|
|||
|
|
bm.StartStage(idx);
|
|||
|
|
yield return null;
|
|||
|
|
yield return null;
|
|||
|
|
CostumeLayers cl = null;
|
|||
|
|
foreach (var u in bm.AliveUnits(Faction.Player))
|
|||
|
|
if (u.HeroId == id && u.View != null) cl = u.View.GetComponentInChildren<CostumeLayers>();
|
|||
|
|
Assert.IsNotNull(cl, "전투 유닛 꾸미기 레이어");
|
|||
|
|
Assert.Greater(cl.Visible, 0, "착용 레이어 보임");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>목업 대조 캡처(1080×1920 · Logs/costume_capture/ · 직접 실행) — 04 무기 칸 · 05 미보유 상세 · 전투(관우 착용).</summary>
|
|||
|
|
[UnityTest, Explicit]
|
|||
|
|
public IEnumerator Capture_CostumeScreens()
|
|||
|
|
{
|
|||
|
|
yield return Boot();
|
|||
|
|
string dir = Path.Combine(Path.GetDirectoryName(Application.dataPath), "Logs", "costume_capture");
|
|||
|
|
Directory.CreateDirectory(dir);
|
|||
|
|
var og = OutGameRoot.Instance;
|
|||
|
|
var s = og.Session;
|
|||
|
|
var cdb = s.Db.Costume;
|
|||
|
|
var cam = og.Cam != null ? og.Cam : Camera.main;
|
|||
|
|
Func<string, IEnumerator> shot = name => CaptureUtil.Capture(cam, 1080, 1920, Path.Combine(dir, name + ".png"));
|
|||
|
|
string id = Guanyu(s);
|
|||
|
|
// 목업 04 = 삿갓 · 둥근 안경 · 붉은 수술 착용 · 무기 칸 · 금박 장식 보유 · 불꽃 기운 미보유
|
|||
|
|
foreach (var k in new[] { "cos_glasses", "cos_hat_straw", "cos_wpn_tassel", "cos_wpn_gold" }) CostumeRules.Grant(cdb, s.Save, k);
|
|||
|
|
s.CostumeApply(id, new Dictionary<string, string> { { "face", "cos_glasses" }, { "head", "cos_hat_straw" }, { "weapon", "cos_wpn_tassel" } });
|
|||
|
|
og.ShowHero(id);
|
|||
|
|
yield return null;
|
|||
|
|
CostumeWindow.Open(og, id);
|
|||
|
|
Find(og, "Slot_weapon").onClick.Invoke();
|
|||
|
|
yield return new WaitForSecondsRealtime(0.4f);
|
|||
|
|
yield return shot("04_cos_main");
|
|||
|
|
// 목업 05 = 얼굴 칸 · 경극 가면(미보유) 미리보기 → 상세
|
|||
|
|
Find(og, "Slot_face").onClick.Invoke();
|
|||
|
|
Find(og, "Item_cos_mask_opera").onClick.Invoke();
|
|||
|
|
Find(og, "Item_cos_mask_opera").onClick.Invoke();
|
|||
|
|
yield return new WaitForSecondsRealtime(0.4f);
|
|||
|
|
yield return shot("05_cos_preview");
|
|||
|
|
og.CloseModal();
|
|||
|
|
// 전투 = 관우 착용(1-1)
|
|||
|
|
var bm = BattleManager.Instance;
|
|||
|
|
int idx = 0;
|
|||
|
|
for (int i = 0; i < bm.Config.stages.Length; i++)
|
|||
|
|
if (bm.Config.stages[i].chapter == 1 && bm.Config.stages[i].stage == 1) idx = i;
|
|||
|
|
bm.StartStage(idx);
|
|||
|
|
yield return new WaitForSecondsRealtime(1.2f);
|
|||
|
|
yield return shot("06_battle_guanyu");
|
|||
|
|
Debug.Log("[TKS] 외형 캡처 → " + dir);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|