Skip to content

Commit

Permalink
feat: add render feature for headless mode (tilemaps only) (#159)
Browse files Browse the repository at this point in the history
feat: add default feature render to support running headless by disabling it
  • Loading branch information
geieredgar committed Feb 8, 2023
1 parent c052b31 commit 2f8000e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
5 changes: 3 additions & 2 deletions Cargo.toml
Expand Up @@ -15,7 +15,7 @@ members = ["macros"]

[dependencies]
bevy_ecs_ldtk_macros = { version = "0.5.0", optional = true, path = "macros" }
bevy_ecs_tilemap = "0.9"
bevy_ecs_tilemap = { version = "0.9", default-features = false }
bevy = { version = "0.9", default-features = false, features = ["bevy_sprite"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
Expand All @@ -30,9 +30,10 @@ bevy_rapier2d = "0.19"
rand = "0.8"

[features]
default = ["derive"]
default = ["derive", "render"]
derive = ["bevy_ecs_ldtk_macros"]
atlas = ["bevy_ecs_tilemap/atlas"]
render = ["bevy_ecs_tilemap/render"]

[[example]]
name = "platformer"
Expand Down
14 changes: 9 additions & 5 deletions src/systems.rs
@@ -1,12 +1,14 @@
//! System functions used by the plugin for processing ldtk files.

#[cfg(feature = "render")]
use crate::resources::SetClearColor;
use crate::{
app::{LdtkEntityMap, LdtkIntCellMap},
assets::{LdtkAsset, LdtkLevel},
components::*,
ldtk::TilesetDefinition,
level::spawn_level,
resources::{LdtkSettings, LevelEvent, LevelSelection, LevelSpawnBehavior, SetClearColor},
resources::{LdtkSettings, LevelEvent, LevelSelection, LevelSpawnBehavior},
utils::*,
};

Expand All @@ -19,9 +21,9 @@ pub fn process_ldtk_assets(
mut commands: Commands,
mut ldtk_events: EventReader<AssetEvent<LdtkAsset>>,
ldtk_world_query: Query<(Entity, &Handle<LdtkAsset>)>,
ldtk_settings: Res<LdtkSettings>,
mut clear_color: ResMut<ClearColor>,
ldtk_assets: Res<Assets<LdtkAsset>>,
#[cfg(feature = "render")] ldtk_settings: Res<LdtkSettings>,
#[cfg(feature = "render")] mut clear_color: ResMut<ClearColor>,
#[cfg(feature = "render")] ldtk_assets: Res<Assets<LdtkAsset>>,
) {
let mut ldtk_handles_to_respawn = HashSet::new();
let mut ldtk_handles_for_clear_color = HashSet::new();
Expand All @@ -46,6 +48,7 @@ pub fn process_ldtk_assets(
}
}

#[cfg(feature = "render")]
if ldtk_settings.set_clear_color == SetClearColor::FromEditorBackground {
for handle in ldtk_handles_for_clear_color.iter() {
if let Some(ldtk_asset) = ldtk_assets.get(handle) {
Expand All @@ -67,7 +70,7 @@ pub fn apply_level_selection(
ldtk_settings: Res<LdtkSettings>,
ldtk_assets: Res<Assets<LdtkAsset>>,
mut level_set_query: Query<(&Handle<LdtkAsset>, &mut LevelSet)>,
mut clear_color: ResMut<ClearColor>,
#[cfg(feature = "render")] mut clear_color: ResMut<ClearColor>,
) {
if let Some(level_selection) = level_selection {
for (ldtk_handle, mut level_set) in level_set_query.iter_mut() {
Expand All @@ -92,6 +95,7 @@ pub fn apply_level_selection(
if *level_set != new_level_set {
*level_set = new_level_set;

#[cfg(feature = "render")]
if ldtk_settings.set_clear_color == SetClearColor::FromLevelBackground {
clear_color.0 = level.bg_color;
}
Expand Down

0 comments on commit 2f8000e

Please sign in to comment.