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