Fix bug with recipe books table
This commit is contained in:
@@ -50,7 +50,7 @@ module.exports = class CraftingPlan
|
||||
targetItem = @_pending.pop()
|
||||
return unless targetItem?
|
||||
|
||||
recipes = @catalog.findRecipes targetItem.name
|
||||
recipes = @catalog.gatherRecipes targetItem.name
|
||||
return if not recipes.length > 0
|
||||
recipe = recipes[0]
|
||||
|
||||
|
||||
@@ -17,22 +17,39 @@ module.exports = class RecipeBook extends BaseModel
|
||||
|
||||
attributes.description ?= ''
|
||||
attributes.recipes ?= []
|
||||
attributes.enabled ?= true
|
||||
super attributes, options
|
||||
|
||||
# Public Methods ###############################################################################
|
||||
|
||||
findRecipes: (name)->
|
||||
result = []
|
||||
gatherNames: (result)->
|
||||
return unless @enabled
|
||||
|
||||
for recipe in @recipes
|
||||
continue if result[recipe.name]
|
||||
result[recipe.name] = value:recipe.name, label:"#{recipe.name} (from #{@modName} #{@modVersion})"
|
||||
|
||||
return result
|
||||
|
||||
gatherRecipes: (name, result)->
|
||||
return unless @enabled
|
||||
|
||||
for recipe in @recipes
|
||||
if recipe.name is name
|
||||
result.push recipe
|
||||
|
||||
return result
|
||||
|
||||
hasRecipe: (name)->
|
||||
for recipe in @recipes
|
||||
return true if recipe.name is name
|
||||
return false
|
||||
|
||||
# Object Overrides #############################################################################
|
||||
|
||||
toString: ->
|
||||
return "RecipeBook (#{@cid}) {
|
||||
enabled:#{@enabled},
|
||||
modName:#{@modName},
|
||||
modVersion:#{@modVersion},
|
||||
recipes:#{@recipes.length} items}"
|
||||
|
||||
@@ -21,27 +21,29 @@ module.exports = class RecipeCatalog extends BaseModel
|
||||
|
||||
# Public Methods ###############################################################################
|
||||
|
||||
findRecipes: (name)->
|
||||
result = []
|
||||
gatherNames: ->
|
||||
nameData = {}
|
||||
for book in @books
|
||||
for recipe in book.findRecipes name
|
||||
result.push recipe
|
||||
book.gatherNames nameData
|
||||
|
||||
return result
|
||||
|
||||
getRecipeNames: ->
|
||||
nameHash = {}
|
||||
for book in @books
|
||||
for recipe in book.recipes
|
||||
nameHash[recipe.name] = "#{recipe.name} (from #{book.modName} #{book.modVersion})"
|
||||
|
||||
names = (k for k, v of nameHash).sort()
|
||||
result = []
|
||||
names = _.keys(nameData).sort()
|
||||
for name in names
|
||||
result.push value:name, label:nameHash[name]
|
||||
result.push nameData[name]
|
||||
return result
|
||||
|
||||
gatherRecipes: (name)->
|
||||
result = []
|
||||
for book in @books
|
||||
book.gatherRecipes name, result
|
||||
|
||||
return result
|
||||
|
||||
hasRecipe: (name)->
|
||||
for book in @books
|
||||
return true if book.hasRecipe(name)
|
||||
return false
|
||||
|
||||
loadBook: (url)->
|
||||
w.promise (resolve, reject)=>
|
||||
@trigger Event.load.started, this, url
|
||||
@@ -59,6 +61,7 @@ module.exports = class RecipeCatalog extends BaseModel
|
||||
@books.sort (a, b)->
|
||||
return 0 if a.modName is b.modName
|
||||
return if a.modName < b.modName then -1 else +1
|
||||
book.on Event.change, => @trigger Event.change, this
|
||||
|
||||
return book
|
||||
|
||||
|
||||
Reference in New Issue
Block a user