Skip to content

Commit 94fb840

Browse files
committed
refactor: split wiki generator from CLI
1 parent 9e032a9 commit 94fb840

5 files changed

Lines changed: 133 additions & 23 deletions

File tree

.github/workflows/release.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ on:
1010
- "LICENSE"
1111
- ".gitignore"
1212
- "docs/**"
13+
- "src/Wiki"
1314
pull_request:
1415
branches: [ "main" ]
1516
paths-ignore:

.github/workflows/wiki-catalog.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
- name: Generate wiki content
2525
run: |
2626
mkdir -p wiki_content
27-
dotnet run --project src/CLI -- wiki-gen wiki_content
27+
dotnet run --project src/Wiki -- wiki-gen wiki_content
2828
2929
- name: Clone wiki repository
3030
run: |

src/CLI/Program.cs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,6 @@ public static int Main(string[] args)
2222
return 1;
2323
}
2424

25-
if (args.Length > 0 && args[0] == "wiki-gen")
26-
{
27-
string wikiOutputDir = args.Length > 1 ? args[1] : "./wiki-output";
28-
WikiCatalog.Run(wikiOutputDir);
29-
30-
return 0;
31-
}
32-
3325
// Parse arguments
3426
string? inputFile = null;
3527
string? dbpfPackage = null;
@@ -563,7 +555,6 @@ private static void PrintTree(AssetNode node, int indent)
563555
Console.Write(sn.Value);
564556
break;
565557
case NumberNode nn:
566-
// Se for HashId/StringHash/Hex, pinta de Azul, senão Magenta
567558
if (nn.Format == NumberFormat.Hex)
568559
Console.ForegroundColor = ConsoleColor.Blue;
569560
else
@@ -576,7 +567,6 @@ private static void PrintTree(AssetNode node, int indent)
576567
Console.Write(bn.DisplayValue);
577568
break;
578569
case EnumNode en:
579-
// Azul para enums
580570
Console.ForegroundColor = ConsoleColor.Blue;
581571
Console.Write(en.DisplayValue);
582572
break;
@@ -589,7 +579,7 @@ private static void PrintTree(AssetNode node, int indent)
589579
Console.Write(sn.TypeName);
590580
break;
591581
case AssetNode an when an.Kind == AssetNodeKind.Asset:
592-
Console.ForegroundColor = ConsoleColor.Green; // Asset path verde
582+
Console.ForegroundColor = ConsoleColor.Green;
593583
Console.Write(an.DisplayValue);
594584
break;
595585
default:
@@ -599,7 +589,6 @@ private static void PrintTree(AssetNode node, int indent)
599589
}
600590
}
601591

602-
// --- Fechar ---
603592
Console.ForegroundColor = ConsoleColor.DarkGray;
604593
Console.Write(")");
605594
Console.ResetColor();
Lines changed: 112 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,36 @@
11
using System.Text;
22
using ReCap.Parser;
33

4-
namespace ReCap.Parser.CLI.Commands;
4+
namespace ReCap.Wiki;
55

6-
public static class WikiCatalog
6+
/// <summary>
7+
/// Wiki generator for ReCap.Parser asset catalog documentation.
8+
/// </summary>
9+
public static class Program
710
{
811
private static readonly Dictionary<string, HashSet<string>> _usagesMap = new();
912
private const string FolderStructures = "Structures";
1013
private const string FolderEnums = "Enums";
1114
private const string FolderCatalog = "Catalog";
1215

13-
public static void Run(string outputDir)
16+
public static int Main(string[] args)
17+
{
18+
string outputDir = args.Length > 0 ? args[0] : "./wiki-output";
19+
20+
try
21+
{
22+
GenerateWiki(outputDir);
23+
return 0;
24+
}
25+
catch (Exception ex)
26+
{
27+
Console.Error.WriteLine($"Error: {ex.Message}");
28+
Console.Error.WriteLine(ex.StackTrace);
29+
return 1;
30+
}
31+
}
32+
33+
private static void GenerateWiki(string outputDir)
1434
{
1535
Console.WriteLine($"[WikiGen] Generating Wiki in: {outputDir}");
1636

@@ -30,10 +50,17 @@ public static void Run(string outputDir)
3050
var loadedCatalogs = new List<AssetCatalog>();
3151
foreach (var type in catalogTypes)
3252
{
33-
try { loadedCatalogs.Add((AssetCatalog)Activator.CreateInstance(type)!); }
34-
catch { Console.WriteLine($"[WikiGen] Warning: Failed to instantiate {type.Name}"); }
53+
try
54+
{
55+
loadedCatalogs.Add((AssetCatalog)Activator.CreateInstance(type)!);
56+
}
57+
catch
58+
{
59+
Console.WriteLine($"[WikiGen] Warning: Failed to instantiate {type.Name}");
60+
}
3561
}
3662

63+
ResolveEnumReferences(loadedCatalogs);
3764
BuildDependencyGraph(loadedCatalogs);
3865

3966
var allStructs = new List<string>();
@@ -64,6 +91,73 @@ public static void Run(string outputDir)
6491
Console.WriteLine($"[WikiGen] Done! {allStructs.Count} Structures, {allEnums.Count} Enums.");
6592
}
6693

94+
private static void ResolveEnumReferences(List<AssetCatalog> catalogs)
95+
{
96+
var globalEnumNames = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
97+
foreach (var cat in catalogs)
98+
{
99+
foreach (var e in cat.EnumNames) globalEnumNames.Add(e);
100+
}
101+
102+
Console.WriteLine($"[WikiGen] Resolving references for {globalEnumNames.Count} Enums...");
103+
104+
foreach (var cat in catalogs)
105+
{
106+
foreach (var structName in cat.StructNames)
107+
{
108+
var def = cat.GetStruct(structName);
109+
if (def == null) continue;
110+
111+
var fieldsList = (List<FieldDefinition>)def.Fields;
112+
113+
for (int i = 0; i < fieldsList.Count; i++)
114+
{
115+
var field = fieldsList[i];
116+
bool isEnum = field.Type == DataType.Enum;
117+
bool isEnumArray = field.Type == DataType.Array && field.ElementType == "Enum";
118+
119+
if ((!isEnum && !isEnumArray) || field.EnumType != null)
120+
continue;
121+
122+
string? resolvedEnum = null;
123+
var specificName = $"{def.Name}.{field.Name}";
124+
if (globalEnumNames.Contains(specificName))
125+
{
126+
resolvedEnum = specificName;
127+
}
128+
else
129+
{
130+
if (globalEnumNames.Contains(field.Name))
131+
{
132+
resolvedEnum = field.Name;
133+
}
134+
else
135+
{
136+
var pascalName = ToPascalCase(field.Name);
137+
if (globalEnumNames.Contains(pascalName))
138+
{
139+
resolvedEnum = pascalName;
140+
}
141+
}
142+
}
143+
144+
if (resolvedEnum != null)
145+
{
146+
fieldsList[i] = field with { EnumType = resolvedEnum };
147+
Console.WriteLine($" Linked: {def.Name}.{field.Name} -> {resolvedEnum}");
148+
}
149+
}
150+
}
151+
}
152+
}
153+
154+
private static string ToPascalCase(string s)
155+
{
156+
if (string.IsNullOrEmpty(s)) return s;
157+
if (char.IsUpper(s[0])) return s;
158+
return char.ToUpper(s[0]) + s.Substring(1);
159+
}
160+
67161
private static void GenerateSidebar(string outputDir, List<string> structs, List<string> enums)
68162
{
69163
var sb = new StringBuilder();
@@ -115,9 +209,10 @@ private static void BuildDependencyGraph(List<AssetCatalog> catalogs)
115209
if (field.Type == DataType.Struct) dep = field.ElementType;
116210
else if (field.Type == DataType.Nullable) dep = field.ElementType;
117211
else if (field.Type == DataType.Enum) dep = field.EnumType;
118-
else if (field.Type == DataType.Array && field.ElementType != null)
212+
else if (field.Type == DataType.Array)
119213
{
120-
if (!Enum.TryParse<DataType>(field.ElementType, true, out _))
214+
if (field.ElementType == "Enum") dep = field.EnumType;
215+
else if (field.ElementType != null && !Enum.TryParse<DataType>(field.ElementType, true, out _))
121216
dep = field.ElementType;
122217
}
123218

@@ -193,7 +288,7 @@ private static string FormatDataType(FieldDefinition field)
193288
var name = field.ElementType ?? "Unknown";
194289
return $"[`({name})`]({name})";
195290
}
196-
291+
197292
if (field.Type == DataType.Nullable)
198293
{
199294
var name = field.ElementType ?? "Unknown";
@@ -203,15 +298,22 @@ private static string FormatDataType(FieldDefinition field)
203298
if (field.Type == DataType.Enum)
204299
{
205300
var name = field.EnumType ?? "Unknown";
206-
return $"`Enum` [`({name})`]({name})";
301+
return name != "Unknown" ? $"`Enum` [`({name})`]({name})" : $"`Enum` `({name})`";
207302
}
208303

209304
if (field.Type == DataType.Array)
210305
{
211306
var inner = field.ElementType ?? "Unknown";
212307
bool isComplexType = !Enum.TryParse<DataType>(inner, true, out _);
213308

214-
if (isComplexType)
309+
if (inner == "Enum")
310+
{
311+
var enumName = field.EnumType ?? "Unknown";
312+
return enumName != "Unknown"
313+
? $"`Array` `Enum` [`({enumName})`]({enumName})"
314+
: $"`Array` `Enum`";
315+
}
316+
else if (isComplexType)
215317
{
216318
return $"`Array` [`({inner})`]({inner})";
217319
}

src/Wiki/ReCap.Parser.CLI.csproj

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net9.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
<LangVersion>13</LangVersion>
9+
<AssemblyName>ReCap.Parser</AssemblyName>
10+
<RootNamespace>ReCap.Parser.Wiki</RootNamespace>
11+
<ApplicationIcon>..\Assets\AppIcon.ico</ApplicationIcon>
12+
</PropertyGroup>
13+
14+
<ItemGroup>
15+
<ProjectReference Include="..\Core\ReCap.Parser.csproj" />
16+
</ItemGroup>
17+
18+
</Project>

0 commit comments

Comments
 (0)