aboutsummaryrefslogtreecommitdiffstats
path: root/src/shared
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/faction.rs21
-rw-r--r--src/shared/player.rs3
2 files changed, 23 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
+ }
+}
diff --git a/src/shared/player.rs b/src/shared/player.rs
index 59e8853..6b21bac 100644
--- a/src/shared/player.rs
+++ b/src/shared/player.rs
@@ -1,3 +1,4 @@
+use crate::shared::faction::*;
use crate::shared::activation::*;
use crate::shared::buffs::*;
use crate::shared::shape::*;
@@ -17,6 +18,7 @@ pub struct PlayerBundle {
buffs: Buffs,
activation: Activation,
shape: Shape,
+ faction: Faction,
replicate: Replicate,
}
@@ -48,6 +50,7 @@ impl PlayerBundle {
buffs: Buffs::default(),
activation: Activation::default(),
shape: Shape::player(),
+ faction: Faction::default(),
replicate,
}
}