Add label showing tool names

This commit is contained in:
Andrew Miner
2015-01-08 14:57:43 -08:00
parent fb3db0f393
commit 7954b86140
4 changed files with 24 additions and 3 deletions
@@ -32,6 +32,7 @@ module.exports = class CraftingTableController extends BaseController
@$next = @$('.next')
@$prev = @$('.prev')
@$tool = @$('.tool p')
super
refresh: ->
@@ -42,6 +43,8 @@ module.exports = class CraftingTableController extends BaseController
if @model.hasPrevStep then @$prev.addClass 'enabled'
if @model.hasNextStep then @$next.addClass 'enabled'
@$tool.html @model.toolNames
super
# Backbone.View Overrides ######################################################################
+10 -1
View File
@@ -15,6 +15,7 @@ module.exports = class CraftingTable extends BaseModel
constructor: (attributes={}, options={})->
if not attributes.plan? then throw new Error "attributes.plan is required"
attributes.grid ?= new CraftingGrid modPack:attributes.plan.modPack
attributes.modPack ?= attributes.plan.modPack
super attributes, options
@plan.on 'change', => @reset()
@@ -26,6 +27,7 @@ module.exports = class CraftingTable extends BaseModel
hasPrevStep: { get:@hasPrevStep }
hasSteps: { get:@hasSteps }
step: { get:@getStep, set:@setStep }
toolNames: { get:@getToolNames }
}
# Public Methods ###############################################################################
@@ -48,7 +50,7 @@ module.exports = class CraftingTable extends BaseModel
return @_step
setStep: (newStep)->
newStep = Math.max 0, Math.min @_steps.length, newStep
newStep = Math.max 0, Math.min @_steps.length - 1, newStep
@_step = newStep
@grid.recipe = @_steps[@_step]?.recipe
@@ -59,6 +61,13 @@ module.exports = class CraftingTable extends BaseModel
hasSteps: ->
return @_steps.length > 0
getToolNames: ->
recipe = @_steps[@_step]?.recipe
return '' unless recipe?
toolSlugs = (stack.itemSlug for stack in recipe.tools)
toolNames = (@modPack.findName(slug) for slug in toolSlugs).join ', '
return toolNames
# Object Overrides #############################################################################
toString: ->