173 lines
7.6 KiB
C#
173 lines
7.6 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Reflection;
|
|
using NUnit.Framework;
|
|
using TKS.OutGame;
|
|
using UnityEngine;
|
|
using UnityEngine.SceneManagement;
|
|
using UnityEngine.TestTools;
|
|
|
|
namespace TKS.Tests
|
|
{
|
|
/// <summary>
|
|
/// 사운드 1차 적용(2026-11-20 · 개발요청_사운드 §5-2): ① 소리 표의 모든 이름이 파일로 풀림 ② 스킬 · 배경음악 표 · 코드 소리 이름이 소리 표에 있음
|
|
/// ③ 가상 실행 중 재생 0 ④ 전투에서 발동 · 발사 · 타격 소리가 Sound.Trace 에 실제로 찍힘. 기대 소리 이름은 표(SoundHooks.Skills)에서 읽는다.
|
|
/// </summary>
|
|
public class SoundTests
|
|
{
|
|
BattleManager bm;
|
|
|
|
[UnitySetUp]
|
|
public IEnumerator SetUp()
|
|
{
|
|
WorldProgress.Reset();
|
|
SaveStore.UseMemory(true);
|
|
SceneManager.LoadScene("Battle");
|
|
yield return null;
|
|
yield return null;
|
|
bm = BattleManager.Instance;
|
|
Assert.IsNotNull(bm);
|
|
var wm = WorldMapScreen.Instance;
|
|
if (wm != null && wm.HasData) wm.EnterStage(0, 0);
|
|
yield return null;
|
|
SkillSystem.AutoTap = true;
|
|
Time.timeScale = 20f;
|
|
Sound.Traced.Clear();
|
|
Sound.Trace = true;
|
|
}
|
|
|
|
[UnityTearDown]
|
|
public IEnumerator TearDown()
|
|
{
|
|
Sound.Trace = false;
|
|
Sound.Traced.Clear();
|
|
Sim.Active = false;
|
|
SkillSystem.AutoTap = false;
|
|
Time.timeScale = 1f;
|
|
yield return null;
|
|
}
|
|
|
|
IEnumerator Fresh()
|
|
{
|
|
bm.StopAllCoroutines();
|
|
bm.ClearUnits();
|
|
bm.ForcePhase(BattlePhase.PlayerTurn);
|
|
bm.SetTurnForTest(1);
|
|
yield return null;
|
|
Sound.Traced.Clear();
|
|
}
|
|
|
|
[UnityTest]
|
|
public IEnumerator Table_EveryKeyResolvesToClips()
|
|
{
|
|
yield return null;
|
|
var keys = Sound.Keys();
|
|
Assert.Greater(keys.Count, 0, "sound_events.csv 줄");
|
|
var missing = new List<string>();
|
|
int clips = 0;
|
|
foreach (var k in keys)
|
|
{
|
|
var ev = Sound.Find(k);
|
|
if (ev.clips.Length == 0) missing.Add(k + " (빈 칸)");
|
|
foreach (var p in ev.clips)
|
|
{
|
|
clips++;
|
|
if (Sound.LoadClip(p) == null) missing.Add(k + " → " + p);
|
|
}
|
|
}
|
|
Assert.IsEmpty(missing, "AudioClip null: " + string.Join(", ", missing));
|
|
Debug.Log("[SoundTests] 소리 이름 " + keys.Count + " · 파일 " + clips);
|
|
}
|
|
|
|
[UnityTest]
|
|
public IEnumerator Table_SkillBgmAndCodeKeysExist()
|
|
{
|
|
yield return null;
|
|
var bad = new List<string>();
|
|
int n = 0;
|
|
foreach (var kv in SoundHooks.Skills)
|
|
foreach (var v in new[] { kv.Value.cast, kv.Value.launch, kv.Value.hit, kv.Value.voice })
|
|
{
|
|
if (v.Length == 0) continue;
|
|
n++;
|
|
if (!Sound.Has(v)) bad.Add("skill_sfx " + kv.Key + " → " + v);
|
|
}
|
|
Assert.Greater(SoundHooks.Skills.Count, 0, "skill_sfx.csv 줄");
|
|
foreach (var kv in SoundHooks.BgmTable)
|
|
{
|
|
if (kv.Value.Length == 0) continue;
|
|
var ev = Sound.Find(kv.Value);
|
|
if (ev == null) bad.Add("sound_bgm " + kv.Key + " → " + kv.Value);
|
|
else if (ev.bus != "bgm") bad.Add("sound_bgm " + kv.Key + " → " + kv.Value + " (e_bus " + ev.bus + ")");
|
|
}
|
|
Assert.Greater(SoundHooks.BgmTable.Count, 0, "sound_bgm.csv 줄");
|
|
foreach (var f in typeof(SoundKeys).GetFields(BindingFlags.Public | BindingFlags.Static))
|
|
{
|
|
var v = f.GetValue(null) as string;
|
|
if (v != null && !Sound.Has(v)) bad.Add("SoundKeys." + f.Name + " → " + v);
|
|
}
|
|
Assert.IsEmpty(bad, string.Join(", ", bad));
|
|
Debug.Log("[SoundTests] 스킬 소리 칸 " + n + " · 배경음악 줄 " + SoundHooks.BgmTable.Count);
|
|
}
|
|
|
|
[UnityTest]
|
|
public IEnumerator Sim_PlaysNothing()
|
|
{
|
|
yield return Fresh();
|
|
var a = bm.SpawnUnit(UnitType.Archer, Faction.Player, new Vector2(0f, -3f), "궁", 1f, 1f, false);
|
|
var e = bm.SpawnUnit(UnitType.Infantry, Faction.Enemy, new Vector2(0f, 1f), "적", 1f, 1f, false);
|
|
bm.Skills.BeginBattle();
|
|
Sound.Traced.Clear();
|
|
Sim.Active = true;
|
|
try
|
|
{
|
|
Sound.Play(SoundKeys.BtHitArrow);
|
|
Sim.Run(bm.ResolveForTest(a, e.Position, false, new ActionOutcome()));
|
|
}
|
|
finally
|
|
{
|
|
Sim.Active = false;
|
|
}
|
|
Assert.IsEmpty(Sound.Traced, "가상 실행 중 재생: " + string.Join(", ", Sound.Traced));
|
|
Assert.IsTrue(Sound.Play(SoundKeys.BtHitArrow), "가상 실행 밖에서는 재생");
|
|
CollectionAssert.Contains(Sound.Traced, SoundKeys.BtHitArrow);
|
|
}
|
|
|
|
[UnityTest]
|
|
public IEnumerator Battle_TraceHasCastLaunchHit()
|
|
{
|
|
Assert.IsNotNull(Sound.CurrentBgm, "전투 배경음악(sound_bgm.csv)");
|
|
yield return Fresh();
|
|
// 궁병 사격 = 발사 bt_shot_arrow + 타격(병종 또는 치명타)
|
|
var a = bm.SpawnUnit(UnitType.Archer, Faction.Player, new Vector2(-2f, -3f), "궁", 1f, 1f, false);
|
|
var e1 = bm.SpawnUnit(UnitType.Infantry, Faction.Enemy, new Vector2(-2f, 1f), "적1", 1f, 1f, false);
|
|
e1.MaxHp = e1.Hp = 100000;
|
|
// 유비 액티브(스킬 버튼 예약 → 돌진 → 타격) = 표 skill_sfx.csv 의 s_cast · s_launch · s_hit
|
|
var liu = bm.SpawnUnit(UnitType.Infantry, Faction.Player, new Vector2(3f, -3f), "유비", 1f, 1f, false);
|
|
var s = bm.Skills.AttachHero(liu, "liubei");
|
|
Assert.IsNotNull(s);
|
|
var e2 = bm.SpawnUnit(UnitType.Spear, Faction.Enemy, new Vector2(3f, 0f), "적2", 1f, 1f, false);
|
|
e2.MaxHp = e2.Hp = 100000;
|
|
bm.Skills.BeginBattle();
|
|
Sound.Traced.Clear();
|
|
|
|
yield return bm.ResolveForTest(a, e1.Position, false, new ActionOutcome());
|
|
CollectionAssert.Contains(Sound.Traced, SoundKeys.BtShotArrow, "궁병 발사");
|
|
Assert.IsTrue(Sound.Traced.Contains(SoundKeys.BtHitArrow) || Sound.Traced.Contains(SoundKeys.BtCrit), "궁병 타격: " + string.Join(", ", Sound.Traced));
|
|
|
|
yield return new WaitForSecondsRealtime(0.4f); // 신음 최소 간격(f_min_gap)을 넘겨 다음 행동
|
|
var row = SoundHooks.Skills[s.Active.Id];
|
|
Sound.Traced.Clear();
|
|
bm.Skills.TapActive(liu);
|
|
Assert.IsTrue(s.Reserved, "예약");
|
|
yield return bm.ResolveForTest(liu, new Vector2(3f, 1f), false, new ActionOutcome());
|
|
Debug.Log("[SoundTests] Trace = " + string.Join(", ", Sound.Traced));
|
|
if (row.cast.Length > 0) CollectionAssert.Contains(Sound.Traced, row.cast, "스킬 발동(s_cast)");
|
|
if (row.voice.Length > 0) CollectionAssert.Contains(Sound.Traced, row.voice, "스킬 음성(s_voice)");
|
|
if (row.launch.Length > 0) CollectionAssert.Contains(Sound.Traced, row.launch, "스킬 행동 시작(s_launch)");
|
|
if (row.hit.Length > 0) Assert.IsTrue(Sound.Traced.Contains(row.hit) || Sound.Traced.Contains(SoundKeys.BtCrit), "스킬 타격(s_hit)");
|
|
CollectionAssert.Contains(Sound.Traced, SoundKeys.BtHurt, "맞는 쪽 신음");
|
|
}
|
|
}
|
|
}
|