Skip to content
简体中文

Typed game configuration ​

Files and project setup ​

  1. Install GeWuYou.GFramework.Game and GeWuYou.GFramework.Game.SourceGenerators.
  2. Put schemas under schemas/. Put YAML files in the directory specified by x-gframework-config-path, with one record per file.
  3. The NuGet generator includes schemas/**/*.schema.json as compilation inputs. With project references, configure AdditionalFiles in the consuming project.
  4. After building, use the generated tables and registration helpers in GFramework.Game.Config.Generated.

Schema and data ​

The GodotIntegration example defines an integer ID and a speed range for each record:

json
{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "x-gframework-config-path": "config/gameplay",
  "type": "object",
  "additionalProperties": false,
  "required": ["id", "speed"],
  "properties": {
    "id": { "type": "integer" },
    "speed": { "type": "number", "minimum": 20, "maximum": 600 }
  }
}
yaml
# Copyright (c) 2025-2026 GeWuYou
# SPDX-License-Identifier: Apache-2.0
id: 1
speed: 220

Set additionalProperties: false explicitly on objects. Declare one items schema for an array. Represent variations with explicit object fields and use supported object conditions for validation. See the configuration generator reference for keywords and diagnostics.

Load and read tables ​

csharp
using GFramework.Game.Config;
using GFramework.Game.Config.Generated;

var registry = new ConfigRegistry();
var loader = new YamlConfigLoader("config-root")
    .RegisterAllGeneratedConfigTables();
await loader.LoadAsync(registry);

Set config-root to the directory containing config/ and schemas/. After loading, resolve a generated table from the registry and look up records by ID. Provide the registry to consumers as an instance dependency. Use GameConfigBootstrap to manage loading and the reload handle together.

Godot exports and reloads ​

Use GodotYamlConfigLoader to read schema and YAML files from res://. Include these text files in the export preset. During development, enable hot reload for an accessible filesystem path. Log reload diagnostics and keep the previous table when a reload fails. Dispose the reload handle when the session ends.

To combine base and extension data, see content packs. To edit configuration, see the VS Code configuration tool.

Apache License 2.0