GridPositioner2D
AUTO-GENERATED FILE – DO NOT EDIT MANUALLY
Controls the on-grid cursor used by building/interaction systems.
Source File: addons/grid_building/systems/grid_targeting/grid_positioner/grid_positioner_2d.gd
Extends: Node2D
Properties
- Property:
input_processing_enabled: bool = false- Public flag & API for enabling/disabling input processing (used by tests)
Private Properties
- Property:
_debug_settings: [GBDebugSettings](./gb-debug-settings/) = null(private) - Property:
_logger: [GBLogger](./gb-logger/) = null(private) - Property:
_actions: [GBActions](./gb-actions/) = null(private) - Property:
_targeting_state : [GridTargetingState](./grid-targeting-state/) :(private) - The state of the building/targeting system holding a reference to this positioner. - Property:
_targeting_settings : [GridTargetingSettings](./grid-targeting-settings/)(private) - Property:
_mode_state : [ModeState](./mode-state/) :(private) - Property:
_last_mouse_world: Vector2 = Vector2.ZERO(private) - Property:
_has_mouse_world: bool = false(private) - Property:
_enabled_internal: bool = false(private) - Property:
_last_mouse_input_status := GBMouseInputStatus.new()(private) - Property:
_last_gate_allowed: bool = false(private) - Property:
_last_manual_recenter_mode: int = GBEnums.CenteringMode.CENTER_ON_SCREEN(private) - Property:
_last_visibility_event_reason: String = ""(private)
Constants
- Constant:
LOG_PREFIX : String = "[GridPositioner2D]"
Public Methods
set_input_processing_enabled
Public API used by tests to enable input handling on this node.
is_input_processing_enabled
is_input_ready
Public helper: returns true when dependencies are injected and a target map is assigned
are_dependencies_ready
Helper: returns true when all critical dependencies are injected (logger, settings, mode state) Use this to guard input methods that need to log or access settings
resolve_gb_dependencies
Standard dependency injection method called by GBInjectorSystem. This is the primary integration pattern - implement this method to participate in DI. Internally delegates to set_dependencies() for actual wiring.
move_to_viewport_center_tile
Move positioner to the center tile of the viewport/camera view. Returns the tile coordinate where the positioner was positioned, or Vector2i.ZERO if failed.
move_to_cursor_center_tile
Move positioner to the center tile at the cursor location when available. Falls back to viewport mouse, then TileMap global, then view center. Returns the tile coordinate where the positioner was positioned.
get_last_manual_recenter_mode
Retrieve the last manual recenter mode applied.
remove_self_as_positioner
Removes this object from being set to the _targeting_state.positioner property
update_visibility
Uses whether the mouse movement was consumed by UI to determine if the positioner and child objects should be visible or invisible. Only called when hide_on_handled is true
should_be_visible
Returns whether the positioner should be visible given current mode/settings. Mouse handled gating remains event-driven and is not applied here.
set_dependencies
Internal dependency injection helper method.
For runtime use, prefer implementing resolve_gb_dependencies() which is called by GBInjectorSystem.
This method is primarily for testing and advanced use cases where you need explicit control.
p_states GBStates providing .targeting and .mode
p_config GBConfig for settings (expects settings.targeting)
p_logger Optional GBLogger for diagnostics
p_actions Optional GBActions for keyboard bindings
enable_input When true, enable input processing immediately (default true)
get_runtime_issues
Checks if the properties of the GridPositioner2D are set properly during gameplay. Returns validation issues if dependencies are missing, empty array if valid.
return: Array[String] - List of validation issues (empty if valid)
validate_dependencies
Runtime validation logs all issues that should be resolved at runtime
Call after all dependencies are expected to be resolved.
get_visual_node
Visual helpers are provided by GBSearchUtils universally
is_visual_visible
log_current_visual_state
Helper: explicit render state log for manual triggering if needed
is_positioner_active
(Stack summary moved to GBDiagnostics.format_stack_summary) Whether the positioner is active and should update each frame
should_hide_under_handled_ui
Whether the positioner should hide when the mouse events are handled by UI
are_dependencies_resolved
Check if all critical dependencies have been resolved
to_diagnostic_string
Diagnostics: concise state summary for tests and debug logging Safe to call even before dependency injection - provides fallback values
Private Methods
_init
Flags: private
Fail fast design. Defaults should be explicitly set by scenes or tests.
_ready
Flags: private
_physics_process
Flags: private
_process
Flags: private
_input
Flags: private
Handles all input for the positioner including mouse movement, keyboard movement, and visibility INPUT: All mouse movement is handled here in response to events; not in physics.
_handle_mouse_motion_event
Flags: private
Extracted helper: handle an InputEventMouseMotion event (snapped move + visibility)
_convert_screen_to_world
Flags: private
Deprecated: Use GBPositioning2DUtils.get_tile_from_global_position() and move_to_tile_center() instead. This function has been removed to maintain DRY principles and single source of truth. Single source of truth: centralized screen-to-world coordinate conversion Delegates to GBPositioning2DUtils for DRY compliance and maintainability
_move_to_cached_mouse_world
Flags: private
Deprecated: Use GBPositioning2DUtils.get_tile_from_global_position() and move_to_tile_center() instead. This function has been removed to maintain DRY principles and single source of truth. Move the positioner back to its cached mouse world location when available.
_cache_current_world_position
Flags: private
Cache the current global position as the latest mouse world reference.
_get_active_viewport
Flags: private
Helper: retrieve active Viewport for the current target map (may be null)
_get_active_camera
Flags: private
Helper: retrieve active Camera2D from a viewport (may be null)
_is_disabled_in_off_mode
Flags: private
Helper: check if positioner should be disabled when in OFF mode Returns true if positioner should be blocked from input/positioning in OFF mode
_is_mouse_cursor_on_screen
Flags: private
Helper: check if mouse cursor is within viewport bounds Returns true if mouse cursor is within the visible viewport area
_is_mouse_follow_allowed
Flags: private
Helper: decide whether mouse-follow behavior should run this frame
_mouse_input_gate
Flags: private
Returns a gate result for handling mouse input with an explicit reason when blocked
_apply_mouse_world
Flags: private
Centralizes caching + movement application and diagnostics
_log_mouse_motion
Flags: private
Helper: structured mouse motion log
_log_mouse_gate
Flags: private
Helper: structured mouse gate log
_apply_recenter_on_enable
Flags: private
Recenter behavior when movement/input becomes enabled again User-specified logic: move to mouse cursor if mouse enabled and cursor on screen, otherwise move to center tile position Respects the active when off setting - no positioning changes when disabled in OFF mode
_apply_positioning_and_visibility_sequence
Flags: private
Apply positioning and then visibility in proper sequence after dependency injection This ensures Camera2D is available for positioning and visibility is updated based on final position
_recenter_decision_to_string
Flags: private
_handle_mouse_movement
Flags: private
Handle mouse movement to update positioner position.
If a mouse_global_override is provided (e.g., from InputEventMouseMotion),
it will be used instead of querying the viewport/cursor state. This enables
compatibility with tests (SceneRunner) and hidden cursor scenarios.
_move_positioner_by_tile
Flags: private
Moves the positioner by a specified number of tiles in a given direction.
p_direction: Vector2 - Direction vector (e.g., Vector2(1,0) for right, Vector2(0,1) for down)
_apply_recenter
Flags: private
Apply manual recenter logic based on settings.
_exit_tree
Flags: private
_on_mode_changed
Flags: private
_should_be_visible_for_mode
Flags: private
Helper to compute visibility given an explicit mode value
_set_visible_state
Flags: private
Helper to keep this node and its visual in sync for visibility
_schedule_end_of_frame_state_log
Flags: private
Schedule end-of-frame state logging (deferred to next frame to catch final state)
_log_end_of_frame_state_async
Flags: private
Async log of end-of-frame state (called deferred)
_log_screen_and_mouse_state
Flags: private
Diagnostic: log screen/camera bounds, positioner screen relation, mouse world, and tile info
_visibility_context
Flags: private
Build a visibility context string: first hidden ancestor, alpha, z-index, and position
_set_visibility_reason
Flags: private
_visibility_decision_trace
Flags: private
_get_debug_log_mode
Flags: private
_is_logging_mode
Flags: private
_is_visibility_logging_enabled
Flags: private
_is_mouse_input_logging_enabled
Flags: private
_is_positioning_logging_enabled
Flags: private
_is_state_flow_logging_enabled
Flags: private
_log_debug
Flags: private
_log_visibility
Flags: private
_log_mouse
Flags: private
_log_positioning
Flags: private
_log_state_flow
Flags: private
_test_convert_screen_to_world
Flags: private
Unit test helper: verify screen-to-world coordinate conversion Returns the converted world position for testing purposes
_test_get_tile_center_from_screen
Flags: private
Unit test helper: verify tile center calculation Returns the tile coordinate and world position for testing
_apply_visibility_result
Flags: private