diff --git a/common/src/comp/inventory/item/mod.rs b/common/src/comp/inventory/item/mod.rs index 32a0ba8bd2..2b932eed74 100644 --- a/common/src/comp/inventory/item/mod.rs +++ b/common/src/comp/inventory/item/mod.rs @@ -219,7 +219,9 @@ impl TagExampleInfo for Material { #[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)] pub enum ItemTag { + /// Used to indicate that an item is composed of this material Material(Material), + /// Used to indicate that an item is composed of this material kind MaterialKind(MaterialKind), Cultist, Potion, diff --git a/common/src/comp/inventory/item/modular.rs b/common/src/comp/inventory/item/modular.rs index 9793af1d57..e6522344b5 100644 --- a/common/src/comp/inventory/item/modular.rs +++ b/common/src/comp/inventory/item/modular.rs @@ -369,7 +369,7 @@ pub fn modify_name<'a>(item_name: &'a str, item: &'a Item) -> Cow<'a, str> { /// manifests in voxygen (Main component, material, hands) pub type ModularWeaponKey = (String, String, Hands); -pub fn weapon_to_key(mod_weap: &dyn ItemDesc) -> ModularWeaponKey { +pub fn weapon_to_key(mod_weap: impl ItemDesc) -> ModularWeaponKey { let hands = if let ItemKind::Tool(tool) = &*mod_weap.kind() { tool.hands } else { diff --git a/server/src/persistence/character/conversions.rs b/server/src/persistence/character/conversions.rs index 10bb54c36d..c80dc3c428 100644 --- a/server/src/persistence/character/conversions.rs +++ b/server/src/persistence/character/conversions.rs @@ -258,10 +258,12 @@ pub fn convert_waypoint_from_database_json( } // Used to handle cases of modular items that are composed of components. -// Returns a mutable reference to the parent of an item that is a component. If -// parent item is itself a component, recursively goes through inventory until -// it grabs component. -fn get_mutable_parent_item<'a, 'b, T>( +// When called with the index of a component's parent item, it can get a mutable +// reference to that parent item so that the component can be added to the +// parent item. If the item corresponding to the index this is called on is +// itself a component, recursively goes through inventory until it grabs +// component. +fn get_mutable_item<'a, 'b, T>( index: usize, inventory_items: &'a [Item], item_indices: &'a HashMap, @@ -271,14 +273,14 @@ fn get_mutable_parent_item<'a, 'b, T>( where 'b: 'a, { - // First checks if parent item is itself also a component, if it is, tries to - // get a mutable reference to itself by getting a mutable reference to the item - // that is its own parent + // First checks if item is a component, if it is, tries to get a mutable + // reference to itself by getting a mutable reference to the item that is its + // parent if inventory_items[index].position.contains("component_") { if let Some(parent) = item_indices .get(&inventory_items[index].parent_container_item_id) .and_then(move |i| { - get_mutable_parent_item( + get_mutable_item( *i, inventory_items, item_indices, @@ -294,9 +296,8 @@ where .split('_') .nth(1) .and_then(|s| s.parse::().ok()); - // Returns mutable reference to parent item of original item, by grabbing - // the component representing the parent item from the parent item's parent - // item + // Returns mutable reference to component item by accessing the component + // through its parent item item component_index.and_then(move |i| parent.persistence_access_mutable_component(i)) } else { None @@ -394,7 +395,7 @@ pub fn convert_inventory_from_database_items( )); } } else if let Some(&j) = item_indices.get(&db_item.parent_container_item_id) { - if let Some(parent) = get_mutable_parent_item( + if let Some(parent) = get_mutable_item( j, inventory_items, &item_indices, @@ -460,7 +461,7 @@ pub fn convert_loadout_from_database_items( .map_err(convert_error)?; } else if let Some(&j) = item_indices.get(&db_item.parent_container_item_id) { if let Some(parent) = - get_mutable_parent_item(j, database_items, &item_indices, &mut loadout, &|l, s| { + get_mutable_item(j, database_items, &item_indices, &mut loadout, &|l, s| { l.get_mut_item_at_slot_using_persistence_key(s).ok() }) { diff --git a/voxygen/src/hud/crafting.rs b/voxygen/src/hud/crafting.rs index bd0cc90d57..1450778326 100644 --- a/voxygen/src/hud/crafting.rs +++ b/voxygen/src/hud/crafting.rs @@ -28,7 +28,7 @@ use conrod_core::{ widget_ids, Color, Colorable, Labelable, Positionable, Sizeable, Widget, WidgetCommon, }; use i18n::Localization; -use std::{borrow::Cow, sync::Arc}; +use std::sync::Arc; use strum::{EnumIter, IntoEnumIterator}; @@ -464,22 +464,23 @@ impl<'a> Widget for Crafting<'a> { .all(|&substring| output_name.contains(substring)) }, SearchFilter::Input => recipe.inputs().any(|(input, _, _)| { - let input_name = match input { - RecipeInput::Item(def) => def.name(), - RecipeInput::Tag(tag) => Cow::Borrowed(tag.name()), - RecipeInput::TagSameItem(tag) => Cow::Borrowed(tag.name()), - // Works, but probably will have some...interesting false positives - // Code reviewers probably required to do magic to make not hacky + let search = |input_name: &str| { + let input_name = input_name.to_lowercase(); + search_keys + .iter() + .all(|&substring| input_name.contains(substring)) + }; + + match input { + RecipeInput::Item(def) => search(&def.name()), + RecipeInput::Tag(tag) => search(tag.name()), + RecipeInput::TagSameItem(tag) => search(tag.name()), RecipeInput::ListSameItem(defs) => { - Cow::Owned(defs.iter().map(|def| def.name()).collect()) + defs.iter().any(|def| search(&def.name())) }, } - .to_lowercase(); - search_keys - .iter() - .all(|&substring| input_name.contains(substring)) }), - _ => false, + SearchFilter::Nonexistant => false, }) .map(|(name, recipe)| { let has_materials = self.client.available_recipes().get(name.as_str()).is_some(); diff --git a/voxygen/src/ui/widgets/item_tooltip.rs b/voxygen/src/ui/widgets/item_tooltip.rs index 5598ce285e..21af8ca104 100644 --- a/voxygen/src/ui/widgets/item_tooltip.rs +++ b/voxygen/src/ui/widgets/item_tooltip.rs @@ -471,7 +471,7 @@ impl<'a> Widget for ItemTooltip<'a> { let item_kind = util::kind_text(item, i18n).to_string(); let material = item.tags().iter().find_map(|t| match t { - ItemTag::Material(material) => Some(material), + ItemTag::MaterialKind(material) => Some(material), _ => None, }); @@ -479,7 +479,7 @@ impl<'a> Widget for ItemTooltip<'a> { format!( "{} ({})", item_kind, - util::material_kind_text(&material.material_kind(), i18n) + util::material_kind_text(material, i18n) ) } else { item_kind