Switch to using EquipSlot key instead of String

This commit is contained in:
juliancoffee 2021-05-23 21:37:41 +03:00
parent 22b1880ae5
commit 8c1643cad9
2 changed files with 50 additions and 53 deletions

View File

@ -1,28 +1,32 @@
({
// Weapons
"active_mainhand": Item("common.items.weapons.sword_1h.bloodsteel-0"),
"active_offhand": Item("common.items.weapons.sword_1h.bloodsteel-0"),
ActiveMainhand: Item("common.items.weapons.sword_1h.bloodsteel-0"),
ActiveOffhand: Item("common.items.weapons.sword_1h.bloodsteel-0"),
"inactive_mainhand": Item("common.items.weapons.sword_1h.bloodsteel-0"),
"inactive_offhand": Item("common.items.weapons.sword_1h.bloodsteel-0"),
InactiveMainhand: Item("common.items.weapons.sword_1h.bloodsteel-0"),
InactiveOffhand: Item("common.items.weapons.sword_1h.bloodsteel-0"),
// Gear
"head": Item("common.items.npc_armor.biped_small.myrmidon.head.myrmidon"),
"shoulder": Item("common.items.armor.twigsflowers.shoulder"),
"chest": Item("common.items.armor.twigsflowers.chest"),
"hands": Item("common.items.armor.twigsflowers.hand"),
"pants": Item("common.items.armor.twigsflowers.pants"),
"feet": Item("common.items.armor.twigsflowers.foot"),
"belt": Item("common.items.armor.twigsflowers.belt"),
Armor(Head): Item("common.items.npc_armor.biped_small.myrmidon.head.myrmidon"),
Armor(Shoulders): Item("common.items.armor.twigsflowers.shoulder"),
Armor(Chest): Item("common.items.armor.twigsflowers.chest"),
Armor(Hands): Item("common.items.armor.twigsflowers.hand"),
Armor(Legs): Item("common.items.armor.twigsflowers.pants"),
Armor(Feet): Item("common.items.armor.twigsflowers.foot"),
Armor(Belt): Item("common.items.armor.twigsflowers.belt"),
// Biju
"back": Item("common.items.armor.misc.back.dungeon_purple"),
"neck": Item("common.items.armor.misc.neck.plain_1"),
"ring1": Item("common.items.armor.misc.ring.gold"),
"ring2": Item("common.items.armor.misc.ring.gold"),
Armor(Back): Item("common.items.armor.misc.back.dungeon_purple"),
Armor(Neck): Item("common.items.armor.misc.neck.plain_1"),
Armor(Ring1): Item("common.items.armor.misc.ring.gold"),
Armor(Ring2): Item("common.items.armor.misc.ring.gold"),
// Misc
"lantern": Item("common.items.lantern.black_0"),
"tabard": Item("common.items.debug.admin"),
"glider": Item("common.items.glider.glider_basic_red"),
Lantern: Item("common.items.lantern.black_0"),
Armor(Tabard): Item("common.items.debug.admin"),
Glider: Item("common.items.glider.glider_basic_red"),
Armor(Bag1): Item("common.items.armor.misc.bag.tiny_leather_pouch"),
Armor(Bag2): Item("common.items.armor.misc.bag.tiny_leather_pouch"),
Armor(Bag3): Item("common.items.armor.misc.bag.tiny_leather_pouch"),
Armor(Bag4): Item("common.items.armor.misc.bag.tiny_leather_pouch"),
})

View File

@ -72,7 +72,7 @@ enum ItemSpec {
}
#[derive(Debug, Deserialize, Clone)]
pub struct LoadoutSpec(HashMap<String, ItemSpec>);
pub struct LoadoutSpec(HashMap<EquipSlot, ItemSpec>);
impl assets::Asset for LoadoutSpec {
type Loader = assets::RonLoader;
@ -331,7 +331,7 @@ impl LoadoutBuilder {
},
(_, Some(ItemSpec::Choice(_))) => {
let err = format!(
"Using choice of choices in ({}): {}. Unimplemented.",
"Using choice of choices in ({}): {:?}. Unimplemented.",
asset_specifier, key,
);
if cfg!(tests) {
@ -345,73 +345,66 @@ impl LoadoutBuilder {
}
},
};
match key.as_str() {
"active_mainhand" => {
match key {
EquipSlot::ActiveMainhand => {
loadout = loadout.active_mainhand(Some(item));
},
"active_offhand" => {
EquipSlot::ActiveOffhand => {
loadout = loadout.active_offhand(Some(item));
},
"inactive_mainhand" => {
EquipSlot::InactiveMainhand => {
loadout = loadout.inactive_mainhand(Some(item));
},
"inactive_offhand" => {
EquipSlot::InactiveOffhand => {
loadout = loadout.inactive_offhand(Some(item));
},
"head" => {
EquipSlot::Armor(ArmorSlot::Head) => {
loadout = loadout.head(Some(item));
},
"shoulder" => {
EquipSlot::Armor(ArmorSlot::Shoulders) => {
loadout = loadout.shoulder(Some(item));
},
"chest" => {
EquipSlot::Armor(ArmorSlot::Chest) => {
loadout = loadout.chest(Some(item));
},
"hands" => {
EquipSlot::Armor(ArmorSlot::Hands) => {
loadout = loadout.hands(Some(item));
},
"pants" => {
EquipSlot::Armor(ArmorSlot::Legs) => {
loadout = loadout.pants(Some(item));
},
"feet" => {
EquipSlot::Armor(ArmorSlot::Feet) => {
loadout = loadout.feet(Some(item));
},
"belt" => {
EquipSlot::Armor(ArmorSlot::Belt) => {
loadout = loadout.belt(Some(item));
},
"back" => {
EquipSlot::Armor(ArmorSlot::Back) => {
loadout = loadout.back(Some(item));
},
"neck" => {
EquipSlot::Armor(ArmorSlot::Neck) => {
loadout = loadout.neck(Some(item));
},
"ring1" => {
EquipSlot::Armor(ArmorSlot::Ring1) => {
loadout = loadout.ring1(Some(item));
},
"ring2" => {
EquipSlot::Armor(ArmorSlot::Ring2) => {
loadout = loadout.ring2(Some(item));
},
"lantern" => {
EquipSlot::Lantern => {
loadout = loadout.lantern(Some(item));
},
"tabard" => {
EquipSlot::Armor(ArmorSlot::Tabard) => {
loadout = loadout.tabard(Some(item));
},
"glider" => {
EquipSlot::Glider => {
loadout = loadout.glider(Some(item));
},
_ => {
if cfg!(tests) {
panic!(
"Unexpected key in loadout asset ({}): {}",
asset_specifier, key
);
} else {
warn!(
"Unexpected key in loadout asset ({}): {}",
asset_specifier, key
);
}
EquipSlot::Armor(slot @ ArmorSlot::Bag1)
| EquipSlot::Armor(slot @ ArmorSlot::Bag2)
| EquipSlot::Armor(slot @ ArmorSlot::Bag3)
| EquipSlot::Armor(slot @ ArmorSlot::Bag4) => {
loadout = loadout.bag(slot, Some(item));
},
};
}
@ -775,8 +768,8 @@ mod tests {
//
// Things that will be catched - invalid assets paths
// FIXME: if item is used in some branch of rng test may miss it
// TODO: as of now there is no rng generation of items
// validate assets for all possible branches
// TODO: as of now there is no rng generation of items.
// Validate assets for all possible branches
#[test]
fn test_loadout_configs() {
let test_weapons = vec![