ThreeKingdomsSlingshot/Assets/Scripts/Editor/TestMenu.cs

235 lines
14 KiB
C#

using System.Collections.Generic;
using System.IO;
using System.Text;
using UnityEditor;
using UnityEngine;
namespace TKS.EditorTools
{
/// <summary>
/// 플레이 테스트 전용 메뉴(PD 2026-11-18 「테스트 전용 전 스테이지 열기 및 기준 스펙 편성」 + 게임성 변경안 조준 전환).
/// 값 = PlayerPrefs(TestOptions) — 이 PC 의 에디터에서만 켜진다 · Play 중에도 바꿀 수 있다(편성은 다음 전투부터).
/// </summary>
public static class TestMenu
{
const string Root = "TKS/테스트/";
[MenuItem(Root + "전 스테이지 열기 (군량 면제)", false, 1)]
static void UnlockAll() { TestOptions.UnlockAllStages = !TestOptions.UnlockAllStages; Log(); }
[MenuItem(Root + "전 스테이지 열기 (군량 면제)", true)]
static bool UnlockAllCheck() { Menu.SetChecked(Root + "전 스테이지 열기 (군량 면제)", TestOptions.UnlockAllStages); return true; }
[MenuItem(Root + "기준 스펙 (성장 무시 · 스킬 Lv1)", false, 2)]
static void Spec() { TestOptions.StandardSpec = !TestOptions.StandardSpec; Log(); }
[MenuItem(Root + "기준 스펙 (성장 무시 · 스킬 Lv1)", true)]
static bool SpecCheck() { Menu.SetChecked(Root + "기준 스펙 (성장 무시 · 스킬 Lv1)", TestOptions.StandardSpec); return true; }
[MenuItem(Root + "기준 편성 — 무작위 영웅 5명 (병종당 최대 2)", false, 20)]
static void RandomLineup()
{
var pool = new List<KeyValuePair<string, string>>(); // id, 병종 키
var errors = new List<string>();
var path = Path.Combine(Application.dataPath, "Data/OutGame/heroes.csv");
foreach (var r in StageTable.ReadCsv(File.ReadAllText(path, Encoding.UTF8), "heroes.csv", errors))
{
string soldier;
if (r.TryGetValue("is_soldier", out soldier) && (soldier == "1" || soldier.ToLowerInvariant() == "true")) continue;
pool.Add(new KeyValuePair<string, string>(r["id"], r["unit_type"]));
}
var rng = new System.Random();
var count = new Dictionary<string, int>();
var ids = new List<string>();
while (ids.Count < 5 && pool.Count > 0)
{
var p = pool[rng.Next(pool.Count)];
pool.Remove(p);
int n;
count.TryGetValue(p.Value, out n);
if (n >= 2) continue;
count[p.Value] = n + 1;
ids.Add(p.Key);
}
TestOptions.LineupIds = string.Join(";", ids.ToArray());
Log();
}
[MenuItem(Root + "기준 편성 — 내 편성 쓰기 (비우기)", false, 21)]
static void ClearLineup() { TestOptions.LineupIds = ""; Log(); }
[MenuItem(Root + "조준 — 끌기 거리 + 붉은 구간 치명타 (새)", false, 40)]
static void AimDrag() { TestOptions.AimModeOverride = 1; Log(); }
[MenuItem(Root + "조준 — 끌기 거리 + 붉은 구간 치명타 (새)", true)]
static bool AimDragCheck() { Menu.SetChecked(Root + "조준 — 끌기 거리 + 붉은 구간 치명타 (새)", AimRules.Mode == 1); return true; }
[MenuItem(Root + "조준 — 게이지 거리 (기존 · 보류)", false, 41)]
static void AimGauge() { TestOptions.AimModeOverride = 0; Log(); }
[MenuItem(Root + "조준 — 게이지 거리 (기존 · 보류)", true)]
static bool AimGaugeCheck() { Menu.SetChecked(Root + "조준 — 게이지 거리 (기존 · 보류)", AimRules.Mode == 0); return true; }
[MenuItem(Root + "조준 — 표 값 따름 (ib_ui.csv aim_mode)", false, 42)]
static void AimTable() { TestOptions.AimModeOverride = -1; Log(); }
// 외형 꾸미기 지급(2026-11-20 · 얻는 곳 = PD 결정 대기 → 시험 = 테스트 지급 · Play 중 지금 세이브에)
[MenuItem(Root + "꾸미기 — 전부 지급 (Play 중)", false, 50)]
static void CostumeAll() { CostumeGive(true); }
[MenuItem(Root + "꾸미기 — 하나씩 지급 (Play 중)", false, 51)]
static void CostumeOne() { CostumeGive(false); }
static void CostumeGive(bool all)
{
var root = TKS.OutGame.OutGameRoot.Instance;
if (!Application.isPlaying || root == null || root.Session == null)
{
Debug.LogWarning("[TKS 테스트] 꾸미기 지급 = Play 중에만");
return;
}
int n = root.Session.CostumeGrant(all);
Debug.Log("[TKS 테스트] 꾸미기 지급 " + n + "개 · 보유 " + root.Session.Save.costumes.Count);
}
// 첫 실행 흐름(2026-11-24) — 내 세이브를 지우지 않고 새 유저의 흐름(인트로 → 서장 1 ~ 3막 → 본영 · 등용 · 출정 1-1 · 군영 소개)을 본다
// 「처음부터 보기」 하나만 누르면 된다(시험 세이브를 켜고 + 새로 만듦) — 2026-11-24 PD 「시험 세이브 지우기 해도 처음부터 시작되지 않아」
// (그 전 = 켜기 · 지우기가 따로였고 「모두 끄기」가 켜 둔 것을 꺼서 내 세이브로 실행됨)
const string FirstFlowFreshItem = Root + "첫 실행 흐름 — 처음부터 보기 (시험 세이브 새로 · 내 세이브는 그대로)";
const string FirstFlowItem = Root + "첫 실행 흐름 — 시험 세이브 쓰는 중 (체크를 끄면 내 세이브)";
const string FirstFlowDeleteKey = "TKS_FF_DELETE_PENDING";
static string FirstFlowSavePath
{
get { return Path.Combine(Application.persistentDataPath, OutGame.SaveStore.FirstFlowTestFile); }
}
/// <summary>시험 세이브를 켜고 새로 만든다 → 다음 Play = 인트로부터. Play 중이면 Play 를 끈 뒤에 지운다(돌던 세션이 세이브를 다시 쓰지 않게). CLI: -executeMethod TKS.EditorTools.TestMenu.FirstFlowFresh</summary>
[MenuItem(FirstFlowFreshItem, false, 55)]
public static void FirstFlowFresh()
{
TestOptions.FirstFlowSave = true;
if (EditorApplication.isPlayingOrWillChangePlaymode)
{
SessionState.SetBool(FirstFlowDeleteKey, true);
EditorApplication.isPlaying = false;
Notify("첫 실행 흐름: Play 를 끄고 시험 세이브를 새로 만듭니다 — 다시 Play 하면 인트로부터");
return;
}
if (File.Exists(FirstFlowSavePath)) File.Delete(FirstFlowSavePath);
Notify("첫 실행 흐름: 시험 세이브를 새로 만들었습니다 — Play 하면 인트로부터 (내 세이브는 그대로)");
}
/// <summary>시험 세이브를 쓰는가(체크) — 끄면 내 세이브 · 다시 켜면 시험 세이브의 이어 하던 곳부터.</summary>
[MenuItem(FirstFlowItem, false, 56)]
public static void FirstFlowSave()
{
TestOptions.FirstFlowSave = !TestOptions.FirstFlowSave;
Notify(TestOptions.FirstFlowSave ? "첫 실행 흐름: 시험 세이브를 씁니다(이어 하던 곳부터 · 다음 Play 부터)" : "첫 실행 흐름: 내 세이브로 돌아갑니다(다음 Play 부터)");
}
[MenuItem(FirstFlowItem, true)]
static bool FirstFlowSaveCheck() { Menu.SetChecked(FirstFlowItem, TestOptions.FirstFlowSave); return true; }
// 튜토리얼 스킵(2026-11-26 PD 「게임을 초기화 한 후 튜토리얼을 종료한 직후 로비 진입상태로 시작」) — 시험 세이브를 새로 만들고 Play →
// 타이틀을 누르면 튜토리얼(인트로 · 서장 · 등용 · 편성 · 출정 1-1 · 군영 소개)을 끝낸 세이브로 본영 로비(OutGame/FirstFlow/FirstFlowSkip) · 내 세이브는 그대로
const string SkipTutorialItem = Root + "튜토리얼 스킵 — 튜토리얼을 끝낸 직후 로비로 시작 (시험 세이브 새로 · 내 세이브는 그대로)";
const string SkipReplayKey = "TKS_SKIP_TUT_REPLAY";
const string SkipStartSceneKey = "TKS_SKIP_TUT_START_SCENE"; // 이번 Play 전의 시작 씬(없음 = 빈 글자)
/// <summary>CLI: -executeMethod TKS.EditorTools.TestMenu.SkipTutorial</summary>
[MenuItem(SkipTutorialItem, false, 57)]
public static void SkipTutorial()
{
TestOptions.FirstFlowSave = true;
TestOptions.SkipTutorial = true;
SessionState.SetBool(SkipReplayKey, true);
if (EditorApplication.isPlayingOrWillChangePlaymode)
{
SessionState.SetBool(FirstFlowDeleteKey, true);
EditorApplication.isPlaying = false; // 끈 뒤(FirstFlowHook) 지우고 다시 Play
return;
}
if (File.Exists(FirstFlowSavePath)) File.Delete(FirstFlowSavePath);
SkipReplay(true);
}
/// <summary>now = 바로 Play(메뉴) · false = 다음 에디터 틱에(Play 를 끈 알림 안에서는 바로 켜지 않음).</summary>
static void SkipReplay(bool now)
{
if (!SessionState.GetBool(SkipReplayKey, false)) return;
SessionState.EraseBool(SkipReplayKey);
Notify("튜토리얼 스킵: 시험 세이브를 새로 만들고 Play — 타이틀을 누르면 튜토리얼을 끝낸 본영 로비 (내 세이브는 그대로)");
// 게임 처음(빌드 첫 씬 = 스플래시)부터 — 열려 있는 씬과 무관 · 이번 Play 한 번만(EnteredPlayMode 에서 원래대로)
var first = EditorBuildSettings.scenes.Length > 0 ? AssetDatabase.LoadAssetAtPath<SceneAsset>(EditorBuildSettings.scenes[0].path) : null;
if (first != null)
{
var prev = UnityEditor.SceneManagement.EditorSceneManager.playModeStartScene;
SessionState.SetString(SkipStartSceneKey, prev != null ? AssetDatabase.GetAssetPath(prev) : "");
UnityEditor.SceneManagement.EditorSceneManager.playModeStartScene = first;
}
if (now) EditorApplication.EnterPlaymode();
else EditorApplication.update += PlayNextTick;
}
static void PlayNextTick()
{
EditorApplication.update -= PlayNextTick;
EditorApplication.EnterPlaymode();
}
[InitializeOnLoadMethod]
static void FirstFlowHook()
{
EditorApplication.playModeStateChanged += s =>
{
if (s == PlayModeStateChange.EnteredEditMode && SessionState.GetBool(FirstFlowDeleteKey, false))
{
SessionState.EraseBool(FirstFlowDeleteKey);
if (File.Exists(FirstFlowSavePath)) File.Delete(FirstFlowSavePath);
if (SessionState.GetBool(SkipReplayKey, false)) SkipReplay(false); // 튜토리얼 스킵 = 지운 뒤 다시 Play
else Notify("첫 실행 흐름: 시험 세이브를 새로 만들었습니다 — Play 하면 인트로부터 (내 세이브는 그대로)");
}
if (s == PlayModeStateChange.EnteredPlayMode && SessionState.GetString(SkipStartSceneKey, null) != null)
{
string prev = SessionState.GetString(SkipStartSceneKey, "");
SessionState.EraseString(SkipStartSceneKey);
UnityEditor.SceneManagement.EditorSceneManager.playModeStartScene = prev.Length > 0 ? AssetDatabase.LoadAssetAtPath<SceneAsset>(prev) : null; // 튜토리얼 스킵이 바꾼 시작 씬을 원래대로
}
// Play 를 켤 때마다 어느 세이브로 도는지 알림(시험 세이브를 켜 둔 채 내 세이브인 줄 아는 일이 없게)
if (s == PlayModeStateChange.EnteredPlayMode && TestOptions.FirstFlowSave)
Notify("시험 세이브로 Play 중(첫 실행 흐름) — 내 세이브는 쓰지 않음 · 끄기 = TKS/테스트/첫 실행 흐름 — 시험 세이브 쓰는 중");
};
}
/// <summary>콘솔 + 에디터 창 위 알림(막지 않는 알림 · 대화 상자 아님).</summary>
static void Notify(string msg)
{
Debug.Log("[TKS 테스트] " + msg);
foreach (var w in Resources.FindObjectsOfTypeAll<EditorWindow>())
if (w != null && (w.GetType().Name == "GameView" || w is SceneView)) w.ShowNotification(new GUIContent(msg), 4.0);
}
[MenuItem(Root + "모두 끄기", false, 60)]
static void AllOff()
{
if (TestOptions.FirstFlowSave) Notify("첫 실행 흐름: 시험 세이브도 끔 — 내 세이브로 돌아갑니다(다시 보려면 「처음부터 보기」)");
TestOptions.FirstFlowSave = false;
TestOptions.SkipTutorial = false;
TestOptions.UnlockAllStages = false;
TestOptions.StandardSpec = false;
TestOptions.LineupIds = "";
TestOptions.AimModeOverride = -1;
Log();
}
static void Log()
{
AimRules.Refresh();
Debug.Log("[TKS 테스트] 전 스테이지 열기 " + (TestOptions.UnlockAllStages ? "켬" : "끔") + " · 기준 스펙 " + (TestOptions.StandardSpec ? "켬" : "끔") +
" · 기준 편성 " + (TestOptions.LineupIds.Length > 0 ? TestOptions.LineupIds : "내 편성") + " · 조준 " + (AimRules.Mode == 1 ? "끌기 + 붉은 구간" : "게이지 거리") +
(TestOptions.AimModeOverride < 0 ? "(표 값)" : "(메뉴 덮어쓰기)"));
}
}
}