aboutsummaryrefslogtreecommitdiffstats
path: root/src/shared/faction.rs
diff options
context:
space:
mode:
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
+ }
+}