74 lines
1.7 KiB
Rust
74 lines
1.7 KiB
Rust
use std::marker::PhantomData;
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
use crate::InvalidEnumError;
|
|
|
|
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
|
|
#[repr(u8)]
|
|
#[serde(into = "u8", try_from = "u8")]
|
|
pub enum BossType {
|
|
Kholdstare,
|
|
Moldorm,
|
|
Mothula,
|
|
Vitreous,
|
|
Helmasaur,
|
|
Armos,
|
|
Lanmola,
|
|
Blind,
|
|
Arrghus,
|
|
Trinexx,
|
|
// Don't use these. They are only for manual settings passed in by the randomizer web app.
|
|
Agahnim,
|
|
Agahnim2,
|
|
Ganon,
|
|
NoBoss = 255,
|
|
}
|
|
|
|
impl From<BossType> for u8 {
|
|
fn from(t: BossType) -> u8 {
|
|
use BossType::*;
|
|
|
|
match t {
|
|
Kholdstare => 0,
|
|
Moldorm => 1,
|
|
Mothula => 2,
|
|
Vitreous => 3,
|
|
Helmasaur => 4,
|
|
Armos => 5,
|
|
Lanmola => 6,
|
|
Blind => 7,
|
|
Arrghus => 8,
|
|
Trinexx => 9,
|
|
Agahnim => 10,
|
|
Agahnim2 => 11,
|
|
Ganon => 12,
|
|
NoBoss => 255,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl TryFrom<u8> for BossType {
|
|
type Error = InvalidEnumError<Self>;
|
|
|
|
fn try_from(byte: u8) -> Result<Self, Self::Error> {
|
|
match byte {
|
|
0 => Ok(Self::Kholdstare),
|
|
1 => Ok(Self::Moldorm),
|
|
2 => Ok(Self::Mothula),
|
|
3 => Ok(Self::Vitreous),
|
|
4 => Ok(Self::Helmasaur),
|
|
5 => Ok(Self::Armos),
|
|
6 => Ok(Self::Lanmola),
|
|
7 => Ok(Self::Blind),
|
|
8 => Ok(Self::Arrghus),
|
|
9 => Ok(Self::Trinexx),
|
|
10 => Ok(Self::Agahnim),
|
|
11 => Ok(Self::Agahnim2),
|
|
12 => Ok(Self::Ganon),
|
|
255 => Ok(Self::NoBoss),
|
|
_ => Err(InvalidEnumError(PhantomData)),
|
|
}
|
|
}
|
|
}
|