Class IndicatorService
- Namespace
- GridPlacement.GDScript
- Assembly
- MoonBark.GridPlacement.GDScript.dll
IndicatorService - Service component for managing rule-check indicators within IndicatorManager.\n\nThis class is a service component that IndicatorManager uses to handle the creation, placement, and lifecycle management of RuleCheckIndicator instances. It encapsulates the complex logic for indicator setup, collision mapping, and diagnostic reporting while providing a clean interface for IndicatorManager to delegate indicator-related operations.\n\n## Architecture Role IndicatorService acts as a specialized component within the IndicatorManager architecture: - IndicatorManager: Main coordinator that owns and orchestrates indicator operations - IndicatorService: Service component that handles the detailed implementation - IndicatorFactory: Pure logic class for indicator creation and validation\n\n## Key Responsibilities - Execute indicator setup workflows with collision mapping and validation - Manage indicator lifecycle including creation, positioning, and cleanup - Provide diagnostic capabilities and comprehensive error reporting - Handle collision detection integration with CollisionMapper - Generate detailed setup reports for testing and debugging\n\n## Usage Pattern var service = IndicatorService.create_with_injection(container, parent_node) var report = service.setup_indicators(test_object, rules, parent_node) var indicators = service.get_indicators() service.reset()\n\nFor detailed usage guide and examples, see: docs_website/docs/systems/indicator_manager_guide.md\n\nResponsibilities: - Execute indicator setup workflows with collision mapping and validation - Manage indicator lifecycle including creation, positioning, and cleanup - Provide diagnostic capabilities and comprehensive error reporting - Handle collision detection integration with CollisionMapper - Generate detailed setup reports for testing and debugging - Maintain indicator state and provide access to managed indicators - Support comprehensive reset functionality with orphaned indicator detection\n\nKey Features: - Comprehensive reset() function with critical cleanup logging and orphaned indicator detection - Guarded indicator setup with detailed error reporting and diagnostic metadata - Collision mapper integration with test setup management and validation - Grid alignment utilities for stable geometry calculations - Diagnostic information reporting for debugging indicator state and issues - Dependency injection support with comprehensive validation - Signal emission for indicator state changes to support reactive programming
class IndicatorService extends GBInjectable
Properties
p
var p = new_ind.get_parent()
targeting_state
var targeting_state = container.get_targeting_state()
logger
var logger = container.get_logger()
template
var template = container.get_templates().rule_check_indicator
manager
var manager = IndicatorService.new(parent, targeting_state, template, logger)
issues
var issues: Array[String] = []
collision_mapper_injected
var collision_mapper_injected: bool = _collision_mapper.resolve_gb_dependencies(container)
issues
var issues: Array[String] = []
p
var p = new_ind.get_parent()
cleanup_parents
var cleanup_parents: Array = []
children
var children = cleanup_parent.get_children()
p
var p = new_ind.get_parent()
info
var info = {
report
var report = IndicatorSetupReport.new(p_tile_check_rules, _targeting_state, _indicator_template)
testing_indicator
var testing_indicator = get_or_create_testing_indicator(_indicators_parent)
setup_result
var setup_result = IndicatorSetupUtils.execute_indicator_setup(
testing_parent
var testing_parent = testing_indicator.get_parent()
test_setups
var test_setups: Array[CollisionTestSetup2D] = setup_result.test_setups
reconciled
var reconciled: Array[RuleCheckIndicator] = _reconcile_indicators(setup_result.indicators)
colliding_indicators
var colliding_indicators: Array[RuleCheckIndicator] = []
use_cache
var use_cache = false
is_col
var is_col: bool = indicator.cached_is_colliding if use_cache else indicator.is_colliding()
colliding_nodes
var colliding_nodes: Array[Node2D] = []
use_cache
var use_cache = false
is_col
var is_col: bool = indicator.cached_is_colliding if use_cache else indicator.is_colliding()
colliders
var colliders: Array[Node] = []
count
var count: int = indicator.get_collision_count()
collider
var collider = indicator.get_collider(i)
indicators_to_free
var indicators_to_free = to_free.duplicate()
parent
var parent = indicator.get_parent()
min_x
var min_x = tile_pos.x
max_x
var max_x = tile_pos.x
min_y
var min_y = tile_pos.y
max_y
var max_y = tile_pos.y
map
var map = _targeting_state.target_map
indicator_tile
var indicator_tile = map.local_to_map(map.to_local(indicator.global_position))
is_left
var is_left = (tile_pos.x == min_x)
is_right
var is_right = (tile_pos.x == max_x)
is_top
var is_top = (tile_pos.y == min_y)
is_bottom
var is_bottom = (tile_pos.y == max_y)
map_layer
var map_layer = _targeting_state.target_map if _targeting_state else null
final_indicators
var final_indicators: Array[RuleCheckIndicator] = []
existing_by_pos
var existing_by_pos = {}
pos
var pos = _get_indicator_tile_pos(ind)
reused_existing
var reused_existing = []
new_pos
var new_pos = _get_indicator_tile_pos(new_ind)
used
var used: RuleCheckIndicator = null
p
var p = new_ind.get_parent()
leftover
var leftover = existing_by_pos[pos_key]
p2
var p2 = leftover.get_parent()
Methods
create_with_injection
static func create_with_injection(container: PlacementContainer, parent: Node) -> IndicatorService:
Parameters
containerparent
Returns
resolve_gb_dependencies
func resolve_gb_dependencies(container: PlacementContainer) -> bool:
Parameters
container
Returns
force_update
func force_update() -> void:
Returns
get_runtime_issues
func get_runtime_issues() -> Array[String]:
Returns
reset
func reset(parent_node: Node = null) -> void:
Parameters
parent_node
Returns
is_service_ready
func is_service_ready() -> bool:
Returns
get_indicators
func get_indicators() -> Array[RuleCheckIndicator]:
Returns
get_diagnostic_info
func get_diagnostic_info() -> Dictionary:
Returns
get_collision_mapper
func get_collision_mapper() -> CollisionMapper:
Returns
set_indicators
func set_indicators(value: Array[RuleCheckIndicator]) -> void:
Parameters
value
Returns
setup_indicators
func setup_indicators(p_test_object: Node2D, p_tile_check_rules: Array[TileCheckRule]) -> IndicatorSetupReport:
Parameters
p_test_objectp_tile_check_rules
Returns
calculate_indicator_count
func calculate_indicator_count(p_test_object: Node2D, p_tile_check_rules: Array[TileCheckRule]) -> int:
Parameters
p_test_objectp_tile_check_rules
Returns
build_collision_test_setups
func build_collision_test_setups(owner_shapes: Dictionary, tile_size: Vector2i) -> Dictionary:
Parameters
owner_shapestile_size
Returns
build_collision_test_setups_with_targeting_state
func build_collision_test_setups_with_targeting_state(owner_shapes: Dictionary) -> Dictionary:
Parameters
owner_shapes
Returns
gather_collision_shapes
func gather_collision_shapes(test_object: Node2D) -> Dictionary:
Parameters
test_object
Returns
validate_indicator_positions
func validate_indicator_positions(indicators: Array[RuleCheckIndicator], expected_positions: Array[Vector2i]) -> IndicatorSetupUtils.PositionValidationResult:
Parameters
indicatorsexpected_positions
Returns
validate_setup_preconditions
func validate_setup_preconditions(test_object: Node2D, tile_check_rules: Array[TileCheckRule]) -> Array[String]:
Parameters
test_objecttile_check_rules
Returns
get_or_create_testing_indicator
func get_or_create_testing_indicator(parent_node: Node) -> RuleCheckIndicator:
Parameters
parent_node
Returns
get_colliding_indicators
func get_colliding_indicators() -> Array[RuleCheckIndicator]:
Returns
get_colliding_nodes
func get_colliding_nodes() -> Array[Node2D]:
Returns
add_indicators
func add_indicators(new_indicators: Array[RuleCheckIndicator]) -> void:
Parameters
new_indicators
Returns
free_indicators
func free_indicators(to_free: Array[RuleCheckIndicator]) -> void:
Parameters
to_free
Returns
clear_indicators
func clear_indicators() -> void:
Returns
Events
indicators_changed
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.
signal indicators_changed(_indicators: Array[RuleCheckIndicator])