From 2f04c7a6c821f8da711af668e79d7d98242a53b7 Mon Sep 17 00:00:00 2001 From: Steve Pryde Date: Sun, 28 Jul 2024 20:53:48 +0930 Subject: [PATCH] Fix map loading --- Cargo.lock | 6 ++---- Cargo.toml | 6 +++--- src/game/spawn/level.rs | 31 ++++++++++++++++++++++++++++--- 3 files changed, 33 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index aee49cd..3e7c909 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -643,9 +643,7 @@ dependencies = [ [[package]] name = "bevy_ecs_tiled" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab8ef1649a631f081e4b6e04766e6622bd9d101b5d8f7cbd79a8b420401b27a8" +version = "0.3.2" dependencies = [ "bevy", "bevy_ecs_tilemap", @@ -1803,7 +1801,7 @@ checksum = "bd0c93bb4b0c6d9b77f4435b0ae98c24d17f1c45b2ff844c6151a07256ca923b" [[package]] name = "dizzy-ducklings" -version = "0.3.3" +version = "0.3.4" dependencies = [ "bevy", "bevy-inspector-egui", diff --git a/Cargo.toml b/Cargo.toml index d4a083c..56b1379 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,13 +1,13 @@ [package] name = "dizzy-ducklings" authors = ["Steve Pryde "] -version = "0.3.3" +version = "0.3.4" edition = "2021" [dependencies] bevy = { version = "0.14", features = ["wayland"] } -bevy_ecs_tiled = { version = "=0.3.1", features = ["rapier"] } +bevy_ecs_tiled = { version = "0.3.2", path="../../support/bevy_ecs_tiled", features = ["rapier"] } bevy_ecs_tilemap = "0.14" bevy_rapier2d = "0.27" @@ -23,7 +23,7 @@ rand = "0.8" [target.'cfg(target_family = "wasm")'.dependencies] bevy_rapier2d = {version = "0.27.0", features = ["wasm-bindgen"]} -bevy_ecs_tiled = { version = "0.3.1", features = ["rapier"] } +bevy_ecs_tiled = { version = "0.3.2", path="../../support/bevy_ecs_tiled", features = ["rapier"] } [features] default = [ diff --git a/src/game/spawn/level.rs b/src/game/spawn/level.rs index 1ae8f9b..66ec10c 100644 --- a/src/game/spawn/level.rs +++ b/src/game/spawn/level.rs @@ -24,6 +24,7 @@ pub(super) fn plugin(app: &mut App) { app.observe(cleanup_level); app.observe(on_end_level); app.observe(on_game_completed); + app.add_systems(Update, on_level_added.run_if(in_state(Screen::Playing))); app.add_systems(Update, on_fade_completed.run_if(in_state(Screen::Playing))); app.add_systems(OnExit(Screen::Playing), exit_playing); } @@ -95,6 +96,9 @@ fn start_new_game(_trigger: Trigger, mut commands: Commands) { #[derive(Event, Debug)] pub struct SpawnLevel; +#[derive(Component, Debug)] +pub struct LevelLoaded; + #[derive(Component)] pub struct LevelMarker; @@ -161,12 +165,33 @@ fn spawn_level( } }); - commands.trigger(ResetFrameCounter); - commands.trigger(SpawnPlayer); - commands.trigger(SpawnDuckling); + log::warn!("SPAWNED LEVEL"); + + // commands.trigger(ResetFrameCounter); commands.trigger(UpdateScore); } +fn on_level_added( + mut events: EventReader>, + mut commands: Commands, + map: Query<(Entity, &Handle), Without>, +) { + for event in events.read() { + if let AssetEvent::LoadedWithDependencies { id } = event { + for (entity, handle) in map.iter() { + if handle.id() == *id { + log::warn!("MAP LOADED"); + commands.entity(entity).insert(LevelLoaded); + commands.trigger(SpawnPlayer); + commands.trigger(SpawnDuckling); + commands.trigger(ResetFrameCounter); + return; + } + } + } + } +} + #[derive(Component, Debug, Clone, Copy, PartialEq, Default, Reflect)] pub struct PlayerSpawnPoint;