154 lines
8.0 KiB
C#
154 lines
8.0 KiB
C#
|
|
using System.Collections.Generic;
|
|||
|
|
using System.IO;
|
|||
|
|
using System.Text;
|
|||
|
|
using TKS.OutGame;
|
|||
|
|
using UnityEditor;
|
|||
|
|
using UnityEngine;
|
|||
|
|
|
|||
|
|
namespace TKS.EditorTools
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// 1장 학습 판 표(Assets/Data/Stages/tutorial_{stage,layout,guide,config}.csv · 기획 tables/ 사본 · 개발 요청서 C5 · 2026-11-12)
|
|||
|
|
/// → Resources/Tutorial/TutorialDb. 메뉴 TKS/Import Tutorial 또는
|
|||
|
|
/// CLI: Unity.exe -batchmode -nographics -projectPath <proj> -executeMethod TKS.EditorTools.TutorialImporter.Import -quit
|
|||
|
|
/// 스테이지 표(stages.csv · generals.csv · factions.csv)와 대조한다 — 배치 표의 적 수·무장이 stages.csv 행과 다르면 중단(자산 변경 없음).
|
|||
|
|
/// 스테이지 표·기믹 표를 먼저 임포트해 둘 것(셋을 한 번에 = ImportWithStages).
|
|||
|
|
/// </summary>
|
|||
|
|
public static class TutorialImporter
|
|||
|
|
{
|
|||
|
|
public const string AssetFolder = "Assets/Resources/Tutorial";
|
|||
|
|
public const string AssetPath = AssetFolder + "/TutorialDb.asset";
|
|||
|
|
|
|||
|
|
[MenuItem("TKS/Import Tutorial (1장 학습 판 임포트)")]
|
|||
|
|
public static void Import()
|
|||
|
|
{
|
|||
|
|
ImportAll();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>스테이지 표 → 기믹 표 → 1장 학습 판 표 순서로 모두 임포트(1장 표를 바꿨을 때 · CLI 용).</summary>
|
|||
|
|
public static void ImportWithStages()
|
|||
|
|
{
|
|||
|
|
StageImporter.Import();
|
|||
|
|
GimmickImporter.ImportAll();
|
|||
|
|
ImportAll();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public static string[] ReadFiles()
|
|||
|
|
{
|
|||
|
|
var dir = Path.Combine(Application.dataPath, TutorialTables.Folder);
|
|||
|
|
var texts = new string[TutorialTables.Files.Length];
|
|||
|
|
for (int i = 0; i < texts.Length; i++)
|
|||
|
|
{
|
|||
|
|
var p = Path.Combine(dir, TutorialTables.Files[i]);
|
|||
|
|
texts[i] = File.Exists(p) ? File.ReadAllText(p, Encoding.UTF8) : null;
|
|||
|
|
}
|
|||
|
|
return texts;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public static bool ImportAll()
|
|||
|
|
{
|
|||
|
|
var errors = new List<string>();
|
|||
|
|
var r = Build(errors);
|
|||
|
|
if (errors.Count > 0)
|
|||
|
|
{
|
|||
|
|
foreach (var e in errors) Debug.LogError("[TKS] 1장 학습 판 표 오류 · " + e);
|
|||
|
|
Debug.LogError("[TKS] 1장 학습 판 임포트 중단(오류 " + errors.Count + ") · 자산 변경 없음");
|
|||
|
|
return false;
|
|||
|
|
}
|
|||
|
|
if (!AssetDatabase.IsValidFolder("Assets/Resources")) AssetDatabase.CreateFolder("Assets", "Resources");
|
|||
|
|
if (!AssetDatabase.IsValidFolder(AssetFolder)) AssetDatabase.CreateFolder("Assets/Resources", "Tutorial");
|
|||
|
|
var db = AssetDatabase.LoadAssetAtPath<TutorialDb>(AssetPath);
|
|||
|
|
if (db == null)
|
|||
|
|
{
|
|||
|
|
db = ScriptableObject.CreateInstance<TutorialDb>();
|
|||
|
|
AssetDatabase.CreateAsset(db, AssetPath);
|
|||
|
|
}
|
|||
|
|
db.stages = r.stages;
|
|||
|
|
db.layout = r.layout;
|
|||
|
|
db.guide = r.guide;
|
|||
|
|
db.config = r.config;
|
|||
|
|
EditorUtility.SetDirty(db);
|
|||
|
|
AssetDatabase.SaveAssets();
|
|||
|
|
TutorialTables.Invalidate();
|
|||
|
|
Debug.Log("[TKS] 1장 학습 판 임포트 완료 · 판 " + r.stages.Count + " · 배치 " + r.layout.Count + " · 안내 " + r.guide.Count + " · 설정 " + r.config.Count + " · " + AssetPath);
|
|||
|
|
return true;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>표 해석 + 스테이지 표 대조 + 판마다 적 편성(EnemySpawn) 만들기. 오류는 errors 에(테스트도 같이 쓴다).</summary>
|
|||
|
|
public static TutorialTables.Result Build(List<string> errors)
|
|||
|
|
{
|
|||
|
|
var st = StageTable.Parse(StageImporter.ReadFiles());
|
|||
|
|
foreach (var e in st.errors) errors.Add("스테이지 표: " + e);
|
|||
|
|
var gim = GimmickTables.Parse(GimmickImporter.ReadFiles());
|
|||
|
|
var gimIds = new HashSet<string>();
|
|||
|
|
foreach (var d in gim.defs) gimIds.Add(d.id);
|
|||
|
|
var heroes = OutGameData.Default != null ? OutGameData.Default.Heroes : null;
|
|||
|
|
if (heroes == null) errors.Add("영웅 표 자산 없음(TKS/Import OutGame Data 먼저)");
|
|||
|
|
|
|||
|
|
var r = TutorialTables.Parse(ReadFiles(),
|
|||
|
|
id => heroes == null || heroes.Get(id) != null,
|
|||
|
|
id => st.generals.ContainsKey(id),
|
|||
|
|
id => gimIds.Contains(id));
|
|||
|
|
errors.AddRange(r.errors);
|
|||
|
|
if (errors.Count > 0) return r;
|
|||
|
|
|
|||
|
|
var cfg = AssetDatabase.LoadAssetAtPath<BalanceConfig>(ProjectSetup.ConfigPath);
|
|||
|
|
foreach (var s in r.stages)
|
|||
|
|
{
|
|||
|
|
string at = "tutorial_layout.csv " + s.chapter + "-" + s.stage;
|
|||
|
|
var row = st.stages.Find(x => x.chapter == s.chapter && x.stage == s.stage);
|
|||
|
|
if (row == null)
|
|||
|
|
{
|
|||
|
|
errors.Add("tutorial_stage.csv " + s.chapter + "-" + s.stage + ": stages.csv 에 없는 스테이지");
|
|||
|
|
continue;
|
|||
|
|
}
|
|||
|
|
var enemyRows = r.layout.FindAll(x => x.chapter == s.chapter && x.stage == s.stage && x.side == TutSide.Enemy);
|
|||
|
|
if (enemyRows.Count == 0) continue; // 배치 표가 없는 판 = 자동 진형 그대로
|
|||
|
|
|
|||
|
|
// 적 수·무장 = stages.csv 행과 같아야 한다(팝업 「적 구성」·보상 판정이 그 행을 읽는다)
|
|||
|
|
var counts = new int[UnitTypeInfo.Count];
|
|||
|
|
var gens = new List<string>();
|
|||
|
|
foreach (var e in enemyRows)
|
|||
|
|
{
|
|||
|
|
if (e.general) gens.Add(e.unitId + ":" + UnitTypeInfo.Key(e.type) + ":" + (e.boss ? "true" : "false"));
|
|||
|
|
else counts[(int)e.type]++;
|
|||
|
|
}
|
|||
|
|
for (int i = 0; i < counts.Length; i++)
|
|||
|
|
if (counts[i] != row.soldiers[i]) errors.Add(at + ": " + UnitTypeInfo.Key((UnitType)i) + " 수 배치 " + counts[i] + " ≠ stages.csv " + row.soldiers[i]);
|
|||
|
|
var want = new List<string>();
|
|||
|
|
foreach (var g in row.generals) want.Add(g.id + ":" + UnitTypeInfo.Key(g.type) + ":" + (g.boss ? "true" : "false"));
|
|||
|
|
gens.Sort(string.CompareOrdinal);
|
|||
|
|
want.Sort(string.CompareOrdinal);
|
|||
|
|
if (string.Join(";", gens.ToArray()) != string.Join(";", want.ToArray())) errors.Add(at + ": 무장 배치 「" + string.Join(";", gens.ToArray()) + "」 ≠ stages.csv generals 「" + string.Join(";", want.ToArray()) + "」");
|
|||
|
|
|
|||
|
|
StageTable.FactionInfo fac;
|
|||
|
|
if (!st.factions.TryGetValue(row.faction, out fac)) continue; // 스테이지 표 오류로 이미 잡힘
|
|||
|
|
foreach (var e in enemyRows)
|
|||
|
|
{
|
|||
|
|
var sp = new BalanceConfig.EnemySpawn { type = e.type, position = e.pos, isBoss = e.boss, isGeneral = e.general };
|
|||
|
|
if (e.general)
|
|||
|
|
{
|
|||
|
|
// 무장 = generals.csv 이름·그림 · 기본 배율(generals.csv → 비면 보스·엘리트 기본 배율 — 자동 진형과 같은 규칙) × 배치 표 배율
|
|||
|
|
var info = st.generals[e.unitId];
|
|||
|
|
float hp = !float.IsNaN(info.hpMult) ? info.hpMult : cfg == null ? 1f : e.boss ? cfg.bossGeneralHpMult : cfg.eliteGeneralHpMult;
|
|||
|
|
float atk = !float.IsNaN(info.atkMult) ? info.atkMult : cfg == null ? 1f : e.boss ? cfg.bossGeneralAtkMult : cfg.eliteGeneralAtkMult;
|
|||
|
|
sp.name = info.name;
|
|||
|
|
sp.art = info.art;
|
|||
|
|
sp.hpMult = hp * e.hpMult;
|
|||
|
|
sp.atkMult = atk * e.atkMult;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
sp.name = fac.name + " " + UnitTypeInfo.Korean(e.type);
|
|||
|
|
sp.art = fac.art + "_" + UnitTypeInfo.Key(e.type);
|
|||
|
|
sp.hpMult = e.hpMult;
|
|||
|
|
sp.atkMult = e.atkMult;
|
|||
|
|
}
|
|||
|
|
s.enemies.Add(new TutorialEnemy { slot = e.slot, spawn = sp });
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
return r;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|