ValidPlacementTileRule
AUTO-GENERATED FILE — DO NOT EDIT MANUALLY
Source: systems/placement/validators/placement_rules/template_rules/valid_placement_tile_rule.gd
Version: 5.1
class_name: ValidPlacementTileRule
extends: TileCheckRule
Summary
A rule that validates a tile position based on a tilemap’s custom data fields.
This rule checks if a tile at a potential placement position has all the required custom data fields and matching values defined in its expected_tile_custom_data dictionary. It’s used to ensure that a tile can only be placed on a specific type of ground, such as “walkable” or “buildable” tiles.
Usage:
- Assign this rule to a GBCompositionContainer for context wide injection or to a Placeable for placeable specific rule evaluation
- Set the
expected_tile_custom_datadictionary to define the required key-value pairs (e.g.,{ "type": "ground", "variant": "grass" }). - The rule will fail if the tile at the indicator’s position does not contain all the required custom data or if any values do not match.
Signals
(none)
Exports
expected_tile_custom_data- Expected custom data fields and values for valid tiles.
settings- Settings for the valid placement tile rule. Defines custom messages for this rule’s validation.
Methods
_init()_ensure_settings()- Lazy initialization of settings - creates default settings if none are provided
setup()- Creates tile indicators on matching layers to test that colliding tiles exist in shape spaces around the object to be placed
validate_placement()- Check each tile indicator of this test to ensure that they collide with the tilemap
_get_failing_indicators()- Runs the rule against an array of indicators and Returns the failing indicators
tear_down()- Frees tile indicators created for this test when the building system no longer is using this rule
does_tile_have_valid_data()- Validates if tile data contains all expected custom data across provided maps. Returns true only if all expected custom data keys match at least one layer in the tile data.[br][br] [code]p_indicator[/code]: [i]RuleCheckIndicator[/i] - The indicator object marking the tile position to check[br] [code]p_maps[/code]: [i]Array[TileMapLayer][/i] - Array of TileMapLayer or TileMap nodes to check against
_get_tile_position()- Helper function to convert indicator position to tile coordinates
_tile_has_matching_data()- Helper function to check if a tile contains any matching custom data
_test_tile_data_for_all_matches()- Checks if the tile data meets all required custom data matches
_post_setup_validation()