From 12a6419eaa087f34bdde49b3f9227b3cb5575341 Mon Sep 17 00:00:00 2001 From: Alexander Foremny Date: Sat, 23 Mar 2024 13:57:47 +0100 Subject: feat: add client faction --- src/shared/faction.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'src/shared/faction.rs') diff --git a/src/shared/faction.rs b/src/shared/faction.rs index 4ff4a02..7719a0f 100644 --- a/src/shared/faction.rs +++ b/src/shared/faction.rs @@ -1,6 +1,7 @@ use crate::shared::*; +use std::str::FromStr; -#[derive(Component, Clone, Copy, PartialEq, Eq)] +#[derive(Component, Clone, Copy, PartialEq, Eq, Debug, Serialize, Deserialize)] pub enum Faction { Red, Blue, @@ -14,3 +15,21 @@ impl Faction { } } } + +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 + } +} -- cgit v1.2.3