Fix algo. for compacting steps in a crafting plan

This commit is contained in:
Andrew Miner
2015-01-08 15:11:11 -08:00
parent 7954b86140
commit cf9a76df21
+8 -12
View File
@@ -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