GridTargetingState

AUTO-GENERATED FILE – DO NOT EDIT MANUALLY

State for targeting objects within the Grid Building System.

Source File: addons/grid_building/systems/grid_targeting/grid_targeting_state.gd

Extends: GBResource

Signals

  • Signal: ready_changed(value : bool) - Emitted when the readiness status of the state has changed - usually after successful validation.

  • Signal: target_changed(new : Node2D, old : Node2D)

    Emitted when the target node for the state is changed.

    NOTE: Typically target is set by a TargetingShapeCast2D or similar casting node from the runtime scene

  • Signal: positioner_changed(positioner : Node2D) - Emitted when the node responsible for positioning grid building placement objects and indicators is changed on the BuildingState.

  • Signal: target_map_changed(target_map : TileMapLayer)

    Emitted when the targeted map node is changed. This represents the main target TileMapLayer node on the state.

  • Signal: maps_changed(maps : Array[TileMapLayer])

    Emitted when the list of known maps is changed.

    This is a list of maps that can be accessed without the need for any collision check calls.

Properties

  • Property: target : Node2D : - The placed node currently being targeted

  • Property: positioner : Node2D : - Parent node for positioning grid building objects onto the game world.

  • Property: target_map : TileMapLayer :

    The TileMapLayer or TileMap node to be used when determining grid distances in your game world

    You could think of this as the main map node usually where characters stand on

  • Property: maps : Array[TileMapLayer]:

    All maps to be known by the targeting state for testing against without casting for collisions.

    You can exclude any purely cosmetic maps that shouldn’t have gameplay impacts.

  • Property: tile_size: Vector2i : - Tile size property that delegates to the target map’s tile set

  • Property: collision_exclusions: Array[Node] = []

    Nodes that should be excluded from collision detection during indicator validation. This is primarily used during manipulation move operations to exclude the original object being moved, so indicators only detect collisions with OTHER objects.

    IMPORTANT: This list is automatically cleared when:

    • The target changes (manipulation ends and switches to a different target)
    • Manually calling clear_collision_exclusions()

    Usage: Set this at the start of manipulation move operations and it will auto-clear when manipulation ends.

  • Property: is_manual_targeting_active: bool = false

    Flag indicating whether manual targeting mode is currently active. When true, automatic targeting systems (like TargetingShapeCast2D) will not overwrite the manually-set target, and collision_exclusions will persist across target updates. Used during BUILD mode (preview) and MOVE mode (manipulation copy). Set via set_manual_target() and cleared via clear_manual_target().

Private Properties

  • Property: _owner_context : [GBOwnerContext](./gb-owner-context/) (private) - References the user root that serves as the origin for this targeting state
  • Property: _target_signal_connected : bool = false (private)

Public Methods

is_ready

1
is_ready() -> bool

Returns true if the targeting state has all runtime requirements met for operation


clear_collision_exclusions

1
clear_collision_exclusions() -> void

Clears the collision exclusion list. This is called automatically when the target changes (and manipulation is not active), but can also be called manually when ending manipulation operations.


set_manual_target

1
set_manual_target(p_target: Node2D) -> void

Sets a manual target and prevents automatic targeting updates. This prevents automatic targeting systems (like TargetingShapeCast2D) from overwriting the manually-set target. Used during:

  • BUILD mode: Locks preview as target
  • MOVE mode: Locks manipulation copy as target

If p_target is null, clears manual targeting mode (equivalent to clear_manual_target()). Otherwise, enables manual targeting and assigns the target.

p_target The node to manually target, or null to clear manual targeting


clear_manual_target

1
clear_manual_target() -> void

Clears manual targeting mode and resumes automatic targeting. Call this when BUILD or MOVE mode ends to allow TargetingShapeCast2D to automatically update the target again. Note: Does NOT clear the target node itself - only disables the manual targeting flag.


set_map_objects

1
2
3
4
set_map_objects(
    p_target_map: TileMapLayer,
    p_maps: Array[TileMapLayer]
) -> void

Sets the target map and maps array for this targeting state


get_target_map_tile_shape

1
get_target_map_tile_shape() -> TileSet.TileShape

Get the shape of the currently targeted TileMapLayer’s tileset tiles


get_target_map_tile_set

1
get_target_map_tile_set() -> TileSet

Gets the tileset of the currently targeted TileMapLayer


get_tile_size

1
get_tile_size() -> Vector2i

Gets the tile size from the target map’s tile set


set_tile_size

1
set_tile_size(size: Vector2i) -> void

Sets the tile size on the target map’s tile set


validate_runtime

1
validate_runtime(logger: GBLogger = null) -> bool

Ensures that the targeting state is ready for runtime operation and logs any issues found


get_owner

1
get_owner() -> Node

get_owner_root

1
get_owner_root() -> Node

get_origin

1
get_origin() -> Node

Returns the origin node associated with this targeting state. [return] The origin node provided by the owner context or null when unavailable.


get_editor_issues

1
get_editor_issues() -> Array[String]

Returns an array of issues found during editor validation


get_runtime_issues

1
get_runtime_issues() -> Array[String]

Should be called AFTER necessary properties on the state have been set Checks the minimum setup dependencies for the state.


Private Methods

_init

1
_init(p_owner_context : GBOwnerContext)

Flags: private


_revalidate_on_change

1
_revalidate_on_change() -> void

Flags: private

Internal: Re-validate when critical properties change so ‘ready’ flips to true at the right time.


_disconnect_target_signal

1
_disconnect_target_signal() -> void

Flags: private

Disconnects the tree_exiting signal from the current target (if connected)


_on_target_tree_exiting

1
_on_target_tree_exiting() -> void

Flags: private

Called when the current target is about to exit the scene tree


_is_same_context_update

1
_is_same_context_update(new_target: Node2D) -> bool

Flags: private

Checks if the new target is part of the same object tree as any exclusion Returns true if new_target is a child/descendant of an excluded node This helps detect when TargetingShapeCast2D detects a different node of the same logical object