Merge branch 'sam/fix-modular-craft' into 'master'

Fix modular output item showing an item for disallowed combinations

See merge request veloren/veloren!3852
This commit is contained in:
Samuel Keiffer 2023-04-01 23:01:05 +00:00
commit f2419e2920
2 changed files with 15 additions and 11 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_handedness(a: Option<Hands>, b: Option<Hands>) -> bool {
match (a, b) {
(Some(a), Some(b)) => a == b,
_ => true,
@ -416,7 +416,7 @@ pub fn generate_weapon_primary_components(
.get(&(tool, material_id.to_owned()))
.into_iter()
.flatten()
.filter(|(_comp, hand)| compatible_handndess(hand_restriction, *hand))
.filter(|(_comp, hand)| compatible_handedness(hand_restriction, *hand))
.map(|(c, h)| (c.duplicate(ability_map, msm), hand_restriction.or(*h)))
.collect())
} else {
@ -450,7 +450,7 @@ pub fn random_weapon_primary_component(
.get(&(tool, material_id.to_owned()))
.into_iter()
.flatten()
.filter(|(_comp, hand)| compatible_handndess(hand_restriction, *hand))
.filter(|(_comp, hand)| compatible_handedness(hand_restriction, *hand))
.collect::<Vec<_>>();
let (comp, hand) = primary_components
@ -490,8 +490,8 @@ pub fn generate_weapons(
.get(&tool)
.into_iter()
.flatten()
.filter(|(_def, hand)| compatible_handndess(hand_restriction, *hand))
.filter(|(_def, hand)| compatible_handndess(comp_hand, *hand));
.filter(|(_def, hand)| compatible_handedness(hand_restriction, *hand))
.filter(|(_def, hand)| compatible_handedness(comp_hand, *hand));
for (def, _hand) in secondaries {
let secondary = Item::new_from_item_base(
@ -532,7 +532,7 @@ pub fn random_weapon(
.get(&tool)
.into_iter()
.flatten()
.filter(|(_def, hand)| compatible_handndess(hand_restriction, *hand))
.filter(|(_def, hand)| compatible_handedness(hand_restriction, *hand))
.collect::<Vec<_>>();
let secondary_component = {

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_handedness(hand_restriction, *hand_restriction_b)
)
})
.map(|secondary_comp| {