pub struct Bake { /* private fields */ }Expand description
What a game bakes into a pack: which assets of which kinds, the same
way its loaders ask for them (asset as
Formats::load, under as Formats::load_under),
and its stamp. Every other file of the bundle goes into the pack as its
own bytes.
A file whose bytes something other than its kind’s format reads (a
picture the platform draws, a sound it plays, a file another format
reads beside its own) stays as it is, or is baked in a format that
reader knows (under_as): bake only kinds whose
files nothing else reads.
Implementations§
Source§impl Bake
impl Bake
Sourcepub fn new(stamp: impl Into<String>) -> Self
pub fn new(stamp: impl Into<String>) -> Self
A bake of nothing yet, with stamp: the game’s word for the shapes
of its own kinds (its version, say), which Pack::open then asks
for.
Sourcepub fn asset<K: Bakeable>(self, id: &str) -> Self
pub fn asset<K: Bakeable>(self, id: &str) -> Self
This bake, baking the asset of kind K with id id (data/palette
or data/palette.ron).
Sourcepub fn under<K: Bakeable>(self, dir: &str) -> Self
pub fn under<K: Bakeable>(self, dir: &str) -> Self
This bake, baking every file of kind K under directory dir (""
for the whole bundle) whose extension a format of the kind claims.
Sourcepub fn under_as<F>(self, dir: &str, format: F) -> Self
pub fn under_as<F>(self, dir: &str, format: F) -> Self
This bake, baking every file of format’s kind under directory
dir ("" for the whole bundle) whose extension a format of the
kind claims, read with the bake’s formats, and kept in the pack in
format’s own bytes (Encode) instead of the pack’s binary
form: an optimized format derived from its source (ADR-0007 §4),
which whatever reads the file on the target reads as it is. A
one-bit target’s pictures go in as one-bit picture files so, each
at its PNG’s path:
use shuyi_assets::bitmap::OneBitFile;
use shuyi_assets::pack::Bake;
let bake = Bake::new("my-game 1").under_as("", OneBitFile);
assert_eq!(bake.kinds(), ["one-bit picture"]);register registers format where its kind
lacks it, and check proves each such file of the
pack, read by it, equal to its source read with the bake’s
formats. A file baked so is baked as no other kind.
Sourcepub fn kinds(&self) -> Vec<&'static str>
pub fn kinds(&self) -> Vec<&'static str>
The names of the kinds it bakes, each once, in the order first named.
Sourcepub fn register(&self, formats: &mut Formats) -> Result<(), RegisterError>
pub fn register(&self, formats: &mut Formats) -> Result<(), RegisterError>
Registers in formats the format of a baked file of every kind it
bakes (Packed), where it isn’t already: what a game that loads
a pack does at start-up.
Sourcepub fn bake(
&self,
formats: &Formats,
bundle: &Bundle,
target: Option<&str>,
) -> Result<Baked, Vec<ContentError>>
pub fn bake( &self, formats: &Formats, bundle: &Bundle, target: Option<&str>, ) -> Result<Baked, Vec<ContentError>>
The pack of bundle, baked for target: each file this bake names
holds its assets read with formats (or, baked
under_as a format, that format’s bytes), every
other file its own bytes, and its index holds bundle’s fingerprint, which the pack
then stands for. Import settings files go in as their own bytes
too, once they check (Formats::check_import_settings). Refuses
a source with errors: every one of them is returned.
Sourcepub fn load(&self, formats: &Formats, bundle: &Bundle) -> Vec<ContentError>
pub fn load(&self, formats: &Formats, bundle: &Bundle) -> Vec<ContentError>
Reads every asset this bake names from bundle with formats, as
the game’s loaders would, and drops them: what shuyi bake times,
from the sources and from the pack. Every error found.
Sourcepub fn check(
&self,
formats: &Formats,
source: &Bundle,
pack: &Bundle,
) -> Vec<ContentError>
pub fn check( &self, formats: &Formats, source: &Bundle, pack: &Bundle, ) -> Vec<ContentError>
Every way pack (a bundle of a baked pack) differs from source,
the bundle it was baked from: an asset this bake names that reads
differently from the two with formats (which must have the pack’s
formats: register), a file the pack lacks or
adds, or one kept as its own bytes that changed. None if the pack
is true to its sources.