Skip to content

Placement Validation System Fix

Date: 2025-08-07 Author: AI Assistant Issue: PlacementManager not properly validating rules, indicators stable, and API consistency

Problem Description

Recent regressions caused: 1. Validator active_rules cleared after successful setup due to indicator setup calling tear_down() 2. Rule application attempted to call non-existent execute() on rules (should be apply()) 3. WithinTilemapBoundsRule used results.problems instead of results.issues 4. Excessively verbose per-indicator logs risked output overflow

Root Cause Analysis

  • PlacementManager.setup_indicators() invoked tear_down(), which cleared active_rules right after try_setup() succeeded, leading to "No active rules" during validation.
  • The base PlacementRule defines apply(). Some code still assumed execute() from older API.
  • Terminology migration missed one spot in within_tilemap_bounds_rule.gd.
  • Debug level was VERBOSE and logging per-indicator masks produced massive output.

Solutions

  1. Preserve validator state during indicator setup
  2. File: addons/grid_building/placement/manager/placement_manager.gd
  3. Change: setup_indicators() now only resets indicators and redraws; it no longer calls tear_down().

  4. Use correct rule application method

  5. File: addons/grid_building/placement/manager/components/placement_validator.gd
  6. Change: apply_rules() now calls rule.apply() for each active rule.

  7. Fix terminology in bounds rule helper

  8. File: addons/grid_building/placement/placement_rules/template_rules/within_tilemap_bounds_rule.gd
  9. Change: _is_over_valid_tile() assigns results.issues = p_indicator.validate() and checks results.issues.is_empty().

  10. Logging guidance to prevent overflow

  11. Doc: terminology_conventions.md
  12. Added guidance to reduce message count when logs are too noisy (lower debug level, aggregate duplicates, prefer per-rule summaries).

Files Modified

  • addons/grid_building/placement/manager/placement_manager.gd
  • addons/grid_building/placement/manager/components/placement_validator.gd
  • addons/grid_building/placement/placement_rules/template_rules/within_tilemap_bounds_rule.gd
  • terminology_conventions.md

Validation

  • Indicators now remain active and rules stay set after setup.
  • Collision checks pass/fail correctly; zero collisions no longer cause failure unless another rule fails.
  • Successful builds trigger apply() on rules such as SpendMaterialsRuleGeneric without errors.

Follow-up

  • Keep per-rule PASS/FAIL logs; disable per-indicator spam when not debugging.
  • If further failures occur, inspect PlacementValidator.validate() rule result reasons to pinpoint the rule.

Vendor runner configuration (GdUnit)

  • We treat addons/gdUnit4/GdUnitRunner.cfg as a project-customized artifact (port, runtime flags, enumerated suites).
  • See test/grid_building_test/docs/gdunit_runner_customizations.md for invariants and regeneration steps.