Browse Source

Character: sectionid, charclass to use enums

cleanuppery
jake 1 year ago
parent
commit
c309e51f02
  1. 62
      src/character/character.rs

62
src/character/character.rs

@ -1,12 +1,10 @@
// TODO: ch_class to CharacterClass enum
// TODO: section_id to SectionId enum
// TODO: techniques to enum // TODO: techniques to enum
use psopacket::PSOPacketData; use psopacket::PSOPacketData;
use crate::{PSOPacketData, PacketParseError}; use crate::{PSOPacketData, PacketParseError};
#[repr(u32)]
#[derive(Copy, Clone, Hash, PartialEq, Eq)]
pub enum Class {
#[repr(u8)]
#[derive(PSOPacketData, Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub enum CharacterClass {
HUmar, HUmar,
HUnewearl, HUnewearl,
HUcast, HUcast,
@ -21,28 +19,35 @@ pub enum Class {
FOnewearl, FOnewearl,
} }
impl std::convert::From<u8> for Class {
fn from(f: u8) -> Class {
impl Default for CharacterClass {
fn default() -> CharacterClass {
CharacterClass::HUmar
}
}
impl std::convert::From<u8> for CharacterClass {
fn from(f: u8) -> CharacterClass {
match f { match f {
0 => Class::HUmar,
1 => Class::HUnewearl,
2 => Class::HUcast,
3 => Class::RAmar,
4 => Class::RAcast,
5 => Class::RAcaseal,
6 => Class::FOmarl,
7 => Class::FOnewm,
8 => Class::FOnewearl,
9 => Class::HUcaseal,
10 => Class::RAmarl,
11 => Class::FOmar,
0 => CharacterClass::HUmar,
1 => CharacterClass::HUnewearl,
2 => CharacterClass::HUcast,
3 => CharacterClass::RAmar,
4 => CharacterClass::RAcast,
5 => CharacterClass::RAcaseal,
6 => CharacterClass::FOmarl,
7 => CharacterClass::FOnewm,
8 => CharacterClass::FOnewearl,
9 => CharacterClass::HUcaseal,
10 => CharacterClass::RAmarl,
11 => CharacterClass::FOmar,
_ => panic!("unknown class") _ => panic!("unknown class")
} }
} }
} }
#[repr(u8)]
#[derive(PSOPacketData, Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub enum SectionID { pub enum SectionID {
Viridia, Viridia,
Greenill, Greenill,
@ -56,6 +61,11 @@ pub enum SectionID {
Whitill, Whitill,
} }
impl Default for SectionID {
fn default() -> SectionID {
SectionID::Viridia
}
}
#[derive(PSOPacketData, Copy, Clone)] #[derive(PSOPacketData, Copy, Clone)]
@ -80,8 +90,8 @@ pub struct Character {
pub _unused: [u8; 11], pub _unused: [u8; 11],
pub play_time: u32, pub play_time: u32,
pub name_color_checksum: u32, pub name_color_checksum: u32,
pub section_id: u8,
pub ch_class: u8,
pub section_id: SectionID,
pub ch_class: CharacterClass,
pub v2flags: u8, pub v2flags: u8,
pub version: u8, pub version: u8,
pub v1flags: u32, pub v1flags: u32,
@ -149,8 +159,8 @@ pub struct SelectScreenCharacter {
pub model: u8, pub model: u8,
pub _unused: [u8; 15], pub _unused: [u8; 15],
pub name_color_checksum: u32, pub name_color_checksum: u32,
pub section_id: u8,
pub ch_class: u8,
pub section_id: SectionID,
pub ch_class: CharacterClass,
pub v2flags: u8, pub v2flags: u8,
pub version: u8, pub version: u8,
pub v1flags: u32, pub v1flags: u32,
@ -301,8 +311,8 @@ pub struct FullCharacter {
pub guildcard_desc: [u16; 88], pub guildcard_desc: [u16; 88],
pub _reserved1: u8, pub _reserved1: u8,
pub _reserved2: u8, pub _reserved2: u8,
pub section_id: u8,
pub char_class: u8,
pub section_id: SectionID,
pub char_class: CharacterClass,
pub _unknown2: u32, pub _unknown2: u32,
pub symbol_chats: [u8; 0x4E0], pub symbol_chats: [u8; 0x4E0],
pub shortcuts: [u8; 2624], pub shortcuts: [u8; 2624],

Loading…
Cancel
Save