Skip to content

Commit

Permalink
feat(unstable-load-from-file): use snake_case for properties and Came…
Browse files Browse the repository at this point in the history
…lCase for enums
  • Loading branch information
jcornaz committed Jun 20, 2022
1 parent fce68d4 commit 59bb025
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 29 deletions.
15 changes: 3 additions & 12 deletions assets/coin.animation.yml
Original file line number Diff line number Diff line change
@@ -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]
24 changes: 11 additions & 13 deletions src/animation/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -22,7 +21,6 @@ pub(super) struct AnimationDto {
}

#[derive(Deserialize)]
#[serde(rename_all = "kebab-case")]
enum ModeDto {
Repeat,
RepeatFrom(usize),
Expand Down Expand Up @@ -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
Expand All @@ -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
/// ```
///
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -256,7 +254,7 @@ mod tests {
fn parse_yaml_repeat() {
// given
let content = "
mode: repeat
mode: Repeat
frames:
- index: 0
duration: 100";
Expand All @@ -272,7 +270,7 @@ mod tests {
fn parse_yaml_once() {
// given
let content = "
mode: once
mode: Once
frames:
- index: 0
duration: 100";
Expand All @@ -289,7 +287,7 @@ mod tests {
// given
let content = "
mode:
repeat-from: 1
RepeatFrom: 1
frames:
- index: 0
duration: 100
Expand Down Expand Up @@ -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
Expand All @@ -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]
";

Expand Down
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
//! ```
//!
Expand Down

0 comments on commit 59bb025

Please sign in to comment.