1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
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<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
}
}
|