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

Headless mode #159

Merged
merged 3 commits into from
Feb 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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