From cf9a76df21adb5fb4ec2bcd66d689128a15c8dc3 Mon Sep 17 00:00:00 2001 From: Andrew Miner Date: Thu, 8 Jan 2015 15:11:11 -0800 Subject: [PATCH] Fix algo. for compacting steps in a crafting plan --- src/scripts/models/crafting_table.coffee | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/scripts/models/crafting_table.coffee b/src/scripts/models/crafting_table.coffee index fb6e61c8a..aa037278b 100644 --- a/src/scripts/models/crafting_table.coffee +++ b/src/scripts/models/crafting_table.coffee @@ -76,18 +76,14 @@ module.exports = class CraftingTable extends BaseModel # Private Methods ############################################################################## _compactSteps: -> - @_steps = [] - currentStep = null + steps = {} for recipe in @plan.steps - if currentStep? - if currentStep.recipe.name is recipe.name - currentStep.multiplier += 1 - else - currentStep = null + step = steps[recipe.name] + if not step? + steps[recipe.name] = multiplier:1, recipe:recipe + else + step.multiplier += 1 - if not currentStep - currentStep = multiplier:1, recipe:recipe - @_steps.push currentStep - - return @_steps + @_steps = (step for name, step of steps) + return this