From 59bb02541886dd83ede7d7bb5e987397d0691900 Mon Sep 17 00:00:00 2001 From: Jonathan Cornaz Date: Mon, 20 Jun 2022 19:27:46 +0000 Subject: [PATCH] feat(unstable-load-from-file): use snake_case for properties and CamelCase for enums --- assets/coin.animation.yml | 15 +++------------ src/animation/parse.rs | 24 +++++++++++------------- src/lib.rs | 8 ++++---- 3 files changed, 18 insertions(+), 29 deletions(-) diff --git a/assets/coin.animation.yml b/assets/coin.animation.yml index 55d933f..1dfaad1 100644 --- a/assets/coin.animation.yml +++ b/assets/coin.animation.yml @@ -1,12 +1,3 @@ -mode: repeat -frames: - - index: 0 - duration: 100 - - index: 1 - duration: 100 - - index: 2 - duration: 100 - - index: 3 - duration: 100 - - index: 4 - duration: 100 +mode: Repeat +frame_duration: 100 +frames: [0, 1, 2, 3, 4] diff --git a/src/animation/parse.rs b/src/animation/parse.rs index e1a4981..d285082 100644 --- a/src/animation/parse.rs +++ b/src/animation/parse.rs @@ -12,7 +12,6 @@ use serde::{ use super::{Frame, Mode, SpriteSheetAnimation}; #[derive(Deserialize)] -#[serde(deny_unknown_fields, rename_all = "kebab-case")] pub(super) struct AnimationDto { #[serde(default)] mode: ModeDto, @@ -22,7 +21,6 @@ pub(super) struct AnimationDto { } #[derive(Deserialize)] -#[serde(rename_all = "kebab-case")] enum ModeDto { Repeat, RepeatFrom(usize), @@ -136,7 +134,7 @@ impl SpriteSheetAnimation { /// # The mode can be one of: 'once', 'repeat', 'ping-pong' /// # or 'repeat-from: n' (where 'n' is the frame-index to repeat from) /// # The default is 'repeat' - /// mode: ping-pong + /// mode: PingPong /// frames: /// - index: 0 # index in the sprite sheet for that frame /// duration: 100 # duration of the frame in milliseconds @@ -148,7 +146,7 @@ impl SpriteSheetAnimation { /// /// There is also a short-hand notation if all frames have the same duration: /// ```yaml - /// frame-duration: 100 + /// frame_duration: 100 /// frames: [0, 1, 2] # sequence of frame indices /// ``` /// @@ -165,10 +163,10 @@ impl SpriteSheetAnimation { /// # Yaml schema /// /// ```yaml - /// # The mode can be one of: 'once', 'repeat', 'ping-pong' - /// # or 'repeat-from: n' (where 'n' is the frame-index to repeat from) + /// # The mode can be one of: 'Once', 'Repeat', 'PingPong' + /// # or 'RepeatFrom: n' (where 'n' is the frame-index to repeat from) /// # The default is 'repeat' - /// mode: ping-pong + /// mode: PingPong /// frames: /// - index: 0 # index in the sprite sheet for that frame /// duration: 100 # duration of the frame in milliseconds @@ -213,7 +211,7 @@ mod tests { fn parse_yaml() { // given let content = " - mode: ping-pong + mode: PingPong frames: - index: 0 # index in the sprite sheet for that frame duration: 100 # duration of the frame in milliseconds @@ -256,7 +254,7 @@ mod tests { fn parse_yaml_repeat() { // given let content = " - mode: repeat + mode: Repeat frames: - index: 0 duration: 100"; @@ -272,7 +270,7 @@ mod tests { fn parse_yaml_once() { // given let content = " - mode: once + mode: Once frames: - index: 0 duration: 100"; @@ -289,7 +287,7 @@ mod tests { // given let content = " mode: - repeat-from: 1 + RepeatFrom: 1 frames: - index: 0 duration: 100 @@ -322,7 +320,7 @@ mod tests { fn parse_yaml_same_duraton_for_all_frames() { // given let content = " - frame-duration: 100 + frame_duration: 100 frames: - index: 0 - index: 1 @@ -348,7 +346,7 @@ mod tests { fn parse_yaml_same_duraton_for_all_frames_short_hand() { // given let content = " - frame-duration: 100 + frame_duration: 100 frames: [0, 1, 2] "; diff --git a/src/lib.rs b/src/lib.rs index d2c1688..7ae3094 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -114,11 +114,11 @@ //! //! First, create an asset file with the extension `.animation.yml`: //! ```yaml -//! # The mode can be one of: 'once', 'repeat', 'ping-pong' -//! # or 'repeat-from: n' (where 'n' is the frame-index to repeat from) +//! # The mode can be one of: 'Once', 'Repeat', 'PingPong' +//! # or 'RepeatFrom: n' (where 'n' is the frame-index to repeat from) //! # The default is 'repeat' -//! mode: ping-pong -//! frame-duration: 100 # duration of the frame in milliseconds +//! mode: PingPong +//! frame_duration: 100 # duration of the frame in milliseconds //! frames: [0, 1, 2] # Sequence of frame index //! ``` //!