ThreeKingdomsSlingshot/Assets/Scripts/Editor/TestMenu.cs

180 lines
9.9 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; }
[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);
Notify("첫 실행 흐름: 시험 세이브를 새로 만들었습니다 — Play 하면 인트로부터 (내 세이브는 그대로)");
}
// 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.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 ? "(표 값)" : "(메뉴 덮어쓰기)"));
}
}
}