pub struct Formats {
pub limits: Limits,
/* private fields */
}Expand description
The formats of every kind (module docs).
Fields§
§limits: LimitsThe limits Formats::load and Formats::load_under decode with.
Implementations§
Source§impl Formats
impl Formats
Sourcepub fn standard() -> Self
pub fn standard() -> Self
A registry with the engine’s standard formats, those that need
nothing of the game (Formats::register_standard).
Sourcepub fn register_standard(&mut self) -> Result<(), RegisterError>
pub fn register_standard(&mut self) -> Result<(), RegisterError>
Registers the engine’s standard formats after those already here: every format of the engine that needs nothing of the game. The formats that read a game’s own types (its map features, dialogue directives, actions, shots) or follow its rules (the glyphs it needs, its language rules) are the game’s to register, with them.
Sourcepub fn register<F: Format>(&mut self, format: F) -> Result<(), RegisterError>
pub fn register<F: Format>(&mut self, format: F) -> Result<(), RegisterError>
Adds format after the formats of its kind, unless one of them has
its id or claims one of its extensions.
Sourcepub fn replace<F: Format>(
&mut self,
format: F,
) -> Result<Vec<&'static str>, RegisterError>
pub fn replace<F: Format>( &mut self, format: F, ) -> Result<Vec<&'static str>, RegisterError>
Adds format in place of the formats of its kind that have its id or
claim one of its extensions (after them all if none does), and
returns their ids.
Sourcepub fn register_import_settings<S: ImportSettings>(
&mut self,
) -> Result<(), RegisterError>
pub fn register_import_settings<S: ImportSettings>( &mut self, ) -> Result<(), RegisterError>
Registers the section of import settings S (ADR-0057), so
check_import_settings knows it.
Refuses, in this order, a second section of its name, a type that
can’t read () (a field with no default) and one that reads
(shuyi_probe: ()) (it doesn’t deny unknown fields).
Sourcepub fn import_settings_sections(&self) -> Vec<&'static str>
pub fn import_settings_sections(&self) -> Vec<&'static str>
The names of the sections of import settings registered, in order.
Sourcepub fn check_import_settings(&self, bundle: &Bundle) -> Vec<ContentError>
pub fn check_import_settings(&self, bundle: &Bundle) -> Vec<ContentError>
Every problem of every settings file of bundle (ADR-0057): a file
that doesn’t read, a section no one registered or that doesn’t read
as its type, and a <name>.meta whose file the bundle lacks (and
doesn’t leave out on purpose) or is itself a settings file.
Sourcepub fn ids<K: AssetKind>(&self) -> Vec<&'static str>
pub fn ids<K: AssetKind>(&self) -> Vec<&'static str>
The ids of kind K’s formats, in the order they are tried.
Sourcepub fn extensions<K: AssetKind>(&self) -> Vec<&'static str>
pub fn extensions<K: AssetKind>(&self) -> Vec<&'static str>
The extensions kind K’s formats claim, in their order.
Sourcepub fn claims<K: AssetKind>(&self, path: &str) -> bool
pub fn claims<K: AssetKind>(&self, path: &str) -> bool
Whether a format of kind K claims the extension of the file at
path.
Sourcepub fn decode<K: AssetKind>(
&self,
file: &AssetPath,
bytes: &[u8],
cx: &DecodeCx<'_>,
) -> Result<K, Vec<ContentError>>
pub fn decode<K: AssetKind>( &self, file: &AssetPath, bytes: &[u8], cx: &DecodeCx<'_>, ) -> Result<K, Vec<ContentError>>
The asset of kind K in bytes, the contents of file, by the
lookup rule: the formats that sniff bytes in order, then the one
that claims file’s extension. The first that decodes it gives the
asset; when none does, the errors are the first one’s. A
watch_decodes watch is told before and after.
Sourcepub fn find<K: AssetKind>(
&self,
bundle: &Bundle,
id: &str,
) -> Result<String, ContentError>
pub fn find<K: AssetKind>( &self, bundle: &Bundle, id: &str, ) -> Result<String, ContentError>
The path of the asset of kind K with id id: the file at id
itself if bundle has one, else the one file at id and an
extension kind K’s formats claim (images/card is
images/card.png, or images/card.txtimg once a format claims
that).
Sourcepub fn load<K: AssetKind>(
&self,
bundle: &Bundle,
id: &str,
) -> Result<K, Vec<ContentError>>
pub fn load<K: AssetKind>( &self, bundle: &Bundle, id: &str, ) -> Result<K, Vec<ContentError>>
The asset of kind K with id id in bundle (Formats::find),
decoded with the registry’s limits.
Sourcepub fn load_under<K: AssetKind>(
&self,
bundle: &Bundle,
dir: &str,
) -> Result<BTreeMap<&'static str, K>, Vec<ContentError>>
pub fn load_under<K: AssetKind>( &self, bundle: &Bundle, dir: &str, ) -> Result<BTreeMap<&'static str, K>, Vec<ContentError>>
Every asset of kind K in bundle under directory dir ("" for
the whole bundle): each file there whose extension a format of the
kind claims, by path. Reports every problem of every file.
All or nothing over a tree: the assets come only when every file
reads, and folders below dir are read too. A loader that checks
each file after reading wants Formats::load_each instead.
Sourcepub fn load_each<K: AssetKind>(
&self,
bundle: &Bundle,
dir: &str,
) -> BTreeMap<&'static str, Result<K, Vec<ContentError>>>
pub fn load_each<K: AssetKind>( &self, bundle: &Bundle, dir: &str, ) -> BTreeMap<&'static str, Result<K, Vec<ContentError>>>
Each asset of kind K directly inside directory dir of bundle
("" for the root), by path: each file there whose extension a
format of the kind claims, with its asset or its errors.
File by file in one folder: a broken file leaves the others read,
so checks that run after still see every good file, and folders
below dir (which may hold another kind with the same extension)
are not read. A missing folder gives an empty map.