Added comments in areas that were lacking.

This commit is contained in:
Sam 2021-10-06 18:29:09 -04:00
parent 794b072d3e
commit 356057afc4
3 changed files with 12 additions and 23 deletions

View File

@ -804,14 +804,14 @@ impl Item {
.any(|tag| matches!(tag, ItemTag::SalvageInto(_)))
}
// Attempts to salvage an item, returning the salvaged items if salvageable,
// else the original item is not Theoretically supports returning multiple
// items, only returns one per tag in the item for now
// Attempts to salvage an item by consuming it, returns the salvaged items if
// salvageable, else the original item
pub fn try_salvage(self) -> Result<Vec<Item>, 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
.tags

View File

@ -37,6 +37,11 @@ impl Recipe {
let mut recipe_inputs = Vec::new();
let mut unsatisfied_requirements = Vec::new();
// Checks each input against a slot in the inventory. If the slot contains an
// item that fulfills the need of the input, takes from the inventory up to the
// quantity needed for the crafting input. If the item either cannot be used, or
// there is insufficient quantity, adds input and number of materials needed to
// unsatisfied requirements.
self.inputs
.iter()
.enumerate()
@ -65,10 +70,12 @@ impl Recipe {
}
});
// If there are no unsatisfied requirements, create the items produced by the
// recipe in the necessary quantity, else insert the ingredients back into the
// inventory
if unsatisfied_requirements.is_empty() {
let (item_def, quantity) = &self.output;
let crafted_item =
Item::new_from_item_def(Arc::clone(item_def), &[], ability_map, msm);
let crafted_item = Item::new_from_item_def(Arc::clone(item_def), &[], ability_map, msm);
let mut crafted_items = Vec::with_capacity(*quantity as usize);
for _ in 0..*quantity {
crafted_items.push(crafted_item.duplicate(ability_map, msm));

View File

@ -647,24 +647,6 @@ pub fn handle_inventory(server: &mut Server, entity: EcsEntity, manip: comp::Inv
comp::InventoryUpdate::new(comp::InventoryUpdateEvent::Craft),
);
}
// Drop the item if there wasn't enough space
// if let Some(Some((item, amount))) = craft_result {
// let ability_map = &state.ecs().read_resource::<AbilityMap>();
// let msm =
// state.ecs().read_resource::<MaterialStatManifest>();
// for _ in 0..amount {
// dropped_items.push((
// state
// .read_component_copied::<comp::Pos>(entity)
// .unwrap_or_default(),
// state
// .read_component_copied::<comp::Ori>(entity)
// .unwrap_or_default(),
// item.duplicate(ability_map, &msm),
// ));
// }
// }
},
comp::InventoryManip::Sort => {
inventory.sort();