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

Add LDTK 1.3.0 support

parent a00e2cc7
No related branches found
No related tags found
No related merge requests found
...@@ -2077,7 +2077,7 @@ dependencies = [ ...@@ -2077,7 +2077,7 @@ dependencies = [
[[package]] [[package]]
name = "micro_ldtk" name = "micro_ldtk"
version = "0.3.0-beta.2" version = "0.3.0"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"bevy", "bevy",
......
[package] [package]
name = "micro_ldtk" name = "micro_ldtk"
version = "0.3.0" version = "0.4.0"
edition = "2021" edition = "2021"
authors = [ authors = [
...@@ -11,7 +11,8 @@ description = "Load data from LDTK, index it and make it accessible through Bevy ...@@ -11,7 +11,8 @@ description = "Load data from LDTK, index it and make it accessible through Bevy
license = "Apache-2.0" license = "Apache-2.0"
[features] [features]
default = ["ldtk_1_2_5", "autotile"] default = ["ldtk_1_3_0", "autotile"]
ldtk_1_3_0 = []
ldtk_1_2_5 = [] ldtk_1_2_5 = []
ldtk_1_2_4 = [] ldtk_1_2_4 = []
ldtk_1_2_3 = [] ldtk_1_2_3 = []
......
...@@ -38,6 +38,7 @@ corresponding version of LDTK and save it again. ...@@ -38,6 +38,7 @@ corresponding version of LDTK and save it again.
| Feature Flag | Uses Schema Version | | 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_2_5` | [v1.2.5](https://github.com/deepnight/ldtk/blob/v1.2.5/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_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) | | `ldtk_1_2_3`, `ldtk_1_2_2` | [v1.2.2](https://github.com/deepnight/ldtk/blob/v1.2.2/docs/JSON_SCHEMA.json) |
......
This diff is collapsed.
...@@ -12,6 +12,8 @@ mod data_1_2_2; ...@@ -12,6 +12,8 @@ mod data_1_2_2;
mod data_1_2_4; mod data_1_2_4;
#[cfg(feature = "ldtk_1_2_5")] #[cfg(feature = "ldtk_1_2_5")]
mod data_1_2_5; mod data_1_2_5;
#[cfg(feature = "ldtk_1_3_0")]
mod data_1_3_0;
use bevy::asset::{AssetLoader, BoxedFuture, LoadContext, LoadedAsset}; use bevy::asset::{AssetLoader, BoxedFuture, LoadContext, LoadedAsset};
use bevy::reflect::{TypeUuid, Uuid}; use bevy::reflect::{TypeUuid, Uuid};
...@@ -29,6 +31,8 @@ pub use data_1_2_2::*; ...@@ -29,6 +31,8 @@ pub use data_1_2_2::*;
pub use data_1_2_4::*; pub use data_1_2_4::*;
#[cfg(feature = "ldtk_1_2_5")] #[cfg(feature = "ldtk_1_2_5")]
pub use data_1_2_5::*; pub use data_1_2_5::*;
#[cfg(feature = "ldtk_1_3_0")]
pub use data_1_3_0::*;
#[derive(thiserror::Error, Debug)] #[derive(thiserror::Error, Debug)]
pub enum ParseError { pub enum ParseError {
...@@ -44,6 +48,44 @@ impl Project { ...@@ -44,6 +48,44 @@ impl Project {
pub fn from_bytes(bytes: &[u8]) -> Result<Self, ParseError> { pub fn from_bytes(bytes: &[u8]) -> Result<Self, ParseError> {
serde_json::from_slice(bytes).map_err(|e| ParseError::SerdeError(format!("{}", e))) serde_json::from_slice(bytes).map_err(|e| ParseError::SerdeError(format!("{}", e)))
} }
pub fn get_all_levels(&self) -> Vec<&Level> {
if self.worlds.len() > 0 {
self.worlds
.iter()
.flat_map(|world| world.levels.iter())
.collect()
} else {
self.levels.iter().collect()
}
}
#[cfg(any(
feature = "ldtk_1_2_5",
feature = "ldtk_1_2_4",
feature = "ldtk_1_2_3",
feature = "ldtk_1_2_2",
feature = "ldtk_1_2_1",
feature = "ldtk_1_2_0",
feature = "ldtk_1_1_3",
feature = "ldtk_1_1_2",
feature = "ldtk_1_1_1",
feature = "ldtk_1_1_0",
feature = "ldtk_1_0_0"
))]
pub fn get_world_levels(&self, identifier: impl ToString) -> Vec<&Level> {
vec![]
}
#[cfg(any(feature = "ldtk_1_3_0",))]
pub fn get_world_levels(&self, identifier: impl ToString) -> Vec<&Level> {
let id = identifier.to_string();
self.worlds
.iter()
.find(|world| world.identifier == id)
.map(|list| list.levels.iter().collect())
.unwrap_or_else(Vec::new)
}
} }
pub type LdtkProject = Project; pub type LdtkProject = Project;
...@@ -166,7 +208,7 @@ mod autotile_support { ...@@ -166,7 +208,7 @@ mod autotile_support {
mod test { mod test {
use crate::ldtk::Project; use crate::ldtk::Project;
#[test] #[cfg_attr(feature = "ldtk_1_2_5", test)]
pub fn load_project() { pub fn load_project() {
const project_data: &[u8] = include_bytes!("./test_data/ver_1_2_5.ldtk"); const project_data: &[u8] = include_bytes!("./test_data/ver_1_2_5.ldtk");
......
...@@ -4,7 +4,20 @@ mod map_query; ...@@ -4,7 +4,20 @@ mod map_query;
mod pregen; mod pregen;
mod system; mod system;
#[cfg(any(feature = "ldtk_1_2_5", feature = "ldtk_1_2_4"))] #[cfg(any(
feature = "ldtk_1_3_0",
feature = "ldtk_1_2_5",
feature = "ldtk_1_2_4",
feature = "ldtk_1_2_3",
feature = "ldtk_1_2_2",
feature = "ldtk_1_2_1",
feature = "ldtk_1_2_0",
feature = "ldtk_1_1_3",
feature = "ldtk_1_1_2",
feature = "ldtk_1_1_1",
feature = "ldtk_1_1_0",
feature = "ldtk_1_0_0",
))]
pub mod ldtk; pub mod ldtk;
pub static mut LDTK_TILE_SCALE: AtomicU32 = AtomicU32::new(32); pub static mut LDTK_TILE_SCALE: AtomicU32 = AtomicU32::new(32);
......
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