Display error state when calculation is impossible

This commit is contained in:
Andrew Miner
2015-11-10 20:32:20 -08:00
parent ff398b4a2f
commit 05d1f39464
3 changed files with 30 additions and 15 deletions
@@ -8,6 +8,7 @@ All rights reserved.
_ = require 'underscore'
AdsenseController = require './adsense_controller'
CraftPage = require '../models/craft_page'
Craftsman = require '../models/crafting/craftsman'
CraftsmanWorkingController = require './craftsman_working_controller'
{Event} = require '../constants'
InventoryController = require './inventory_controller'
@@ -144,21 +145,24 @@ module.exports = class CraftPageController extends PageController
_refreshSectionVisibility: ->
return unless @_rendered
toShow = []
toHide = []
if @model.craftsman.want.isEmpty
for $el in [@$toolsSection, @$ingredientsSection, @$stepsSection]
@hide $el
@show @$instructionsSection
@hide @$workingSection
toShow.push el for el in [@$instructionsSection]
toHide.push el for el in [@$toolsSection, @$ingredientsSection, @$stepsSection, @$workingSection]
else if @model.craftsman.stage is Craftsman::STAGE.INVALID
toShow.push el for el in [@$workingSection]
toHide.push el for el in [@$instructionsSection, @$toolsSection, @$ingredientsSection, @$stepsSection]
else if not @model.craftsman.complete
for $el in [@$toolsSection, @$ingredientsSection, @$stepsSection]
@hide $el
@hide @$instructionsSection
@show @$workingSection
toShow.push el for el in [@$workingSection]
toHide.push el for el in [@$instructionsSection, @$toolsSection, @$ingredientsSection, @$stepsSection]
else
for $el in [@$toolsSection, @$ingredientsSection, @$stepsSection]
@show $el
@hide @$instructionsSection
@hide @$workingSection
toShow.push el for el in [@$toolsSection, @$ingredientsSection, @$stepsSection]
toHide.push el for el in [@$instructionsSection, @$workingSection]
@show $el for $el in toShow
@hide $el for $el in toHide
_refreshSteps: ->
steps = @model.craftsman.plan?.steps or []
@@ -25,6 +25,7 @@ module.exports = class CraftsmanWorkingController extends BaseController
onDidRender: ->
@$message = @$('.message p')
@$count = @$('.count p')
@$waiting = @$('.waiting')
super
refresh: ->
@@ -36,6 +37,7 @@ module.exports = class CraftsmanWorkingController extends BaseController
_refreshStatusText: ->
return unless @$message? and @$count?
waitingVisible = true
switch @model.stage
when Craftsman::STAGE.WAITING
@$message.html 'Preparing crafting calculation...'
@@ -52,3 +54,9 @@ module.exports = class CraftsmanWorkingController extends BaseController
when Craftsman::STAGE.COMPLETE
@$message.html 'All done!'
@$count.html ''
when Craftsman::STAGE.INVALID
@$message.html 'Couldn\'t make a crafting plan'
@$count.html ''
waitingVisible = false
if waitingVisible then @show @$waiting else @hide @$waiting
+6 -3
View File
@@ -30,6 +30,7 @@ module.exports = class Craftsman extends BaseModel
PLANNING: 'computing plans'
ANALYZING: 'analyzing plans'
COMPLETE: 'complete'
INVALID: 'invalid'
constructor: (modPack)->
if not modPack? then throw new Error 'modPack is required'
@@ -41,7 +42,7 @@ module.exports = class Craftsman extends BaseModel
@_modPack = modPack
reset = _.throttle (=> @reset()), 100
reset = _.debounce (=> @reset()), 100
@_have = new Inventory modPack:@_modPack
@_have.on Event.change, reset
@@ -71,6 +72,9 @@ module.exports = class Craftsman extends BaseModel
else if not @_graphBuilder.complete
@_graphBuilder.expandGraph @GRAPH_STEP_INCREMENT
@stageCount = @_graphBuilder.stepCount
else if not @_graphBuilder.rootNode.valid
@stage = @STAGE.INVALID
@stageCount = 0
else if not @_planBuilder?
logger.debug => "Craftsman finished computing graph:\n#{@_graphBuilder.rootNode}"
@@ -92,7 +96,6 @@ module.exports = class Craftsman extends BaseModel
@_planEvaluator.findBestPlan PlanEvaluator::CRITERIA.FEWEST_STEPS
@_planEvaluator.findBestPlan PlanEvaluator::CRITERIA.LEAST_MATERIALS
]
@_plans[0].computeRequired()
@stage = @STAGE.COMPLETE
@stageCount = 0
@@ -118,7 +121,7 @@ module.exports = class Craftsman extends BaseModel
Object.defineProperties @prototype,
complete:
get: -> @_plans?
get: -> @stage in [@STAGE.COMPLETE, @STAGE.INVALID]
have:
get: -> @_have