Store tool and modVersion enabled states
This commit is contained in:
@@ -13,19 +13,23 @@ Inventory = require './inventory'
|
|||||||
module.exports = class CraftingPlan extends BaseModel
|
module.exports = class CraftingPlan extends BaseModel
|
||||||
|
|
||||||
constructor: (attributes={}, options={})->
|
constructor: (attributes={}, options={})->
|
||||||
|
options.storage ?= window.localStorage
|
||||||
|
|
||||||
if not attributes.modPack then throw new Error 'modPack is required'
|
if not attributes.modPack then throw new Error 'modPack is required'
|
||||||
|
attributes.includingTools ?= options.storage.getItem('includingTools')
|
||||||
attributes.includingTools ?= false
|
attributes.includingTools ?= false
|
||||||
super attributes, options
|
super attributes, options
|
||||||
|
|
||||||
@have = new Inventory
|
@have = new Inventory
|
||||||
@want = new Inventory
|
@want = new Inventory
|
||||||
@need = new Inventory
|
@need = new Inventory
|
||||||
@result = new Inventory
|
@result = new Inventory
|
||||||
|
@storage = options.storage
|
||||||
|
|
||||||
@have.on 'change', => @craft()
|
@have.on 'change', => @craft()
|
||||||
@want.on 'change', => @craft()
|
@want.on 'change', => @craft()
|
||||||
@modPack.on 'change', => @craft()
|
@modPack.on 'change', => @craft()
|
||||||
@on 'change:includingTools', => @craft()
|
@on 'change:includingTools', => @onIncludingToolsChanged()
|
||||||
|
|
||||||
@clear()
|
@clear()
|
||||||
|
|
||||||
@@ -55,6 +59,12 @@ module.exports = class CraftingPlan extends BaseModel
|
|||||||
|
|
||||||
@trigger 'change', this
|
@trigger 'change', this
|
||||||
|
|
||||||
|
# Event Methods ################################################################################
|
||||||
|
|
||||||
|
onIncludingToolsChanged: ->
|
||||||
|
@storage.setItem 'includingTools', "#{@includingTools}"
|
||||||
|
@craft()
|
||||||
|
|
||||||
# Object Overrides #############################################################################
|
# Object Overrides #############################################################################
|
||||||
|
|
||||||
toString: ->
|
toString: ->
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ All rights reserved.
|
|||||||
BaseModel = require './base_model'
|
BaseModel = require './base_model'
|
||||||
CraftingPlan = require './crafting_plan'
|
CraftingPlan = require './crafting_plan'
|
||||||
CraftingTable = require './crafting_table'
|
CraftingTable = require './crafting_table'
|
||||||
|
{Event} = require '../constants'
|
||||||
ModPack = require './mod_pack'
|
ModPack = require './mod_pack'
|
||||||
|
|
||||||
########################################################################################################################
|
########################################################################################################################
|
||||||
@@ -21,8 +22,8 @@ module.exports = class ItemPage extends BaseModel
|
|||||||
attributes.table ?= new CraftingTable plan:attributes.plan
|
attributes.table ?= new CraftingTable plan:attributes.plan
|
||||||
super attributes, options
|
super attributes, options
|
||||||
|
|
||||||
@modPack.on 'change', => @_consumeParams()
|
@modPack.on Event.change, => @_consumeParams()
|
||||||
@plan.on 'change', => @_updateLocation()
|
@plan.on Event.change, => @_updateLocation()
|
||||||
|
|
||||||
# Private Methods ##############################################################################
|
# Private Methods ##############################################################################
|
||||||
|
|
||||||
|
|||||||
@@ -146,7 +146,6 @@ module.exports = class ModPack extends BaseModel
|
|||||||
onModVersionLoaded: (url, data, status, xhr)->
|
onModVersionLoaded: (url, data, status, xhr)->
|
||||||
try
|
try
|
||||||
modVersion = @loadModVersionData data
|
modVersion = @loadModVersionData data
|
||||||
modVersion.enabled = true
|
|
||||||
|
|
||||||
logger.info "loaded ModVersion from #{url}: #{modVersion}"
|
logger.info "loaded ModVersion from #{url}: #{modVersion}"
|
||||||
@trigger Event.load.succeeded, this, modVersion
|
@trigger Event.load.succeeded, this, modVersion
|
||||||
|
|||||||
@@ -13,16 +13,26 @@ BaseModel = require './base_model'
|
|||||||
module.exports = class ModVersion extends BaseModel
|
module.exports = class ModVersion extends BaseModel
|
||||||
|
|
||||||
constructor: (attributes={}, options={})->
|
constructor: (attributes={}, options={})->
|
||||||
|
options.storage ?= window.localStorage
|
||||||
|
|
||||||
if _.isEmpty(attributes.name) then throw new Error 'name cannot be empty'
|
if _.isEmpty(attributes.name) then throw new Error 'name cannot be empty'
|
||||||
if _.isEmpty(attributes.version) then throw new Error 'version cannot be empty'
|
if _.isEmpty(attributes.version) then throw new Error 'version cannot be empty'
|
||||||
|
|
||||||
attributes.description ?= ''
|
attributes.description ?= ''
|
||||||
attributes.enabled ?= attributes.name in RequiredMods
|
attributes.enabled ?= true
|
||||||
attributes.items ?= {}
|
attributes.items ?= {}
|
||||||
attributes.names ?= {}
|
attributes.names ?= {}
|
||||||
attributes.slug ?= _.slugify attributes.name
|
attributes.slug ?= _.slugify attributes.name
|
||||||
super attributes, options
|
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 ###############################################################################
|
# Public Methods ###############################################################################
|
||||||
|
|
||||||
addItem: (item)->
|
addItem: (item)->
|
||||||
|
|||||||
Reference in New Issue
Block a user