building_and_placement_tests

AUTO-GENERATED FILE – DO NOT EDIT MANUALLY

Comprehensive placement tests consolidating multiple validator and rule scenarios Replaces placement_validator_test, placement_validator_rules_test, and rules_validation_test

Source File: /addons/grid_building/test/placement/workflows/building_and_placement_tests.gd

Extends: GdUnitTestSuite

Properties

  • Property: placement_validator: [PlacementValidator](./placement-validator/)
  • Property: logger: [GBLogger](./gb-logger/)
  • Property: gb_owner: [GBOwner](./gb-owner/)
  • Property: user_node: Node2D
  • Property: env: [BuildingTestEnvironment](./building-test-environment/)
  • Property: runner: GdUnitSceneRunner

Private Properties

  • Property: _container: [GBCompositionContainer](./gb-composition-container/) (private)
  • Property: _targeting_system: [GridTargetingSystem](./grid-targeting-system/) (private)
  • Property: _targeting_state: [GridTargetingState](./grid-targeting-state/) (private)
  • Property: _positioner: [GridPositioner2D](./grid-positioner2-d/) (private)
  • Property: _isolation_state: GBTestIsolation.BuildingTestIsolationState (private)
  • Property: _placed_positions: Array[Vector2] (private)
  • Property: _building_system: [BuildingSystem](./building-system/) (private)
  • Property: _map: TileMapLayer (private)
  • Property: _indicator_manager: [IndicatorManager](./indicator-manager/) (private)
  • Property: _build_success_count: int (private)
  • Property: _build_failed_count: int (private)
  • Property: _last_build_report: [PlacementReport](./placement-report/) (private)
  • Property: _last_build_was_dragging: bool (private)
  • Property: _on_build_success_callable: Callable (private)
  • Property: _on_build_failed_callable: Callable (private)

Constants

  • Constant: GBTestIsolation := preload("res://test/helpers/gb_test_isolation.gd")

  • Constant: TILE_SIZE_PX: Vector2 = Vector2(16, 16)

    File scope: Comprehensive placement + drag-build integration tests with DRY helpers Map bounds (expected): 30x30 tiles with used_rect approx (-15,-15) -> (15,15) Placeable under test for drag-build spacing: RECT_4X2 (4 tiles wide, 2 tiles tall) Spacing rules for drag multi-build:

    • Horizontal separation: >= 4 tiles
    • Vertical separation: >= 2 tiles
  • Constant: TILE_CENTER_OFFSET: Vector2 = TILE_SIZE_PX / 2.0 # (8.0, 8.0) - offset from tile corner to center

  • Constant: H_SEP_TILES: int = 4

  • Constant: V_SEP_TILES: int = 2

  • Constant: SAFE_LEFT_TILE: Vector2i = Vector2i(-2, 0)

  • Constant: SAFE_RIGHT_TILE: Vector2i = Vector2i(2, 0)

  • Constant: SAFE_CENTER_UP_TILE: Vector2i = Vector2i(0, 2)

  • Constant: RECT_WIDTH_PX: float = 48.0 # Test rectangle width in pixels

  • Constant: RECT_HEIGHT_PX: float = 64.0 # Test rectangle height in pixels

  • Constant: RECT_TILES_W: int = 3 # Expected tiles width (48/16 = 3)

  • Constant: RECT_TILES_H: int = 4 # Expected tiles height (64/16 = 4)

  • Constant: RECT_EXPECTED_TILES: int = 12 # Total expected tiles (3 × 4 = 12)

  • Constant: TEST_COLLISION_LAYER: int = 1 # Standard collision layer for tests

  • Constant: TEST_WORLD_ORIGIN: Vector2 = Vector2.ZERO # Tile corner (not center!)

  • Constant: TEST_TILE_CENTER: Vector2 = TILE_CENTER_OFFSET # (8.0, 8.0) - actual tile center for positioning

  • Constant: TEST_TILE_ORIGIN: Vector2i = Vector2i.ZERO # Test position at tile origin

  • Constant: BLOCKING_BODY_SIZE: Vector2 = Vector2(32, 32) # Match tile size for blocking

  • Constant: BLOCKING_BODY_LAYER: int = 1 # Layer 1 detected by collision rules

  • Constant: BLOCKING_BODY_MASK: int = 0 # Don't detect anything itself

  • Constant: TEST_CONTAINER: [GBCompositionContainer](./gb-composition-container/) = preload("res://addons/grid_building/test/resources/composition_containers/test_composition_container.tres")

  • Constant: DIAG_SUITE: String = "BuildingAndPlacementTests"

Public Methods

format_debug

1
format_debug(msg: String) -> String

format_debug_lines

1
2
3
4
format_debug_lines(
    title: String,
    lines: Array[String]
) -> String

before

1
before() -> void

before_test

1
before_test() -> void

after

1
after() -> void

after_test

1
after_test() -> void

test_placement_validation_basic_empty_rules_fails

1
test_placement_validation_basic_empty_rules_fails() -> void

test_parented_polygon_offsets_stable_when_positioner_moves

1
test_parented_polygon_offsets_stable_when_positioner_moves() -> void

test_large_rectangle_generates_full_grid_of_indicators

1
test_large_rectangle_generates_full_grid_of_indicators() -> void

Test: Large rectangular building generates full grid of indicators Expected: 3x4 tile rectangle (48x64 pixels with 16x16 tile size) should produce 12 tiles total


test_isolated_rect_48x64_tile_offsets

1
test_isolated_rect_48x64_tile_offsets() -> void

Isolated unit-style test: verify polygon -> tile offsets for a 48x64 rectangle This lives inside the same integration suite to reuse environment setup and helpers


test_building_mode_enter_exit

1
test_building_mode_enter_exit() -> void

test_building_placement_attempt

1
test_building_placement_attempt() -> void

test_building_state_transitions

1
test_building_state_transitions() -> void

test_building_state_persistence

1
test_building_state_persistence() -> void

test_drag_build_initialization

1
test_drag_build_initialization() -> void

test_drag_build_functionality

1
test_drag_build_functionality() -> void

test_single_placement_per_tile_constraint

1
test_single_placement_per_tile_constraint() -> void

test_tile_placement_validation

1
test_tile_placement_validation() -> void

test_preview_name_consistency

1
test_preview_name_consistency() -> void

test_preview_rotation_consistency

1
test_preview_rotation_consistency() -> void

test_complete_building_workflow

1
test_complete_building_workflow() -> void

test_building_error_recovery

1
test_building_error_recovery() -> void

test_building_system_dependencies

1
test_building_system_dependencies() -> void

test_building_system_validation

1
test_building_system_validation() -> void

test_drag_build_single_placement_regression

1
test_drag_build_single_placement_regression() -> void

test_preview_indicator_consistency

1
test_preview_indicator_consistency() -> void

on_build_success

1
on_build_success(data: BuildActionData) -> void

on_build_failed

1
on_build_failed(data: BuildActionData) -> void

Private Methods

_format_debug

1
_format_debug(msg: String) -> String

Flags: private


_create_static_body_with_rect

1
2
3
4
5
6
_create_static_body_with_rect(
    shape_size: Vector2,
    layer: int = 1,
    mask: int = 0,
    shape_name: String = ""
) -> StaticBody2D

Flags: private

Creates a StaticBody2D with a rectangular collision shape. Caller is responsible for parenting the body and calling auto_free if needed.


_move_positioner_to_tile

1
_move_positioner_to_tile(tile: Vector2i) -> void

Flags: private


_wait_for_drag_physics_update

1
_wait_for_drag_physics_update() -> void

Flags: private

DRY Helper: Wait for DragManager to process tile change in physics frame DragManager detects tile changes in _physics_process(), so we need to wait for physics frames Uses scene_runner for deterministic frame simulation instead of actual physics timing


_enter_build_mode_for_rect_4x2_and_start_drag

1
_enter_build_mode_for_rect_4x2_and_start_drag() -> Dictionary

Flags: private


_assert_build_attempted

1
_assert_build_attempted(context: String = "") -> void

Flags: private


_expect_placements

1
2
3
4
_expect_placements(
    expected: int,
    context: String = ""
) -> void

Flags: private


_doc_tile_coverage

1
_doc_tile_coverage(tile: Vector2i) -> String

Flags: private


_find_safe_center_tile_for_rect_4x2

1
_find_safe_center_tile_for_rect_4x2() -> Vector2i

Flags: private

Finds a safe tile inside the map whose 4x2 coverage (x-2..x+1, y-1..y) has TileData. Scans from map center outward to avoid edges and sparse areas.


_find_prevalidated_start_tile_for_rect_4x2

1
_find_prevalidated_start_tile_for_rect_4x2() -> Vector2i

Flags: private

After drag has started and indicators are configured, find a start tile that passes validate_placement(). Scans center-out across safe bounds and returns the first passing tile; falls back to current position if none.


_create_test_rules

1
_create_test_rules(rule_type: String) -> Array[PlacementRule]

Flags: private


_setup_blocking_collision

1
_setup_blocking_collision() -> void

Flags: private


_debug_collision_detection

1
_debug_collision_detection() -> void

Flags: private

Debug collision detection to understand what’s happening


_collect_offsets

1
2
3
4
5
_collect_offsets(
    mapper: CollisionMapper,
    poly: CollisionPolygon2D,
    tile_map: TileMapLayer
) -> Array[Vector2i]

Flags: private


_collect_placement_diagnostics

1
_collect_placement_diagnostics(context: String = "") -> String

Flags: private

Diagnostic helper to build a compact string of relevant context for failure messages


_format_validation_failure_details

1
2
3
4
5
6
7
_format_validation_failure_details(
    scenario: String,
    rule_type: String,
    expected: bool,
    result: ValidationResults,
    rules: Array[PlacementRule]
) -> String

Flags: private

Enhanced diagnostic formatter for validation failures - provides structured, human and AI readable context


_is_position_within_map_bounds

1
_is_position_within_map_bounds(world_pos: Vector2) -> bool

Flags: private

Helper to check if a position is within the tilemap bounds


_prepare_target_for_successful_build

1
_prepare_target_for_successful_build(_tile: Vector2i = SAFE_LEFT_TILE) -> void

Flags: private


_setup_test_object_collision_shapes

1
_setup_test_object_collision_shapes() -> void

Flags: private


_setup_target_collision_shape_for_validation

1
_setup_target_collision_shape_for_validation() -> void

Flags: private

Setup minimal collision shape under target for validation tests This is needed because rules generate indicators from collision shapes under the target. Without collision shapes, rules that check collision/bounds treat zero indicators as failure. This method adds a lightweight collision shape specifically for validation (not building).


_resolve_tile_for_build

1
_resolve_tile_for_build(preferred_tile: Vector2i) -> Vector2i

Flags: private


_find_valid_tile_within_map_bounds

1
_find_valid_tile_within_map_bounds() -> Vector2i

Flags: private

Find a valid tile within the actual map bounds that has tile data


_tile_has_data

1
_tile_has_data(tile: Vector2i) -> bool

Flags: private


_create_placeable_with_no_rules

1
_create_placeable_with_no_rules() -> Placeable

Flags: private


_get_container_config_debug

1
_get_container_config_debug() -> String

Flags: private

Helper method for debugging container configuration



Grid Building v5.0.8 | Generated 24/05/2026