|
|
|
@ -4,7 +4,6 @@ use crate::models::version::Version;
|
|
|
|
|
use crate::{DataError, DataResult};
|
|
|
|
|
use itertools::*;
|
|
|
|
|
use std::collections::HashMap;
|
|
|
|
|
use std::iter::FromIterator;
|
|
|
|
|
use std::sync::Arc;
|
|
|
|
|
|
|
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
@ -26,28 +25,30 @@ impl Enchantments {
|
|
|
|
|
|
|
|
|
|
/// Returns a map of enchantments indexed by ID
|
|
|
|
|
pub fn enchantments(&self) -> DataResult<HashMap<u32, Enchantment>> {
|
|
|
|
|
Ok(HashMap::from_iter(
|
|
|
|
|
self.enchantments_array()?.into_iter().map(|e| (e.id, e)),
|
|
|
|
|
))
|
|
|
|
|
Ok(self
|
|
|
|
|
.enchantments_array()?
|
|
|
|
|
.into_iter()
|
|
|
|
|
.map(|e| (e.id, e))
|
|
|
|
|
.collect())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Returns a map of enchantments indexed by Name
|
|
|
|
|
pub fn enchantments_by_name(&self) -> DataResult<HashMap<String, Enchantment>> {
|
|
|
|
|
Ok(HashMap::from_iter(
|
|
|
|
|
self.enchantments_array()?
|
|
|
|
|
.into_iter()
|
|
|
|
|
.map(|e| (e.name.clone(), e)),
|
|
|
|
|
))
|
|
|
|
|
Ok(self
|
|
|
|
|
.enchantments_array()?
|
|
|
|
|
.into_iter()
|
|
|
|
|
.map(|e| (e.name.clone(), e))
|
|
|
|
|
.collect())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Returns enchantments grouped by category
|
|
|
|
|
pub fn enchantments_by_category(&self) -> DataResult<HashMap<String, Vec<Enchantment>>> {
|
|
|
|
|
Ok(HashMap::from_iter(
|
|
|
|
|
self.enchantments_array()?
|
|
|
|
|
.into_iter()
|
|
|
|
|
.group_by(|e| e.category.clone())
|
|
|
|
|
.into_iter()
|
|
|
|
|
.map(|(key, group)| (key, group.collect())),
|
|
|
|
|
))
|
|
|
|
|
Ok(self
|
|
|
|
|
.enchantments_array()?
|
|
|
|
|
.into_iter()
|
|
|
|
|
.group_by(|e| e.category.clone())
|
|
|
|
|
.into_iter()
|
|
|
|
|
.map(|(key, group)| (key, group.collect()))
|
|
|
|
|
.collect())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|