Grid Placement

CollisionMapper

AUTO-GENERATED FILE — DO NOT EDIT MANUALLY

Source: systems/placement/processors/collision_mapper.gd

Version: 5.1

class_name: CollisionMapper extends: RefCounted

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.

See: Collision Mapping guide

Signals

(none)

Exports

(none)

Methods

  • get_runtime_issues()
    • [b]Validation[/b] Returns a list of issues if required state is missing; empty when valid. [b]Returns[/b]: Array[String]
  • _init()
    • [b]Constructor[/b] Inject targeting service and logger. [b]Parameters[/b]: • [code]targeting_service[/code]: TargetingService2D – provides map and positioner.
  • resolve_gb_dependencies()
    • [b]Manual Injection[/b] Resolve dependencies from the container after construction. Useful when the mapper is instantiated without the factory. [b]Returns[/b] - [i]bool[/i] - Whether the injection was successful or not
  • setup()
    • [b]Setup[/b] Wire the test indicator and per-object collision test setups; invalidates internal caches. Call whenever either changes to ensure fresh geometry. [b]Parameters[/b]: • [code]p_test_indicator[/code]: RuleCheckIndicator – the reusable indicator shape/owner. • [code]p_collision_object_test_setups[/code]: Array[CollisionScenarioBuilder2D] – precomputed shape info.
  • map_collision_positions_to_rules()
    • [b]Map collision positions to rules[/b] Builds a dictionary of [code]tile_offset -> [TileCheckRule][/code] by resolving tile coverage for each rule’s collision layer mask and aggregating applicable rules at each tile. [b]Parameters[/b]: • [code]col_objects[/code]: Array[Node2D] – CollisionObject2Ds and/or CollisionPolygon2Ds to consider. • [code]tile_check_rules[/code]: Array[TileCheckRule] – rules with [code]apply_to_objects_mask[/code] used for filtering. [b]Returns[/b]: Dictionary[Vector2i, Array] – tile offset to list of rules that apply at that offset.
  • get_collision_tile_positions_with_mask()
    • [b]Resolve tile offsets with a collision mask[/b] Produces [code]tile_offset -> [Node2D][/code] by inspecting each source and applying collision layer filtering. Handles both CollisionShape2D and CollisionPolygon2D nodes by checking their parent CollisionObject2D for layer matching. Aggregates all sources with no preference and de-duplicates per tile. [b]Parameters[/b]: • [code]col_objects[/code]: Array[Node2D] – CollisionShape2D and CollisionPolygon2D nodes to process • [code]collision_mask[/code]: int – layer mask to match via the parent CollisionObject2D. [b]Returns[/b]: Dictionary[Vector2i, Array] – tile offset to list of contributing collision nodes.
  • _get_tile_offsets_for_resolved_object()
    • 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 CollisionScenarioBuilder2D (may be null for CollisionPolygon2D) @return Dictionary[Vector2i, Array] of tile offsets

  • get_tile_offsets_for_collision_polygon()
    • [b]Get tile offsets for a collision polygon[/b] Returns tile offsets for a CollisionPolygon2D or CollisionShape2D. [b]Parameters[/b]: [code]collision_obj[/code] – The collision object to process, [code]tile_map[/code] – The tile map to use for coordinate conversion. [b]Returns[/b]: Dictionary – tile positions mapped to collision objects.
  • get_tile_offsets_for_test_collisions()
    • [b]Resolve tile offsets for a single node[/b] Dispatch to polygon or shape path depending on the object type. Returns [code]offset -> owners[/code].

[b]Parameters[/b]: [code]test_data[/code] – CollisionScenarioBuilder2D for a CollisionObject2D or the polygon node. [b]Returns[/b]: Dictionary[Vector2i, Array] – Tile positions mapped to Array of owning Node2D objects. [i]Note: GDScript doesn’t support nested typed collections, so Array values are untyped but contain Node2D objects[/i].

  • get_rect_tile_positions()
    • [b]Absolute tiles overlapped by an axis‑aligned rectangle[/b] Returns absolute tile coordinates overlapped by a rectangle centered at a world position. Uses symmetric distribution to avoid half‑tile drift. [b]Parameters[/b]: • [code]global_center_position[/code]: Vector2 – center in world space. • [code]transformed_rect_size[/code]: Vector2 – rectangle size in world units. [b]Returns[/b]: Array[Vector2i]
  • does_indicator_overlap_shape()
    • [b]Indicator ↔ Shape overlap[/b] Uses Godot’s native Shape2D API to test collision between indicator and a target shape. [b]Returns[/b]: bool – [code]true[/code] if overlapping.
  • _guard_setup_complete()
    • [b]Guard: Setup Validation[/b] Checks if setup() has been called and logs warnings if incomplete. [b]Returns[/b]: bool – true if setup is complete, false otherwise (logs and prevents continuation).