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