From cb691b0907f9fc680bd4042cdd87714edbbbfc12 Mon Sep 17 00:00:00 2001 From: Ryan Walters Date: Wed, 10 Sep 2025 00:26:49 -0500 Subject: [PATCH] refactor: move animation components into new systems/animation submodule --- src/systems/{ => animation}/blinking.rs | 0 .../directional.rs} | 32 ++----------------- src/systems/animation/linear.rs | 30 +++++++++++++++++ src/systems/animation/mod.rs | 7 ++++ src/systems/mod.rs | 10 +++--- 5 files changed, 43 insertions(+), 36 deletions(-) rename src/systems/{ => animation}/blinking.rs (100%) rename src/systems/{animation.rs => animation/directional.rs} (78%) create mode 100644 src/systems/animation/linear.rs create mode 100644 src/systems/animation/mod.rs diff --git a/src/systems/blinking.rs b/src/systems/animation/blinking.rs similarity index 100% rename from src/systems/blinking.rs rename to src/systems/animation/blinking.rs diff --git a/src/systems/animation.rs b/src/systems/animation/directional.rs similarity index 78% rename from src/systems/animation.rs rename to src/systems/animation/directional.rs index ea858d7..305ca2b 100644 --- a/src/systems/animation.rs +++ b/src/systems/animation/directional.rs @@ -1,13 +1,12 @@ use bevy_ecs::{ component::Component, query::{Has, Or, With, Without}, - resource::Resource, system::{Query, Res}, }; use crate::{ - systems::{DeltaTime, Dying, Frozen, Position, Renderable, Velocity}, - texture::animated::{DirectionalTiles, TileSequence}, + systems::{DeltaTime, Dying, Frozen, LinearAnimation, Looping, Position, Renderable, Velocity}, + texture::animated::DirectionalTiles, }; /// Directional animation component with shared timing across all directions @@ -33,33 +32,6 @@ impl DirectionalAnimation { } } -/// Tag component to mark animations that should loop when they reach the end -#[derive(Component, Clone, Copy, Debug, PartialEq, Eq)] -pub struct Looping; - -/// Linear animation component for non-directional animations (frightened ghosts) -#[derive(Component, Resource, Clone)] -pub struct LinearAnimation { - pub tiles: TileSequence, - pub current_frame: usize, - pub time_bank: u16, - pub frame_duration: u16, - pub finished: bool, -} - -impl LinearAnimation { - /// Creates a new linear animation with the given tiles and frame duration - pub fn new(tiles: TileSequence, frame_duration: u16) -> Self { - Self { - tiles, - current_frame: 0, - time_bank: 0, - frame_duration, - finished: false, - } - } -} - /// Updates directional animated entities with synchronized timing across directions. /// /// This runs before the render system to update sprites based on current direction and movement state. diff --git a/src/systems/animation/linear.rs b/src/systems/animation/linear.rs new file mode 100644 index 0000000..258249b --- /dev/null +++ b/src/systems/animation/linear.rs @@ -0,0 +1,30 @@ +use crate::texture::animated::TileSequence; +use bevy_ecs::component::Component; +use bevy_ecs::resource::Resource; + +/// Tag component to mark animations that should loop when they reach the end +#[derive(Component, Clone, Copy, Debug, PartialEq, Eq)] +pub struct Looping; + +/// Linear animation component for non-directional animations (frightened ghosts) +#[derive(Component, Resource, Clone)] +pub struct LinearAnimation { + pub tiles: TileSequence, + pub current_frame: usize, + pub time_bank: u16, + pub frame_duration: u16, + pub finished: bool, +} + +impl LinearAnimation { + /// Creates a new linear animation with the given tiles and frame duration + pub fn new(tiles: TileSequence, frame_duration: u16) -> Self { + Self { + tiles, + current_frame: 0, + time_bank: 0, + frame_duration, + finished: false, + } + } +} diff --git a/src/systems/animation/mod.rs b/src/systems/animation/mod.rs new file mode 100644 index 0000000..68bb0db --- /dev/null +++ b/src/systems/animation/mod.rs @@ -0,0 +1,7 @@ +mod blinking; +mod directional; +mod linear; + +pub use self::blinking::*; +pub use self::directional::*; +pub use self::linear::*; diff --git a/src/systems/mod.rs b/src/systems/mod.rs index f1ad0df..69ba4e4 100644 --- a/src/systems/mod.rs +++ b/src/systems/mod.rs @@ -10,12 +10,11 @@ pub mod profiling; #[cfg_attr(coverage_nightly, coverage(off))] pub mod render; -pub mod animation; -pub mod blinking; -pub mod collision; +mod animation; +mod collision; pub mod common; -pub mod ghost; -pub mod hud; +mod ghost; +mod hud; pub mod input; pub mod item; pub mod lifetime; @@ -27,7 +26,6 @@ pub mod state; pub use self::animation::*; pub use self::audio::*; -pub use self::blinking::*; pub use self::collision::*; pub use self::common::*; pub use self::debug::*;