From 36da0cf981ba3c6110b516445fdfbedac0f53339 Mon Sep 17 00:00:00 2001 From: Sam Date: Sat, 20 Nov 2021 20:23:51 -0500 Subject: [PATCH] Removed inner toolkind from ModularBase::Tool. --- common/src/comp/inventory/item/mod.rs | 2 +- common/src/comp/inventory/item/modular.rs | 33 +++++++++++++++++------ common/src/recipe.rs | 6 ++--- 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/common/src/comp/inventory/item/mod.rs b/common/src/comp/inventory/item/mod.rs index 2a892ef2d9..03bb8555dc 100644 --- a/common/src/comp/inventory/item/mod.rs +++ b/common/src/comp/inventory/item/mod.rs @@ -405,7 +405,7 @@ where { Ok(match serialized_item_base { // TODO: Make this work - "modular" => ItemBase::Modular(ModularBase::Tool(ToolKind::Empty)), + "modular" => ItemBase::Modular(ModularBase::Tool), item_definition_id => { ItemBase::Raw(Arc::::load_expect_cloned(item_definition_id)) }, diff --git a/common/src/comp/inventory/item/modular.rs b/common/src/comp/inventory/item/modular.rs index 586d44e654..4531fd4903 100644 --- a/common/src/comp/inventory/item/modular.rs +++ b/common/src/comp/inventory/item/modular.rs @@ -11,13 +11,13 @@ use std::{borrow::Cow, sync::Arc}; #[derive(Clone, Debug, Serialize, Deserialize)] pub enum ModularBase { - Tool(ToolKind), + Tool, } impl ModularBase { pub(super) fn duplicate(&self) -> Self { match self { - ModularBase::Tool(toolkind) => ModularBase::Tool(*toolkind), + ModularBase::Tool => ModularBase::Tool, } } @@ -53,9 +53,20 @@ impl ModularBase { .fold(tool::Stats::one(), |a, b| a * b) } + let toolkind = components + .iter() + .find_map(|comp| match &*comp.kind() { + ItemKind::ModularComponent(ModularComponent::ToolPrimaryComponent { + toolkind, + .. + }) => Some(*toolkind), + _ => None, + }) + .unwrap_or(ToolKind::Empty); + match self { - ModularBase::Tool(toolkind) => Cow::Owned(ItemKind::Tool(tool::Tool { - kind: *toolkind, + ModularBase::Tool => Cow::Owned(ItemKind::Tool(tool::Tool { + kind: toolkind, hands: resolve_hands(components), stats: resolve_stats(components, msm), })), @@ -67,7 +78,7 @@ impl ModularBase { /// the damage component is created from. pub fn generate_name(&self, components: &[Item]) -> Cow { match self { - ModularBase::Tool(_toolkind) => { + ModularBase::Tool => { let name = components .iter() .find_map(|comp| match &*comp.kind() { @@ -101,9 +112,15 @@ impl ModularBase { .fold(Quality::Low, |a, b| a.max(b.quality())) } - pub fn ability_spec(&self, _components: &[Item]) -> Option> { + pub fn ability_spec(&self, components: &[Item]) -> Option> { match self { - ModularBase::Tool(toolkind) => Some(Cow::Owned(AbilitySpec::Tool(*toolkind))), + ModularBase::Tool => components.iter().find_map(|comp| match &*comp.kind() { + ItemKind::ModularComponent(ModularComponent::ToolPrimaryComponent { + toolkind, + .. + }) => Some(Cow::Owned(AbilitySpec::Tool(*toolkind))), + _ => None, + }), } } } @@ -329,7 +346,7 @@ pub fn random_weapon( // Create modular weapon let components = vec![primary_component, secondary_component]; Ok(Item::new_from_item_base( - ItemBase::Modular(ModularBase::Tool(tool)), + ItemBase::Modular(ModularBase::Tool), &components, &ability_map, &msm, diff --git a/common/src/recipe.rs b/common/src/recipe.rs index 610241b558..efe5412e35 100644 --- a/common/src/recipe.rs +++ b/common/src/recipe.rs @@ -288,7 +288,7 @@ pub fn modular_weapon( let hands_check = hands_a.map_or(true, |hands| hands_b.map_or(true, |hands2| hands == hands2)); if hands_check { - Ok(tool_a) + Ok(()) } else { Err(ModularWeaponError::DifferentHands) } @@ -303,7 +303,7 @@ pub fn modular_weapon( }; match compatiblity { - Ok(tool_kind) => { + Ok(()) => { // Remove components from inventory let primary_component = inv .take(primary_component, ability_map, msm) @@ -315,7 +315,7 @@ pub fn modular_weapon( // Create modular weapon let components = vec![primary_component, secondary_component]; Ok(Item::new_from_item_base( - ItemBase::Modular(modular::ModularBase::Tool(tool_kind)), + ItemBase::Modular(modular::ModularBase::Tool), &components, ability_map, msm,