From dea1bdcf031040fc7be5c44cf5688e0eb66e9556 Mon Sep 17 00:00:00 2001 From: TudbuT Date: Sat, 23 Nov 2024 18:33:27 +0100 Subject: [PATCH] use player spawn oneshot --- src/game.rs | 7 +++---- src/game/player.rs | 2 +- src/game/scene.rs | 12 ++++++++---- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/game.rs b/src/game.rs index c08533e..528bc10 100644 --- a/src/game.rs +++ b/src/game.rs @@ -1,7 +1,7 @@ use bevy::prelude::*; use bevy_rapier2d::prelude::*; use player::player_plugin; -use scene::{scene_plugin, PlayerSpawnEvent}; +use scene::{scene_plugin, PlayerCoords}; use crate::AppState; @@ -10,9 +10,8 @@ mod scene; mod set; pub const WORLD_DEPTH: f32 = 0.5; +pub const PLAYER_DEPTH: f32 = 0.5; pub fn game_plugin(app: &mut App) { - (app) - .add_event::() - .add_plugins((player_plugin, scene_plugin)); + app.add_plugins((player_plugin, scene_plugin)); } diff --git a/src/game/player.rs b/src/game/player.rs index 85d46a4..9078dcb 100644 --- a/src/game/player.rs +++ b/src/game/player.rs @@ -15,7 +15,7 @@ mod animation; struct Player; #[derive(Resource)] -struct PlayerSpawnOneshot(SystemId); +pub struct PlayerSpawnOneshot(pub SystemId); impl FromWorld for PlayerSpawnOneshot { fn from_world(world: &mut World) -> Self { diff --git a/src/game/scene.rs b/src/game/scene.rs index e3337cb..a950d96 100644 --- a/src/game/scene.rs +++ b/src/game/scene.rs @@ -11,11 +11,13 @@ use readformat::{readf, readf1}; use crate::game::WORLD_DEPTH; use crate::AppState; +use super::player::PlayerSpawnOneshot; + #[derive(Component)] struct Block; -#[derive(Event)] -pub struct PlayerSpawnEvent { +#[derive(Resource, Default)] +pub struct PlayerCoords { x: f32, y: f32, block_size: f32, @@ -38,6 +40,7 @@ pub(super) fn import_text_world( assets: Res, mut meshes: ResMut>, mut materials: ResMut>, + mut player_spawn_oneshot: Res, ) { let world_string = fs::read_to_string("assets/world.txt").expect("need a world to load"); let [info_string, world_string] = &readf("info section\n{}\nworld section\n{}", &world_string) @@ -84,11 +87,12 @@ pub(super) fn import_text_world( let x = i as f32 * wi.block_size; let y = current_y as f32 * wi.block_size; if tex == "[player]" { - commands.trigger(PlayerSpawnEvent { + commands.insert_resource(PlayerCoords { x, y, block_size: wi.block_size, - }) + }); + commands.run_system(player_spawn_oneshot.0); } else { spawn_block( &mut commands,