Validation: Configuration (5.0.3)
This page outlines validation utilities for configuration validation at initialization, checking that settings, resources, and dependencies are properly configured when the scene loads.
Configuration Validation with PlacementValidator
In 5.0.3: PlacementValidator handles validation. It uses placement rules to validate potential placements at runtime.
Core Validation Classes
- PlacementValidator: The main class that orchestrates validation. It takes a list of rules and evaluates them against the current placement context.
- ValidationResults: A data container that captures the outcome of validation. It holds
is_successful,issues(errors), andwarnings.
How It Works
- Setup: Create a
PlacementValidatorwith your configured rules. - Validation: Call
validate_placement(context)to check a potential placement. - Results: Get a
ValidationResultsobject with success status and any issues.
ValidationResults
| Property | Type | Description |
|---|---|---|
is_successful | bool | True if no blocking issues were found. |
issues | Array[String] | List of critical errors that prevent operation. |
warnings | Array[String] | List of non-critical observations. |
Usage Example
By standardizing on PlacementRule, the system can transparently inspect, validate, and execute rules without needing to know the specific logic of every single rule type.
Tips
- Keep configuration validation fast; it runs during entity creation or system startup.
- Differentiate between Invalid Configuration (developer error, e.g., missing resource) and Invalid Placement (player error, e.g., placing inside a wall).
- Use
ValidationResultsto combine results from multiple rules into a single report.
Related Guides
Validated By
The validation architecture is verified by the following test suites, which ensure that validation result containers and rule components behave correctly under various configurations.
- Configuration Validation: res://addons/grid_building/test/utilities/gb_configuration_validator_test.gd - Verifies that the injector correctly triggers validation after wiring.
- Result Management: res://addons/grid_building/test/rules/validation/valid_placement_tile_rule_test.gd - Tests tile rule validation and placement correctness.
- System Integration: res://addons/grid_building/test/rules/validation/rule_system_integration_tests.gd - Validates the full sequence of validation logic within the placement systems.