1
Fork 0
mirror of https://github.com/redstrate/Physis.git synced 2025-04-20 11:47:46 +00:00

Begin Race and Subrace enums at 1

This simplifies charsave parsing and will be useful in other projects
like Kawari.
This commit is contained in:
Joshua Goins 2025-03-31 15:33:57 -04:00
parent a34361b956
commit 50ea4dde40
2 changed files with 34 additions and 117 deletions

View file

@ -10,104 +10,15 @@ use binrw::{BinRead, BinWrite};
use crate::race::{Gender, Race, Subrace}; use crate::race::{Gender, Race, Subrace};
fn convert_dat_race(x: u8) -> Race {
match x {
1 => Race::Hyur,
2 => Race::Elezen,
3 => Race::Lalafell,
4 => Race::Miqote,
5 => Race::Roegadyn,
6 => Race::AuRa,
7 => Race::Hrothgar,
8 => Race::Viera,
_ => Race::Hyur,
}
}
fn convert_race_dat(race: &Race) -> u8 {
match race {
Race::Hyur => 1,
Race::Elezen => 2,
Race::Lalafell => 3,
Race::Miqote => 4,
Race::Roegadyn => 5,
Race::AuRa => 6,
Race::Hrothgar => 7,
Race::Viera => 8,
}
}
fn convert_dat_gender(x: u8) -> Gender {
match x {
0 => Gender::Male,
1 => Gender::Female,
_ => Gender::Male,
}
}
fn convert_gender_dat(gender: &Gender) -> u8 {
match gender {
Gender::Male => 0,
Gender::Female => 1,
}
}
fn convert_dat_subrace(x: u8) -> Subrace {
match x {
1 => Subrace::Midlander,
2 => Subrace::Highlander,
3 => Subrace::Wildwood,
4 => Subrace::Duskwight,
5 => Subrace::Plainsfolk,
6 => Subrace::Dunesfolk,
7 => Subrace::Seeker,
8 => Subrace::Keeper,
9 => Subrace::SeaWolf,
10 => Subrace::Hellsguard,
11 => Subrace::Raen,
12 => Subrace::Xaela,
13 => Subrace::Hellion,
14 => Subrace::Lost,
15 => Subrace::Rava,
16 => Subrace::Veena,
_ => Subrace::Midlander,
}
}
fn convert_subrace_dat(subrace: &Subrace) -> u8 {
match subrace {
Subrace::Midlander => 1,
Subrace::Highlander => 2,
Subrace::Wildwood => 3,
Subrace::Duskwight => 4,
Subrace::Plainsfolk => 5,
Subrace::Dunesfolk => 6,
Subrace::Seeker => 7,
Subrace::Keeper => 8,
Subrace::SeaWolf => 9,
Subrace::Hellsguard => 10,
Subrace::Raen => 11,
Subrace::Xaela => 12,
Subrace::Hellion => 13,
Subrace::Lost => 14,
Subrace::Rava => 15,
Subrace::Veena => 16,
}
}
#[binrw] #[binrw]
#[br(little)] #[br(little)]
#[repr(C)] #[repr(C)]
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct CustomizeData { pub struct CustomizeData {
/// The race of the character. /// The race of the character.
#[br(map = convert_dat_race)]
#[bw(map = convert_race_dat)]
pub race: Race, pub race: Race,
/// The gender of the character. /// The gender of the character.
#[br(map = convert_dat_gender)]
#[bw(map = convert_gender_dat)]
pub gender: Gender, pub gender: Gender,
/// The age of the character. Normal = 1, Old = 3, Young = 4. /// The age of the character. Normal = 1, Old = 3, Young = 4.
@ -117,8 +28,6 @@ pub struct CustomizeData {
pub height: u8, pub height: u8,
/// The character's subrace. /// The character's subrace.
#[br(map = convert_dat_subrace)]
#[bw(map = convert_subrace_dat)]
pub subrace: Subrace, pub subrace: Subrace,
/// The character's selected face. /// The character's selected face.

View file

@ -1,49 +1,57 @@
// SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com> // SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com>
// SPDX-License-Identifier: GPL-3.0-or-later // SPDX-License-Identifier: GPL-3.0-or-later
use binrw::binrw;
#[binrw]
#[brw(repr = u8)]
#[derive(PartialEq, Eq, Clone, Debug)] #[derive(PartialEq, Eq, Clone, Debug)]
#[repr(u8)] #[repr(u8)]
/// Gender of the character. /// Gender of the character.
pub enum Gender { pub enum Gender {
Male, Male = 0,
Female, Female = 1,
} }
#[binrw]
#[brw(repr = u8)]
#[derive(PartialEq, Eq, Clone, Debug)] #[derive(PartialEq, Eq, Clone, Debug)]
#[repr(u8)] #[repr(u8)]
/// The race's "subrace". Each race has two subraces, which are actually identical (even down to the ids!) /// The race's "subrace". Each race has two subraces, which are actually identical (even down to the ids!)
/// with the exception of Hyurs, which have two unique subraces that are really two separate races. /// with the exception of Hyurs, which have two unique subraces that are really two separate races.
pub enum Subrace { pub enum Subrace {
Midlander, Midlander = 1,
Highlander, Highlander = 2,
Wildwood, Wildwood = 3,
Duskwight, Duskwight = 4,
Plainsfolk, Plainsfolk = 5,
Dunesfolk, Dunesfolk = 6,
Seeker, Seeker = 7,
Keeper, Keeper = 8,
SeaWolf, SeaWolf = 9,
Hellsguard, Hellsguard = 10,
Raen, Raen = 11,
Xaela, Xaela = 12,
Hellion, Hellion = 13,
Lost, Lost = 14,
Rava, Rava = 15,
Veena, Veena = 16,
} }
#[binrw]
#[brw(repr = u8)]
#[derive(PartialEq, Eq, Clone, Debug)] #[derive(PartialEq, Eq, Clone, Debug)]
#[repr(u8)] #[repr(u8)]
/// The major races of Eorzea. /// The major races of Eorzea.
pub enum Race { pub enum Race {
Hyur, Hyur = 1,
Elezen, Elezen = 2,
Lalafell, Lalafell = 3,
Miqote, Miqote = 4,
Roegadyn, Roegadyn = 5,
AuRa, AuRa = 6,
Hrothgar, Hrothgar = 7,
Viera, Viera = 8,
} }
/// Gets a proper race identifier (such as 101, for Hyur-Midlander-Males) given a race, a subrace, /// Gets a proper race identifier (such as 101, for Hyur-Midlander-Males) given a race, a subrace,