refactor: extract game constants from main.gd into constants.gd - #153
Conversation
- Move WORKER_NAMES, BUILD_COSTS, BUILD_UNLOCKS, RESOURCE_COLORS, STRUCTURE_COLORS, TILE_BACKDROPS, WORKER_BADGE_COLORS to scripts/constants.gd - main.gd re-exports via Constants alias — zero behavioral change - Add 28 regression tests covering all constant values - Reduces main.gd by ~40 lines (first step toward splitting simulation/UI/dock geometry boundaries)
|
✅ Automated recommendation: APPROVE Analysis engine: MiniMax-M2.7@https://litellm.jory.dev/v1 (anthropic) PR Review: Extract Game Constants from main.gdRecommendation: Approve This PR cleanly extracts pure-data constants from Change-by-Change Findings
constants.gd correctly declares all constants as
main.gd uses test_constants.gd extends
Standards Compliance
Linked Issue FitIssue #125 acceptance criteria:
Evidence Provider FindingsNone configured — no findings to report. Tool Harness FindingsNo tool requests executed (planning mode only). Not applicable. Unknowns / Needs VerificationNone — all evidence is complete:
|
Fixes #125
What changed
Extracted all pure-data constants from
scripts/main.gdinto a dedicatedscripts/constants.gdmodule. main.gd now re-exports viaConstantsalias —zero behavioral change.
Files:
scripts/constants.gd— new centralised constants module (49 lines)tests/test_constants.gd— 28 regression tests covering every constant valuescripts/main.gd— replaced 40 lines of inline const definitions with re-export aliasesAcceptance criteria
has zero runtime dependencies, no side effects, and is the lowest-risk
boundary to split.
all 28 tests verify exact constant values; main.gd references are transparent
re-exports.
Remaining split plan
The next extraction seams, ordered by safety and impact:
Simulation engine (
_on_tick,choose_task,step_worker,do_gather/do_haul/do_build, task gathering helpers) — ~250 lines ofpure game logic with minimal scene dependencies. Extract to
scripts/simulation.gd.Rendering layer (
render_all,render_world,render_worker_overlay,render_sidebar,render_build_buttons, tile icon/amount/style helpers) —~150 lines. Extract to
scripts/rendering.gd. Depends on simulation statebut not the other way around.
UI/menu state (
toggle_menu,close_menu,open_build_popup,open_settings,close_settings,wire_controls, startup menu) — ~120lines. Extract to
scripts/ui.gd.Dock geometry / window management (
apply_dock_position,apply_anchor_layout,position_popup_panel,_processedge snapping) —~100 lines. Already partially extracted via
layout_math.gd; remainingDisplayServer calls could move to
scripts/dock.gd.Persistence (
persist,save_game,load_saved_game,bootstrap_state,load_or_boot) — already partially handled bygame_state.gd. Remaining state lifecycle could be consolidated.Each step should follow the same pattern: write tests first, extract, verify
no behavioral change, then proceed to the next seam.