aboutsummaryrefslogtreecommitdiffstats
path: root/src/shared/faction.rs
blob: d3086d8915790ffd2e7d2d6474ca8a3b16061f54 (plain)
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(Message, Component, Clone, Copy, PartialEq, Eq, Debug, Serialize, Deserialize)]
pub enum Faction {
    Purple,
    Yellow,
}

impl Faction {
    pub fn to_color(self) -> Color {
        match self {
            Faction::Purple => Color::PURPLE,
            Faction::Yellow => Color::YELLOW,
        }
    }
}

impl FromStr for Faction {
    type Err = String;

    fn from_str(s: &str) -> Result<Faction, String> {
        match s {
            "purple" => Ok(Faction::Purple),
            "yellow" => Ok(Faction::Yellow),
            _ => Err(format!("unknown faction: {}", s)),
        }
    }
}

impl Default for Faction {
    fn default() -> Self {
        Faction::Yellow
    }
}