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