diff --git a/src/level.rs b/src/level.rs index 67a0ccaf..09675f50 100644 --- a/src/level.rs +++ b/src/level.rs @@ -269,7 +269,16 @@ pub fn spawn_level( } } - for layer_instance in layer_instances.iter().rev() { + for layer_instance in layer_instances + .iter() + .filter(|layer| { + !ldtk_settings + .exclusions + .layer_identifiers + .contains(&layer.identifier) + }) + .rev() + { let layer_offset = Vec2::new( layer_instance.px_total_offset_x as f32, -layer_instance.px_total_offset_y as f32, @@ -550,10 +559,10 @@ pub fn spawn_level( .filter(|(_, v)| **v != 0) { let grid_coords = int_grid_index_to_grid_coords( - i, - layer_instance.c_wid as u32, - layer_instance.c_hei as u32, - ).expect("int_grid_csv indices should be within the bounds of 0..(layer_width * layer_height)"); + i, + layer_instance.c_wid as u32, + layer_instance.c_hei as u32, + ).expect("int_grid_csv indices should be within the bounds of 0..(layer_width * layer_height)"); if let Some(tile_entity) = storage.get(&grid_coords.into()) { let mut entity_commands = commands.entity(tile_entity); diff --git a/src/lib.rs b/src/lib.rs index 32dcf677..ef748bc7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -156,7 +156,7 @@ pub mod prelude { plugin::{LdtkPlugin, ProcessLdtkApi}, resources::{ IntGridRendering, LdtkSettings, LevelBackground, LevelEvent, LevelSelection, - LevelSpawnBehavior, SetClearColor, + LevelSpawnBehavior, SetClearColor, SpawnExclusions, }, }; diff --git a/src/resources/mod.rs b/src/resources/mod.rs index db7e701c..89e8fd0d 100644 --- a/src/resources/mod.rs +++ b/src/resources/mod.rs @@ -1,6 +1,8 @@ //! Resources and events used by the plugin. use bevy::prelude::*; +#[allow(unused_imports)] +use crate::assets::LdtkProject; #[allow(unused_imports)] use crate::components::LdtkWorldBundle; @@ -67,12 +69,21 @@ pub enum LevelBackground { Nonexistent, } +/// Specifies data that should be ignored completely when spawning levels. Excluded items will still +/// be present in the [`LdtkProject`] but will not cause any entities to be spawned in the world. +#[derive(Clone, Eq, PartialEq, Debug, Default)] +pub struct SpawnExclusions { + /// List of layer `Identifier` names (not UIDs) to skip spawning as tilemaps. + pub layer_identifiers: Vec, +} + /// Settings resource for the plugin. /// Check out the documentation for each field type to learn more. -#[derive(Copy, Clone, Eq, PartialEq, Debug, Default, Resource)] +#[derive(Clone, Eq, PartialEq, Debug, Default, Resource)] pub struct LdtkSettings { pub level_spawn_behavior: LevelSpawnBehavior, pub set_clear_color: SetClearColor, pub int_grid_rendering: IntGridRendering, pub level_background: LevelBackground, + pub exclusions: SpawnExclusions, }