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

1
create_with_injection(container: GBCompositionContainer) -> CollisionMapper

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

1
get_runtime_issues() -> Array[String]

Validation Returns a list of issues if required state is missing; empty when valid. Returns: Array[String]


resolve_gb_dependencies

1
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


setup

1
2
3
4
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.


get_tile_offsets_for_collision_polygon

1
2
3
4
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.


get_tile_offsets_for_test_collisions

1
2
3
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.


get_rect_tile_positions

1
2
3
4
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]


Private Methods

_init

1
2
3
4
_init(
    targeting_state: GridTargetingState,
    p_logger: GBLogger
) -> void

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

1
2
3
4
_get_tile_offsets_for_resolved_object(
    collision_node: Node2D,
    test_setup: CollisionTestSetup2D
) -> Dictionary[Vector2i, Array]

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

1
_guard_setup_complete() -> bool

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).