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 " #{stack}"
result.push "Start with:" result.push "Start with:"
if @_need?
@_need.each (stack)-> @_need.each (stack)->
result.push " #{stack}" result.push " #{stack}"
@@ -108,6 +109,7 @@ module.exports = class CraftingPlan
result.push " #{step}" result.push " #{step}"
result.push "To produce:" result.push "To produce:"
if @_made?
@_made.each (stack)-> @_made.each (stack)->
result.push " #{stack}" result.push " #{stack}"
@@ -17,7 +17,7 @@ module.exports = class PlanEvaluator
if not plans? then throw new Error 'plans is required' if not plans? then throw new Error 'plans is required'
@_plans = plans @_plans = plans
@_lastScored = 0 @_lastScored = -1
@_normalized = false @_normalized = false
# Public Methods ############################################################################### # Public Methods ###############################################################################
@@ -41,7 +41,7 @@ module.exports = class PlanEvaluator
return if @complete return if @complete
maxPlanIndex = Math.min @_lastScored + count, @_plans.length - 1 maxPlanIndex = Math.min @_lastScored + count, @_plans.length - 1
for i in [@_lastScored..maxPlanIndex] for i in [(@_lastScored + 1)..maxPlanIndex]
@_plans[i].computeRequired() @_plans[i].computeRequired()
@_scorePlan @_plans[i] @_scorePlan @_plans[i]
@_lastScored = i @_lastScored = i
+1 -1
View File
@@ -90,7 +90,7 @@ module.exports = class Inventory extends BaseModel
if qualifiedSlug? if qualifiedSlug?
newSlugs.push qualifiedSlug newSlugs.push qualifiedSlug
newStacks.push new Stack itemSlug:qualifiedSlug, stack.quantity newStacks.push new Stack itemSlug:qualifiedSlug, quantity:stack.quantity
else else
newSlugs.push itemSlug newSlugs.push itemSlug
newStacks.push stack newStacks.push stack
+14 -3
View File
@@ -66,20 +66,31 @@ module.exports = class SimpleInventory
localize: -> localize: ->
if not @modPack? then throw new Error 'localize requires @modPack' if not @modPack? then throw new Error 'localize requires @modPack'
changed = false
newSlugs = [] newSlugs = []
newStacks = []
for itemSlug in @_itemSlugs for itemSlug in @_itemSlugs
stack = @_stacks[itemSlug] stack = @_stacks[itemSlug]
continue unless stack?
qualifiedSlug = if itemSlug.isQualified then itemSlug else null
if not qualifiedSlug?
qualifiedSlug = @modPack.findItem(itemSlug)?.slug qualifiedSlug = @modPack.findItem(itemSlug)?.slug
changed = qualifiedSlug?
if qualifiedSlug? if qualifiedSlug?
delete @_stacks[itemSlug]
newSlugs.push qualifiedSlug newSlugs.push qualifiedSlug
@_stacks[qualifiedSlug] = stack newStacks.push new Stack itemSlug:qualifiedSlug, quantity:stack.quantity
stack.itemSlug = qualifiedSlug
else else
newSlugs.push itemSlug newSlugs.push itemSlug
newStacks.push stack
if changed
@_itemSlugs = newSlugs @_itemSlugs = newSlugs
@_stacks = {}
for stack in newStacks
@_stacks[stack.itemSlug] = stack
@_sort() @_sort()
pop: -> pop: ->