Skip to content
Snippets Groups Projects
Verified Commit df3dfe92 authored by Louis's avatar Louis :fire:
Browse files

Support external level files

parent b7a772dc
No related branches found
Tags v0.7.0
No related merge requests found
......@@ -1567,7 +1567,7 @@ dependencies = [
[[package]]
name = "micro_ldtk"
version = "0.6.1"
version = "0.7.0"
dependencies = [
"anyhow",
"bevy",
......
[package]
name = "micro_ldtk"
version = "0.6.1"
version = "0.7.0"
edition = "2021"
authors = [
......
......@@ -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) |
......
......@@ -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(())
})
......
......@@ -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,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment