factoriax.playground.editor.main#

The main loop of the level editor.

The module makes the window, reads the events, holds the tool state, and draws each frame. It follows the same structure as factoriax.playground.play.main.

The editor writes to the numpy arrays of EditorState, and touches no JAX state. It converts to a Level for a save and for a play session.

class factoriax.playground.editor.main.ToolState(tool: str = 'paint', block: int = <factory>, machine: int = 0, direction: int = <factory>, entity: tuple[str, int] | None=None, brush: ResourceBrush = <factory>, show_resources: bool = False, show_help: bool = False, cursor_tile: tuple[int, int] | None=None, painting: bool = False, last_paint_tile: tuple[int, int] | None=None, right_erasing: bool = False, tool_before_erase: str = 'paint', machine_before_erase: int = 0, entity_before_erase: tuple[str, int] | None=None, fill_start: tuple[int, int] | None=None, fill_rect: tuple[int, int, int, int] | None=None, middle_dragging: bool = False, middle_last: tuple[int, int]=(0, 0), toolbar_scroll: int = 0, inventory_mode: bool = False, inv_target: tuple[str, int, int] | None=None, inv_focused_slot: int = 0)#

The tool, the brush, and the drag that the editor has active.

This class holds what the user selects and does, and holds no part of the level. EditorState holds the level.

One object keeps the main loop small, and gives each helper function the full context in one argument.

The three *_before_erase fields hold the tool that the user had before a right button drag. The editor puts that tool back at the end of the drag.

property brush_name: str#

Name of the active brush, for the status bar.

cancel_fill() → None#

Cancel an in-progress fill-rect selection.

property layer: str#

Return the active editing layer name.

Returns:

"inventory", "entity", "machine", or "terrain".

Return type:

type

property resource_info: str#

Ore amount of the brush, for the status bar.

stop_painting() → None#

End any active paint or erase drag.

factoriax.playground.editor.main.main(screen: Surface | None = None) → None#

Run the Factoriax level editor.

Parameters:

screen – Existing pygame display surface to reuse. When None (the default) a new window is created. Press ? for a full list of controls.

factoriax.playground.editor.main.run_play_session(state: EditorState, screen: Surface) → None#

Play the level that the editor has open.

The function converts the editor state to a level, and gives that level to play_level(). The play session holds the full game UI. When the user leaves the session, the editor comes back with the level unchanged.

Parameters:
  • state – Editor state to play. The function does not modify it.

  • screen – Display surface. The play session draws on the same surface.