Files
craft-libs/crates/gridcraft-format/README.md
T
FredApps 9a6d894200 Add craft-gridcraft-format: GridCraft's native JSON workbook (#1749)
GridCraft's native workbook format, moved from storytold/gridcraft at
1d0b311b: the `.json`/`.scjson` extensions (crates/engine/src/io.rs), the
reader and its error text (io.rs), and the pretty writer with newer macros kept
unread and appended to `macros` as the file held them
(crates/engine/src/macros/mod.rs json_bytes).

The Workbook model, the index rebuilds after a read, and macro reading stay in
GridCraft. The consumer's golden test shows saved bytes are unchanged.

Part of #778.
2026-11-16 02:03:41 +01:00

1.0 KiB

craft-gridcraft-format

GridCraft's native workbook file is one pretty-printed UTF-8 JSON object, with a two-space indent and no newline at the end. It is saved as .json, or as .scjson by older builds.

The workbook is a type parameter. GridCraft owns the model, and after a read it rebuilds the model's indexes, drops cells outside the grid and reads the macros. This crate owns the bytes:

  • EXTENSIONS and is_extension name the format.
  • read(bytes) reads a workbook. A failure reads as "not a GridCraft JSON workbook: …".
  • write(workbook) writes one with serde_json's pretty printer.
  • write_with_kept(workbook, field, kept) appends entries that a newer version wrote, and this build kept without reading, to the top-level list field, as the file held them. With nothing kept, the output is exactly write's. Otherwise the workbook goes through a serde_json::Value first, so its object keys come out in map order, as GridCraft has always written them.

There is no unsafe and no panics, and it builds for wasm32-unknown-unknown.