Skip to content

Commit

Permalink
Add function to interpret class names as parts
Browse files Browse the repository at this point in the history
  • Loading branch information
widberg committed Nov 9, 2023
1 parent 515a156 commit 2fa7692
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions bff/src/macros/classes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,38 @@ macro_rules! classes {
$($class(Box<$class>),)*
}

#[derive(serde::Serialize, Debug, serde::Deserialize)]
#[serde(untagged)]
pub enum ClassType {
$($class,)*
}

pub enum ClassNameStyle {
Z,
Caps,
}

impl TryFrom<crate::names::Name> for (ClassType, ClassNameStyle, crate::names::NameType) {
type Error = ();

fn try_from(name: crate::names::Name) -> Result<(ClassType, ClassNameStyle, crate::names::NameType), ()> {
use crate::traits::NamedClass;
match name {
$(crate::names::Name::Asobo32($class::NAME) => Ok((ClassType::$class, ClassNameStyle::Z, crate::names::NameType::Asobo32)),
crate::names::Name::Asobo32($class::NAME_LEGACY) => Ok((ClassType::$class, ClassNameStyle::Caps, crate::names::NameType::Asobo32)),
crate::names::Name::AsoboAlternate32($class::NAME) => Ok((ClassType::$class, ClassNameStyle::Z, crate::names::NameType::AsoboAlternate32)),
crate::names::Name::AsoboAlternate32($class::NAME_LEGACY) => Ok((ClassType::$class, ClassNameStyle::Caps, crate::names::NameType::AsoboAlternate32)),
crate::names::Name::Kalisto32($class::NAME) => Ok((ClassType::$class, ClassNameStyle::Z, crate::names::NameType::Kalisto32)),
crate::names::Name::Kalisto32($class::NAME_LEGACY) => Ok((ClassType::$class, ClassNameStyle::Caps, crate::names::NameType::Kalisto32)),
crate::names::Name::BlackSheep32($class::NAME) => Ok((ClassType::$class, ClassNameStyle::Z, crate::names::NameType::BlackSheep32)),
crate::names::Name::BlackSheep32($class::NAME_LEGACY) => Ok((ClassType::$class, ClassNameStyle::Caps, crate::names::NameType::BlackSheep32)),
crate::names::Name::Asobo64($class::NAME) => Ok((ClassType::$class, ClassNameStyle::Z, crate::names::NameType::Asobo64)),
crate::names::Name::Asobo64($class::NAME_LEGACY) => Ok((ClassType::$class, ClassNameStyle::Caps, crate::names::NameType::Asobo64)),)*
_ => Err(()),
}
}
}

impl crate::traits::TryFromVersionPlatform<&crate::bigfile::resource::Resource> for Class {
type Error = crate::error::Error;

Expand Down

0 comments on commit 2fa7692

Please sign in to comment.