You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
150 lines
3.3 KiB
150 lines
3.3 KiB
#[derive(Debug, Copy, Clone, derive_more::Display)]
|
|
pub enum Episode {
|
|
#[display(fmt="ep1")]
|
|
One,
|
|
#[display(fmt="ep2")]
|
|
Two,
|
|
#[display(fmt="ep4")]
|
|
Four,
|
|
}
|
|
|
|
impl TryFrom<u8> for Episode {
|
|
type Error = ();
|
|
|
|
fn try_from(value: u8) -> Result<Episode, ()> {
|
|
match value {
|
|
1 => Ok(Episode::One),
|
|
2 => Ok(Episode::Two),
|
|
3 => Ok(Episode::Four),
|
|
_ => Err(())
|
|
}
|
|
}
|
|
}
|
|
|
|
impl From<Episode> for u8 {
|
|
fn from(other: Episode) -> u8 {
|
|
match other {
|
|
Episode::One => 1,
|
|
Episode::Two => 2,
|
|
Episode::Four => 3,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Episode {
|
|
pub fn from_quest(value: u8) -> Option<Episode> {
|
|
match value {
|
|
0 => Some(Episode::One),
|
|
1 => Some(Episode::Two),
|
|
2 => Some(Episode::Four),
|
|
_ => None,
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq, derive_more::Display)]
|
|
pub enum Difficulty {
|
|
Normal,
|
|
Hard,
|
|
VeryHard,
|
|
Ultimate,
|
|
}
|
|
|
|
impl TryFrom<u8> for Difficulty {
|
|
type Error = ();
|
|
|
|
fn try_from(value: u8) -> Result<Difficulty, ()> {
|
|
match value {
|
|
0 => Ok(Difficulty::Normal),
|
|
1 => Ok(Difficulty::Hard),
|
|
2 => Ok(Difficulty::VeryHard),
|
|
3 => Ok(Difficulty::Ultimate),
|
|
_ => Err(())
|
|
}
|
|
}
|
|
}
|
|
|
|
impl From<Difficulty> for u8 {
|
|
fn from(other: Difficulty) -> u8 {
|
|
match other {
|
|
Difficulty::Normal => 0,
|
|
Difficulty::Hard => 1,
|
|
Difficulty::VeryHard => 2,
|
|
Difficulty::Ultimate => 3,
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Copy, Clone)]
|
|
pub enum PlayerMode {
|
|
Single,
|
|
Multi,
|
|
}
|
|
|
|
impl PlayerMode {
|
|
pub fn value(&self) -> u8 {
|
|
match self {
|
|
PlayerMode::Single => 1,
|
|
PlayerMode::Multi => 0,
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Copy, Clone, derive_more::Display)]
|
|
pub enum RoomMode {
|
|
#[display(fmt="single")]
|
|
Single {
|
|
episode: Episode,
|
|
difficulty: Difficulty,
|
|
},
|
|
#[display(fmt="multi")]
|
|
Multi {
|
|
episode: Episode,
|
|
difficulty: Difficulty,
|
|
},
|
|
#[display(fmt="challenge")]
|
|
Challenge {
|
|
episode: Episode,
|
|
},
|
|
#[display(fmt="battle")]
|
|
Battle {
|
|
episode: Episode,
|
|
difficulty: Difficulty,
|
|
}
|
|
}
|
|
|
|
|
|
impl RoomMode {
|
|
pub fn difficulty(&self) -> Difficulty {
|
|
match self {
|
|
RoomMode::Single {difficulty, ..} => *difficulty,
|
|
RoomMode::Multi {difficulty, ..} => *difficulty,
|
|
RoomMode::Battle {difficulty, ..} => *difficulty,
|
|
RoomMode::Challenge {..} => Difficulty::Normal,
|
|
}
|
|
}
|
|
|
|
pub fn episode(&self) -> Episode {
|
|
match self {
|
|
RoomMode::Single {episode, ..} => *episode,
|
|
RoomMode::Multi {episode, ..} => *episode,
|
|
RoomMode::Battle {episode, ..} => *episode,
|
|
RoomMode::Challenge {episode, ..} => *episode,
|
|
}
|
|
}
|
|
|
|
pub fn battle(&self) -> bool {
|
|
matches!(self, RoomMode::Battle {..})
|
|
}
|
|
|
|
pub fn challenge(&self) -> bool {
|
|
matches!(self, RoomMode::Challenge {..})
|
|
}
|
|
|
|
pub fn player_mode(&self) -> PlayerMode {
|
|
match self {
|
|
RoomMode::Single {..} => PlayerMode::Single,
|
|
_ => PlayerMode::Multi,
|
|
}
|
|
}
|
|
}
|