#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Manufacturer {
pub code: &'static str,
pub name: &'static str,
pub weapon_types: &'static [&'static str],
pub style: &'static str,
}
pub const MANUFACTURERS: &[Manufacturer] = &[
Manufacturer {
code: "BOR",
name: "Ripper",
weapon_types: &["SM", "SG", "HW", "SR"],
style: "Cult/organic aesthetics",
},
Manufacturer {
code: "DAD",
name: "Daedalus",
weapon_types: &["AR", "SM", "PS", "SG"],
style: "High-tech precision",
},
Manufacturer {
code: "JAK",
name: "Jakobs",
weapon_types: &["AR", "PS", "SG", "SR"],
style: "Old West, semi-auto, high damage per shot",
},
Manufacturer {
code: "MAL",
name: "Maliwan",
weapon_types: &["SM", "SG", "SR", "HW"],
style: "Elemental weapons, energy-based",
},
Manufacturer {
code: "ORD",
name: "Order",
weapon_types: &["AR", "PS", "SR"],
style: "Military precision",
},
Manufacturer {
code: "TED",
name: "Tediore",
weapon_types: &["AR", "PS", "SG", "SM"],
style: "Disposable, thrown on reload",
},
Manufacturer {
code: "TOR",
name: "Torgue",
weapon_types: &["AR", "PS", "SG", "HW"],
style: "Explosive/gyrojet rounds",
},
Manufacturer {
code: "VLA",
name: "Vladof",
weapon_types: &["AR", "SM", "SR", "HW"],
style: "High fire rate, large magazines",
},
Manufacturer {
code: "GRV",
name: "Gravitar",
weapon_types: &[],
style: "Class mods manufacturer",
},
];
pub fn manufacturer_by_code(code: &str) -> Option<&'static Manufacturer> {
MANUFACTURERS.iter().find(|m| m.code == code)
}
pub fn manufacturer_name_by_code(code: &str) -> Option<&'static str> {
manufacturer_by_code(code).map(|m| m.name)
}
pub fn manufacturer_by_name(name: &str) -> Option<&'static Manufacturer> {
MANUFACTURERS
.iter()
.find(|m| m.name.eq_ignore_ascii_case(name))
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_manufacturer_lookup() {
assert_eq!(manufacturer_by_code("JAK").map(|m| m.name), Some("Jakobs"));
assert_eq!(manufacturer_by_code("TOR").map(|m| m.name), Some("Torgue"));
assert_eq!(manufacturer_name_by_code("VLA"), Some("Vladof"));
}
#[test]
fn test_manufacturer_by_name() {
assert_eq!(manufacturer_by_name("Jakobs").map(|m| m.code), Some("JAK"));
assert_eq!(manufacturer_by_name("Torgue").map(|m| m.code), Some("TOR"));
assert_eq!(manufacturer_by_name("Vladof").map(|m| m.code), Some("VLA"));
assert!(manufacturer_by_name("Unknown").is_none());
}
}