From edb68601a3a048f388339eaf324146b3d6c6fe06 Mon Sep 17 00:00:00 2001 From: Avi Weinstock Date: Mon, 5 Apr 2021 10:37:51 -0400 Subject: [PATCH] Address MR 2062 comments: avoid an expect-equivalent pattern. --- common/src/comp/inventory/loadout_builder.rs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/common/src/comp/inventory/loadout_builder.rs b/common/src/comp/inventory/loadout_builder.rs index e66f740524..a4952be1e8 100644 --- a/common/src/comp/inventory/loadout_builder.rs +++ b/common/src/comp/inventory/loadout_builder.rs @@ -599,15 +599,12 @@ impl LoadoutBuilder { let mut item_with_amount = |item_id: &str, amount: &mut f32| { if *amount > 0.0 { let mut item = Item::new_from_asset_expect(&item_id); - if *amount > 1.0 && item.is_stackable() { - let n = rng.gen_range(0..amount.min(100.0) as u32).max(1); - item.set_amount(n).unwrap_or_else(|_| { - panic!("{} should be stackable (n={})", item_id, n) - }); - *amount -= n as f32; + let n = rng.gen_range(0..amount.min(100.0) as u32).max(1); + *amount -= if item.set_amount(n).is_ok() { + n as f32 } else { - *amount -= 1.0; - } + 1.0 + }; Some(item) } else { None