IndicatorService
AUTO-GENERATED FILE – DO NOT EDIT MANUALLY
IndicatorService - Service component for managing rule-check indicators within IndicatorManager.
Source File: addons/grid_building/placement/manager/components/indicator_service.gd
Extends: GBInjectable
Signals
Signal:
indicators_changed(_indicators: Array[RuleCheckIndicator])Emitted when the active RuleCheckIndicators change. Usually in response to a placement or move action that needs rule evaluation for TileCheckRules. Also emitted during reset operations when indicators are cleared.
Private Properties
- Property:
_indicators: Array[RuleCheckIndicator] = [](private) - Property:
_collision_mapper : [CollisionMapper](./collision-mapper/)(private) - Property:
_testing_indicator: [RuleCheckIndicator](./rule-check-indicator/)(private) - Property:
_indicator_template: PackedScene(private) - Property:
_targeting_state: [GridTargetingState](./grid-targeting-state/)(private) - Property:
_logger : [GBLogger](./gb-logger/)(private) - Property:
_indicator_contact_positions: Array = [](private) - Property:
_indicators_parent : Node(private) - Property:
_starting_rotation : float(private) - Property:
_starting_scale : Vector2(private)
Public Methods
create_with_injection
Flags: static
Creates an IndicatorService with dependency injection from container. Container serves as single source of truth for all dependencies. This method handles the complete setup including dependency resolution, validation, and logging of any issues found during initialization.
Parameters:
container: GBCompositionContainer - The dependency container providing all required services
parent: Node2D - The parent node for indicators (required - cannot be resolved from container)
Returns: IndicatorService - Fully configured indicator service with validated dependencies
Note: Callers should check get_runtime_issues() after creation to handle any validation warnings.
resolve_gb_dependencies
Resolves dependencies from the composition container. This method is called during initialization and can be called again if the container becomes available later. Primarily used to inject dependencies into the collision mapper.
Parameters:
container: GBCompositionContainer - The dependency container to resolve dependencies from
Returns: bool - True if dependencies were successfully resolved, false otherwise
force_update
Forces all managed indicators to update their shapecast collision detection. This is useful when the scene state has changed and indicators need to recalculate their collision status without regenerating the indicators themselves. Only processes indicators that are still valid instances.
get_runtime_issues
Validates that all required dependencies and state are properly set. Performs comprehensive validation of the indicator service’s internal state including parent node validity, template availability, targeting state readiness, logger availability, and collision mapper dependency issues.
Returns: Array[String] - List of validation issues (empty if all dependencies are valid)
Note: This method is non-mutating and safe to call frequently for diagnostic purposes.
reset
Performs comprehensive cleanup of all managed indicators and test setups. This enhanced reset function provides critical cleanup logging and orphaned indicator detection to prevent test pollution and ensure proper teardown.
Cleanup sequence:
- Frees all managed indicators with proper validation
- Clears collision mapper test setups
- Cleans up testing indicator with extra validation
- Detects and removes orphaned testing indicators from the scene tree
- Emits indicators_changed signal to notify listeners
Parameters:
parent_node: Node - Optional parent node to check for orphaned indicators
Note: This method includes critical logging for debugging cleanup issues and double-validation to ensure indicators array is properly cleared.
is_service_ready
Checks if the service is in a ready state for indicator operations. Returns true when all critical dependencies are available.
get_indicators
Returns a duplicate of the current indicators array for safe external use. This method provides read-only access to the managed indicators without allowing external modification of the internal indicators array.
Returns: Array[RuleCheckIndicator] - Duplicate of current indicators (safe for external iteration)
get_diagnostic_info
Returns diagnostic information about the current state of the indicator service. This method provides comprehensive diagnostic data useful for debugging indicator cleanup issues, test pollution, and understanding the current state of the service.
The returned dictionary includes:
indicators_count: Number of currently managed indicatorshas_testing_indicator: Whether a testing indicator existstesting_indicator_valid: Whether the testing indicator is a valid instancecollision_mapper_setups_count: Number of collision mapper test setupsorphaned_indicators: Array of orphaned indicators found (currently unused)
Returns: Dictionary - Diagnostic information about the indicator service’s current state
Note: This method is non-mutating and safe to call for debugging purposes.
get_collision_mapper
Gets the collision mapper instance. [returns] The collision mapper instance.
set_indicators
setup_indicators
Creates and positions rule check indicators for validation. This is the main method for setting up indicators based on a test object and tile check rules. The method performs comprehensive validation, collision mapping, and indicator generation with detailed error reporting and diagnostic metadata.
Process overview:
- Validates environment and inputs through guard checks
- Normalizes positioning for stable geometry calculations
- Gathers collision shapes from the test object
- Sets up collision mapper with test configurations
- Maps collision positions to applicable rules
- Generates indicators using the factory pattern
- Builds and returns comprehensive setup report
Parameters:
p_test_object: Node2D - The object being tested for placement
p_tile_check_rules: Array[TileCheckRule] - Rules to create indicators for
parent_node: Node - Parent node to attach indicators to
Returns: IndicatorSetupReport - Contains created indicators plus diagnostic metadata
Note: This method includes extensive logging and error handling to support debugging and testing scenarios. It will return error reports instead of throwing exceptions.
calculate_indicator_count
Calculates the number of indicators that would be created for a test object without actually creating them.
This performs the same collision analysis as setup_indicators but stops before indicator creation.
p_test_object The object to test for placement.
p_tile_check_rules The tile check rules to apply.
[returns] The number of indicators that would be created, or -1 if calculation fails.
build_collision_test_setups
Builds per-owner collision test setups for CollisionMapper using utility function. Creates appropriate test setup configurations for different collision owner types. This is a convenience wrapper around IndicatorSetupUtils.build_collision_test_setups().
Parameters:
owner_shapes: Dictionary[Node2D, Array] - Mapping of collision owners to their shapes
tile_size: Vector2i - Size of tiles for positioning calculations
Returns: Dictionary - Test setups keyed by collision owner
build_collision_test_setups_with_targeting_state
Builds collision test setups using targeting state for more accurate configuration. This variant uses the service’s GridTargetingState for consistent tile size handling. This is a convenience wrapper around IndicatorSetupUtils.build_collision_test_setups_with_factory().
Parameters:
owner_shapes: Dictionary[Node2D, Array] - Mapping of collision owners to their shapes
Returns: Dictionary - Test setups keyed by collision owner
gather_collision_shapes
Gathers collision shapes from a test object. This is a convenience wrapper around IndicatorSetupUtils.gather_collision_shapes().
Parameters:
test_object: Node2D - Object to gather collision shapes from
Returns: Dictionary[Node2D, Array] - Mapping of collision owners to their shapes
validate_indicator_positions
Validates indicator positions against expected positions. This is a convenience wrapper around IndicatorSetupUtils.validate_indicator_positions().
Parameters:
indicators: Array[RuleCheckIndicator] - Indicators to validate
expected_positions: Array[Vector2i] - Expected tile positions
Returns: IndicatorSetupUtils.PositionValidationResult - Validation result with details
validate_setup_preconditions
Validates setup preconditions for indicator creation. This is a convenience wrapper around IndicatorSetupUtils.validate_setup_preconditions().
Parameters:
test_object: Node2D - Object being tested for placement
tile_check_rules: Array[TileCheckRule] - Rules to validate
Returns: Array[String] - List of validation issues (empty if all valid)
get_or_create_testing_indicator
Gets or creates a testing indicator using the utility function. Uses lazy initialization to create the testing indicator only when needed. This is a convenience wrapper around IndicatorSetupUtils.create_testing_indicator().
Parameters: parent_node - The parent node for the testing indicator
Returns: RuleCheckIndicator - The testing indicator instance, or null if creation fails
get_colliding_indicators
Returns array of indicators that are currently colliding with other objects. Filters all managed indicators to find only those with active collision states. This is useful for determining which placement positions are blocked or invalid.
Returns: Array[RuleCheckIndicator] - Array of indicators currently in collision state
Note: Only includes indicators that are valid instances and have active collisions.
get_colliding_nodes
Returns array of Node2D objects that are colliding with any indicators. Collects all unique collision objects from all colliding indicators. This provides a convenient way to identify which scene objects are blocking placement.
Returns: Array - Array of unique Node2D objects colliding with any managed indicators
Note: Automatically deduplicates colliding nodes to avoid duplicates in the result.
add_indicators
Adds new indicators to the managed collection. Appends the provided indicators to the internal indicators array and emits the indicators_changed signal to notify listeners of the change.
Parameters:
new_indicators: Array[RuleCheckIndicator] - New indicators to add to the collection
Note: Safely handles null or empty arrays by returning early without modification.
free_indicators
Frees and removes indicators from memory and scene tree. Enhanced cleanup method that properly handles indicator lifecycle management with validation and comprehensive cleanup logging.
Parameters:
to_free: Array[RuleCheckIndicator] - Indicators to free and remove
Note: Creates a copy of the array before clearing to avoid modification during iteration. Includes validation and error logging for debugging cleanup issues.
clear_indicators
Private Methods
_init
Flags: private
_find_all_indicators
Flags: private
Helper method to recursively find all RuleCheckIndicator nodes in the scene tree. Used internally for diagnostic purposes to locate indicator instances.
Parameters:
node: Node - Root node to start the recursive search from
result: Array - Array to append found indicators to (modified in-place)
_get_corner_suffix
Flags: private
Helper function to determine if a tile position is at a corner and return appropriate suffix. Analyzes the current indicator positions to determine bounds and identifies corner positions.
Parameters:
tile_pos: Vector2i - The tile position to check for corner status
Returns: String - Corner abbreviation (TL, TR, BL, BR) or empty string if not a corner
_log_summary
Flags: private
_get_indicator_tile_pos
Flags: private
Helper: compute tile position for an indicator using targeting state
_reconcile_indicators
Flags: private
Reconcile newly created indicators with existing managed indicators. Strategy:
- Build a map of existing indicators keyed by tile position
- For each new indicator, compute its tile position; if an existing indicator exists at that position, reuse it: clear its rules and add the rules from the new indicator, update its global_position and visuals, then free the newly created duplicate.
- Any existing indicators not matched are freed.
- Returns the final array of indicators managed by the service.