Store tool and modVersion enabled states
This commit is contained in:
@@ -13,19 +13,23 @@ 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
|
||||
|
||||
@have = new Inventory
|
||||
@want = new Inventory
|
||||
@need = new Inventory
|
||||
@result = new Inventory
|
||||
@have = new Inventory
|
||||
@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: ->
|
||||
|
||||
@@ -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 ##############################################################################
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)->
|
||||
|
||||
Reference in New Issue
Block a user