Massive refactoring to clean up models
* Tweak style of quantity label in output box to be more visible * Move data files for all mods under a directory for the specific version of the mod * Add a `silent` property to the base model to prevent models which shouldn't be observed from emitting events * Change the term "itemSlug" to just "slug" across the board * Change all models so that they don't require their parent in their constructors and so that they don't automatically add themselves to their parents lists * Remove a bunch of unnecessary event triggering * Tighten up access to various lists of children across all models * Refactor the guts of the V2 parser into an abstract base class so it can be used for other parsers in the future * Remove a number of unused methods
This commit is contained in:
@@ -16,35 +16,18 @@ ModVersionParser = require './mod_version_parser'
|
||||
module.exports = class ModPack extends BaseModel
|
||||
|
||||
constructor: (attributes={}, options={})->
|
||||
attributes.modVersions ?= []
|
||||
super attributes, options
|
||||
|
||||
@_modVersions = []
|
||||
|
||||
# Public Methods ###############################################################################
|
||||
|
||||
addModVersion: (modVersion)->
|
||||
if modVersion.modPack isnt this then throw new Error "the mod version must be associated with this mod pack"
|
||||
return if @modVersions.indexOf(modVersion) isnt -1
|
||||
|
||||
@modVersions.push modVersion
|
||||
@trigger Event.add, modVersion, this
|
||||
|
||||
@modVersions.sort (a, b)-> a.compareTo b
|
||||
@trigger Event.sort, this
|
||||
@trigger Event.change, this
|
||||
return this
|
||||
|
||||
enableModsForItem: (name)->
|
||||
for modVersion in @modVersions
|
||||
continue if modVersion.enabled
|
||||
if modVersion.hasRecipe name
|
||||
modVersion.enabled = true
|
||||
|
||||
findItem: (itemSlug, options={})->
|
||||
findItem: (slug, options={})->
|
||||
options.includeDisabled ?= false
|
||||
|
||||
for modVersion in @modVersions
|
||||
for modVersion in @_modVersions
|
||||
continue unless modVersion.enabled or options.includeDisabled
|
||||
item = modVersion.items[itemSlug]
|
||||
item = modVersion.findItem slug
|
||||
return item if item?
|
||||
|
||||
return null
|
||||
@@ -53,9 +36,9 @@ module.exports = class ModPack extends BaseModel
|
||||
options.includeDisabled ?= false
|
||||
slug = _.slugify name
|
||||
|
||||
for modVersion in @modVersions
|
||||
for modVersion in @_modVersions
|
||||
continue unless modVersion.enabled or options.includeDisabled
|
||||
item = modVersion.items[slug]
|
||||
item = modVersion.findItem slug
|
||||
return item if item?
|
||||
|
||||
return null
|
||||
@@ -63,12 +46,12 @@ module.exports = class ModPack extends BaseModel
|
||||
findName: (slug, options={})->
|
||||
options.includeDisabled ?= false
|
||||
|
||||
for modVersion in @modVersions
|
||||
for modVersion in @_modVersions
|
||||
continue unless modVersion.enabled or options.includeDisabled
|
||||
name = modVersion.findName slug
|
||||
return name if name
|
||||
|
||||
return slug
|
||||
return null
|
||||
|
||||
findItemDisplay: (slug)->
|
||||
result = {}
|
||||
@@ -76,39 +59,50 @@ module.exports = class ModPack extends BaseModel
|
||||
if item?
|
||||
result.modSlug = item.modVersion.slug
|
||||
result.modVersion = item.modVersion.version
|
||||
result.itemSlug = item.slug
|
||||
result.slug = item.slug
|
||||
result.itemName = item.name
|
||||
else
|
||||
result.modSlug = _.slugify DefaultModVersions[0].name
|
||||
result.modVersion = DefaultModVersions[0].version
|
||||
result.itemSlug = slug
|
||||
result.slug = slug
|
||||
result.itemName = @findName slug, includeDisabled:true
|
||||
|
||||
result.iconUrl = Url.itemIcon result
|
||||
result.itemUrl = Url.item result
|
||||
return result
|
||||
|
||||
hasRecipe: (name, options={})->
|
||||
options.includeDisabled ?= false
|
||||
|
||||
for modVersion in @modVersions
|
||||
continue unless modVersion.enabled or options.includeDisabled
|
||||
return true if modVersion.hasRecipe name
|
||||
|
||||
return false
|
||||
|
||||
isValidName: (name, options={})->
|
||||
options.includeDisabled ?= false
|
||||
|
||||
slug = _.slugify name
|
||||
for modVersion in @modVersions
|
||||
for modVersion in @_modVersions
|
||||
continue unless modVersion.enabled or options.includeDisabled
|
||||
name = modVersion.findName slug
|
||||
return true if name
|
||||
|
||||
return false
|
||||
|
||||
# Property Methods #############################################################################
|
||||
|
||||
addModVersion: (modVersion)->
|
||||
return if @_modVersions.indexOf(modVersion) isnt -1
|
||||
|
||||
@_modVersions.push modVersion
|
||||
@trigger Event.add, modVersion, this
|
||||
|
||||
@_modVersions.sort (a, b)-> a.compareTo b
|
||||
@trigger Event.change, this
|
||||
|
||||
return this
|
||||
|
||||
eachModVersion: (callback)->
|
||||
for modVersion in @_modVersions
|
||||
callback modVersion
|
||||
|
||||
getModVersions: ->
|
||||
return @_modVersions[..]
|
||||
|
||||
# Object Overrides #############################################################################
|
||||
|
||||
toString: ->
|
||||
return "ModPack (#{@cid}) {modVersions:#{@modVersions.length} items}"
|
||||
return "ModPack (#{@cid}) {modVersions:#{@_modVersions.length} items}"
|
||||
|
||||
Reference in New Issue
Block a user