Skip to main content

ssab/
lib.rs

1//! The `.ssab` / `.ssqb` binary format — SpriteStudio's on-disk runtime data.
2//!
3//! This crate is the schema, not a library of behaviour: almost everything under
4//! [`ssab`] and [`ssqb`] is FlatBuffers code generated from `fbs/ssab.fbs` and
5//! `fbs/ssqb.fbs`. It sits between the two halves of the SDK — `ssconverter` writes
6//! these binaries, `ssruntime` reads them zero-copy.
7//!
8//! | Module | Root table | Holds |
9//! |---|---|---|
10//! | [`ssab`] | `SsAnimeBinary` | animations, parts, keyframes, cell maps, effects |
11//! | [`ssqb`] | `SsSequenceBinary` | sequence packs (`.ssqe`) |
12//!
13//! # Reading (default)
14//!
15//! The default feature set is read-only and zero-copy, which is what a Player wants:
16//! accessors borrow directly out of the mapped buffer, with no parse step and no
17//! allocation.
18//!
19//! ```no_run
20//! use ssab::ssab::ss::format::root_as_ss_anime_binary;
21//!
22//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
23//! let bytes = std::fs::read("character.ssab")?;
24//! let binary = root_as_ss_anime_binary(&bytes)?;
25//! println!("{}", binary.name());
26//! for anime in binary.animations() {
27//!     println!("  {} @ {} fps", anime.name(), anime.fps());
28//! }
29//! # Ok(())
30//! # }
31//! ```
32//!
33//! # Writing (`converter`)
34//!
35//! Enabling `converter` selects the modules generated with the FlatBuffers *object API*
36//! (`--gen-object-api`), which add owned `
T` structs that can be built up in memory and
37//! packed back into a buffer. Only tools that emit data need this; it implies `std`.
38//!
39//! # Feature flags
40//!
41//! | Feature | Purpose |
42//! |---|---|
43//! | `std` *(default)* | `std` support in `flatbuffers`. Disable for `no_std` Players. |
44//! | `converter` | Read/write object API (`SsAnimeBinaryT` and friends). Implies `std`. |
45//!
46//! # Validation
47//!
48//! `root_as_*` verifies the buffer; the `_unchecked` variants do not. `ssruntime`
49//! deliberately uses the unchecked path in the playback hot loop, which is why
50//! validating untrusted assets is the Player's responsibility.
51//!
52//! # Regenerating
53//!
54//! The Rust modules are generated output — edit `fbs/*.fbs` and re-run
55//! `scripts/generate.sh` (or `.ps1`), which needs `flatc` on `PATH`. Never hand-edit
56//! `src/runtime/` or `src/converter/`.
57//!
58//! See the [schema documentation](https://github.com/cri-middleware/SpriteStudio-SDK/blob/HEAD/libs/ssab/SCHEMA.md)
59//! for the field-by-field design spec.
60
61#![cfg_attr(not(feature = "std"), no_std)]
62#![warn(missing_docs)]
63extern crate flatbuffers;
64
65// The `ssab` / `ssqb` modules are `flatc` output, so `missing_docs` is waived for
66// them. The attribute sits on the declaration, not inside the generated file, so
67// that `scripts/generate.{sh,ps1}` cannot wipe it.
68
69#[allow(missing_docs)]
70#[rustfmt::skip]
71#[cfg(feature = "converter")]
72#[path = "converter/ssab.rs"]
73pub mod ssab;
74
75#[allow(missing_docs)]
76#[rustfmt::skip]
77#[cfg(feature = "converter")]
78#[path = "converter/ssqb.rs"]
79pub mod ssqb;
80
81#[allow(missing_docs)]
82#[rustfmt::skip]
83#[cfg(not(feature = "converter"))]
84#[path = "runtime/ssab.rs"]
85pub mod ssab;
86
87#[allow(missing_docs)]
88#[rustfmt::skip]
89#[cfg(not(feature = "converter"))]
90#[path = "runtime/ssqb.rs"]
91pub mod ssqb;
92
93/// A `PartAnimationData` field with no run: the animation has no keys for that
94/// attribute on that part. It is the fields' schema default, so it is never written.
95pub const NO_KEYS: u32 = u32::MAX;
96
97/// `Keyframes.curve` for a key that reads neither a curve nor an easing rate.
98pub const NO_CURVE: u16 = u16::MAX;
99
100/// The `.ssab` schema version the converter stamps into every pack it emits and
101/// the runtime refuses to read anything else as.
102///
103/// Both `version` fields declare no FlatBuffers default, so an absent one reads as
104/// `0` and is refused too.
105// Raise it in the same commit that changes the wire format, and
106// `an_emitted_pack_carries_its_schema_version` proves the bytes still carry it.
107pub const SSAB_SCHEMA_VERSION: u32 = 1;
108
109/// The `.ssqb` counterpart of [`SSAB_SCHEMA_VERSION`].
110pub const SSQB_SCHEMA_VERSION: u32 = 1;
111
112/// `.ssab` schema version. See [`SSAB_SCHEMA_VERSION`].
113pub fn ssab_schema_version() -> u32 {
114    SSAB_SCHEMA_VERSION
115}
116
117/// `.ssqb` schema version. See [`SSQB_SCHEMA_VERSION`].
118pub fn ssqb_schema_version() -> u32 {
119    SSQB_SCHEMA_VERSION
120}