mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Addressed review comments
This commit is contained in:
parent
d6ac9c43d7
commit
85c2a85817
@ -337,12 +337,15 @@ pub enum ModularWeaponCreationError {
|
||||
}
|
||||
|
||||
/// Creates a random modular weapon primary component when provided with a
|
||||
/// toolkind, material, and optionally the handedness Note: The component
|
||||
/// produced is not necessarily restricted to that handedness, but rather is
|
||||
/// able to produce a weapon of that handedness depending on what secondary
|
||||
/// component is used Returns the comptabile handednesses that can be used with
|
||||
/// provided restriction and generated component (useful for cases where no
|
||||
/// restriction was passed in, but generated component has a restriction)
|
||||
/// toolkind, material, and optionally the handedness
|
||||
///
|
||||
/// Note: The component produced is not necessarily restricted to that
|
||||
/// handedness, but rather is able to produce a weapon of that handedness
|
||||
/// depending on what secondary component is used
|
||||
///
|
||||
/// Returns the comptabile handednesses that can be used with provided
|
||||
/// restriction and generated component (useful for cases where no restriction
|
||||
/// was passed in, but generated component has a restriction)
|
||||
pub fn random_weapon_primary_component(
|
||||
tool: ToolKind,
|
||||
material: Material,
|
||||
|
@ -238,7 +238,6 @@ fn commit_trade(ecs: &specs::World, trade: &PendingTrade) -> TradeResult {
|
||||
}
|
||||
|
||||
// Hashmap to compute merged stackable stacks, including overflow checks
|
||||
// TODO: add a ComponentKey struct to compare items properly, see issue #1226
|
||||
let mut stackable_items: HashMap<ItemDefinitionIdOwned, TradeQuantities> = HashMap::new();
|
||||
for who in [0, 1].iter().cloned() {
|
||||
for (slot, quantity) in trade.offers[who].iter() {
|
||||
|
@ -886,26 +886,22 @@ impl<'a> Widget for Crafting<'a> {
|
||||
invslot: self.show.crafting_fields.recipe_inputs.get(&0).copied(),
|
||||
requirement: match recipe_kind {
|
||||
RecipeKind::ModularWeapon => |item, _, _| {
|
||||
item.map_or(false, |item| {
|
||||
matches!(
|
||||
&*item.kind(),
|
||||
ItemKind::ModularComponent(
|
||||
ModularComponent::ToolPrimaryComponent { .. }
|
||||
)
|
||||
matches!(
|
||||
&*item.kind(),
|
||||
ItemKind::ModularComponent(
|
||||
ModularComponent::ToolPrimaryComponent { .. }
|
||||
)
|
||||
})
|
||||
)
|
||||
},
|
||||
RecipeKind::Component(_) => |item, comp_recipes, info| {
|
||||
if let Some(CraftSlotInfo::Tool(toolkind)) = info {
|
||||
item.map_or(false, |item| {
|
||||
comp_recipes
|
||||
.iter()
|
||||
.filter(|(key, _)| key.toolkind == toolkind)
|
||||
.any(|(key, _)| {
|
||||
Some(key.material.as_str())
|
||||
== item.item_definition_id().itemdef_id()
|
||||
})
|
||||
})
|
||||
comp_recipes
|
||||
.iter()
|
||||
.filter(|(key, _)| key.toolkind == toolkind)
|
||||
.any(|(key, _)| {
|
||||
Some(key.material.as_str())
|
||||
== item.item_definition_id().itemdef_id()
|
||||
})
|
||||
} else {
|
||||
false
|
||||
}
|
||||
@ -977,26 +973,22 @@ impl<'a> Widget for Crafting<'a> {
|
||||
invslot: self.show.crafting_fields.recipe_inputs.get(&1).copied(),
|
||||
requirement: match recipe_kind {
|
||||
RecipeKind::ModularWeapon => |item, _, _| {
|
||||
item.map_or(false, |item| {
|
||||
matches!(
|
||||
&*item.kind(),
|
||||
ItemKind::ModularComponent(
|
||||
ModularComponent::ToolSecondaryComponent { .. }
|
||||
)
|
||||
matches!(
|
||||
&*item.kind(),
|
||||
ItemKind::ModularComponent(
|
||||
ModularComponent::ToolSecondaryComponent { .. }
|
||||
)
|
||||
})
|
||||
)
|
||||
},
|
||||
RecipeKind::Component(_) => |item, comp_recipes, info| {
|
||||
if let Some(CraftSlotInfo::Tool(toolkind)) = info {
|
||||
item.map_or(false, |item| {
|
||||
comp_recipes
|
||||
.iter()
|
||||
.filter(|(key, _)| key.toolkind == toolkind)
|
||||
.any(|(key, _)| {
|
||||
key.modifier.as_deref()
|
||||
== item.item_definition_id().itemdef_id()
|
||||
})
|
||||
})
|
||||
comp_recipes
|
||||
.iter()
|
||||
.filter(|(key, _)| key.toolkind == toolkind)
|
||||
.any(|(key, _)| {
|
||||
key.modifier.as_deref()
|
||||
== item.item_definition_id().itemdef_id()
|
||||
})
|
||||
} else {
|
||||
false
|
||||
}
|
||||
|
@ -3475,13 +3475,13 @@ impl Hud {
|
||||
}
|
||||
} else if let (Inventory(i), Crafting(c)) = (a, b) {
|
||||
// Add item to crafting input
|
||||
if (c.requirement)(
|
||||
inventories
|
||||
.get(client.entity())
|
||||
.and_then(|inv| inv.get(i.slot)),
|
||||
client.component_recipe_book(),
|
||||
c.info,
|
||||
) {
|
||||
if inventories
|
||||
.get(client.entity())
|
||||
.and_then(|inv| inv.get(i.slot))
|
||||
.map_or(false, |item| {
|
||||
(c.requirement)(item, client.component_recipe_book(), c.info)
|
||||
})
|
||||
{
|
||||
self.show
|
||||
.crafting_fields
|
||||
.recipe_inputs
|
||||
|
@ -243,7 +243,7 @@ impl<'a> SlotKey<AbilitiesSource<'a>, img_ids::Imgs> for AbilitySlot {
|
||||
pub struct CraftSlot {
|
||||
pub index: u32,
|
||||
pub invslot: Option<InvSlotId>,
|
||||
pub requirement: fn(Option<&Item>, &ComponentRecipeBook, Option<CraftSlotInfo>) -> bool,
|
||||
pub requirement: fn(&Item, &ComponentRecipeBook, Option<CraftSlotInfo>) -> bool,
|
||||
pub info: Option<CraftSlotInfo>,
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user