1
Fork 0
mirror of https://github.com/redstrate/Physis.git synced 2025-04-24 21:37:46 +00:00
physis/src/equipment.rs

75 lines
2.1 KiB
Rust
Raw Normal View History

2022-07-19 19:29:41 -04:00
use crate::race::{Gender, get_race_id, Race, Subrace};
#[repr(u8)]
/// The slot the item is for.
2022-07-19 19:29:41 -04:00
pub enum Slot {
/// The head slot. Shorthand is "met".
2022-07-19 19:29:41 -04:00
Head,
/// The hands slot. Shorthand is "glv".
2022-07-19 19:29:41 -04:00
Hands,
/// The legs slot. Shorthand is "dwn".
2022-07-19 19:29:41 -04:00
Legs,
/// The feet slot. Shorthand is "sho".
2022-07-19 19:29:41 -04:00
Feet,
/// The body or chest slot. Shorthand is "top".
2022-07-19 19:29:41 -04:00
Body,
/// The earrings slot. Shorthand is "ear".
2022-07-19 19:29:41 -04:00
Earring,
/// The neck slot. Shorthand is "nek".
2022-07-19 19:29:41 -04:00
Neck,
/// The ring slot. Shorthand is "rir".
2022-07-19 19:29:41 -04:00
Rings,
/// The wrists slot. Shorthand is "wrs".
2022-07-19 19:29:41 -04:00
Wrists,
}
/// Returns the shorthand abbreviation of `slot`. For example, Body's shorthand is "top".
2022-07-19 19:29:41 -04:00
pub fn get_slot_abbreviation(slot: Slot) -> &'static str {
match slot {
Slot::Head => "met",
Slot::Hands => "glv",
Slot::Legs => "dwn",
Slot::Feet => "sho",
Slot::Body => "top",
Slot::Earring => "ear",
Slot::Neck => "nek",
Slot::Rings => "rir",
Slot::Wrists => "wrs"
}
}
/// Determines the correct slot from an id. This can fail, so a None is returned when no slot matches
/// that id.
2022-07-19 19:29:41 -04:00
pub fn get_slot_from_id(id: i32) -> Option<Slot> {
match id {
3 => Some(Slot::Head),
5 => Some(Slot::Hands),
7 => Some(Slot::Legs),
8 => Some(Slot::Feet),
4 => Some(Slot::Body),
9 => Some(Slot::Earring),
10 => Some(Slot::Neck),
12 => Some(Slot::Rings),
11 => Some(Slot::Wrists),
_ => None
}
}
/// Builds a game path to the equipment specified.
2022-07-19 19:29:41 -04:00
pub fn build_equipment_path(model_id: i32, race: Race, subrace: Subrace, gender: Gender, slot: Slot) -> String {
format!("chara/equipment/e{:04}/model/c{:04}e{:04}_{}.mdl",
model_id,
get_race_id(race, subrace, gender).unwrap(),
model_id,
get_slot_abbreviation(slot))
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_equipment_path() {
assert_eq!(build_equipment_path(0, Race::Hyur, Subrace::Midlander, Gender::Male, Slot::Body), "chara/equipment/e0000/model/c0101e0000_top.mdl");
}
}