Move all /item URLs to /crafting

This commit is contained in:
Andrew Miner
2015-02-07 12:37:44 -08:00
parent 4c5d1256bc
commit 0f73fc18a0
9 changed files with 49 additions and 48 deletions
-48
View File
@@ -1,48 +0,0 @@
###
Crafting Guide - item_page.coffee
Copyright (c) 2014-2015 by Redwood Labs
All rights reserved.
###
BaseModel = require './base_model'
CraftingPlan = require './crafting_plan'
CraftingTable = require './crafting_table'
{Event} = require '../constants'
InventoryParser = require './inventory_parser'
ModPack = require './mod_pack'
########################################################################################################################
module.exports = class ItemPage extends BaseModel
constructor: (attributes={}, options={})->
attributes.modPack ?= new ModPack
attributes.params ?= null
attributes.plan ?= new CraftingPlan modPack:attributes.modPack
attributes.table ?= new CraftingTable plan:attributes.plan
super attributes, options
@_parser = new InventoryParser
@modPack.on Event.change, => @_consumeParams()
@on Event.change + ':params', => @_consumeParams()
# Private Methods ##############################################################################
_consumeParams: ->
return unless @params?
@plan.want.clear()
if not @params.inventoryText?
@params = null
else
inventory = @_parser.parse @params.inventoryText
inventory.each (stack)=>
item = @modPack.findItemByName stack.slug, enableAsNeeded:true
return unless item? and item.isCraftable
@plan.want.add stack.slug, stack.quantity
inventory.remove stack.slug
if inventory.isEmpty then @params = null