mundane.engine.serialize

Serialisation helpers: turn a 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

Functions

_jsonify(→ object)

Recursively convert dataclass-derived data to JSON-native values (any Enum -> its value).

state_to_dict(→ dict[str, object])

Return a plain, JSON-ready dict for state. After M1 it holds only ids and scalars.

action_to_dict(→ dict[str, object])

Return a JSON-ready dict for action: its discriminator tag plus its fields.

dumps(→ str)

Serialise obj to a pretty-printed JSON string.

canonical_json(→ str)

Serialise obj deterministically for hashing: sorted keys, no insignificant whitespace.

Module Contents

mundane.engine.serialize._TAG_BY_TYPE[source]
mundane.engine.serialize._jsonify(value: object) object[source]

Recursively convert dataclass-derived data to JSON-native values (any Enum -> its value).

mundane.engine.serialize.state_to_dict(state: mundane.engine.state.GameState) dict[str, object][source]

Return a plain, JSON-ready dict for state. After M1 it holds only ids and scalars.

mundane.engine.serialize.action_to_dict(action: mundane.engine.actions.Action) dict[str, object][source]

Return a JSON-ready dict for action: its discriminator tag plus its fields.

mundane.engine.serialize.dumps(obj: object) str[source]

Serialise obj to a pretty-printed JSON string.

mundane.engine.serialize.canonical_json(obj: object) str[source]

Serialise obj deterministically for hashing: sorted keys, no insignificant whitespace.