Skip to content

Commit c6dd99b

Browse files
authored
Merge pull request #59 from FelixEngl/main
Make `Animation` serializable via optional `serde` feature
2 parents 28e02ef + d0e38e8 commit c6dd99b

7 files changed

Lines changed: 39 additions & 11 deletions

File tree

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## 5.1.0 - 2026-01-04
4+
5+
### Added
6+
7+
- Added feature-flag `serde`.
8+
- Added serde support to `Animation` struct.
9+
310
## 5.0.0 - 2025-11-04
411

512
This release comes with a significant rework of the high-level API that tightens up the relationships between spritesheets, clips and animations.

Cargo.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "bevy_spritesheet_animation"
3-
version = "5.0.0"
3+
version = "5.1.0"
44
description = "A Bevy plugin for animating sprites"
55
repository = "https://github.com/merwaaan/bevy_spritesheet_animation"
66
readme = "README.md"
@@ -20,17 +20,21 @@ default = [
2020
]
2121
custom_cursor = ["bevy/custom_cursor"]
2222

23+
# Allows to serialize the animations
24+
serde = ["dep:serde"]
25+
2326
[dependencies]
2427
bevy = { version = "0.17.0", default-features = false, features = [
2528
"bevy_log",
2629
"bevy_sprite",
2730
"bevy_pbr",
2831
"bevy_ui"
2932
] }
33+
serde = { version = "1.0.228", optional = true }
3034

3135
[dev-dependencies]
3236
approx = "0.5.1"
33-
bevy = { version = "0.17.0", features = [
37+
bevy = { version = "0.17", features = [
3438
# Needed for the "stress" example as it uses Bevy's FPS overlay
3539
"bevy_dev_tools"
3640
] }

README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -379,13 +379,14 @@ For more examples, browse the [examples/](examples) directory.
379379

380380
# Compatibility
381381

382-
| bevy | bevy_spritesheet_animation |
383-
| ---- | -------------------------- |
384-
| 0.17 | 4.0.0 |
385-
| 0.16 | 3.0.0 |
386-
| 0.15 | 2.0.0 |
387-
| 0.14 | 0.2.0 |
388-
| 0.13 | 0.1.0 |
382+
| bevy | bevy_spritesheet_animation |
383+
|--------|----------------------------|
384+
| 0.17 | 5.0.0 |
385+
| 0.17 | 4.0.0 |
386+
| 0.16 | 3.0.0 |
387+
| 0.15 | 2.0.0 |
388+
| 0.14 | 0.2.0 |
389+
| 0.13 | 0.1.0 |
389390

390391
# Credits
391392

src/animation.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
use bevy::prelude::*;
2+
#[cfg(feature = "serde")]
3+
use serde::{Deserialize, Serialize};
24

35
use crate::{clip::Clip, easing::Easing};
46

57
/// The duration of an [Animation].
68
#[derive(Debug, Clone, Copy, Reflect)]
9+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
710
#[reflect(Debug)]
811
pub enum AnimationDuration {
912
/// Specifies the duration of one frame in milliseconds (default = `PerFrame(100)`).
@@ -20,6 +23,7 @@ impl Default for AnimationDuration {
2023

2124
/// How many times an [Animation] repeats.
2225
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash, Reflect)]
26+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2327
#[reflect(Debug, PartialEq, Hash)]
2428
pub enum AnimationRepeat {
2529
/// Loops forever (default).
@@ -31,6 +35,7 @@ pub enum AnimationRepeat {
3135

3236
/// The direction in which the frames of an [Animation] are played.
3337
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash, Reflect)]
38+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
3439
#[reflect(Debug, PartialEq, Hash)]
3540
pub enum AnimationDirection {
3641
/// Frames play from left to right (default).
@@ -84,6 +89,7 @@ pub enum AnimationDirection {
8489
/// # }
8590
/// ```
8691
#[derive(Asset, Debug, Clone, Reflect)]
92+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8793
#[reflect(Debug)]
8894
pub struct Animation {
8995
pub(crate) clips: Vec<Clip>,

src/clip.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
1+
#[cfg(feature = "serde")]
2+
use serde::{Deserialize, Serialize};
13
use std::{
24
fmt,
35
sync::atomic::{AtomicUsize, Ordering},
46
};
57

6-
use bevy::{platform::collections::HashMap, prelude::*};
7-
88
use crate::{
99
animation::{AnimationDirection, AnimationDuration},
1010
easing::Easing,
1111
events::Marker,
1212
};
13+
use bevy::{platform::collections::HashMap, prelude::*};
1314

1415
/// An opaque identifier for a [Clip]
1516
///
1617
/// Clip-related [AnimationEvents](crate::prelude::AnimationEvent) will contain this ID.
1718
///
1819
/// Wen creating animations, use [AnimationBuilder::get_current_clip_id()](crate::prelude::AnimationBuilder::get_current_clip_id) to retrieve a clip's ID.
1920
#[derive(Clone, Copy, Eq, PartialEq, Hash, Reflect)]
21+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(transparent))]
2022
#[reflect(Debug, PartialEq, Hash)]
2123
pub struct ClipId {
2224
pub(crate) value: usize,
@@ -68,6 +70,7 @@ impl ClipId {
6870
///
6971
/// See [AnimationEvent](crate::prelude::AnimationEvent) for more details.
7072
#[derive(Debug, Clone, Reflect)]
73+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7174
#[reflect(Debug)]
7275
pub struct Clip {
7376
id: ClipId,

src/easing.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#[cfg(feature = "serde")]
2+
use serde::{Deserialize, Serialize};
13
use std::f32::consts::PI;
24

35
use bevy::prelude::*;
@@ -9,6 +11,7 @@ use bevy::prelude::*;
911
/// - <https://easings.net/>
1012
/// - <http://robertpenner.com/easing/penner_chapter7_tweening.pdf>
1113
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Reflect)]
14+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1215
#[reflect(Debug, PartialEq, Hash)]
1316
pub enum EasingVariety {
1417
Quadratic,
@@ -41,6 +44,7 @@ pub enum EasingVariety {
4144
/// # }
4245
/// ```
4346
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash, Reflect)]
47+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
4448
#[reflect(Debug, Default, PartialEq, Hash)]
4549
pub enum Easing {
4650
/// Linear interpolation.

src/events.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#[cfg(feature = "serde")]
2+
use serde::{Deserialize, Serialize};
13
use std::{
24
fmt,
35
sync::atomic::{AtomicUsize, Ordering},
@@ -157,6 +159,7 @@ pub enum AnimationEvent {
157159
///
158160
/// Add markers to a clip with [AnimationBuilder::add_clip_marker()](crate::prelude::AnimationBuilder::add_clip_marker).
159161
#[derive(Clone, Copy, Eq, PartialEq, Hash, Reflect)]
162+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(transparent))]
160163
#[reflect(Debug, PartialEq, Hash)]
161164
pub struct Marker {
162165
pub(crate) value: usize,

0 commit comments

Comments
 (0)