use crate::shared::*; use std::str::FromStr; #[derive(Component, Clone, Copy, PartialEq, Eq, Debug, Serialize, Deserialize)] pub enum Faction { Purple, Yellow, } impl Faction { pub fn to_color(self) -> Color { match self { Faction::Purple => Color::PURPLE, Faction::Yellow => Color::YELLOW, } } } impl FromStr for Faction { type Err = String; fn from_str(s: &str) -> Result { match s { "purple" => Ok(Faction::Purple), "yellow" => Ok(Faction::Yellow), _ => Err(format!("unknown faction: {}", s)), } } } impl Default for Faction { fn default() -> Self { Faction::Yellow } }