Grid Placement

CollisionProcessor

AUTO-GENERATED FILE — DO NOT EDIT MANUALLY

Source: placement/manager/components/mapper/collision_processor.gd

Version: 5.0

class_name: CollisionProcessor extends: GBInjectable

Summary

Unified Collision Processor

Handles processing for both CollisionObject2D (with shapes) and CollisionPolygon2D. Converts collision geometry to relative tile offsets for indicator positioning.

[b]CRITICAL:[/b] Must use positioner.global_position as coordinate reference to maintain relative offsets. Using collision object position causes positioning displacement.

[b]📖 COMPLETE GUIDE:[/b] /astro_docs/src/content/docs/internal/positioning-regression-fix-guide.mdx

Signals

(none)

Exports

(none)

Methods

  • _init()
  • invalidate_cache()
    • Invalidate all cached geometry data
  • resolve_gb_dependencies()
    • Resolve dependencies from composition container
  • get_runtime_issues()
    • Get runtime validation issues
  • get_tile_offsets_for_collision()
    • Unified public method to process any collision object type Automatically detects the type and delegates to the appropriate handler

[b]RETURN VALUE COORDINATE SYSTEM:[/b] 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)

@param collision_obj: The collision object to process (CollisionObject2D or CollisionPolygon2D) @param test_data: CollisionTestSetup2D for CollisionObject2D (null for CollisionPolygon2D) @param map: The TileMapLayer to map offsets against @param positioner: The positioner node for coordinate transformations (CRITICAL for relative offsets) @return Dictionary[Vector2i, Array] containing RELATIVE tile offsets as keys and collision objects as values

  • _get_tile_offsets_for_collision_polygon()
    • Handle CollisionPolygon2D processing Uses positioner as coordinate reference for consistent positioning behavior
  • _get_tile_offsets_for_collision_object()
    • Handle CollisionObject2D with shapes processing [b]CRITICAL:[/b] Returns offsets relative to positioner position for correct indicator placement. See positioning-regression-fix-guide.mdx for coordinate system details.
  • _initialize_collision_mapping()
    • Initialize collision mapping with validation
  • process_shape_offsets()
    • Process shape offsets for a single collision test setup

[b]COORDINATE MIXING ZONE:[/b] 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.

[b]ABSOLUTE WORLD COORDINATES (used internally):[/b]

  • 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

[b]RELATIVE TILE COORDINATES (return values):[/b]

  • tile_pos - center_tile: converts world tile positions to relative offsets
  • These offsets will be added to positioner position by IndicatorFactory
  • calculate_tile_range()
    • Calculate the tile range that needs to be checked for a shape Returns a dictionary with ‘start’ and ’end_exclusive’ Vector2i values
  • compute_shape_tile_offsets()
    • Compute which tiles a shape overlaps with, returning offset positions
  • _merge_offsets_into_positions()
    • Merge offsets into positions with center tile conversion

[b]FINAL COORDINATE VALIDATION:[/b] 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)

  • _merge_collision_positions()
    • Merge two collision position dictionaries