mirror of
https://github.com/redstrate/Physis.git
synced 2025-04-20 19:57:45 +00:00
Add TryFrom implementations for Race, Tribe, Gender
This commit is contained in:
parent
06e1bb0ead
commit
99238d9b5a
3 changed files with 68 additions and 6 deletions
3
src/error.rs
Normal file
3
src/error.rs
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
// TODO: expand
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct Error;
|
|
@ -156,3 +156,6 @@ mod bcn;
|
||||||
|
|
||||||
/// Reading the binary .dat files in the user folder (e.g. GEARSET.dat)
|
/// Reading the binary .dat files in the user folder (e.g. GEARSET.dat)
|
||||||
pub mod dat;
|
pub mod dat;
|
||||||
|
|
||||||
|
mod error;
|
||||||
|
pub use error::Error;
|
||||||
|
|
64
src/race.rs
64
src/race.rs
|
@ -3,6 +3,8 @@
|
||||||
|
|
||||||
use binrw::binrw;
|
use binrw::binrw;
|
||||||
|
|
||||||
|
use crate::Error;
|
||||||
|
|
||||||
/// The playable genders in the game.
|
/// The playable genders in the game.
|
||||||
#[binrw]
|
#[binrw]
|
||||||
#[brw(repr = u8)]
|
#[brw(repr = u8)]
|
||||||
|
@ -13,6 +15,18 @@ pub enum Gender {
|
||||||
Female = 1,
|
Female = 1,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl std::convert::TryFrom<u8> for Gender {
|
||||||
|
type Error = crate::Error;
|
||||||
|
|
||||||
|
fn try_from(value: u8) -> Result<Self, Error> {
|
||||||
|
match value {
|
||||||
|
0 => Ok(Self::Male),
|
||||||
|
1 => Ok(Self::Female),
|
||||||
|
_ => Err(Error {}),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// The playable tribes in the game.
|
/// The playable tribes in the game.
|
||||||
/// Each race has two similar-looking tribes, with the exception of Highlander Hyur which are visually distinct.
|
/// Each race has two similar-looking tribes, with the exception of Highlander Hyur which are visually distinct.
|
||||||
#[binrw]
|
#[binrw]
|
||||||
|
@ -38,6 +52,32 @@ pub enum Tribe {
|
||||||
Veena = 16,
|
Veena = 16,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl std::convert::TryFrom<u8> for Tribe {
|
||||||
|
type Error = crate::Error;
|
||||||
|
|
||||||
|
fn try_from(value: u8) -> Result<Self, Error> {
|
||||||
|
match value {
|
||||||
|
1 => Ok(Self::Midlander),
|
||||||
|
2 => Ok(Self::Highlander),
|
||||||
|
3 => Ok(Self::Wildwood),
|
||||||
|
4 => Ok(Self::Duskwight),
|
||||||
|
5 => Ok(Self::Plainsfolk),
|
||||||
|
6 => Ok(Self::Dunesfolk),
|
||||||
|
7 => Ok(Self::Seeker),
|
||||||
|
8 => Ok(Self::Keeper),
|
||||||
|
9 => Ok(Self::SeaWolf),
|
||||||
|
10 => Ok(Self::Hellsguard),
|
||||||
|
11 => Ok(Self::Raen),
|
||||||
|
12 => Ok(Self::Xaela),
|
||||||
|
13 => Ok(Self::Hellion),
|
||||||
|
14 => Ok(Self::Lost),
|
||||||
|
15 => Ok(Self::Rava),
|
||||||
|
16 => Ok(Self::Veena),
|
||||||
|
_ => Err(Error {}),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// The playable races in the game.
|
/// The playable races in the game.
|
||||||
#[binrw]
|
#[binrw]
|
||||||
#[brw(repr = u8)]
|
#[brw(repr = u8)]
|
||||||
|
@ -54,6 +94,24 @@ pub enum Race {
|
||||||
Viera = 8,
|
Viera = 8,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl std::convert::TryFrom<u8> for Race {
|
||||||
|
type Error = crate::Error;
|
||||||
|
|
||||||
|
fn try_from(value: u8) -> Result<Self, Error> {
|
||||||
|
match value {
|
||||||
|
1 => Ok(Self::Hyur),
|
||||||
|
2 => Ok(Self::Elezen),
|
||||||
|
3 => Ok(Self::Lalafell),
|
||||||
|
4 => Ok(Self::Miqote),
|
||||||
|
5 => Ok(Self::Roegadyn),
|
||||||
|
6 => Ok(Self::AuRa),
|
||||||
|
7 => Ok(Self::Hrothgar),
|
||||||
|
8 => Ok(Self::Viera),
|
||||||
|
_ => Err(Error {}),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Gets a proper race identifier (such as 101, for Hyur-Midlander-Males) given a race, a tribe,
|
/// Gets a proper race identifier (such as 101, for Hyur-Midlander-Males) given a race, a tribe,
|
||||||
/// and a gender.
|
/// and a gender.
|
||||||
pub fn get_race_id(race: Race, tribe: Tribe, gender: Gender) -> Option<i32> {
|
pub fn get_race_id(race: Race, tribe: Tribe, gender: Gender) -> Option<i32> {
|
||||||
|
@ -93,12 +151,10 @@ pub fn get_race_id(race: Race, tribe: Tribe, gender: Gender) -> Option<i32> {
|
||||||
Gender::Male => Some(1301),
|
Gender::Male => Some(1301),
|
||||||
Gender::Female => Some(1401),
|
Gender::Female => Some(1401),
|
||||||
},
|
},
|
||||||
Race::Hrothgar => {
|
Race::Hrothgar => match gender {
|
||||||
match gender {
|
|
||||||
Gender::Male => Some(1501),
|
Gender::Male => Some(1501),
|
||||||
Gender::Female => Some(1601),
|
Gender::Female => Some(1601),
|
||||||
}
|
},
|
||||||
}
|
|
||||||
Race::Viera => match gender {
|
Race::Viera => match gender {
|
||||||
Gender::Male => Some(1701),
|
Gender::Male => Some(1701),
|
||||||
Gender::Female => Some(1801),
|
Gender::Female => Some(1801),
|
||||||
|
|
Loading…
Add table
Reference in a new issue