Fix bug where items with one plan don't get scored

This commit is contained in:
Andrew Miner
2015-11-15 13:01:33 -08:00
parent b65b18c975
commit 59fb8f507a
4 changed files with 26 additions and 13 deletions
@@ -100,6 +100,7 @@ module.exports = class CraftingPlan
result.push " #{stack}"
result.push "Start with:"
if @_need?
@_need.each (stack)->
result.push " #{stack}"
@@ -108,6 +109,7 @@ module.exports = class CraftingPlan
result.push " #{step}"
result.push "To produce:"
if @_made?
@_made.each (stack)->
result.push " #{stack}"
@@ -17,7 +17,7 @@ module.exports = class PlanEvaluator
if not plans? then throw new Error 'plans is required'
@_plans = plans
@_lastScored = 0
@_lastScored = -1
@_normalized = false
# Public Methods ###############################################################################
@@ -41,7 +41,7 @@ module.exports = class PlanEvaluator
return if @complete
maxPlanIndex = Math.min @_lastScored + count, @_plans.length - 1
for i in [@_lastScored..maxPlanIndex]
for i in [(@_lastScored + 1)..maxPlanIndex]
@_plans[i].computeRequired()
@_scorePlan @_plans[i]
@_lastScored = i
+1 -1
View File
@@ -90,7 +90,7 @@ module.exports = class Inventory extends BaseModel
if qualifiedSlug?
newSlugs.push qualifiedSlug
newStacks.push new Stack itemSlug:qualifiedSlug, stack.quantity
newStacks.push new Stack itemSlug:qualifiedSlug, quantity:stack.quantity
else
newSlugs.push itemSlug
newStacks.push stack
+14 -3
View File
@@ -66,20 +66,31 @@ module.exports = class SimpleInventory
localize: ->
if not @modPack? then throw new Error 'localize requires @modPack'
changed = false
newSlugs = []
newStacks = []
for itemSlug in @_itemSlugs
stack = @_stacks[itemSlug]
continue unless stack?
qualifiedSlug = if itemSlug.isQualified then itemSlug else null
if not qualifiedSlug?
qualifiedSlug = @modPack.findItem(itemSlug)?.slug
changed = qualifiedSlug?
if qualifiedSlug?
delete @_stacks[itemSlug]
newSlugs.push qualifiedSlug
@_stacks[qualifiedSlug] = stack
stack.itemSlug = qualifiedSlug
newStacks.push new Stack itemSlug:qualifiedSlug, quantity:stack.quantity
else
newSlugs.push itemSlug
newStacks.push stack
if changed
@_itemSlugs = newSlugs
@_stacks = {}
for stack in newStacks
@_stacks[stack.itemSlug] = stack
@_sort()
pop: ->