Extract 'swap_equipment' and 'swap_armor' functions

This commit is contained in:
Dr. Dystopia 2021-06-28 16:17:18 +02:00
parent 7c135fb6ff
commit 11d2017bb3

View File

@ -595,119 +595,83 @@ impl LoadoutBuilder {
self.with_asset_expect("common.loadout.default", rng) self.with_asset_expect("common.loadout.default", rng)
} }
#[must_use] fn with_equipment(mut self, equip_slot: EquipSlot, item: Option<Item>) -> Self {
pub fn active_mainhand(mut self, item: Option<Item>) -> Self { self.0.swap(equip_slot, item);
self.0.swap(EquipSlot::ActiveMainhand, item);
self self
} }
#[must_use] #[must_use]
pub fn active_offhand(mut self, item: Option<Item>) -> Self { pub fn active_mainhand(self, item: Option<Item>) -> Self {
self.0.swap(EquipSlot::ActiveOffhand, item); self.with_equipment(EquipSlot::ActiveMainhand, item)
self
} }
#[must_use] #[must_use]
pub fn inactive_mainhand(mut self, item: Option<Item>) -> Self { pub fn active_offhand(self, item: Option<Item>) -> Self {
self.0.swap(EquipSlot::InactiveMainhand, item); self.with_equipment(EquipSlot::ActiveOffhand, item)
self
} }
#[must_use] #[must_use]
pub fn inactive_offhand(mut self, item: Option<Item>) -> Self { pub fn inactive_mainhand(self, item: Option<Item>) -> Self {
self.0.swap(EquipSlot::InactiveOffhand, item); self.with_equipment(EquipSlot::InactiveMainhand, item)
self
} }
#[must_use] #[must_use]
pub fn shoulder(mut self, item: Option<Item>) -> Self { pub fn inactive_offhand(self, item: Option<Item>) -> Self {
self.0.swap(EquipSlot::Armor(ArmorSlot::Shoulders), item); self.with_equipment(EquipSlot::InactiveOffhand, item)
self }
fn with_armor(self, armor_slot: ArmorSlot, item: Option<Item>) -> Self {
self.with_equipment(EquipSlot::Armor(armor_slot), item)
} }
#[must_use] #[must_use]
pub fn chest(mut self, item: Option<Item>) -> Self { pub fn shoulder(self, item: Option<Item>) -> Self {
self.0.swap(EquipSlot::Armor(ArmorSlot::Chest), item); self.with_armor(ArmorSlot::Shoulders, item)
self
} }
#[must_use] #[must_use]
pub fn belt(mut self, item: Option<Item>) -> Self { pub fn chest(self, item: Option<Item>) -> Self { self.with_armor(ArmorSlot::Chest, item) }
self.0.swap(EquipSlot::Armor(ArmorSlot::Belt), item);
self #[must_use]
pub fn belt(self, item: Option<Item>) -> Self { self.with_armor(ArmorSlot::Belt, item) }
#[must_use]
pub fn hands(self, item: Option<Item>) -> Self { self.with_armor(ArmorSlot::Hands, item) }
#[must_use]
pub fn pants(self, item: Option<Item>) -> Self { self.with_armor(ArmorSlot::Legs, item) }
#[must_use]
pub fn feet(self, item: Option<Item>) -> Self { self.with_armor(ArmorSlot::Feet, item) }
#[must_use]
pub fn back(self, item: Option<Item>) -> Self { self.with_armor(ArmorSlot::Back, item) }
#[must_use]
pub fn ring1(self, item: Option<Item>) -> Self { self.with_armor(ArmorSlot::Ring1, item) }
#[must_use]
pub fn ring2(self, item: Option<Item>) -> Self { self.with_armor(ArmorSlot::Ring2, item) }
#[must_use]
pub fn neck(self, item: Option<Item>) -> Self { self.with_armor(ArmorSlot::Neck, item) }
#[must_use]
pub fn lantern(self, item: Option<Item>) -> Self {
self.with_equipment(EquipSlot::Lantern, item)
} }
#[must_use] #[must_use]
pub fn hands(mut self, item: Option<Item>) -> Self { pub fn glider(self, item: Option<Item>) -> Self { self.with_equipment(EquipSlot::Glider, item) }
self.0.swap(EquipSlot::Armor(ArmorSlot::Hands), item);
self
}
#[must_use] #[must_use]
pub fn pants(mut self, item: Option<Item>) -> Self { pub fn head(self, item: Option<Item>) -> Self { self.with_armor(ArmorSlot::Head, item) }
self.0.swap(EquipSlot::Armor(ArmorSlot::Legs), item);
self
}
#[must_use] #[must_use]
pub fn feet(mut self, item: Option<Item>) -> Self { pub fn tabard(self, item: Option<Item>) -> Self { self.with_armor(ArmorSlot::Tabard, item) }
self.0.swap(EquipSlot::Armor(ArmorSlot::Feet), item);
self
}
#[must_use] #[must_use]
pub fn back(mut self, item: Option<Item>) -> Self { pub fn bag(self, which: ArmorSlot, item: Option<Item>) -> Self { self.with_armor(which, item) }
self.0.swap(EquipSlot::Armor(ArmorSlot::Back), item);
self
}
#[must_use]
pub fn ring1(mut self, item: Option<Item>) -> Self {
self.0.swap(EquipSlot::Armor(ArmorSlot::Ring1), item);
self
}
#[must_use]
pub fn ring2(mut self, item: Option<Item>) -> Self {
self.0.swap(EquipSlot::Armor(ArmorSlot::Ring2), item);
self
}
#[must_use]
pub fn neck(mut self, item: Option<Item>) -> Self {
self.0.swap(EquipSlot::Armor(ArmorSlot::Neck), item);
self
}
#[must_use]
pub fn lantern(mut self, item: Option<Item>) -> Self {
self.0.swap(EquipSlot::Lantern, item);
self
}
#[must_use]
pub fn glider(mut self, item: Option<Item>) -> Self {
self.0.swap(EquipSlot::Glider, item);
self
}
#[must_use]
pub fn head(mut self, item: Option<Item>) -> Self {
self.0.swap(EquipSlot::Armor(ArmorSlot::Head), item);
self
}
#[must_use]
pub fn tabard(mut self, item: Option<Item>) -> Self {
self.0.swap(EquipSlot::Armor(ArmorSlot::Tabard), item);
self
}
#[must_use]
pub fn bag(mut self, which: ArmorSlot, item: Option<Item>) -> Self {
self.0.swap(EquipSlot::Armor(which), item);
self
}
#[must_use] #[must_use]
pub fn build(self) -> Loadout { self.0 } pub fn build(self) -> Loadout { self.0 }