From b2b06ccf5a0939a7cdc77e5b92154b546868231d Mon Sep 17 00:00:00 2001 From: Dmitry Stepanov Date: Sun, 9 Jun 2024 23:39:31 +0300 Subject: [PATCH] implemented PartialEq for sprite sheet animation entities - allows sprite sheet animation to be wrapped in InheritableVariable --- fyrox-animation/src/spritesheet/mod.rs | 19 +++++++++++++++---- fyrox-animation/src/spritesheet/signal.rs | 2 +- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/fyrox-animation/src/spritesheet/mod.rs b/fyrox-animation/src/spritesheet/mod.rs index ae8699513..88d048f33 100644 --- a/fyrox-animation/src/spritesheet/mod.rs +++ b/fyrox-animation/src/spritesheet/mod.rs @@ -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 SpriteSheetTexture for T {} +impl SpriteSheetTexture for T {} /// Animation playback status. #[derive(Visit, Reflect, Copy, Clone, Eq, PartialEq, Debug, AsRefStr, EnumString, VariantNames)] @@ -170,6 +170,17 @@ where events: VecDeque, } +impl PartialEq for SpriteSheetAnimation { + 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 TypeUuidProvider for SpriteSheetAnimation where T: SpriteSheetTexture, @@ -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() { @@ -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] diff --git a/fyrox-animation/src/spritesheet/signal.rs b/fyrox-animation/src/spritesheet/signal.rs index d7fe27ca7..d7b2c4580 100644 --- a/fyrox-animation/src/spritesheet/signal.rs +++ b/fyrox-animation/src/spritesheet/signal.rs @@ -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.