diff --git a/Cargo.lock b/Cargo.lock index 8c4ca699098826f1ac6f1285850b8dbb689e4782..aa21e00e91c0dd6ab1e984682c784470969547a4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1567,7 +1567,7 @@ dependencies = [ [[package]] name = "micro_ldtk" -version = "0.6.1" +version = "0.7.0" dependencies = [ "anyhow", "bevy", diff --git a/Cargo.toml b/Cargo.toml index 246a66f69ccc9795f6b05d6b1f96689cf6191207..c46f91f073c28767bba590862fa37b95af2a6459 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "micro_ldtk" -version = "0.6.1" +version = "0.7.0" edition = "2021" authors = [ diff --git a/README.md b/README.md index f4c3a8a1705e55cacacf8352da9873a5b8ff8bbd..872653af9e1261d5c2afb3def7bb99c9f1240992 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ select the schema version you need: ```toml [dependencies] -micro_ldtk = { version = "0.4.1", default-features = false, features = ["ldtk_1_3_0", "autotile"] } +micro_ldtk = { version = "0.7.0", default-features = false, features = ["ldtk_1_3_0", "autotile"] } ``` ### Features @@ -38,7 +38,7 @@ corresponding version of LDTK and save it again. | Feature Flag | Uses Schema Version | |----------------------------|-------------------------------------------------------------------------------| -| `ldtk_1_3_0` | [v1.2.5](https://github.com/deepnight/ldtk/blob/v1.3.0/docs/JSON_SCHEMA.json) | +| `ldtk_1_3_0` | [v1.3.0](https://github.com/deepnight/ldtk/blob/v1.3.0/docs/JSON_SCHEMA.json) | | `ldtk_1_2_5` | [v1.2.5](https://github.com/deepnight/ldtk/blob/v1.2.5/docs/JSON_SCHEMA.json) | | `ldtk_1_2_4` | [v1.2.4](https://github.com/deepnight/ldtk/blob/v1.2.4/docs/JSON_SCHEMA.json) | | `ldtk_1_2_3`, `ldtk_1_2_2` | [v1.2.2](https://github.com/deepnight/ldtk/blob/v1.2.2/docs/JSON_SCHEMA.json) | diff --git a/src/ldtk/mod.rs b/src/ldtk/mod.rs index ffa60bb74332ba02ad0e9958ed3d88837e7654dd..d7e55590b415221a8c266bd843b942e579f49050 100644 --- a/src/ldtk/mod.rs +++ b/src/ldtk/mod.rs @@ -17,6 +17,7 @@ mod data_1_3_0; use bevy::asset::{AssetLoader, AssetPath, BoxedFuture, LoadContext, LoadedAsset}; use bevy::reflect::{TypePath, TypeUuid, Uuid}; + #[cfg(feature = "ldtk_1_0_0")] pub use data_1_0_0::*; #[cfg(any(feature = "ldtk_1_1_1", feature = "ldtk_1_1_0"))] @@ -155,12 +156,23 @@ impl AssetLoader for LdtkLoader { load_context: &'a mut LoadContext, ) -> BoxedFuture<'a, anyhow::Result<(), anyhow::Error>> { Box::pin(async move { + log::debug!( + "Loading ldtk project file {}", + load_context.path().display() + ); + let project = Project::from_bytes(bytes)?; let sub_levels = project .levels .iter() .flat_map(|level| { + log::debug!( + "Checking if level is external: {} [{}]", + level.identifier, + level.external_rel_path.is_some() + ); + level .external_rel_path .as_ref() @@ -172,12 +184,13 @@ impl AssetLoader for LdtkLoader { sub_levels .into_iter() .flat_map(|(id, path)| { - load_context - .path() - .join(path) - .canonicalize() - .map(|path| AssetPath::new(path, Some(id))) - .ok() + log::debug!( + "Checking for file {}", + load_context.path().parent()?.join(&path).display() + ); + + let path = load_context.path().parent()?.join(path); + Some(AssetPath::new(path, Some(id))) }) .collect(), ); @@ -200,6 +213,7 @@ impl AssetLoader for LdtkLevelLoader { load_context: &'a mut LoadContext, ) -> BoxedFuture<'a, anyhow::Result<(), anyhow::Error>> { Box::pin(async move { + log::debug!("Loading ldtkl level file {}", load_context.path().display()); load_context.set_default_asset(LoadedAsset::new(Level::from_bytes(bytes)?)); Ok(()) }) diff --git a/src/pregen.rs b/src/pregen.rs index eeae7d93504253fa4981c0d29fc62e8d31036080..119662bb86dc71898c814d7178cfede4c66472da 100644 --- a/src/pregen.rs +++ b/src/pregen.rs @@ -95,6 +95,24 @@ impl Rasterise for LdtkLevel { } } } + +impl LdtkLevel { + pub fn write_filtered_to_texture( + &self, + buffer: &mut [u8], + format: &TextureFormat, + images: &impl SuppliesImage, + atlas: &impl SuppliesTextureAtlas, + predicate: impl Fn(&LdtkLayer) -> bool, + ) { + for layer in self.layers() { + if predicate(layer) { + layer.write_to_texture(buffer, format, images, atlas); + } + } + } +} + impl Rasterise for LdtkLayer { fn write_to_texture( &self,