ValidPlacementTileRule
Summary
Section titled “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.
Properties
Section titled “Properties”- expected_tile_custom_data = {}
- Expected custom data fields and values for valid tiles. 
- settings: ValidPlacementRuleSettings
- Settings for the valid placement tile rule. Defines custom messages for this rule’s validation. 
Methods
Section titled “Methods”- func _init( p_expected_tile_data: Dictionary )
- func _ensure_settings( ) -> ValidPlacementRuleSettings
- Lazy initialization of settings - creates default settings if none are provided 
- func setup( p_gts: GridTargetingState ) -> Array[String]
- Creates tile indicators on matching layers to test that colliding tiles exist in shape spaces around the object to be placed 
- func validate_placement( ) -> RuleResult
- Check each tile indicator of this test to ensure that they collide with the tilemap 
- func _get_failing_indicators( p_indicators: Array[RuleCheckIndicator] ) -> Array[RuleCheckIndicator]
- Runs the rule against an array of indicators and Returns the failing indicators 
- func tear_down( )
- Frees tile indicators created for this test when the building system no longer is using this rule 
- func does_tile_have_valid_data( p_indicator: RuleCheckIndicator, p_maps: Array[TileMapLayer] ) -> bool
- 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. - p_indicator: RuleCheckIndicator - The indicator object marking the tile position to check- p_maps: Array[TileMapLayer] - Array of TileMapLayer or TileMap nodes to check against
- func _get_tile_position( map: Node2D, indicator: RuleCheckIndicator ) -> Vector2i
- Helper function to convert indicator position to tile coordinates 
- func _tile_has_matching_data( map: Node2D, tile_pos: Vector2i ) -> bool
- Helper function to check if a tile contains any matching custom data 
- func _test_tile_data_for_all_matches( p_tile_data: TileData, p_required_custom_data: Dictionary ) -> bool
- Make sure the tile data has the custom_data requirements - Checks if the tile data meets all required custom data matches 
- func _post_setup_validation( ) -> Array[String]
Source
Section titled “Source”addons/grid_building/placement/placement_rules/template_rules/valid_placement_tile_rule.gd
This API reference is automatically generated from the plugin source code. For implementation examples and usage guides, see the guides section.