CollisionProcessor
Summary
Section titled “Summary”Unified Collision Processor
Handles processing for both CollisionObject2D (with shapes) and CollisionPolygon2D. Converts collision geometry to relative tile offsets for indicator positioning.
CRITICAL: Must use positioner.global_position as coordinate reference to maintain relative offsets. Using collision object position causes positioning displacement.
📖 COMPLETE GUIDE: /astro_docs/src/content/docs/internal/positioning-regression-fix-guide.mdx
Methods
Section titled “Methods”func _init( p_logger: GBLogger ) -> void
func invalidate_cache( ) -> void
Invalidate all cached geometry data
func resolve_gb_dependencies( container: GBCompositionContainer ) -> bool
Resolve dependencies from composition container
func get_runtime_issues( ) -> Array[String]
Get runtime validation issues
func get_tile_offsets_for_collision( collision_obj: Node2D, test_data: CollisionTestSetup2D, map: TileMapLayer, positioner: Node2D ) -> Dictionary[Vector2i, Array]
Unified public method to process any collision object type Automatically detects the type and delegates to the appropriate handler
RETURN VALUE COORDINATE SYSTEM: Returns Dictionary[Vector2i, Array] where Vector2i keys are RELATIVE tile offsets from the positioner’s tile position, NOT absolute world tile coordinates.
These offsets represent: “tiles relative to positioner where indicators should appear” IndicatorFactory will convert them back to world positions as: indicator_position = positioner.global_position + (offset * tile_size)
collision_obj
: The collision object to process (CollisionObject2D or CollisionPolygon2D)test_data
: CollisionTestSetup2D for CollisionObject2D (null for CollisionPolygon2D)map
: The TileMapLayer to map offsets againstpositioner
: The positioner node for coordinate transformations (CRITICAL for relative offsets) Returns: Dictionary[Vector2i, Array] containing RELATIVE tile offsets as keys and collision objects as valuesfunc _get_tile_offsets_for_collision_polygon( polygon_node: CollisionPolygon2D, map: TileMapLayer, positioner: Node2D ) -> Dictionary[Vector2i, Array]
Handle CollisionPolygon2D processing Uses positioner as coordinate reference for consistent positioning behavior
func _get_tile_offsets_for_collision_object( test_data: CollisionTestSetup2D, map: TileMapLayer, positioner: Node2D ) -> Dictionary[Vector2i, Array]
Handle CollisionObject2D with shapes processing CRITICAL: Returns offsets relative to positioner position for correct indicator placement. See positioning-regression-fix-guide.mdx for coordinate system details.
func _initialize_collision_mapping( positioner: Node2D, collision_positions: Dictionary[Vector2i, Array] ) -> bool
Initialize collision mapping with validation
func process_shape_offsets( rect_test_setup: RectCollisionTestingSetup, test_data: CollisionTestSetup2D, map: TileMapLayer, center_tile: Vector2i, tile_size: Vector2, shape_epsilon: float, col_obj: CollisionObject2D ) -> Dictionary[Vector2i, Array]
Process shape offsets for a single collision test setup
COORDINATE MIXING ZONE: This method combines absolute world coordinates (for collision detection) with relative tile coordinates (for return values). The center_tile parameter is the key bridge between these coordinate systems.
ABSOLUTE WORLD COORDINATES (used internally):
- shape_transform.origin: collision object’s world position - tile_center_world, tile_top_left_world: world coordinates for overlap testing - All geometric calculations happen in world space for accuracy
RELATIVE TILE COORDINATES (return values):
- tile_pos - center_tile: converts world tile positions to relative offsets - These offsets will be added to positioner position by IndicatorFactory
func calculate_tile_range( shape: Shape2D, bounds: Rect2, map: TileMapLayer, tile_size: Vector2, shape_transform: Transform2D ) -> Dictionary
Calculate the tile range that needs to be checked for a shape Returns a dictionary with ‘start’ and ‘end_exclusive’ Vector2i values
func compute_shape_tile_offsets( shape: Shape2D, shape_transform: Transform2D, map: TileMapLayer, tile_size: Vector2, shape_epsilon: float, start_tile: Vector2i, end_exclusive: Vector2i, center_tile: Vector2i, shape_polygon: PackedVector2Array ) -> Array[Vector2i]
Compute which tiles a shape overlaps with, returning offset positions
func _merge_offsets_into_positions( shape_offsets: Array[Vector2i], collision_positions: Dictionary[Vector2i, Array], col_obj: Node2D, center_tile: Vector2i ) -> void
Merge offsets into positions with center tile conversion
FINAL COORDINATE VALIDATION: At this point, shape_offsets contains relative tile offsets (Vector2i) calculated as (tile_pos - center_tile) where center_tile is based on positioner.global_position. These offsets are ready for IndicatorFactory to convert back to world positions as: positioner_position + (offset * tile_size)
func _merge_collision_positions( target_positions: Dictionary[Vector2i, Array], source_positions: Dictionary[Vector2i, Array] ) -> void
Merge two collision position dictionaries
Source
Section titled “Source”addons/grid_building/placement/manager/components/mapper/collision_processor.gd
This API reference is automatically generated from the plugin source code. For implementation examples and usage guides, see the guides section.