Skip to content

Grid Representation: convert

Conversion utilities between GridState and State.

GridState and State are complementary representations of game state:

  • GridState: Mutable, grid-centric, ideal for authoring and editing
  • State: Immutable, ECS-based, optimized for simulation and stepping

Two primary operations:

  • to_state: Build immutable ECS State from a GridState with grid-based entities.
  • from_state: Build mutable GridState from an ECS State for editing/inspection.

Handles wiring of portals, pathfinding targets, inventory & status effect embedding (nested lists -> separate entities), and assigns deterministic EntityIDs.

from_state(state)

Convert an immutable State back into a mutable GridState (grid of generic Entity objects).

grid_state_fn_to_initial_state_fn(grid_state_fn)

Convert a grid-state-building function into an initial state function.

grid_state_to_initial_state_fn(gridstate)

Create the initial State for the given GridState.

to_state(gridstate)

Convert a GridState (grid of BaseEntity objects) into an immutable State.