Skip to main content

Module hot

Module hot 

Source
Expand description

Values that reload (ADR-0071). A Hot value is an asset decoded through the registry by id, which remembers every file its decode asked for: the file itself, the files its format read through DecodeCx (an atlas’s picture, a level’s tileset) and its import settings, found or not. When the platform says files changed, Hot::refresh decodes it again if one of them did. If the new decode fails, the old value stays and the errors come back (Reload::Failed), so a broken file never takes a running game down.

A Hot reads through to its value:

use std::collections::BTreeMap;
use std::sync::Arc;
use shuyi_assets::bundle::{Bundle, Layer};
use shuyi_assets::format::Formats;
use shuyi_assets::hot::{Hot, Reload};
use shuyi_assets::palette::PaletteDef;

let palette = |ink: &str| format!("{{ \"ink\": \"{ink}\" }}").into_bytes();
let files = BTreeMap::from([("palette.ron".to_owned(), palette("#000000"))]);
let layer = Layer::owned("disk".to_owned(), files).unwrap();
let bundle = Bundle::new(vec![layer]);
let formats = Arc::new(Formats::standard());
let mut colors = Hot::<PaletteDef>::load(&formats, &bundle, "palette.ron").unwrap();

assert_eq!(colors.refresh(&["other.ron".to_owned()]), Reload::Unchanged);
assert!(bundle.replace("palette.ron", palette("#ffffff")));
assert_eq!(colors.refresh(&["palette.ron".to_owned()]), Reload::Reloaded);
assert_eq!(colors.get("ink"), Some([255, 255, 255]));

Structs§

Hot
An asset of kind T that decodes again when a file it read changes (the module docs).

Enums§

Reload
What a Hot::refresh did.