From 6ff7317e056beb96bb7223991c75560bb666b4b6 Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 11 Oct 2021 19:29:50 -0400 Subject: [PATCH] Added function that returns the output of salvaging an item when result just needs to be checked. --- common/src/comp/inventory/item/mod.rs | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/common/src/comp/inventory/item/mod.rs b/common/src/comp/inventory/item/mod.rs index eb6eec9cc6..19a38f3a00 100644 --- a/common/src/comp/inventory/item/mod.rs +++ b/common/src/comp/inventory/item/mod.rs @@ -804,16 +804,8 @@ impl Item { .any(|tag| matches!(tag, ItemTag::SalvageInto(_))) } - // Attempts to salvage an item by consuming it, returns the salvaged items if - // salvageable, else the original item - pub fn try_salvage(self) -> Result, Item> { - if !self.is_salvageable() { - return Err(self); - } - - // Creates one item for every salvage tag in the target item - let salvaged_items: Vec<_> = self - .item_def + pub fn salvage_output(&self) -> impl Iterator { + self.item_def .tags .iter() .filter_map(|tag| { @@ -824,6 +816,18 @@ impl Item { } }) .map(|material| material.asset_identifier()) + } + + // Attempts to salvage an item by consuming it, returns the salvaged items if + // salvageable, else the original item + pub fn try_salvage(self) -> Result, Item> { + if !self.is_salvageable() { + return Err(self); + } + + // Creates one item for every salvage tag in the target item + let salvaged_items: Vec<_> = self + .salvage_output() .map(|asset| Item::new_from_asset_expect(asset)) .collect();