Don't automatically recalculate crafting plans

Instead, any time a change is made which invalidates a crafting plan,
update the visual display to show that the plan is out of date, and
add some extra affordances to recalculate.
This commit is contained in:
Andrew Miner
2016-04-23 11:46:35 -07:00
parent f9b65dd892
commit 962165dc8e
14 changed files with 541 additions and 57 deletions
@@ -27,7 +27,7 @@ module.exports = class CraftingStep
addToolsTo: (targetInventory)->
for stack in @_recipe.tools
targetInventory.add stack.itemSlug, stack.quantity
targetInventory.add stack.itemSlug, stack.quantity, insert:true
completeInto: (targetInventory)->
for stack in @_recipe.output
+20 -14
View File
@@ -22,32 +22,30 @@ module.exports = class Craftsman extends BaseModel
@::PLAN_STEP_INCREMENT = 39
@::STAGE =
WAITING: 'waiting'
EMPTY: 'empty'
READY: 'ready'
GRAPHING: 'examining recipes'
PLANNING: 'computing plans'
ANALYZING: 'analyzing plans'
COMPLETE: 'complete'
INVALID: 'invalid'
OUTDATED: 'outdated'
constructor: (modPack)->
if not modPack? then throw new Error 'modPack is required'
attributes =
paused: false
stage: @STAGE.WAITING
stage: @STAGE.READY
stageCount: 0
super attributes, {}
@_modPack = modPack
reset = _.debounce (=> @reset()), 100
@_have = new Inventory modPack:@_modPack
@_have.on c.event.change, reset
@_have.on c.event.change, => @_resetStage()
@_want = new Inventory modPack:@_modPack
@_want.on c.event.change, reset
@_want.on c.event.change, => @_resetStage()
@on c.event.change + ':paused', reset
@on c.event.change + ':stage', => logger.info "Craftsman has started #{@stage}..."
@on 'scheduleNextWork', => @_scheduleNextWork()
@reset()
@@ -60,10 +58,7 @@ module.exports = class Craftsman extends BaseModel
@_planEvaluator = null
@_plans = null
@stage = @STAGE.WAITING
@stageCount = 0
@_scheduleNextWork()
@_resetStage()
work: ->
return if @_want.isEmpty
@@ -121,7 +116,7 @@ module.exports = class Craftsman extends BaseModel
Object.defineProperties @prototype,
complete:
get: -> @stage in [@STAGE.COMPLETE, @STAGE.INVALID]
get: -> @stage in [@STAGE.COMPLETE, @STAGE.INVALID, @STAGE.OUTDATED]
have:
get: -> @_have
@@ -134,8 +129,19 @@ module.exports = class Craftsman extends BaseModel
# Private Methods ##############################################################################
_resetStage: ->
@stageCount = 0
if @want.isEmpty
if @stage isnt @STAGE.EMPTY
@stage = @STAGE.EMPTY
@reset()
else if not @_plans?
@stage = @STAGE.READY
else
@stage = @STAGE.OUTDATED
_scheduleNextWork: ->
return if @paused
return if @want.isEmpty
return if @complete
+8 -4
View File
@@ -29,10 +29,10 @@ module.exports = class Inventory extends BaseModel
# Public Methods ###############################################################################
add: (itemSlug, quantity=1)->
add: (itemSlug, quantity=1, options={})->
return this unless quantity > 0
@_add itemSlug, quantity
@_add itemSlug, quantity, options
@trigger c.event.add, this, itemSlug, quantity
@trigger c.event.change, this
return this
@@ -209,7 +209,8 @@ module.exports = class Inventory extends BaseModel
# Private Methods ##############################################################################
_add: (itemSlug, quantity=1)->
_add: (itemSlug, quantity=1, options={})->
options.insert ?= false
return unless itemSlug?
return unless quantity > 0
@@ -218,7 +219,10 @@ module.exports = class Inventory extends BaseModel
stack = new Stack itemSlug:itemSlug, quantity:quantity
@listenTo stack, c.event.change, => @trigger c.event.change, this
@_stacks[itemSlug] = stack
@_itemSlugs.push itemSlug
if options.insert
@_itemSlugs.unshift itemSlug
else
@_itemSlugs.push itemSlug
@_sort()
else
stack.quantity += quantity
+1
View File
@@ -40,6 +40,7 @@ module.exports = class CraftPage extends BaseModel
inventory.each (stack)=>
item = @modPack.findItem stack.itemSlug, enableAsNeeded:true
return unless item? and item.isCraftable
@craftsman.want.add stack.itemSlug, stack.quantity
inventory.remove stack.itemSlug