Skip to content

Commit

Permalink
[#36] Improve EarShape
Browse files Browse the repository at this point in the history
  • Loading branch information
Orchaldir committed Sep 10, 2023
1 parent 6742df7 commit b162d1d
Showing 1 changed file with 2 additions and 38 deletions.
40 changes: 2 additions & 38 deletions rpg_tools_core/src/model/character/appearance/ear/shape.rs
Original file line number Diff line number Diff line change
@@ -1,50 +1,14 @@
use crate::ui::{UiVisitor, UI};
use macro_convert::Convert;
use macro_ui::ui;
use serde::{Deserialize, Serialize};
use std::fmt;
use EarShape::*;

/// How many ears does the character have?
#[derive(ui, Default, Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[derive(Convert, ui, Default, Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub enum EarShape {
/// Like an elf's ears.
Pointed,
Round,
#[default]
Square,
}

impl EarShape {
pub fn get_all() -> Vec<EarShape> {
vec![Pointed, Round, Square]
}
}

impl fmt::Display for EarShape {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{:?}", self)
}
}

impl From<&str> for EarShape {
fn from(shape: &str) -> Self {
match shape {
"Pointed" => Pointed,
"Round" => Round,
_ => Square,
}
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_conversion() {
for shape in EarShape::get_all() {
let string = shape.to_string();
assert_eq!(shape, EarShape::from(&*string));
}
}
}

0 comments on commit b162d1d

Please sign in to comment.