mundane.engine.serialize ======================== .. py:module:: mundane.engine.serialize .. autoapi-nested-parse:: Serialisation helpers: turn a :class:`GameState` into plain, JSON-ready data. This is deliberately one-way (state -> dict -> JSON): the export/download feature never reads the file back. Round-trip *loading* is out of scope; if it is added later, decode with msgspec (``msgspec.json.decode(data, type=GameState)``, msgspec ships with Litestar) rather than a hand-written decoder. Attributes ---------- .. autoapisummary:: mundane.engine.serialize._TAG_BY_TYPE Functions --------- .. autoapisummary:: mundane.engine.serialize._jsonify mundane.engine.serialize.state_to_dict mundane.engine.serialize.action_to_dict mundane.engine.serialize.dumps mundane.engine.serialize.canonical_json Module Contents --------------- .. py:data:: _TAG_BY_TYPE .. py:function:: _jsonify(value: object) -> object Recursively convert dataclass-derived data to JSON-native values (any Enum -> its value). .. py:function:: state_to_dict(state: mundane.engine.state.GameState) -> dict[str, object] Return a plain, JSON-ready dict for ``state``. After M1 it holds only ids and scalars. .. py:function:: action_to_dict(action: mundane.engine.actions.Action) -> dict[str, object] Return a JSON-ready dict for ``action``: its discriminator tag plus its fields. .. py:function:: dumps(obj: object) -> str Serialise ``obj`` to a pretty-printed JSON string. .. py:function:: canonical_json(obj: object) -> str Serialise ``obj`` deterministically for hashing: sorted keys, no insignificant whitespace.