Allow item stacks as input for recipes

* Create the SlotController and refactor it into the various places
  where a crafting grid or crafting output is displayed
* Update the Recipe model to allow each "input" stack to retain the
  count indicated in the data file. This required changing how a few
  other classes interact with it in order for them to get the full
  stack back again for each input (instead of just getting the item
  slug)
* Update the ModVersionParser to allow for full stacks to be given
  as input and refactored common code out for handling input/output/
  tools stacks
This commit is contained in:
Andrew Miner
2015-04-07 19:21:02 -07:00
parent 2ba4dca95b
commit 144aa1bf32
17 changed files with 244 additions and 3426 deletions
@@ -0,0 +1,58 @@
###
Crafting Guide - slot_controller.coffee
Copyright (c) 2015 by Redwood Labs
All rights reserved.
###
BaseController = require './base_controller'
########################################################################################################################
module.exports = class SlotController extends BaseController
constructor: (options={})->
if not options.imageLoader? then throw new Error 'options.imageLoader is required'
if not options.modPack? then throw new Error 'options.modPack is required'
# options.model should be a Stack
options.templateName = 'slot'
options.useAnimations = false
super options
@imageLoader = options.imageLoader
@modPack = options.modPack
# BaseController Overrides #####################################################################
onDidRender: ->
@$link = @$('a')
@$image = @$('img')
@$quantity = @$('.quantity')
super
refresh: ->
if @model?
display = @modPack.findItemDisplay @model.itemSlug
@$link.attr 'href', display.itemUrl
@imageLoader.load display.iconUrl, @$image
@show @$image
if @model.quantity > 1
@$quantity.html @model.quantity
else
@$quantity.html ''
else
@$link.removeAttr 'href'
@$quantity.html ''
@$image.removeAttr 'src'
@hide @$image
super
# Backbone.View Overrides ######################################################################
events: ->
return _.extend super,
'click a': 'routeLinkClick'