GDShrapt.Builder provides a fluent API for programmatic GDScript 2.0 (Godot 4.x) code generation. Key Features: - Fluent building API for creating complete GDScript AST nodes - Factory methods for all declarations, expressions, and statements - Three building styles: Short (GD.Class), Fluent (chained calls), Token-based (manual control) - Extension methods for AST manipulation and code generation - Full support for GDScript 4.x constructs: lambdas, annotations, typed arrays, enums Usage: GD.Declaration.Class(...), GD.Expression.Call(...), GD.Statement.If(...) Requires: GDShrapt.Reader
$ dotnet add package GDShrapt.BuilderFluent API for programmatic GDScript 2.0 (Godot 4.x) code generation.
using GDShrapt.Reader;
// Create a simple class
var classDecl = GD.Declaration.Class(
GD.Atribute.Extends("Node2D"),
GD.Atribute.Export(),
GD.Declaration.Variable("health", "int", GD.Expression.Number(100)),
GD.Declaration.Method(GD.Syntax.Identifier("_ready"),
GD.Expression.Call(GD.Expression.Identifier("print"),
GD.Expression.String("Hello, Godot 4!")).ToStatement()
)
);
classDecl.UpdateIntendation();
Console.WriteLine(classDecl.ToString());
var variable = GD.Declaration.Variable("health", "int", GD.Expression.Number(100));
var classDecl = GD.Declaration.Class()
.WithExtends("Node2D")
.AddVariable("health", "int")
.AddMethod("_ready");
var variable = new GDVariableDeclaration();
variable.VarKeyword = new GDVarKeyword();
variable.Identifier = new GDIdentifier { Sequence = "health" };
GD.Atribute.Export() // @export
GD.Atribute.ExportRange(0, 100) // @export_range(0, 100)
GD.Atribute.Onready() // @onready
GD.Atribute.Tool() // @tool
GD.Expression.GetNode("Sprite") // $Sprite
GD.Expression.GetUniqueNode("Player") // %Player
GD.Expression.Lambda(body) // func(): body
GD.Expression.Await(signal) // await signal
GD.Statement.If(condition, thenStatements)
GD.Statement.For("i", range, body)
GD.Statement.Match(expression, cases)
| Package | Description |
|---|---|
| GDShrapt.Reader | Core parser and AST (required) |
| GDShrapt.Validator | Compiler-style AST validation |
| GDShrapt.Linter | Style checking and naming conventions |
| GDShrapt.Formatter | Code formatting with type inference |
Full documentation and examples: GitHub Repository
MIT License - see LICENSE for details.