Fix modular crafting window showing an item output when it is not possible to craft two components together.

This commit is contained in:
Sam 2023-04-01 17:22:01 -04:00
parent 335fa514aa
commit 352d34557e
2 changed files with 10 additions and 6 deletions

View File

@ -392,7 +392,7 @@ pub enum ModularWeaponCreationError {
/// Check if hand restrictions are compatible.
///
/// If at least on of them is omitted, check is passed.
fn compatible_handndess(a: Option<Hands>, b: Option<Hands>) -> bool {
pub fn compatible_handndess(a: Option<Hands>, b: Option<Hands>) -> bool {
match (a, b) {
(Some(a), Some(b)) => a == b,
_ => true,

View File

@ -1122,15 +1122,19 @@ impl<'a> Widget for Crafting<'a> {
let output_item = match recipe_kind {
RecipeKind::ModularWeapon => {
if let Some((primary_comp, toolkind)) = primary_slot
if let Some((primary_comp, toolkind, hand_restriction)) = primary_slot
.invslot
.and_then(|slot| self.inventory.get(slot))
.and_then(|item| {
if let ItemKind::ModularComponent(
ModularComponent::ToolPrimaryComponent { toolkind, .. },
ModularComponent::ToolPrimaryComponent {
toolkind,
hand_restriction,
..
},
) = &*item.kind()
{
Some((item, *toolkind))
Some((item, *toolkind, *hand_restriction))
} else {
None
}
@ -1143,8 +1147,8 @@ impl<'a> Widget for Crafting<'a> {
matches!(
&*item.kind(),
ItemKind::ModularComponent(
ModularComponent::ToolSecondaryComponent { toolkind: toolkind_b, .. }
) if toolkind == *toolkind_b
ModularComponent::ToolSecondaryComponent { toolkind: toolkind_b, hand_restriction: hand_restriction_b, .. }
) if toolkind == *toolkind_b && modular::compatible_handndess(hand_restriction, *hand_restriction_b)
)
})
.map(|secondary_comp| {