mirror of
https://github.com/Xevion/Pac-Man.git
synced 2025-12-14 04:12:23 -06:00
refactor: reorganize systems properly, move events to events.rs
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
use bevy_ecs::event::Event;
|
use bevy_ecs::event::Event;
|
||||||
|
|
||||||
use crate::input::commands::GameCommand;
|
use crate::systems::input::GameCommand;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, Event)]
|
#[derive(Debug, Clone, Copy, Event)]
|
||||||
pub enum GameEvent {
|
pub enum GameEvent {
|
||||||
@@ -5,12 +5,12 @@ include!(concat!(env!("OUT_DIR"), "/atlas_data.rs"));
|
|||||||
use crate::constants::CANVAS_SIZE;
|
use crate::constants::CANVAS_SIZE;
|
||||||
use crate::entity::direction::Direction;
|
use crate::entity::direction::Direction;
|
||||||
use crate::error::{GameError, GameResult, TextureError};
|
use crate::error::{GameError, GameResult, TextureError};
|
||||||
use crate::input::commands::GameCommand;
|
use crate::events::GameEvent;
|
||||||
use crate::map::builder::Map;
|
use crate::map::builder::Map;
|
||||||
use crate::systems::components::{
|
use crate::systems::components::{
|
||||||
DeltaTime, DirectionalAnimated, GlobalState, PlayerBundle, PlayerControlled, Position, Renderable, Velocity,
|
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::movement::movement_system;
|
||||||
use crate::systems::render::{directional_render_system, render_system, BackbufferResource, MapTextureResource};
|
use crate::systems::render::{directional_render_system, render_system, BackbufferResource, MapTextureResource};
|
||||||
use crate::texture::animated::AnimatedTexture;
|
use crate::texture::animated::AnimatedTexture;
|
||||||
@@ -25,16 +25,13 @@ use sdl2::video::{Window, WindowContext};
|
|||||||
use sdl2::EventPump;
|
use sdl2::EventPump;
|
||||||
|
|
||||||
use crate::asset::{get_asset_bytes, Asset};
|
use crate::asset::{get_asset_bytes, Asset};
|
||||||
use crate::input::{handle_input, Bindings};
|
|
||||||
use crate::map::render::MapRenderer;
|
use crate::map::render::MapRenderer;
|
||||||
|
use crate::systems::input::{input_system, Bindings, GameCommand};
|
||||||
use crate::{
|
use crate::{
|
||||||
constants,
|
constants,
|
||||||
texture::sprite::{AtlasMapper, SpriteAtlas},
|
texture::sprite::{AtlasMapper, SpriteAtlas},
|
||||||
};
|
};
|
||||||
|
|
||||||
use self::events::GameEvent;
|
|
||||||
|
|
||||||
pub mod events;
|
|
||||||
pub mod state;
|
pub mod state;
|
||||||
|
|
||||||
/// The `Game` struct is the main entry point for the game.
|
/// The `Game` struct is the main entry point for the game.
|
||||||
@@ -170,8 +167,8 @@ impl Game {
|
|||||||
|
|
||||||
schedule.add_systems(
|
schedule.add_systems(
|
||||||
(
|
(
|
||||||
handle_input,
|
input_system,
|
||||||
interact_system,
|
player_system,
|
||||||
movement_system,
|
movement_system,
|
||||||
directional_render_system,
|
directional_render_system,
|
||||||
render_system,
|
render_system,
|
||||||
|
|||||||
@@ -1,11 +0,0 @@
|
|||||||
use crate::entity::direction::Direction;
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
|
||||||
pub enum GameCommand {
|
|
||||||
MovePlayer(Direction),
|
|
||||||
Exit,
|
|
||||||
TogglePause,
|
|
||||||
ToggleDebug,
|
|
||||||
MuteAudio,
|
|
||||||
ResetLevel,
|
|
||||||
}
|
|
||||||
@@ -6,9 +6,9 @@ pub mod audio;
|
|||||||
pub mod constants;
|
pub mod constants;
|
||||||
pub mod entity;
|
pub mod entity;
|
||||||
pub mod error;
|
pub mod error;
|
||||||
|
pub mod events;
|
||||||
pub mod game;
|
pub mod game;
|
||||||
pub mod helpers;
|
pub mod helpers;
|
||||||
pub mod input;
|
|
||||||
pub mod map;
|
pub mod map;
|
||||||
pub mod platform;
|
pub mod platform;
|
||||||
pub mod systems;
|
pub mod systems;
|
||||||
|
|||||||
@@ -12,9 +12,9 @@ mod constants;
|
|||||||
|
|
||||||
mod entity;
|
mod entity;
|
||||||
mod error;
|
mod error;
|
||||||
|
mod events;
|
||||||
mod game;
|
mod game;
|
||||||
mod helpers;
|
mod helpers;
|
||||||
mod input;
|
|
||||||
mod map;
|
mod map;
|
||||||
mod platform;
|
mod platform;
|
||||||
mod systems;
|
mod systems;
|
||||||
|
|||||||
@@ -5,13 +5,15 @@ use bevy_ecs::{
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
error::GameError,
|
error::GameError,
|
||||||
game::events::GameEvent,
|
events::GameEvent,
|
||||||
input::commands::GameCommand,
|
systems::{
|
||||||
systems::components::{GlobalState, PlayerControlled, Velocity},
|
components::{GlobalState, PlayerControlled, Velocity},
|
||||||
|
input::GameCommand,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
// Handles
|
// Handles
|
||||||
pub fn interact_system(
|
pub fn player_system(
|
||||||
mut events: EventReader<GameEvent>,
|
mut events: EventReader<GameEvent>,
|
||||||
mut state: ResMut<GlobalState>,
|
mut state: ResMut<GlobalState>,
|
||||||
mut players: Query<(&PlayerControlled, &mut Velocity)>,
|
mut players: Query<(&PlayerControlled, &mut Velocity)>,
|
||||||
@@ -7,9 +7,17 @@ use bevy_ecs::{
|
|||||||
};
|
};
|
||||||
use sdl2::{event::Event, keyboard::Keycode, EventPump};
|
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)]
|
#[derive(Debug, Clone, Resource)]
|
||||||
pub struct Bindings {
|
pub struct Bindings {
|
||||||
@@ -42,7 +50,7 @@ impl Default for Bindings {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn handle_input(bindings: Res<Bindings>, mut writer: EventWriter<GameEvent>, mut pump: NonSendMut<&'static mut EventPump>) {
|
pub fn input_system(bindings: Res<Bindings>, mut writer: EventWriter<GameEvent>, mut pump: NonSendMut<&'static mut EventPump>) {
|
||||||
for event in pump.poll_iter() {
|
for event in pump.poll_iter() {
|
||||||
match event {
|
match event {
|
||||||
Event::Quit { .. } => {
|
Event::Quit { .. } => {
|
||||||
@@ -4,6 +4,7 @@
|
|||||||
//! and resources.
|
//! and resources.
|
||||||
|
|
||||||
pub mod components;
|
pub mod components;
|
||||||
pub mod interact;
|
pub mod control;
|
||||||
|
pub mod input;
|
||||||
pub mod movement;
|
pub mod movement;
|
||||||
pub mod render;
|
pub mod render;
|
||||||
|
|||||||
Reference in New Issue
Block a user