CollisionMapper
Summary
Section titled “Summary”Responsibilities: - Translate CollisionShape2D / CollisionPolygon2D geometry into tile offsets used by placement rules and indicators. - Apply filtering, normalization, and heuristics to remove slivers and normalize pivots for consistent indicators. - Provide caching and utility helpers consumed by IndicatorManager and the placement pipeline.
Properties
Section titled “Properties”indicator_contact_positions: Array = []
test_indicator: RuleCheckIndicator
test_setups: Array[CollisionTestSetup2D] = []
Maps each CollisionObject2D to its CollisionTestSetup2D for collision testing.
Methods
Section titled “Methods”static func create_with_injection( container: GBCompositionContainer ) -> CollisionMapper
Factory Creates a CollisionMapper with injected dependencies and validates wiring. This is the preferred method for instantiating a CollisionMapper for test suites to avoid manual injection or instancing owning parent nodes. Returns: CollisionMapper – a ready instance; logs warnings if injection issues are found.
func get_runtime_issues( ) -> Array[String]
Validation Returns a list of issues if required state is missing; empty when valid. Returns: Array[String]
func _init( targeting_state: GridTargetingState, p_logger: GBLogger ) -> void
Constructor Inject targeting state and logger. Parameters: •
targeting_state
: GridTargetingState – provides map and positioner. •p_logger
: GBLogger – for diagnostics.func resolve_gb_dependencies( container: GBCompositionContainer ) -> bool
Manual Injection Resolve dependencies from the container after construction. Useful when the mapper is instantiated without the factory. Returns - bool - Whether the injection was successful or not
func setup( p_test_indicator: RuleCheckIndicator, p_collision_object_test_setups: Array[CollisionTestSetup2D] ) -> void
Setup Wire the test indicator and per-object collision test setups; invalidates internal caches. Call whenever either changes to ensure fresh geometry. Parameters: •
p_test_indicator
: RuleCheckIndicator – the reusable indicator shape/owner. •p_collision_object_test_setups
: Array[CollisionTestSetup2D] – precomputed shape info.func _get_tile_offsets_for_resolved_object( collision_node: Node2D, test_setup: CollisionTestSetup2D ) -> Dictionary[Vector2i, Array]
Process a resolved collision object to get tile offsets
collision_node
: The original collision node (CollisionObject2D, CollisionShape2D, or CollisionPolygon2D)test_setup
: The resolved CollisionTestSetup2D (may be null for CollisionPolygon2D) Returns: Dictionary[Vector2i, Array] of tile offsetsfunc get_tile_offsets_for_collision_polygon( collision_obj: Node2D, tile_map: TileMapLayer ) -> Dictionary[Vector2i, Array]
Get tile offsets for a collision polygon Returns tile offsets for a CollisionPolygon2D or CollisionShape2D. Parameters:
collision_obj
– The collision object to process,tile_map
– The tile map to use for coordinate conversion. Returns: Dictionary – tile positions mapped to collision objects.func get_tile_offsets_for_test_collisions( test_data: CollisionTestSetup2D ) -> Dictionary[Vector2i, Array]
Resolve tile offsets for a single node Dispatch to polygon or shape path depending on the object type. Returns
offset -> owners
. Parameters:test_data
– CollisionTestSetup2D for a CollisionObject2D or the polygon node. Returns: Dictionary – offsets to contributing nodes for that source.func get_rect_tile_positions( global_center_position: Vector2, transformed_rect_size: Vector2 ) -> Array[Vector2i]
Absolute tiles overlapped by an axis‑aligned rectangle Returns absolute tile coordinates overlapped by a rectangle centered at a world position. Uses symmetric distribution to avoid half‑tile drift. Parameters: •
global_center_position
: Vector2 – center in world space. •transformed_rect_size
: Vector2 – rectangle size in world units. Returns: Array[Vector2i]func _guard_setup_complete( ) -> bool
Guard: Setup Validation Checks if setup() has been called and logs warnings if incomplete. Returns: bool – true if setup is complete, false otherwise (logs and prevents continuation).
Source
Section titled “Source”addons/grid_building/placement/manager/components/mapper/collision_mapper.gd
This API reference is automatically generated from the plugin source code. For implementation examples and usage guides, see the guides section.