|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +CommandForgeGenerator is a C# Source Generator that converts YAML-based command definitions (commands.yaml) from CommandForgeEditor into strongly-typed C# code. It generates type-safe command classes from game scripting definitions. |
| 8 | + |
| 9 | +## Build and Development Commands |
| 10 | + |
| 11 | +### Building the Project |
| 12 | +```bash |
| 13 | +# Build entire solution |
| 14 | +dotnet build |
| 15 | + |
| 16 | +# Build specific project |
| 17 | +dotnet build CommandForgeGenerator/CommandForgeGenerator.csproj |
| 18 | + |
| 19 | +# Build in Release mode |
| 20 | +dotnet build -c Release |
| 21 | + |
| 22 | +# Create NuGet package |
| 23 | +dotnet pack CommandForgeGenerator/CommandForgeGenerator.csproj -c Release |
| 24 | +``` |
| 25 | + |
| 26 | +### Running Tests |
| 27 | +```bash |
| 28 | +# Run all tests |
| 29 | +dotnet test |
| 30 | + |
| 31 | +# Run tests with detailed output |
| 32 | +dotnet test --logger "console;verbosity=detailed" |
| 33 | +``` |
| 34 | + |
| 35 | +## Architecture Overview |
| 36 | + |
| 37 | +### Source Generator Pipeline |
| 38 | +1. **Entry Point**: `CommandForgeGeneratorSourceGenerator` (CommandForgeGenerator.cs:9) - Implements `IIncrementalGenerator` |
| 39 | +2. **YAML Processing**: `CommandSemanticsLoader` (Semantic/CommandSemanticsLoader.cs) - Parses commands.yaml files |
| 40 | +3. **Code Generation**: `CodeGenerator` (CodeGenerate/CodeGenerator.cs) - Generates C# classes from parsed semantics |
| 41 | + |
| 42 | +### Key Components |
| 43 | + |
| 44 | +**YAML to Semantics Flow**: |
| 45 | +- YAML files are converted to JSON using embedded YamlDotNet |
| 46 | +- JSON is parsed using custom parser (`Json/JsonParser.cs`) |
| 47 | +- Semantics are extracted into `CommandsSemantics` data structures |
| 48 | + |
| 49 | +**Generated Code Structure**: |
| 50 | +- `ICommandForgeCommand.g.cs` - Base interface for all commands |
| 51 | +- `CommandId.g.cs` - Enum for command identifiers |
| 52 | +- `[CommandName].g.cs` - Individual command classes with typed properties |
| 53 | +- `CommandForgeLoader.g.cs` - Loader that deserializes JSON into command objects |
| 54 | + |
| 55 | +**Property Type Mapping**: |
| 56 | +- `string`, `int`, `float`, `bool` - Basic types |
| 57 | +- `enum` → `string` |
| 58 | +- `command` → `CommandId` |
| 59 | +- `vector2/3/4` → `UnityEngine.Vector2/3/4` |
| 60 | +- `vector2/3int` → `UnityEngine.Vector2/3Int` |
| 61 | + |
| 62 | +### Important Implementation Details |
| 63 | + |
| 64 | +1. **Conditional Compilation**: All generated code is wrapped in `#if ENABLE_COMMAND_FORGE_GENERATOR` |
| 65 | +2. **Newtonsoft.Json Dependency**: Generated code requires Newtonsoft.Json for deserialization |
| 66 | +3. **Unity Integration**: Vector types use global::UnityEngine namespace |
| 67 | +4. **Error Handling**: Exceptions during generation create an Error.g.cs file with diagnostics |
| 68 | + |
| 69 | +## Testing Approach |
| 70 | + |
| 71 | +Tests use xUnit and Microsoft.CodeAnalysis.CSharp.SourceGenerators.Testing.XUnit for verifying generated code. Test projects reference the generator as an Analyzer. |
0 commit comments