using System.Collections.Generic; using System.Globalization; using UnityEngine; namespace TKS.OutGame { /// /// 첫 실행 흐름 표(PD 2026-11-24 「최초 게임 실행 시 게임 Flow」 · 요청서 = 조직 레포 공유/기획팀_산출물/삼국지슬링샷/개발요청_최초실행흐름_2026-11-24.md) — /// Resources/UI/FirstFlow: first_flow_config(값 · 좌표 · 색 · 시간 · ScreenTable 형식) · first_flow_lines(대사 줄) · first_flow_intro(인트로 장) · first_flow_text(글자 · UiText). /// 문구 · 수치 · 영웅 · 배너 · 스테이지는 모두 표에서 읽는다(C45) — 가신(retainer) = gacha.csv first_ten_hero 의 영웅. /// public static class FirstFlowData { public const string Folder = "UI/FirstFlow/"; public const string ConfigPath = Folder + "first_flow_config"; public const string LinesPath = Folder + "first_flow_lines"; public const string IntroPath = Folder + "first_flow_intro"; public const string TextPath = Folder + "first_flow_text"; public const string Talk = "talk"; public const string Point = "point"; public const string Press = "press"; public const string DoneNext = "next"; public const string DoneLobby = "lobby"; public const string DoneEnd = "end"; public const string Helper = "helper"; public const string Retainer = "retainer"; public const string ScreenLobby = "lobby"; public const string ScreenRecruit = "recruit"; public const string ScreenMap = "worldmap"; public const string ScreenCamp = "camp"; public const string ScreenFormation = "formation"; /// 건너뛰는 조건(s_skip_if): 첫 등용을 이미 함 · 가신이 이미 출전 편성에 있음. public const string SkipFirstPullDone = "first_pull_done"; public const string SkipRetainerPlaced = "retainer_placed"; /// 줄이 끝난 뒤 할 일(s_on_done): 편성 화면의 지금 편성을 저장. public const string AfterSaveFormation = "save_formation"; /// 대상 이름 안의 자리 표시 = 가신(gacha.csv first_pull_hero)의 영웅 id. public const string RetainerToken = "{retainer}"; public const string WaitStageClear = "stage_clear"; public const string OnShowBanner = "banner"; /// 줄이 뜰 때 할 일(s_on_show): focus:<군영 장소 id> = 그 장소로 화면을 옮김. public const string OnShowFocus = "focus"; static readonly string[] Modes = { Talk, Point, Press }; static readonly string[] Dones = { DoneNext, DoneLobby, DoneEnd }; static readonly string[] Speakers = { Helper, Retainer }; static readonly string[] Screens = { ScreenLobby, ScreenRecruit, ScreenMap, ScreenCamp, ScreenFormation }; static readonly string[] Skips = { SkipFirstPullDone, SkipRetainerPlaced }; /// 대사 한 줄(first_flow_lines). public class Line { public int step; public string speaker = ""; public string[] screens = new string[0]; public string mode = Talk; /// 대상이 있는 화면(s_target 의 / 앞) · 오브젝트 이름들(+ 로 여럿 = 합친 칸). public string targetScreen = ""; public string[] targetNames = new string[0]; public string face = ""; public string textKey = ""; public string done = DoneNext; public string onShow = ""; public string onDone = ""; public string skipIf = ""; public int skipTo; public int gate; public string wait = ""; public bool HasTarget { get { return targetScreen.Length > 0 && targetNames.Length > 0; } } public bool OnScreen(string screen) { return System.Array.IndexOf(screens, screen) >= 0; } } /// 인트로 한 장(first_flow_intro). public class Cut { public int no; public float sec; public string picture = ""; public string captionKey = ""; public Color dummyColor = Color.gray; public string dummyKey = ""; public string enter = "fade"; public float enterSec; public float scaleFrom = 1f; public float scaleTo = 1f; public Vector2 pivot = new Vector2(0.5f, 0.5f); public float rise; public float shake; } static bool loaded; static ScreenTable cfg; static readonly List lines = new List(); static readonly List cuts = new List(); static readonly Dictionary> texts = new Dictionary>(); /// 표를 다시 읽게 한다(테스트 · 표 교체). public static void Reload() { loaded = false; } static void Ensure() { if (loaded) return; loaded = true; lines.Clear(); cuts.Clear(); cfg = ScreenTable.Load(ConfigPath); // 글자 표 = 여기서 직접 읽는다(UiText 의 표 보관은 Play 를 다시 켜도 남아 고친 문구가 반영되지 않음 — 문구는 PD 가 자주 고친다) texts.Clear(); var rows = UiText.Rows(TextPath); if (rows != null) foreach (var r in rows) { string k = S(r, "s_key"); if (k.Length > 0) texts[k] = r; } rows = UiText.Rows(LinesPath); if (rows != null) foreach (var r in rows) { var l = new Line { step = I(r, "n_step"), speaker = S(r, "e_speaker"), screens = Split(S(r, "l_screen"), ';'), mode = S(r, "e_mode"), face = S(r, "e_face"), textKey = S(r, "s_text_key"), done = S(r, "e_done").Length > 0 ? S(r, "e_done") : DoneNext, onShow = S(r, "s_on_show"), onDone = S(r, "s_on_done"), skipIf = S(r, "s_skip_if"), skipTo = I(r, "n_skip_to"), gate = I(r, "n_gate"), wait = S(r, "s_wait"), }; string t = S(r, "s_target"); int slash = t.IndexOf('/'); if (slash > 0) { l.targetScreen = t.Substring(0, slash).Trim(); l.targetNames = Split(t.Substring(slash + 1), '+'); } if (l.step > 0) lines.Add(l); } lines.Sort((a, b) => a.step.CompareTo(b.step)); rows = UiText.Rows(IntroPath); if (rows != null) foreach (var r in rows) { var c = new Cut { no = I(r, "n_cut"), sec = F(r, "f_sec", 5f), picture = S(r, "s_picture"), captionKey = S(r, "s_caption_key"), dummyKey = S(r, "s_dummy_key"), enter = S(r, "e_in"), enterSec = F(r, "f_in_sec", 0f), scaleFrom = F(r, "f_scale_from", 1f), scaleTo = F(r, "f_scale_to", 1f), pivot = new Vector2(F(r, "f_pivot_x", 0.5f), F(r, "f_pivot_y", 0.5f)), rise = F(r, "f_rise", 0f), shake = F(r, "f_shake", 0f), }; Color col; if (ColorUtility.TryParseHtmlString(S(r, "s_dummy_color"), out col)) c.dummyColor = col; if (c.no > 0) cuts.Add(c); } cuts.Sort((a, b) => a.no.CompareTo(b.no)); } /// 값 표(없으면 null = 첫 실행 흐름 없음). public static ScreenTable Cfg { get { Ensure(); return cfg; } } public static List Lines { get { Ensure(); return lines; } } public static List Cuts { get { Ensure(); return cuts; } } /// 표가 있어 흐름을 돌릴 수 있는가(값 표 + 대사 줄). public static bool Ready { get { Ensure(); return cfg != null && lines.Count > 0; } } public static bool HasText(string key) { Ensure(); return !string.IsNullOrEmpty(key) && texts.ContainsKey(key); } /// 글자 표(first_flow_text) 키 → 지금 언어 글자(빈 칸 = ko · 키 없음 = 키 그대로 · UiText 와 같은 규칙). public static string T(string key) { Ensure(); Dictionary r; if (string.IsNullOrEmpty(key) || !texts.TryGetValue(key, out r)) return key ?? ""; string v; if (r.TryGetValue(UiText.Lang, out v) && v.Length > 0) return v; return r.TryGetValue(UiText.Fallback, out v) ? v : key; } public static Line LineOf(int step) { foreach (var l in Lines) if (l.step == step) return l; return null; } public static int LastStep { get { return Lines.Count > 0 ? Lines[Lines.Count - 1].step : 0; } } // ---------- 값 표 읽기 ---------- public static string Str(string key, string def = "") { return Cfg != null ? Cfg.S(key, def) : def; } public static float Num(string key, float def = 0f) { return Cfg != null ? Cfg.Num(key, def) : def; } public static string[] List(string key) { return Cfg != null && Cfg.Has(key) ? Cfg.L(key) : new string[0]; } public static Color Col(string key, Color def) { return Cfg != null && Cfg.Has(key) ? Cfg.Color(key, def) : def; } /// 「장-판」 글자를 장 · 판으로(예 1-1). public static bool ParseStage(string key, out int chapter, out int stage) { chapter = stage = 0; var p = (key ?? "").Split('-'); return p.Length == 2 && int.TryParse(p[0].Trim(), NumberStyles.Integer, CultureInfo.InvariantCulture, out chapter) && int.TryParse(p[1].Trim(), NumberStyles.Integer, CultureInfo.InvariantCulture, out stage) && chapter > 0 && stage > 0; } /// 「이름:값」 칸의 값(이름이 다르면 null). public static string Arg(string cell, string name) { if (string.IsNullOrEmpty(cell)) return null; int i = cell.IndexOf(':'); if (i <= 0 || cell.Substring(0, i).Trim() != name) return null; return cell.Substring(i + 1).Trim(); } // ---------- 표 검사(임포트 · 테스트 — 오류 문장 목록 · 0 = 통과) ---------- public static readonly string[] RequiredKeys = { "prologue_battle", "canvas", "dim", "start_delay_sec", "talk", "bubble", "bubble_small", "bubble_text", "name_tag", "portrait", "portrait_small", "next_mark", "focus_frame", "finger", "speaker.helper", "speaker.retainer", "fade", "act_in", "lobby_in", "start_heroes", "camp_focus_sec", "sortie_stage", "sortie_cluster", "sortie_hp_pct", "sortie_timing", "intro_canvas", "intro_bg", "intro_open_sec", "intro_scroll", "intro_picture", "intro_caption", "intro_dots", "intro_hint", "intro_skip", "intro_end", }; public static List Check(OutGameData db, BalanceConfig balance) { var e = new List(); Reload(); if (Cfg == null) { e.Add(ConfigPath + ": 표 없음"); return e; } foreach (var k in RequiredKeys) if (!Cfg.Has(k)) e.Add(ConfigPath + ": 필수 키 「" + k + "」 없음"); string pid = Str("prologue_battle"); var pb = ContentTables.Find("scenario_battles", "s_id", pid); if (pb == null || pb.I("n_no") != 0) e.Add(ConfigPath + ": prologue_battle 「" + pid + "」 = scenario_battles 의 서장(n_no 0)이 아님"); if (Lines.Count == 0) e.Add(LinesPath + ": 줄 없음"); bool needRetainer = false; for (int i = 0; i < Lines.Count; i++) { var l = Lines[i]; string at = LinesPath + " n_step " + l.step + ": "; if (l.step != i + 1) e.Add(at + "줄 번호가 1부터 차례가 아님"); if (System.Array.IndexOf(Speakers, l.speaker) < 0) e.Add(at + "e_speaker 「" + l.speaker + "」"); if (System.Array.IndexOf(Modes, l.mode) < 0) e.Add(at + "e_mode 「" + l.mode + "」"); if (System.Array.IndexOf(Dones, l.done) < 0) e.Add(at + "e_done 「" + l.done + "」"); if (l.screens.Length == 0) e.Add(at + "l_screen 비었음"); foreach (var sc in l.screens) if (System.Array.IndexOf(Screens, sc) < 0) e.Add(at + "l_screen 「" + sc + "」"); if (l.mode != Talk && !l.HasTarget) e.Add(at + l.mode + " 줄에 s_target 없음"); if (l.HasTarget && System.Array.IndexOf(Screens, l.targetScreen) < 0) e.Add(at + "s_target 화면 「" + l.targetScreen + "」"); if (l.HasTarget && !l.OnScreen(l.targetScreen)) e.Add(at + "s_target 화면이 l_screen 에 없음"); if (!HasText(l.textKey)) e.Add(at + "s_text_key 「" + l.textKey + "」 가 글자 표에 없음"); if (l.skipIf.Length > 0 && System.Array.IndexOf(Skips, l.skipIf) < 0) e.Add(at + "s_skip_if 「" + l.skipIf + "」"); if (l.onDone.Length > 0 && l.onDone != AfterSaveFormation) e.Add(at + "s_on_done 「" + l.onDone + "」"); if (l.skipIf.Length > 0 && (LineOf(l.skipTo) == null || l.skipTo <= l.step)) e.Add(at + "n_skip_to " + l.skipTo); if (l.gate != 0 && (LineOf(l.gate) == null || l.gate >= l.step || LineOf(l.gate).mode != Press || !LineOf(l.gate).OnScreen(ScreenLobby))) e.Add(at + "n_gate " + l.gate + " = 본영 로비의 누르기 줄이 아님"); if (l.wait.Length > 0) { int ch, st; string key = Arg(l.wait, WaitStageClear); if (key == null || !ParseStage(key, out ch, out st)) e.Add(at + "s_wait 「" + l.wait + "」"); else if (balance != null && StageOf(balance, ch, st) == null) e.Add(at + "s_wait 스테이지 " + key + " 없음"); } if (l.onShow.Length > 0) { string bid = Arg(l.onShow, OnShowBanner); if (bid == null && Arg(l.onShow, OnShowFocus) == null) e.Add(at + "s_on_show 「" + l.onShow + "」"); else if (bid != null && db != null && db.Gacha != null && db.Gacha.Get(bid) == null) e.Add(at + "s_on_show 배너 「" + bid + "」 가 gacha_banners.csv 에 없음"); } if (l.speaker == Retainer) needRetainer = true; } if (Lines.Count > 0 && Lines[Lines.Count - 1].done != DoneEnd) e.Add(LinesPath + ": 마지막 줄의 e_done 이 end 가 아님"); if (needRetainer && db != null && db.Gacha != null && (db.Gacha.FirstPullHero.Length == 0 || db.Heroes == null || db.Heroes.Get(db.Gacha.FirstPullHero) == null)) e.Add("gacha.csv: first_pull_hero 가 비어 가신(retainer) 대사를 말할 영웅이 없음"); if (Cuts.Count == 0) e.Add(IntroPath + ": 장 없음"); for (int i = 0; i < Cuts.Count; i++) { var c = Cuts[i]; string at = IntroPath + " n_cut " + c.no + ": "; if (c.no != i + 1) e.Add(at + "장 번호가 1부터 차례가 아님"); if (c.sec <= 0f) e.Add(at + "f_sec"); if (!HasText(c.captionKey)) e.Add(at + "s_caption_key 「" + c.captionKey + "」 가 글자 표에 없음"); if (c.enter != "fade" && c.enter != "slide") e.Add(at + "e_in 「" + c.enter + "」"); if (c.scaleFrom <= 0f || c.scaleTo <= 0f) e.Add(at + "f_scale"); } int ach, ast; if (!ParseStage(Str("sortie_stage"), out ach, out ast) || (balance != null && StageOf(balance, ach, ast) == null)) e.Add(ConfigPath + ": sortie_stage 「" + Str("sortie_stage") + "」 스테이지 없음"); foreach (var k in new[] { "ff_name_helper", "ff_intro_skip", "ff_intro_hint", "ff_retry", "ff_sortie_enemy", "ff_sortie_victim", "ff_sortie_tip_skill", "ff_sortie_retainer", "ff_sortie_tip_heal", "ff_sortie_bar_select", "ff_sortie_bar_skill", "ff_sortie_bar_attack", "ff_sortie_bar_aim" }) if (!HasText(k)) e.Add(TextPath + ": 키 「" + k + "」 없음"); return e; } public static BalanceConfig.StageDef StageOf(BalanceConfig cfg, int chapter, int stage) { if (cfg == null || cfg.stages == null) return null; foreach (var s in cfg.stages) if (s.chapter == chapter && s.stage == stage) return s; return null; } static string S(Dictionary r, string k) { string v; return r.TryGetValue(k, out v) && v != null ? v.Trim() : ""; } static int I(Dictionary r, string k) { int v; return int.TryParse(S(r, k), NumberStyles.Integer, CultureInfo.InvariantCulture, out v) ? v : 0; } static float F(Dictionary r, string k, float def) { float v; return float.TryParse(S(r, k), NumberStyles.Float, CultureInfo.InvariantCulture, out v) ? v : def; } static string[] Split(string s, char sep) { var list = new List(); foreach (var p in (s ?? "").Split(sep)) if (p.Trim().Length > 0) list.Add(p.Trim()); return list.ToArray(); } } }