Store tool and modVersion enabled states

This commit is contained in:
Andrew Miner
2015-01-12 14:18:07 -08:00
parent 3e70c0deef
commit fef9d155d8
4 changed files with 29 additions and 9 deletions
+11 -1
View File
@@ -13,7 +13,10 @@ Inventory = require './inventory'
module.exports = class CraftingPlan extends BaseModel
constructor: (attributes={}, options={})->
options.storage ?= window.localStorage
if not attributes.modPack then throw new Error 'modPack is required'
attributes.includingTools ?= options.storage.getItem('includingTools')
attributes.includingTools ?= false
super attributes, options
@@ -21,11 +24,12 @@ module.exports = class CraftingPlan extends BaseModel
@want = new Inventory
@need = new Inventory
@result = new Inventory
@storage = options.storage
@have.on 'change', => @craft()
@want.on 'change', => @craft()
@modPack.on 'change', => @craft()
@on 'change:includingTools', => @craft()
@on 'change:includingTools', => @onIncludingToolsChanged()
@clear()
@@ -55,6 +59,12 @@ module.exports = class CraftingPlan extends BaseModel
@trigger 'change', this
# Event Methods ################################################################################
onIncludingToolsChanged: ->
@storage.setItem 'includingTools', "#{@includingTools}"
@craft()
# Object Overrides #############################################################################
toString: ->
+3 -2
View File
@@ -8,6 +8,7 @@ All rights reserved.
BaseModel = require './base_model'
CraftingPlan = require './crafting_plan'
CraftingTable = require './crafting_table'
{Event} = require '../constants'
ModPack = require './mod_pack'
########################################################################################################################
@@ -21,8 +22,8 @@ module.exports = class ItemPage extends BaseModel
attributes.table ?= new CraftingTable plan:attributes.plan
super attributes, options
@modPack.on 'change', => @_consumeParams()
@plan.on 'change', => @_updateLocation()
@modPack.on Event.change, => @_consumeParams()
@plan.on Event.change, => @_updateLocation()
# Private Methods ##############################################################################
-1
View File
@@ -146,7 +146,6 @@ module.exports = class ModPack extends BaseModel
onModVersionLoaded: (url, data, status, xhr)->
try
modVersion = @loadModVersionData data
modVersion.enabled = true
logger.info "loaded ModVersion from #{url}: #{modVersion}"
@trigger Event.load.succeeded, this, modVersion
+11 -1
View File
@@ -13,16 +13,26 @@ BaseModel = require './base_model'
module.exports = class ModVersion extends BaseModel
constructor: (attributes={}, options={})->
options.storage ?= window.localStorage
if _.isEmpty(attributes.name) then throw new Error 'name cannot be empty'
if _.isEmpty(attributes.version) then throw new Error 'version cannot be empty'
attributes.description ?= ''
attributes.enabled ?= attributes.name in RequiredMods
attributes.enabled ?= true
attributes.items ?= {}
attributes.names ?= {}
attributes.slug ?= _.slugify attributes.name
super attributes, options
enabled = options.storage.getItem("#{@slug}.enabled")
if enabled?
logger.debug "loading #{@slug}.enabled as #{@enabled}"
@enabled = enabled is 'true'
@on 'change:enabled', =>
logger.debug "saving #{@slug}.enabled as #{@enabled}"
options.storage.setItem "#{@slug}.enabled", "#{@enabled}"
# Public Methods ###############################################################################
addItem: (item)->