Skip to content

Commit

Permalink
implemented PartialEq for sprite sheet animation entities
Browse files Browse the repository at this point in the history
- allows sprite sheet animation to be wrapped in InheritableVariable
  • Loading branch information
mrDIMAS committed Jun 9, 2024
1 parent 6301799 commit b2b06cc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
19 changes: 15 additions & 4 deletions fyrox-animation/src/spritesheet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ use strum_macros::{AsRefStr, EnumString, VariantNames};
pub mod signal;

/// Trait for anything that can be used as a texture.
pub trait SpriteSheetTexture: Clone + Visit + Reflect + 'static {}
pub trait SpriteSheetTexture: PartialEq + Clone + Visit + Reflect + 'static {}

impl<T: Clone + Visit + Reflect + 'static> SpriteSheetTexture for T {}
impl<T: PartialEq + Clone + Visit + Reflect + 'static> SpriteSheetTexture for T {}

/// Animation playback status.
#[derive(Visit, Reflect, Copy, Clone, Eq, PartialEq, Debug, AsRefStr, EnumString, VariantNames)]
Expand Down Expand Up @@ -170,6 +170,17 @@ where
events: VecDeque<Event>,
}

impl<T: SpriteSheetTexture> PartialEq for SpriteSheetAnimation<T> {
fn eq(&self, other: &Self) -> bool {
self.frames_container == other.frames_container
&& self.current_frame == other.current_frame
&& self.speed == other.speed
&& self.looping == other.looping
&& self.signals == other.signals
&& self.texture == other.texture
}
}

impl<T> TypeUuidProvider for SpriteSheetAnimation<T>
where
T: SpriteSheetTexture,
Expand Down Expand Up @@ -261,7 +272,7 @@ where
/// # };
/// # use fyrox_core::{reflect::prelude::*, visitor::prelude::*};
/// #
/// #[derive(Clone, Reflect, Visit, Debug)]
/// #[derive(PartialEq, Clone, Reflect, Visit, Debug)]
/// struct MyTexture {}
///
/// fn extract_animations() {
Expand Down Expand Up @@ -554,7 +565,7 @@ mod test {
};
use fyrox_core::{algebra::Vector2, math::Rect, reflect::prelude::*, visitor::prelude::*};

#[derive(Clone, Reflect, Visit, Debug)]
#[derive(PartialEq, Clone, Reflect, Visit, Debug)]
struct MyTexture {}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion fyrox-animation/src/spritesheet/signal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use fyrox_core::uuid_provider;

/// Animation signal is used as a point at which to notify external observers that animation just
/// started to play a specific frame.
#[derive(Visit, Reflect, Debug, Clone)]
#[derive(PartialEq, Visit, Reflect, Debug, Clone)]
pub struct Signal {
/// Signal id. It should be used to distinguish different signals. For example, `JUMP` signal
/// can have `id = 0`, while `CROUCH` signal - `id = 1`, etc.
Expand Down

0 comments on commit b2b06cc

Please sign in to comment.