mirror of
https://github.com/Xevion/Pac-Man.git
synced 2025-12-06 01:15:42 -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 crate::input::commands::GameCommand;
|
||||
use crate::systems::input::GameCommand;
|
||||
|
||||
#[derive(Debug, Clone, Copy, Event)]
|
||||
pub enum GameEvent {
|
||||
@@ -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,
|
||||
|
||||
@@ -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 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;
|
||||
|
||||
@@ -12,9 +12,9 @@ mod constants;
|
||||
|
||||
mod entity;
|
||||
mod error;
|
||||
mod events;
|
||||
mod game;
|
||||
mod helpers;
|
||||
mod input;
|
||||
mod map;
|
||||
mod platform;
|
||||
mod systems;
|
||||
|
||||
@@ -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<GameEvent>,
|
||||
mut state: ResMut<GlobalState>,
|
||||
mut players: Query<(&PlayerControlled, &mut Velocity)>,
|
||||
@@ -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<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() {
|
||||
match event {
|
||||
Event::Quit { .. } => {
|
||||
@@ -4,6 +4,7 @@
|
||||
//! and resources.
|
||||
|
||||
pub mod components;
|
||||
pub mod interact;
|
||||
pub mod control;
|
||||
pub mod input;
|
||||
pub mod movement;
|
||||
pub mod render;
|
||||
|
||||
Reference in New Issue
Block a user