[partial] 支持使用AudioClipName 查询
This commit is contained in:
@@ -50,7 +50,7 @@ namespace ExcelTool.Parser
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 将所有枚举的 Id 汇总,生成 EnumIds.cs 静态常量类
|
/// 将所有枚举的 Id 汇总,生成 EnumIds.cs 静态常量类
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static bool GenEnumIds(List<ParsedEnum> enumSheets, string outputDir, string nameSpace = "")
|
public static bool GenEnumIds(List<ParsedEnum> enumSheet, string outputDir, string nameSpace = "")
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -62,11 +62,19 @@ namespace ExcelTool.Parser
|
|||||||
|
|
||||||
sb.Append("\tpublic static class EnumIds\n\t{\n");
|
sb.Append("\tpublic static class EnumIds\n\t{\n");
|
||||||
|
|
||||||
foreach (ParsedEnum enumSheet in enumSheets)
|
foreach (ParsedEnum parsedEnum in enumSheet)
|
||||||
sb.Append($"\t\tpublic const uint {enumSheet.EnumName} = {enumSheet.Id};\n");
|
sb.AppendLine($"\t\tpublic const uint {parsedEnum.EnumName} = {parsedEnum.Id};\n");
|
||||||
|
|
||||||
|
sb.AppendLine("\t\tpublic static void RegisterAllGameState()\n\t\t{");
|
||||||
|
foreach (ParsedEnum parsedEnum in enumSheet)
|
||||||
|
{
|
||||||
|
sb.AppendLine($"\t\t\tStateGroupRegistry.Register<{parsedEnum.EnumName}>({parsedEnum.Id});");
|
||||||
|
}
|
||||||
|
sb.AppendLine("\t\t}");
|
||||||
|
|
||||||
sb.Append("\t}\n");
|
sb.Append("\t}\n");
|
||||||
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(nameSpace))
|
if (!string.IsNullOrEmpty(nameSpace))
|
||||||
sb.Append("}\n");
|
sb.Append("}\n");
|
||||||
|
|
||||||
|
|||||||
@@ -43,6 +43,12 @@ namespace ExcelTool.Parser
|
|||||||
sb.Append("}\n");
|
sb.Append("}\n");
|
||||||
|
|
||||||
FileManager.WriteToFile(Path.Combine(outputDir, $"{sheet.SheetName}.cs"), sb.ToString());
|
FileManager.WriteToFile(Path.Combine(outputDir, $"{sheet.SheetName}.cs"), sb.ToString());
|
||||||
|
|
||||||
|
// ── AudioObjectDefinitions 生成(仅针对 AudioObject 表) ─────────────────────
|
||||||
|
if (sheet.SheetName == "AudioObject")
|
||||||
|
{
|
||||||
|
GenerateAudioObjectDefinitions(parsedSheets, outputDir, nameSpace);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -161,7 +167,7 @@ namespace ExcelTool.Parser
|
|||||||
sb.Append($"\tList<{name}> m_{camel}InfoList;\n\n");
|
sb.Append($"\tList<{name}> m_{camel}InfoList;\n\n");
|
||||||
|
|
||||||
sb.Append($"\tpublic List<{name}> {name}List()\n\t{{\n");
|
sb.Append($"\tpublic List<{name}> {name}List()\n\t{{\n");
|
||||||
sb.Append($"\t\tthis.m_{camel}InfoList ??= new List<{name}>(m_{camel}Infos.Values);\n");
|
sb.Append($"\t\tthis.m_{camel}InfoList ??= new List<{name}>(this.m_{camel}Infos.Values);\n");
|
||||||
sb.Append($"\t\treturn this.m_{camel}InfoList;\n\t}}\n\n");
|
sb.Append($"\t\treturn this.m_{camel}InfoList;\n\t}}\n\n");
|
||||||
|
|
||||||
sb.Append($"\tpublic void DeSerialize(BinaryReader reader)\n\t{{\n");
|
sb.Append($"\tpublic void DeSerialize(BinaryReader reader)\n\t{{\n");
|
||||||
@@ -183,6 +189,94 @@ namespace ExcelTool.Parser
|
|||||||
sb.Append("\t}\n}\n");
|
sb.Append("\t}\n}\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void GenerateAudioObjectDefinitions(List<ParsedSheet> parsedSheets, string outputDir, string nameSpace)
|
||||||
|
{
|
||||||
|
ParsedSheet audioSheet = parsedSheets.Find(s => s.SheetName == "AudioObject");
|
||||||
|
if (audioSheet == null) return;
|
||||||
|
|
||||||
|
// 假设字段名:Id(uint), Names(list<string>)
|
||||||
|
Dictionary<uint, List<string>> idToNames = new();
|
||||||
|
Dictionary<string, List<uint>> nameToIds = new();
|
||||||
|
|
||||||
|
int idIndex = audioSheet.Headers.FindIndex(h => h.FieldName == "Id");
|
||||||
|
int namesIndex = audioSheet.Headers.FindIndex(h => h.FieldName == "Name");
|
||||||
|
|
||||||
|
foreach (TableExcelRow row in audioSheet.Data.Rows)
|
||||||
|
{
|
||||||
|
// 根据 Headers 找到列索引
|
||||||
|
if (idIndex < 0 || namesIndex < 0) continue;
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(row.StrList[idIndex])) continue;
|
||||||
|
|
||||||
|
uint id = Convert.ToUInt32(row.StrList[idIndex]);
|
||||||
|
|
||||||
|
// Names 是用分隔符(例如 ',')拼接的字符串
|
||||||
|
string rawNames = row.StrList[namesIndex];
|
||||||
|
List<string> names = new(rawNames.Split([','], StringSplitOptions.RemoveEmptyEntries));
|
||||||
|
|
||||||
|
idToNames[id] = names;
|
||||||
|
|
||||||
|
foreach (var name in names)
|
||||||
|
{
|
||||||
|
if (!nameToIds.TryGetValue(name, out var list))
|
||||||
|
{
|
||||||
|
list = new List<uint>();
|
||||||
|
nameToIds[name] = list;
|
||||||
|
}
|
||||||
|
list.Add(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
StringBuilder sb = new();
|
||||||
|
sb.Append("/* auto generated, do not modify */\n");
|
||||||
|
sb.Append("using System.Collections.Generic;\n\n");
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(nameSpace))
|
||||||
|
sb.Append($"namespace {nameSpace}\n{{\n");
|
||||||
|
|
||||||
|
sb.Append("public static class AudioObjectDefinitions\n{\n");
|
||||||
|
|
||||||
|
// NameToId
|
||||||
|
sb.Append("\tpublic static readonly Dictionary<string, uint> NameToId = new()\n\t{\n");
|
||||||
|
foreach (var kv in nameToIds)
|
||||||
|
{
|
||||||
|
uint minId = uint.MaxValue;
|
||||||
|
foreach (uint id in kv.Value)
|
||||||
|
if (id < minId) minId = id;
|
||||||
|
|
||||||
|
sb.Append($"\t\t{{ \"{kv.Key}\", {minId} }},\n");
|
||||||
|
}
|
||||||
|
sb.Append("\t};\n\n");
|
||||||
|
|
||||||
|
// AmbiguousNames
|
||||||
|
sb.Append("\tpublic static readonly HashSet<string> AmbiguousNames = new()\n\t{\n");
|
||||||
|
foreach (var kv in nameToIds)
|
||||||
|
{
|
||||||
|
if (kv.Value.Count > 1)
|
||||||
|
sb.Append($"\t\t\"{kv.Key}\",\n");
|
||||||
|
}
|
||||||
|
sb.Append("\t};\n\n");
|
||||||
|
|
||||||
|
// SharedIdNames
|
||||||
|
sb.Append("\tpublic static readonly HashSet<string> SharedIdNames = new()\n\t{\n");
|
||||||
|
foreach (var kv in idToNames)
|
||||||
|
{
|
||||||
|
var names = kv.Value;
|
||||||
|
for (int i = 1; i < names.Count; i++)
|
||||||
|
{
|
||||||
|
sb.Append($"\t\t\"{names[i]}\",\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sb.Append("\t};\n");
|
||||||
|
|
||||||
|
sb.Append("}\n");
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(nameSpace))
|
||||||
|
sb.Append("}\n");
|
||||||
|
|
||||||
|
FileManager.WriteToFile(Path.Combine(outputDir, "AudioObjectDefinitions.cs"), sb.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
// ──────────────────────────────────────────────────────────────────────────
|
// ──────────────────────────────────────────────────────────────────────────
|
||||||
// 工具方法
|
// 工具方法
|
||||||
// ──────────────────────────────────────────────────────────────────────────
|
// ──────────────────────────────────────────────────────────────────────────
|
||||||
|
|||||||
@@ -4,11 +4,7 @@ namespace ExcelTool.Parser
|
|||||||
{
|
{
|
||||||
public class TableExcelRow
|
public class TableExcelRow
|
||||||
{
|
{
|
||||||
public List<string> StrList { get; set; }
|
public List<string> StrList { get; set; } = [];
|
||||||
public TableExcelRow()
|
|
||||||
{
|
|
||||||
StrList = new List<string>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Add(string str)
|
public void Add(string str)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -226,9 +226,9 @@ namespace ExcelTool
|
|||||||
"\t\telse\n" +
|
"\t\telse\n" +
|
||||||
"\t\t{\n" +
|
"\t\t{\n" +
|
||||||
$"\t\t\twriter.Write({name}.Count);\n" +
|
$"\t\t\twriter.Write({name}.Count);\n" +
|
||||||
$"\t\t\tfor (int i = 0; i < {name}.Count; i++)\n" +
|
$"\t\t\tforeach (var t in {name})\n" +
|
||||||
"\t\t\t{\n" +
|
"\t\t\t{\n" +
|
||||||
$"\t\t\t\twriter.Write({name}[i]);\n" +
|
$"\t\t\t\twriter.Write(t);\n" +
|
||||||
"\t\t\t}\n" +
|
"\t\t\t}\n" +
|
||||||
"\t\t}\n";
|
"\t\t}\n";
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user