CollisionMapper
AUTO-GENERATED FILE – DO NOT EDIT MANUALLY
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.
Source File: addons/grid_building/placement/manager/components/mapper/collision_mapper.gd
Extends: GBInjectable
Properties
- Property:
indicator_contact_positions: Array = [] - Property:
test_indicator: [RuleCheckIndicator](./rule-check-indicator/) - Property:
test_setups: Array[CollisionTestSetup2D] = []- Maps each CollisionObject2D to its CollisionTestSetup2D for collision testing.
Private Properties
- Property:
_targeting_state: [GridTargetingState](./grid-targeting-state/)(private) - Property:
_logger: [GBLogger](./gb-logger/)(private) - Property:
_collision_processor: [CollisionProcessor](./collision-processor/)(private) - Property:
_object_resolver: [CollisionObjectResolver](./collision-object-resolver/)(private)
Constants
- Constant:
_CollisionUtilities = preload("res://addons/grid_building/placement/manager/components/mapper/collision_utilities.gd")- Note: CollisionObjectResolver is registered as class_name and can be used directly - Constant:
MIN_POLY_TILE_OVERLAP_RATIO := 0.12
Public Methods
create_with_injection
Flags: static
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.
get_runtime_issues
Validation Returns a list of issues if required state is missing; empty when valid. Returns: Array[String]
resolve_gb_dependencies
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
setup
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.
get_tile_offsets_for_collision_polygon
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.
get_tile_offsets_for_test_collisions
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.
get_rect_tile_positions
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]
Private Methods
_init
Flags: private
Constructor
Inject targeting state and logger.
Parameters:
• targeting_state: GridTargetingState – provides map and positioner.
• p_logger: GBLogger – for diagnostics.
_get_tile_offsets_for_resolved_object
Flags: private
Process a resolved collision object to get tile offsets
@param collision_node: The original collision node (CollisionObject2D, CollisionShape2D, or CollisionPolygon2D) @param test_setup: The resolved CollisionTestSetup2D (may be null for CollisionPolygon2D) @return Dictionary[Vector2i, Array] of tile offsets
_guard_setup_complete
Flags: private
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).