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 centerConstant:
H_SEP_TILES: int = 4Constant:
V_SEP_TILES: int = 2Constant:
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 pixelsConstant:
RECT_HEIGHT_PX: float = 64.0 # Test rectangle height in pixelsConstant:
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 testsConstant:
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 positioningConstant:
TEST_TILE_ORIGIN: Vector2i = Vector2i.ZERO # Test position at tile originConstant:
BLOCKING_BODY_SIZE: Vector2 = Vector2(32, 32) # Match tile size for blockingConstant:
BLOCKING_BODY_LAYER: int = 1 # Layer 1 detected by collision rulesConstant:
BLOCKING_BODY_MASK: int = 0 # Don't detect anything itselfConstant:
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
| |
format_debug_lines
| |
before
| |
before_test
| |
after
| |
after_test
| |
test_placement_validation_basic_empty_rules_fails
| |
test_parented_polygon_offsets_stable_when_positioner_moves
| |
test_large_rectangle_generates_full_grid_of_indicators
| |
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
| |
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
| |
test_building_placement_attempt
| |
test_building_state_transitions
| |
test_building_state_persistence
| |
test_drag_build_initialization
| |
test_drag_build_functionality
| |
test_single_placement_per_tile_constraint
| |
test_tile_placement_validation
| |
test_preview_name_consistency
| |
test_preview_rotation_consistency
| |
test_complete_building_workflow
| |
test_building_error_recovery
| |
test_building_system_dependencies
| |
test_building_system_validation
| |
test_drag_build_single_placement_regression
| |
test_preview_indicator_consistency
| |
on_build_success
| |
on_build_failed
| |
Private Methods
_format_debug
| |
Flags: private
_create_static_body_with_rect
| |
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
| |
Flags: private
_wait_for_drag_physics_update
| |
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
| |
Flags: private
_assert_build_attempted
| |
Flags: private
_expect_placements
| |
Flags: private
_doc_tile_coverage
| |
Flags: private
_find_safe_center_tile_for_rect_4x2
| |
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
| |
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
| |
Flags: private
_setup_blocking_collision
| |
Flags: private
_debug_collision_detection
| |
Flags: private
Debug collision detection to understand what’s happening
_collect_offsets
| |
Flags: private
_collect_placement_diagnostics
| |
Flags: private
Diagnostic helper to build a compact string of relevant context for failure messages
_format_validation_failure_details
| |
Flags: private
Enhanced diagnostic formatter for validation failures - provides structured, human and AI readable context
_is_position_within_map_bounds
| |
Flags: private
Helper to check if a position is within the tilemap bounds
_prepare_target_for_successful_build
| |
Flags: private
_setup_test_object_collision_shapes
| |
Flags: private
_setup_target_collision_shape_for_validation
| |
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
| |
Flags: private
_find_valid_tile_within_map_bounds
| |
Flags: private
Find a valid tile within the actual map bounds that has tile data
_tile_has_data
| |
Flags: private
_create_placeable_with_no_rules
| |
Flags: private
_get_container_config_debug
| |
Flags: private
Helper method for debugging container configuration
Grid Building v5.0.8 | Generated 24/05/2026