Add a "Random Item" link to the breadcrumb bar

fixes #216
This commit is contained in:
Andrew Miner
2016-05-07 12:25:21 -07:00
parent 841fac38d3
commit da1419d6b6
8 changed files with 87 additions and 38 deletions
+6
View File
@@ -93,6 +93,12 @@ module.exports = class Mod extends BaseModel
# Item Methods #################################################################################
chooseRandomItem: ->
effectiveModVersion = @_activeModVersion or @getModVersion Mod.Version.Latest
return null unless effectiveModVersion?
return effectiveModVersion.chooseRandomItem()
eachItem: (callback)->
effectiveModVersion = @_activeModVersion or @getModVersion Mod.Version.Latest
effectiveModVersion.eachItem callback
+6
View File
@@ -25,6 +25,12 @@ module.exports = class ModPack extends BaseModel
# Item Methods #################################################################################
chooseRandomItem: ->
return null unless @_mods.length > 0
modIndex = Math.floor Math.random() * @_mods.length
return @_mods[modIndex].chooseRandomItem()
findItem: (itemSlug, options={})->
options.includeDisabled ?= false
@@ -59,6 +59,10 @@ module.exports = class ModVersion extends BaseModel
return null if result.length is 0
return result
chooseRandomItem: ->
itemIndex = Math.floor Math.random() * @_slugs.length
return @_slugs[itemIndex]
eachItem: (callback)->
for slug in @_slugs
item = @findItem slug