factoriax.playground.play.game_ui#
Reusable game UI: menus, hotbar, click regions, and event dispatch.
Extracted from factoriax.playground.play.main so that both the play loop
and the debugger can share the same input handling and menu rendering
without duplicating code. GameUI owns a PlayState internally
and translates pygame events into GameUIResult values that
the caller can act on.
GameUI does NOT step the environment, manage the pygame window, or handle recording. Those responsibilities remain with the caller.
- class factoriax.playground.play.game_ui.GameUI(params: EnvParams, kb_lookup: dict[tuple[int, int], frozenset[str]], *, ctrl_lookup: dict[str, frozenset[str]] | None = None, welcome_open: bool = True)#
Reusable game UI component for menus, hotbar, and input dispatch.
Owns a
PlayStateinternally. Callers feed it pygame events and the currentEnvState. It returns rendered overlays and action intents viaGameUIResult.- Parameters:
kb_lookup – Key lookup table from
welcome_open – Whether to show the welcome screen initially
- handle_event(event: Event, state: EnvState) GameUIResult#
Process a single pygame event and return the result.
The caller is responsible for acting on the result: stepping the environment if
result.actionis set, resetting ifresult.resetis True, and quitting ifresult.quitis True.- Parameters:
event – Pygame event to process.
state – Current environment state.
Report whether any menu or overlay is open.
- render_frame(state: EnvState, ui_w: int, ui_h: int, tile_px: int, world_ox: int, world_oy: int, achievements: Array | None = None) tuple[ndarray, list[ClickRegion]]#
Draw one frame, with every open overlay.
The function draws the world first, and then each open menu over it.
- Parameters:
state – Current environment state.
ui_w – UI canvas width.
ui_h – UI canvas height.
tile_px – Tile pixel size.
world_ox – World X offset within canvas.
world_oy – World Y offset within canvas.
achievements – Achievement flags from the wrapper state. Required when the achievement menu is open.