Files
website/src/coffee/controllers/craftsman_working_controller.coffee
T

63 lines
2.2 KiB
CoffeeScript

###
Crafting Guide - crafting_grid_controller.coffee
Copyright (c) 2015 by Redwood Labs
All rights reserved.
###
BaseController = require './base_controller'
Craftsman = require '../models/crafting/craftsman'
{Event} = require '../constants'
########################################################################################################################
module.exports = class CraftsmanWorkingController extends BaseController
constructor: (options={})->
if not options.model then throw new Error 'options.model is required'
options.templateName = 'craftsman_working'
super options
@model.on Event.change, => @_refreshStatusText()
# BaseController Methods #######################################################################
onDidRender: ->
@$message = @$('.message p')
@$count = @$('.count p')
@$waiting = @$('.waiting')
super
refresh: ->
@_refreshStatusText()
super
# Private Methods ##############################################################################
_refreshStatusText: ->
return unless @$message? and @$count?
waitingVisible = true
switch @model.stage
when Craftsman::STAGE.WAITING
@$message.html 'Preparing crafting calculation...'
@$count.html ''
when Craftsman::STAGE.GRAPHING
@$message.html 'Researching recipes...'
@$count.html "Found #{@model.stageCount} recipes so far..."
when Craftsman::STAGE.PLANNING
@$message.html 'Figuring out possible crafting plans...'
@$count.html "Found #{@model.stageCount} possibilities so far..."
when Craftsman::STAGE.ANALYZING
@$message.html 'Looking for the best plan...'
@$count.html "Finished checking #{@model.stageCount} so far..."
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