Store want/have in URL/local storage
This commit is contained in:
@@ -5,11 +5,12 @@ 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'
|
||||
ModPack = require './mod_pack'
|
||||
BaseModel = require './base_model'
|
||||
CraftingPlan = require './crafting_plan'
|
||||
CraftingTable = require './crafting_table'
|
||||
{Event} = require '../constants'
|
||||
InventoryParser = require './inventory_parser'
|
||||
ModPack = require './mod_pack'
|
||||
|
||||
########################################################################################################################
|
||||
|
||||
@@ -22,22 +23,27 @@ module.exports = class ItemPage extends BaseModel
|
||||
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: ->
|
||||
logger.debug "consuming params: #{util.inspect(@params)}"
|
||||
return unless @params?
|
||||
|
||||
@plan.want.clear()
|
||||
if not @params?.name?
|
||||
if not @params.inventoryText?
|
||||
@params = null
|
||||
else
|
||||
item = @modPack.findItemByName @params.name, enableAsNeeded:true
|
||||
return unless item? and item.isCraftable
|
||||
inventory = @_parser.parse @params.inventoryText
|
||||
|
||||
quantity = if @params.quantity? then parseInt(@params.quantity) else 1
|
||||
@plan.want.add item.slug, quantity
|
||||
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
|
||||
|
||||
@params = null
|
||||
if inventory.isEmpty then @params = null
|
||||
|
||||
Reference in New Issue
Block a user