Skip to content

GridTargetingSystem

Tracks mouse position on the target map with tile snapping.

Converts screen coordinates to grid coordinates and manages grid-based targeting for placement and manipulation systems.

signal astar_grid_changed( astar_grid: AStarGrid2D )

Emitted when the AStarGrid2D used by the Grid Targeting System is created or changes

target_tile: Vector2

The tile location where the mouse is currently hovering over represented as X / Y values of the _targeting_state.target_map

mouse_handled: bool = false

Whether the mouse input was consumed by GUI already or not

astar_grid = AStarGrid2D.new()

Pathfinding for a 2d Tile Grid through the AStar search algorithm

get_runtime_issues( ) -> Array[String]

Validates that all required dependencies are properly set. Returns list of validation issues (empty if valid).

get_state( ) -> GridTargetingState

Compatibility accessor for older tests expecting get_state(). Returns the underlying GridTargetingState used by this system.

_process( delta: float ) -> void

Continuous positioner updates on _process() instead of only on mouse movement

resolve_gb_dependencies( p_container: GBCompositionContainer ) -> void
move_node_to_closest_valid_tile( p_target_tile: Vector2i, p_positioner: Node2D, p_source: Node2D ) -> Error

Move the positioner to adjust the shown position of any visual _targeting_settings elements. If limit_to_adjacent setting is on, the closest valid target will be limited by the p_source position and the max_tiles_distance.

p_target_tile: Vector2i - Desired tile location to move to

p_positioner: Node2D - Node to move to the target position

p_source: Node2D - Source node for distance calculations when limit_to_adjacent is enabled

move_to_tile( p_node: Node2D, p_tile: Vector2 ) -> Error

Adjust by p_tile_map position to get global position

Moves a target node to the center snapped position of a p_tile on the _targeting_state.target_map.

p_node: Node2D - Node to move to the tile position

p_tile: Vector2 - Tile coordinates to move to

get_tile_from_global_position( p_global_position: Vector2, p_map: Node2D )

Returns the tile on the p_tile_map where the mouse is currently hovering over.

p_global_position: Vector2 - Global position to convert to tile coordinates

p_map: Node2D - TileMap or TileMapLayer to use for coordinate conversion

get_max_tile_distance_tile_to_target( p_node: Node2D, p_target_tile: Vector2i )

Given a target tile, finds the tile that is the closest to the target that does not go above the max tile distance from the p_node Node2D. Returns valid tile Vector2i or null if none available.

p_node: Node2D - Source node for distance calculations

p_target_tile: Vector2i - Target tile to find closest valid tile to

update_astar_grid_2d( p_astar: AStarGrid2D, p_targeting_settings: GridTargetingSettings )

Updates an AStarGrid2D according to a set of GridTargetingSettings.

p_astar: AStarGrid2D - AStar grid to configure

p_targeting_settings: GridTargetingSettings - Settings to apply to the AStar grid

snap_tile_to_region( p_tile: Vector2i, p_region: Rect2i ) -> Vector2i

Give a tile position Vector2i, returns the closest point in the rect2i.

p_tile: Vector2i - Tile position to snap to region bounds

p_region: Rect2i - Rectangle region to snap the tile position within

validate_and_log_issues( ) -> Array[String]

Public manual validation entry point for host projects. Runs get_runtime_issues() and logs issues without relying on timed warnings. Returns the list of issues (empty when valid).

validate_ready( ) -> bool

For tests we expect the system to be inside the scene tree already.

get_targeting_issues( ) -> Array[String]

Gets issues that would prevent the targeting_system from being able to target. This should be called after grid targeting state properties have all been defined

addons/grid_building/systems/grid_targeting/grid_targeting_system.gd


This page was auto-generated from GDScript source. Edit the source file to improve documentation.

Generated on 2025-09-07