#[allow(clippy::too_many_arguments)]
pub(crate) mod constructors;
#[allow(non_upper_case_globals)]
mod data;
pub use wow_world_base::tbc::{
AllowedClass, AllowedRace, Area, BagFamily, Bonding, Faction, Gold, InventoryType,
Item, ItemClassAndSubClass, ItemDamageType, ItemFlag, ItemQuality, ItemSet,
ItemSocket, ItemStat, Language, Map, PageTextMaterial, PvpRank, SheatheType,
Skill, SpellSchool, SpellTriggerType, Spells,
};
pub const fn lookup_item(id: u32) -> Option<&'static Item> {
if id < 17 || id > 39656 {
return None;
}
let index = data::Z________LOOKUP[(id - 17) as usize];
if index == u16::MAX || index as usize > (all_items().len() - 1) {
None
} else {
Some(&all_items()[index as usize])
}
}
pub const fn all_items() -> &'static [Item] {
data::Z________DATA
}
pub fn lookup_items_by_name(needle: &str) -> impl Iterator<Item = &'static Item> + '_ {
all_items().iter().filter(move |item| {
let lower = item.name().to_ascii_lowercase();
lower.contains(needle)
})
}
pub fn lookup_item_by_name(needle: &str) -> Option<&'static Item> {
let needle = needle.to_ascii_lowercase();
for item in all_items() {
let lower = item.name().to_ascii_lowercase();
if lower.contains(&needle) {
return Some(item)
}
}
None
}
#[cfg(test)]
mod test {
use super::lookup_item;
#[test]
fn tests() {
assert!(lookup_item(u32::MIN).is_none());
assert!(lookup_item(u32::MAX).is_none());
const MIN: u32 = 17;
const MAX: u32 = 39656;
assert_eq!(lookup_item(MIN).unwrap().entry(), MIN);
assert_eq!(lookup_item(MAX).unwrap().entry(), MAX);
assert!(lookup_item(MIN - 1).is_none());
assert!(lookup_item(MAX + 1).is_none());
for i in 0..=MAX + 10 {
match lookup_item(i) {
None => {}
Some(e) => assert_eq!(i, e.entry()),
}
}
}
}