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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
use std::str::FromStr;

pub use self::decode::{General, GeneralKey, GeneralState, ParseGeneralError};

pub(crate) mod decode; // pub(crate) for intradoc-links

/// An osu! gamemode.
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]
pub enum GameMode {
    #[default]
    Osu,
    Taiko,
    Catch,
    Mania,
}

thiserror! {
    #[error("invalid game mode")]
    /// Error when failing to parse a [`GameMode`].
    #[derive(Copy, Clone, Debug, PartialEq, Eq)]
    pub struct ParseGameModeError;
}

impl FromStr for GameMode {
    type Err = ParseGameModeError;

    fn from_str(mode: &str) -> Result<Self, Self::Err> {
        match mode {
            "0" => Ok(Self::Osu),
            "1" => Ok(Self::Taiko),
            "2" => Ok(Self::Catch),
            "3" => Ok(Self::Mania),
            _ => Err(ParseGameModeError),
        }
    }
}

impl From<u8> for GameMode {
    fn from(mode: u8) -> Self {
        match mode {
            0 => Self::Osu,
            1 => Self::Taiko,
            2 => Self::Catch,
            3 => Self::Mania,
            _ => Self::Osu,
        }
    }
}

/// The countdown type of a [`Beatmap`].
///
/// [`Beatmap`]: crate::beatmap::Beatmap
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]
pub enum CountdownType {
    #[default]
    None,
    Normal,
    HalfSpeed,
    DoubleSpeed,
}

impl FromStr for CountdownType {
    type Err = ParseCountdownTypeError;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        match s {
            "0" | "None" => Ok(Self::None),
            "1" | "Normal" => Ok(Self::Normal),
            "2" | "Half speed" => Ok(Self::HalfSpeed),
            "3" | "Double speed" => Ok(Self::DoubleSpeed),
            _ => Err(ParseCountdownTypeError),
        }
    }
}

thiserror! {
    #[error("invalid countdown type")]
    /// Error when failing to parse a [`CountdownType`].
    #[derive(Debug)]
    pub struct ParseCountdownTypeError;
}