#[allow(clippy::too_many_arguments)]
pub(crate) mod constructors;
#[allow(non_upper_case_globals)]
mod data;
pub use wow_world_base::tbc::{
AuraMod, Reagent, Spell, SpellEffects, Totem, TotemCategory,
};
pub const fn lookup_spell(id: u32) -> Option<&'static Spell> {
if id < 1 || id > 53085 {
return None;
}
let index = data::Z________LOOKUP[(id - 1) as usize];
if index == u16::MAX || index as usize > (all_spells().len() - 1) {
None
} else {
Some(&all_spells()[index as usize])
}
}
pub const fn all_spells() -> &'static [Spell] {
data::Z________DATA
}
pub fn lookup_spells_by_name(needle: &str) -> impl Iterator<Item = &'static Spell> + '_ {
all_spells().iter().filter(move |spell| {
let lower = spell.spell_name().to_ascii_lowercase();
lower.contains(needle)
})
}
pub fn lookup_spell_by_name(needle: &str) -> Option<&'static Spell> {
let needle = needle.to_ascii_lowercase();
for spell in all_spells() {
let lower = spell.spell_name().to_ascii_lowercase();
if lower.contains(&needle) {
return Some(spell)
}
}
None
}
#[cfg(test)]
mod test {
use super::lookup_spell;
#[test]
fn tests() {
assert!(lookup_spell(u32::MIN).is_none());
assert!(lookup_spell(u32::MAX).is_none());
const MIN: u32 = 1;
const MAX: u32 = 53085;
assert_eq!(lookup_spell(MIN).unwrap().entry(), MIN);
assert_eq!(lookup_spell(MAX).unwrap().entry(), MAX);
assert!(lookup_spell(MIN - 1).is_none());
assert!(lookup_spell(MAX + 1).is_none());
for i in 0..=MAX + 10 {
match lookup_spell(i) {
None => {}
Some(e) => assert_eq!(i, e.entry()),
}
}
}
}