mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-16 20:25:02 +00:00
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.
1.0 KiB
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:
EXTENSIONSandis_extensionname the format.read(bytes)reads a workbook. A failure reads as "not a GridCraft JSON workbook: …".write(workbook)writes one withserde_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 listfield, as the file held them. With nothing kept, the output is exactlywrite's. Otherwise the workbook goes through aserde_json::Valuefirst, 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.