This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Depot.SourceGenerator is a C# source generator that processes Depot (.dpo) files and generates strongly-typed C# classes for game data management. It parses JSON-formatted Depot files containing sheets, columns, and lines, then generates corresponding C# types with proper references and relationships.
Build the entire solution:
dotnet build Depot.SourceGenerator.slnBuild only the generator:
dotnet build Depot.SourceGenerator/Depot.SourceGenerator.csprojBuild the sample project (which references the generator):
dotnet build Depot.SourceGenerator.Sample/Depot.SourceGenerator.Sample.csprojRun the sample project:
dotnet run --project Depot.SourceGenerator.Sample/Depot.SourceGenerator.Sample.csprojView generated files: Generated source files appear in Depot.SourceGenerator.Sample/obj/Debug/net8.0/generated/Depot.SourceGenerator/
- Entry Point (
GeneratorEntry.cs): ImplementsISourceGenerator, filters AdditionalFiles forGenerateDepotSource="true"metadata - File Parsing (
DepotFileData.cs): Parses .dpo JSON files, builds sheet hierarchy including subsheet relationships - Code Generation (
DepotSourceGenerator.cs): Orchestrates code generation for sheets, lines, and references - Type System (
src/DepotTypes/*.cs): 14 column types (bool, enum, file, float, grid, image, int, lineReference, list, longtext, multiple, props, sheetReference, text)
- Sheets: Top-level data containers (becomes
DepotSheetsubclasses) - Subsheets: Nested sheets (Props or Lists) that belong to parent sheets, tracked via
SubsheetTree - Lines: Individual data rows in sheets (becomes
DepotSheetLineinstances) - Columns: Define the schema and types for each field
- LineReferences: Special handling to prevent circular reference issues by using indirection pattern with
LineReferencewrapper classes
For each sheet, the generator creates:
- A
{SheetName}class extendingDepotSheet - A
{SheetName}Lineclass extendingDepotSheetLine - A
{SheetName}LineReferenceclass for lazy-loaded references - Static instances for each line in the sheet
- A static
Linescollection of all line instances
Props (property sheets) generate simpler {SheetName}Props classes without the line infrastructure.
The generator requires MSBuild metadata to identify which .dpo files to process. Consuming projects must:
- Add
<AdditionalFiles Include="file.dpo" GenerateDepotSource="true" />in their .csproj - Either:
- Reference the package with
PrivateAssets="None"to flow props to dependent projects, OR - Create a
Directory.Build.propswithCompilerVisiblePropertyandCompilerVisibleItemMetadatadeclarations (see README.md)
- Reference the package with
The Depot.SourceGenerator.props file (packed into the NuGet package) makes these metadata items visible to the compiler.
- The generator targets
netstandard2.0for compatibility with Roslyn - Newtonsoft.Json is bundled with the generator assembly (packed into
analyzers/dotnet/cs) - LineReferences use lazy initialization to handle circular dependencies between sheets
- Subsheets are processed after parent sheets to ensure proper GUID resolution
- Known issue: sheetref doesn't currently work (per README.md)
- Core runtime types (
DepotSheet,DepotSheetLine, etc.) are generated once viaConstantSourceFiles.Core
Use the launch settings profile in Properties/launchSettings.json to debug the generator itself. Generated code can be inspected in the consuming project's obj/Debug/{tfm}/generated/ directory.