Skip to content

Derive save schema grid sizes from LayoutMath instead of hardcoded array #236

Description

@itsmiso-ai

Problem

validate_save_schema() in scripts/game_state.gd validates save data but uses a hardcoded expected_sizes array for grid dimensions instead of deriving them from LayoutMath:

The validation checks that tile arrays match expected grid sizes, but those sizes are hardcoded rather than computed from the anchor family logic in scripts/layout_math.gd. If the layout math changes grid dimensions, the save validator would reject valid saves or accept invalid ones.

Additionally, the validator checks field types and bounds but does not validate:

  • active_goal has valid values (references a real goal template)
  • completed_goal_ids contains valid goal IDs
  • active_rewards have valid structures
  • colony_stance is a known stance value
  • Tile count internally matches grid_w * grid_h

Fix

  1. Import LayoutMath in game_state.gd or accept grid dimensions as parameters
  2. Compute expected tile counts from the anchor/layout configuration
  3. Add internal consistency checks:
    • state.tiles.size() == state.grid_w * state.grid_h
    • Goal references are valid
    • Colony stance is a known value

Acceptance criteria

  • Grid size validation derived from layout configuration, not hardcoded
  • Internal consistency check: tiles size == grid_w * grid_h
  • Invalid goal IDs rejected on load
  • Invalid colony stance rejected on load
  • tests/test_save_backup.gd updated with edge cases

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions