Add default implementation of Serialize and Deserialize to Timer and Stopwatch (#6248)
# Objective Fixes #6244 ## Solution Uses derive to implement `Serialize` and `Deserialize` for `Timer` and `Stopwatch` ### Things to consider - Should fields such as `finished` and `times_finished_this_tick` in `Timer` be serialized? - Does `Countdown` and `PrintOnCompletionTimer` need to be serialized and deserialized? ## Changelog Added `Serialize` and `Deserialize` implementations to `Timer` and `Stopwatch`, `Countdown`.
This commit is contained in:
parent
132e8fb382
commit
bfbcd47725
@ -45,7 +45,7 @@ wav = ["bevy_audio/wav"]
|
|||||||
# Enable watching file system for asset hot reload
|
# Enable watching file system for asset hot reload
|
||||||
filesystem_watcher = ["bevy_asset/filesystem_watcher"]
|
filesystem_watcher = ["bevy_asset/filesystem_watcher"]
|
||||||
|
|
||||||
serialize = ["bevy_input/serialize", "bevy_window/serialize"]
|
serialize = ["bevy_input/serialize", "bevy_time/serialize", "bevy_window/serialize"]
|
||||||
|
|
||||||
# Display server protocol support (X11 is enabled by default)
|
# Display server protocol support (X11 is enabled by default)
|
||||||
wayland = ["bevy_winit/wayland"]
|
wayland = ["bevy_winit/wayland"]
|
||||||
|
@ -8,6 +8,9 @@ repository = "https://github.com/bevyengine/bevy"
|
|||||||
license = "MIT OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
keywords = ["bevy"]
|
keywords = ["bevy"]
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = []
|
||||||
|
serialize = ["serde"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
# bevy
|
# bevy
|
||||||
@ -18,3 +21,4 @@ bevy_utils = { path = "../bevy_utils", version = "0.9.0-dev" }
|
|||||||
|
|
||||||
# other
|
# other
|
||||||
crossbeam-channel = "0.5.0"
|
crossbeam-channel = "0.5.0"
|
||||||
|
serde = { version = "1", features = ["derive"], optional = true }
|
||||||
|
@ -24,6 +24,7 @@ use bevy_utils::Duration;
|
|||||||
/// assert_eq!(stopwatch.elapsed_secs(), 0.0);
|
/// assert_eq!(stopwatch.elapsed_secs(), 0.0);
|
||||||
/// ```
|
/// ```
|
||||||
#[derive(Clone, Debug, Default, Reflect)]
|
#[derive(Clone, Debug, Default, Reflect)]
|
||||||
|
#[cfg_attr(feature = "serialize", derive(serde::Deserialize, serde::Serialize))]
|
||||||
#[reflect(Default)]
|
#[reflect(Default)]
|
||||||
pub struct Stopwatch {
|
pub struct Stopwatch {
|
||||||
elapsed: Duration,
|
elapsed: Duration,
|
||||||
|
@ -10,6 +10,7 @@ use bevy_utils::Duration;
|
|||||||
///
|
///
|
||||||
/// Paused timers will not have elapsed time increased.
|
/// Paused timers will not have elapsed time increased.
|
||||||
#[derive(Clone, Debug, Default, Reflect)]
|
#[derive(Clone, Debug, Default, Reflect)]
|
||||||
|
#[cfg_attr(feature = "serialize", derive(serde::Deserialize, serde::Serialize))]
|
||||||
#[reflect(Default)]
|
#[reflect(Default)]
|
||||||
pub struct Timer {
|
pub struct Timer {
|
||||||
stopwatch: Stopwatch,
|
stopwatch: Stopwatch,
|
||||||
@ -401,6 +402,7 @@ impl Timer {
|
|||||||
|
|
||||||
/// Specifies [`Timer`] behavior.
|
/// Specifies [`Timer`] behavior.
|
||||||
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash, Default, Reflect)]
|
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash, Default, Reflect)]
|
||||||
|
#[cfg_attr(feature = "serialize", derive(serde::Deserialize, serde::Serialize))]
|
||||||
#[reflect(Default)]
|
#[reflect(Default)]
|
||||||
pub enum TimerMode {
|
pub enum TimerMode {
|
||||||
/// Run once and stop.
|
/// Run once and stop.
|
||||||
|
Loading…
Reference in New Issue
Block a user