Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add exclusions to LdtkSettings and filters to level spawner. #275

Merged
merged 2 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions src/level.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down
13 changes: 12 additions & 1 deletion src/resources/mod.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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 LdtkExclusions {
/// List of layer `Identifier` names (not UIDs) to skip spawning as tilemaps.
pub layer_identifiers: Vec<String>,
}

/// 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: LdtkExclusions,
}