Closes #266. Implements ResourceReader for functions so that you can do stuff like this:
use tiled::{DefaultResourceCache, Loader};
let mut loader = Loader::with_cache_and_reader(
DefaultResourceCache::new(),
// Specify the reader to use. We can use anything that implements `ResourceReader`, e.g. FilesystemResourceReader.
// Any function that has the same signature as `ResourceReader::read_from` also implements it.
// Here we define a reader that embeds the map at "assets/tiled_xml.csv" into the executable, and allow
// accessing it only through "/my-map.tmx"
// ALL maps, tilesets and templates will be read through this function, even if you don't explicitly load them
// (They can be dependencies of one you did want to load in the first place).
// Doing this embedding is useful for places where the OS filesystem is not available (e.g. WASM applications).
|path: &std::path::Path| -> std::io::Result<_> {
if path == std::path::Path::new("/my-map.tmx") {
Ok(std::io::Cursor::new(include_bytes!("../assets/tiled_csv.tmx")))
} else {
Err(std::io::ErrorKind::NotFound.into())
}
}
);
Also adds a FAQ section on loading embedded maps and improves Loader::with_cache_and_reader docs.
Closes #266. Implements ResourceReader for functions so that you can do stuff like this:
Also adds a FAQ section on loading embedded maps and improves
Loader::with_cache_and_reader
docs.