diff --git a/src/game/events.rs b/src/events.rs similarity index 85% rename from src/game/events.rs rename to src/events.rs index f8a41f0..90d5285 100644 --- a/src/game/events.rs +++ b/src/events.rs @@ -1,6 +1,6 @@ use bevy_ecs::event::Event; -use crate::input::commands::GameCommand; +use crate::systems::input::GameCommand; #[derive(Debug, Clone, Copy, Event)] pub enum GameEvent { diff --git a/src/game/mod.rs b/src/game/mod.rs index 9b0360b..5c56540 100644 --- a/src/game/mod.rs +++ b/src/game/mod.rs @@ -5,12 +5,12 @@ include!(concat!(env!("OUT_DIR"), "/atlas_data.rs")); use crate::constants::CANVAS_SIZE; use crate::entity::direction::Direction; use crate::error::{GameError, GameResult, TextureError}; -use crate::input::commands::GameCommand; +use crate::events::GameEvent; use crate::map::builder::Map; use crate::systems::components::{ DeltaTime, DirectionalAnimated, GlobalState, PlayerBundle, PlayerControlled, Position, Renderable, Velocity, }; -use crate::systems::interact::interact_system; +use crate::systems::control::player_system; use crate::systems::movement::movement_system; use crate::systems::render::{directional_render_system, render_system, BackbufferResource, MapTextureResource}; use crate::texture::animated::AnimatedTexture; @@ -25,16 +25,13 @@ use sdl2::video::{Window, WindowContext}; use sdl2::EventPump; use crate::asset::{get_asset_bytes, Asset}; -use crate::input::{handle_input, Bindings}; use crate::map::render::MapRenderer; +use crate::systems::input::{input_system, Bindings, GameCommand}; use crate::{ constants, texture::sprite::{AtlasMapper, SpriteAtlas}, }; -use self::events::GameEvent; - -pub mod events; pub mod state; /// The `Game` struct is the main entry point for the game. @@ -170,8 +167,8 @@ impl Game { schedule.add_systems( ( - handle_input, - interact_system, + input_system, + player_system, movement_system, directional_render_system, render_system, diff --git a/src/input/commands.rs b/src/input/commands.rs deleted file mode 100644 index 81f4757..0000000 --- a/src/input/commands.rs +++ /dev/null @@ -1,11 +0,0 @@ -use crate::entity::direction::Direction; - -#[derive(Debug, Clone, Copy)] -pub enum GameCommand { - MovePlayer(Direction), - Exit, - TogglePause, - ToggleDebug, - MuteAudio, - ResetLevel, -} diff --git a/src/lib.rs b/src/lib.rs index 6d2f054..3668b97 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,9 +6,9 @@ pub mod audio; pub mod constants; pub mod entity; pub mod error; +pub mod events; pub mod game; pub mod helpers; -pub mod input; pub mod map; pub mod platform; pub mod systems; diff --git a/src/main.rs b/src/main.rs index 2b9453d..907a875 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,9 +12,9 @@ mod constants; mod entity; mod error; +mod events; mod game; mod helpers; -mod input; mod map; mod platform; mod systems; diff --git a/src/systems/interact.rs b/src/systems/control.rs similarity index 87% rename from src/systems/interact.rs rename to src/systems/control.rs index 3855519..b98385e 100644 --- a/src/systems/interact.rs +++ b/src/systems/control.rs @@ -5,13 +5,15 @@ use bevy_ecs::{ use crate::{ error::GameError, - game::events::GameEvent, - input::commands::GameCommand, - systems::components::{GlobalState, PlayerControlled, Velocity}, + events::GameEvent, + systems::{ + components::{GlobalState, PlayerControlled, Velocity}, + input::GameCommand, + }, }; // Handles -pub fn interact_system( +pub fn player_system( mut events: EventReader, mut state: ResMut, mut players: Query<(&PlayerControlled, &mut Velocity)>, diff --git a/src/input/mod.rs b/src/systems/input.rs similarity index 88% rename from src/input/mod.rs rename to src/systems/input.rs index 97ae3cf..44f4df4 100644 --- a/src/input/mod.rs +++ b/src/systems/input.rs @@ -7,9 +7,17 @@ use bevy_ecs::{ }; use sdl2::{event::Event, keyboard::Keycode, EventPump}; -use crate::{entity::direction::Direction, game::events::GameEvent, input::commands::GameCommand}; +use crate::{entity::direction::Direction, events::GameEvent}; -pub mod commands; +#[derive(Debug, Clone, Copy)] +pub enum GameCommand { + MovePlayer(Direction), + Exit, + TogglePause, + ToggleDebug, + MuteAudio, + ResetLevel, +} #[derive(Debug, Clone, Resource)] pub struct Bindings { @@ -42,7 +50,7 @@ impl Default for Bindings { } } -pub fn handle_input(bindings: Res, mut writer: EventWriter, mut pump: NonSendMut<&'static mut EventPump>) { +pub fn input_system(bindings: Res, mut writer: EventWriter, mut pump: NonSendMut<&'static mut EventPump>) { for event in pump.poll_iter() { match event { Event::Quit { .. } => { diff --git a/src/systems/mod.rs b/src/systems/mod.rs index 11f7459..c984ae3 100644 --- a/src/systems/mod.rs +++ b/src/systems/mod.rs @@ -4,6 +4,7 @@ //! and resources. pub mod components; -pub mod interact; +pub mod control; +pub mod input; pub mod movement; pub mod render;