aboutsummaryrefslogtreecommitdiffstats
path: root/src/shared/faction.rs
diff options
context:
space:
mode:
authorLibravatar Alexander Foremny <aforemny@posteo.de>2024-03-23 13:57:47 +0100
committerLibravatar Alexander Foremny <aforemny@posteo.de>2024-03-23 13:57:47 +0100
commit12a6419eaa087f34bdde49b3f9227b3cb5575341 (patch)
tree8b8dbadc50e81cef1386c2711edf0479e37d35ec /src/shared/faction.rs
parent23d32213ff8832d2c4360618eb511a0098153818 (diff)
feat: add client faction
Diffstat (limited to 'src/shared/faction.rs')
-rw-r--r--src/shared/faction.rs21
1 files changed, 20 insertions, 1 deletions
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<Faction, String> {
+ match s {
+ "red" => Ok(Faction::Red),
+ "blue" => Ok(Faction::Blue),
+ _ => Err(format!("unknown faction: {}", s)),
+ }
+ }
+}
+
+impl Default for Faction {
+ fn default() -> Self {
+ Faction::Blue
+ }
+}