feat: add races and clans
This commit is contained in:
parent
81773c7065
commit
3256fdd18a
|
@ -8,7 +8,7 @@ repository = "https://github.com/jkcclemens/ffxiv_types"
|
|||
license = "MIT"
|
||||
|
||||
[features]
|
||||
default = ["jobs", "roles", "data_centers", "worlds", "all_const"]
|
||||
default = ["jobs", "roles", "data_centers", "worlds", "races", "clans", "all_const"]
|
||||
|
||||
# Every type
|
||||
all_const = []
|
||||
|
@ -26,6 +26,10 @@ roles = []
|
|||
data_centers = []
|
||||
worlds = []
|
||||
|
||||
# Character-related
|
||||
races = []
|
||||
clans = []
|
||||
|
||||
# Serde support
|
||||
with_serde = ["serde", "serde_derive"]
|
||||
|
||||
|
|
|
@ -0,0 +1,131 @@
|
|||
//! Clan types
|
||||
|
||||
use errors::UnknownVariant;
|
||||
|
||||
#[cfg(feature = "races")]
|
||||
use races::Race;
|
||||
|
||||
use std::fmt::{Display, Formatter, Result as FmtResult};
|
||||
use std::str::FromStr;
|
||||
|
||||
/// The clans of the playable races in the game.
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
#[cfg_attr(feature = "with_serde", derive(Serialize, Deserialize))]
|
||||
pub enum Clan {
|
||||
// Au Ra
|
||||
Raen,
|
||||
Xaela,
|
||||
// Elezen
|
||||
Duskwight,
|
||||
Wildwood,
|
||||
// Hyur
|
||||
Highlander,
|
||||
Midlander,
|
||||
// Lalafell
|
||||
Dunesfolk,
|
||||
Plainsfolk,
|
||||
// Miqo'te
|
||||
SeekerOfTheMoon,
|
||||
SeekerOfTheSun,
|
||||
// Roegadyn
|
||||
Hellsguard,
|
||||
SeaWolf,
|
||||
}
|
||||
|
||||
impl Clan {
|
||||
#[cfg(feature = "all_const")]
|
||||
pub const ALL: [Clan; 12] = [
|
||||
Clan::Raen,
|
||||
Clan::Xaela,
|
||||
Clan::Duskwight,
|
||||
Clan::Wildwood,
|
||||
Clan::Highlander,
|
||||
Clan::Midlander,
|
||||
Clan::Dunesfolk,
|
||||
Clan::Plainsfolk,
|
||||
Clan::SeekerOfTheMoon,
|
||||
Clan::SeekerOfTheSun,
|
||||
Clan::Hellsguard,
|
||||
Clan::SeaWolf,
|
||||
];
|
||||
|
||||
/// Returns the string variant of this world.
|
||||
pub fn as_str(&self) -> &'static str {
|
||||
match *self {
|
||||
Clan::Raen => "Raen",
|
||||
Clan::Xaela => "Xaela",
|
||||
Clan::Duskwight => "Duskwight",
|
||||
Clan::Wildwood => "Wildwood",
|
||||
Clan::Highlander => "Highlander",
|
||||
Clan::Midlander => "Midlander",
|
||||
Clan::Dunesfolk => "Dunesfolk",
|
||||
Clan::Plainsfolk => "Plainsfolk",
|
||||
Clan::SeekerOfTheMoon => "SeekerOfTheMoon",
|
||||
Clan::SeekerOfTheSun => "SeekerOfTheSun",
|
||||
Clan::Hellsguard => "Hellsguard",
|
||||
Clan::SeaWolf => "SeaWolf",
|
||||
}
|
||||
}
|
||||
|
||||
pub fn name(&self) -> &'static str {
|
||||
match *self {
|
||||
Clan::Raen => "Raen",
|
||||
Clan::Xaela => "Xaela",
|
||||
Clan::Duskwight => "Duskwight",
|
||||
Clan::Wildwood => "Wildwood",
|
||||
Clan::Highlander => "Highlander",
|
||||
Clan::Midlander => "Midlander",
|
||||
Clan::Dunesfolk => "Dunesfolk",
|
||||
Clan::Plainsfolk => "Plainsfolk",
|
||||
Clan::SeekerOfTheMoon => "Seeker of the Moon",
|
||||
Clan::SeekerOfTheSun => "Seeker of the Sun",
|
||||
Clan::Hellsguard => "Hellsguard",
|
||||
Clan::SeaWolf => "Sea Wolf",
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "races")]
|
||||
pub fn race(&self) -> Race {
|
||||
match *self {
|
||||
Clan::Raen | Clan::Xaela => Race::AuRa,
|
||||
Clan::Duskwight | Clan::Wildwood => Race::Elezen,
|
||||
Clan::Highlander | Clan::Midlander => Race::Hyur,
|
||||
Clan::Dunesfolk | Clan::Plainsfolk => Race::Lalafell,
|
||||
Clan::SeekerOfTheMoon | Clan::SeekerOfTheSun => Race::Miqote,
|
||||
Clan::Hellsguard | Clan::SeaWolf => Race::Roegadyn,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl FromStr for Clan {
|
||||
type Err = UnknownVariant;
|
||||
|
||||
/// Parses a string `s` to return a value of this type.
|
||||
///
|
||||
/// This is case-insensitive.
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
let world = match s.to_lowercase().as_str() {
|
||||
"raen" => Clan::Raen,
|
||||
"xaela" => Clan::Xaela,
|
||||
"duskwight" => Clan::Duskwight,
|
||||
"wildwood" => Clan::Wildwood,
|
||||
"highlander" => Clan::Highlander,
|
||||
"midlander" => Clan::Midlander,
|
||||
"dunesfolk" => Clan::Dunesfolk,
|
||||
"plainsfolk" => Clan::Plainsfolk,
|
||||
"seekerofthemoon" | "seeker of the moon" => Clan::SeekerOfTheMoon,
|
||||
"seekerofthesun" | "seeker of the sun" => Clan::SeekerOfTheSun,
|
||||
"hellsguard" => Clan::Hellsguard,
|
||||
"seawolf" | "sea wolf" => Clan::SeaWolf,
|
||||
_ => return Err(UnknownVariant("Clan", s.into()))
|
||||
};
|
||||
|
||||
Ok(world)
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for Clan {
|
||||
fn fmt(&self, f: &mut Formatter) -> FmtResult {
|
||||
write!(f, "{}", self.name())
|
||||
}
|
||||
}
|
|
@ -4,15 +4,21 @@
|
|||
#[macro_use]
|
||||
extern crate serde_derive;
|
||||
|
||||
#[cfg(feature = "clans")]
|
||||
pub mod clans;
|
||||
#[cfg(feature = "data_centers")]
|
||||
pub mod data_centers;
|
||||
pub mod errors;
|
||||
pub mod jobs;
|
||||
#[cfg(feature = "races")]
|
||||
pub mod races;
|
||||
#[cfg(feature = "roles")]
|
||||
pub mod roles;
|
||||
#[cfg(feature = "worlds")]
|
||||
pub mod worlds;
|
||||
|
||||
#[cfg(feature = "clans")]
|
||||
pub use self::clans::Clan;
|
||||
#[cfg(feature = "data_centers")]
|
||||
pub use self::data_centers::DataCenter;
|
||||
#[cfg(feature = "combat_jobs")]
|
||||
|
@ -21,6 +27,8 @@ pub use self::jobs::Job;
|
|||
pub use self::jobs::NonCombatJob;
|
||||
#[cfg(feature = "job_classifications")]
|
||||
pub use self::jobs::Classification;
|
||||
#[cfg(feature = "races")]
|
||||
pub use self::races::Race;
|
||||
#[cfg(feature = "roles")]
|
||||
pub use self::roles::Role;
|
||||
#[cfg(feature = "worlds")]
|
||||
|
|
|
@ -0,0 +1,95 @@
|
|||
//! Race types
|
||||
|
||||
use errors::UnknownVariant;
|
||||
|
||||
#[cfg(feature = "clans")]
|
||||
use clans::Clan;
|
||||
|
||||
use std::fmt::{Display, Formatter, Result as FmtResult};
|
||||
use std::str::FromStr;
|
||||
|
||||
/// The playable races in the game.
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
#[cfg_attr(feature = "with_serde", derive(Serialize, Deserialize))]
|
||||
pub enum Race {
|
||||
AuRa,
|
||||
Elezen,
|
||||
Hyur,
|
||||
Lalafell,
|
||||
Miqote,
|
||||
Roegadyn,
|
||||
}
|
||||
|
||||
impl Race {
|
||||
#[cfg(feature = "all_const")]
|
||||
pub const ALL: [Race; 6] = [
|
||||
Race::AuRa,
|
||||
Race::Elezen,
|
||||
Race::Hyur,
|
||||
Race::Lalafell,
|
||||
Race::Miqote,
|
||||
Race::Roegadyn,
|
||||
];
|
||||
|
||||
/// Returns the string variant of this world.
|
||||
pub fn as_str(&self) -> &'static str {
|
||||
match *self {
|
||||
Race::AuRa => "AuRa",
|
||||
Race::Elezen => "Elezen",
|
||||
Race::Hyur => "Hyur",
|
||||
Race::Lalafell => "Lalafell",
|
||||
Race::Miqote => "Miqote",
|
||||
Race::Roegadyn => "Roegadyn",
|
||||
}
|
||||
}
|
||||
|
||||
pub fn name(&self) -> &'static str {
|
||||
match *self {
|
||||
Race::AuRa => "Au Ra",
|
||||
Race::Elezen => "Elezen",
|
||||
Race::Hyur => "Hyur",
|
||||
Race::Lalafell => "Lalafell",
|
||||
Race::Miqote => "Miqo'te",
|
||||
Race::Roegadyn => "Roegadyn",
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "clans")]
|
||||
pub fn clans(&self) -> [Clan; 2] {
|
||||
match *self {
|
||||
Race::AuRa => [Clan::Raen, Clan::Xaela],
|
||||
Race::Elezen => [Clan::Duskwight, Clan::Wildwood],
|
||||
Race::Hyur => [Clan::Highlander, Clan::Midlander],
|
||||
Race::Lalafell => [Clan::Dunesfolk, Clan::Plainsfolk],
|
||||
Race::Miqote => [Clan::SeekerOfTheMoon, Clan::SeekerOfTheSun],
|
||||
Race::Roegadyn => [Clan::Hellsguard, Clan::SeaWolf],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl FromStr for Race {
|
||||
type Err = UnknownVariant;
|
||||
|
||||
/// Parses a string `s` to return a value of this type.
|
||||
///
|
||||
/// This is case-insensitive.
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
let world = match s.to_lowercase().as_str() {
|
||||
"aura" | "au ra" => Race::AuRa,
|
||||
"elezen" => Race::Elezen,
|
||||
"hyur" => Race::Hyur,
|
||||
"lalafell" => Race::Lalafell,
|
||||
"miqote" | "miqo'te" => Race::Miqote,
|
||||
"roegadyn" => Race::Roegadyn,
|
||||
_ => return Err(UnknownVariant("Race", s.into()))
|
||||
};
|
||||
|
||||
Ok(world)
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for Race {
|
||||
fn fmt(&self, f: &mut Formatter) -> FmtResult {
|
||||
write!(f, "{}", self.name())
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue