aboutsummaryrefslogtreecommitdiffstats
path: root/src/shared/faction.rs
blob: be9aafc2231e766479cf594209e6c784d75f6522 (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
36
37
use bevy::prelude::*;
use lightyear::prelude::*;
use serde::*;
use std::str::*;

#[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
    }
}