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

Add some new equipment functions needed for VARC tool

* Added deconstruct_equipment_path to grab the model id and slot from
an already made equipment filename.
* Added get_slot_from_abbreviation to be the reverse of
get_slot_abbreviation.
This commit is contained in:
Joshua Goins 2022-08-10 14:51:36 -04:00
parent 715ec49252
commit 5d8e8e23e5

View file

@ -1,6 +1,7 @@
use crate::race::{Gender, get_race_id, Race, Subrace};
#[repr(u8)]
#[derive(Debug, PartialEq)]
/// The slot the item is for.
pub enum Slot {
/// The head slot. Shorthand is "met".
@ -55,6 +56,24 @@ pub fn get_slot_from_id(id: i32) -> Option<Slot> {
}
}
/// Determines the correct slot from an id. This can fail, so a None is returned when no slot matches
/// that id.
pub fn get_slot_from_abbreviation(abrev: &str) -> Option<Slot> {
match abrev {
"met" => Some(Slot::Head),
"glv" => Some(Slot::Hands),
"dwn" => Some(Slot::Legs),
"sho" => Some(Slot::Feet),
"top" => Some(Slot::Body),
"ear" => Some(Slot::Earring),
"nek" => Some(Slot::Neck),
"rir" => Some(Slot::Rings),
"wrs" => Some(Slot::Wrists),
_ => None
}
}
/// Builds a game path to the equipment specified.
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",
@ -64,6 +83,13 @@ pub fn build_equipment_path(model_id: i32, race: Race, subrace: Subrace, gender:
get_slot_abbreviation(slot))
}
pub fn deconstruct_equipment_path(path : &str) -> Option<(i32, Slot)> {
let model_id = &path[6..10];
let slot_name = &path[11..14];
Some((model_id.parse().ok()?, get_slot_from_abbreviation(slot_name)?))
}
#[cfg(test)]
mod tests {
use super::*;