Add "Used as Tool to Make" section on item detail
This commit is contained in:
@@ -170,3 +170,5 @@ module.exports = (grunt)->
|
||||
grunt.registerTask 'build', [ 'copy', 'sass:main', 'jade', 'browserify', 'exorcise' ]
|
||||
|
||||
grunt.registerTask 'dist', ['clean', 'build', 'sass:dist', 'rename:scripts', 'uglify']
|
||||
|
||||
grunt.registerTask 'full-watch', ['clean', 'build', 'watch']
|
||||
|
||||
@@ -30,31 +30,37 @@ module.exports = class ItemPageController extends BaseController
|
||||
|
||||
super options
|
||||
|
||||
@_imageLoader = options.imageLoader
|
||||
@imageLoader = options.imageLoader
|
||||
@_itemSlug = options.itemSlug
|
||||
@_modPack = options.modPack
|
||||
@modPack = options.modPack
|
||||
|
||||
@_modPack.on Event.change, => @tryRefresh()
|
||||
@modPack.on Event.change, => @tryRefresh()
|
||||
|
||||
# BaseController Overrides #####################################################################
|
||||
|
||||
onDidRender: ->
|
||||
@_similarItemsController = @addChild ItemGroupController, '.similar .view__item_group',
|
||||
imageLoader: @_imageLoader
|
||||
modPack: @_modPack
|
||||
@_usedToMakeController = @addChild ItemGroupController, '.usedToMake .view__item_group',
|
||||
imageLoader: @_imageLoader
|
||||
modPack: @_modPack
|
||||
@_usedAsToolToMakeController = @addChild ItemGroupController, '.usedAsToolToMake .view__item_group',
|
||||
imageLoader: @imageLoader
|
||||
modPack: @modPack
|
||||
|
||||
@$byline = @$('.byline')
|
||||
@$bylineLink = @$('.byline a')
|
||||
@$craftingPlanLink = @$('a.craftingPlan')
|
||||
@$name = @$('h1.name')
|
||||
@$recipeContainer = @$('.recipes .panel')
|
||||
@$recipesSection = @$('.recipes')
|
||||
@$similarSection = @$('.similar')
|
||||
@$titleImage = @$('.titleImage img')
|
||||
@$usedToMakeSection = @$('.usedToMake')
|
||||
@_similarItemsController = @addChild ItemGroupController, '.similar .view__item_group',
|
||||
imageLoader: @imageLoader
|
||||
modPack: @modPack
|
||||
|
||||
@_usedToMakeController = @addChild ItemGroupController, '.usedToMake .view__item_group',
|
||||
imageLoader: @imageLoader
|
||||
modPack: @modPack
|
||||
|
||||
@$usedAsToolToMakeSection = @$('.usedAsToolToMake')
|
||||
@$byline = @$('.byline')
|
||||
@$bylineLink = @$('.byline a')
|
||||
@$craftingPlanLink = @$('a.craftingPlan')
|
||||
@$name = @$('h1.name')
|
||||
@$recipeContainer = @$('.recipes .panel')
|
||||
@$recipesSection = @$('.recipes')
|
||||
@$similarSection = @$('.similar')
|
||||
@$titleImage = @$('.titleImage img')
|
||||
@$usedToMakeSection = @$('.usedToMake')
|
||||
super
|
||||
|
||||
refresh: ->
|
||||
@@ -62,10 +68,10 @@ module.exports = class ItemPageController extends BaseController
|
||||
@_resolveItemSlug()
|
||||
|
||||
if @model.item?
|
||||
display = @_modPack.findItemDisplay @model.item.slug
|
||||
display = @modPack.findItemDisplay @model.item.slug
|
||||
@$craftingPlanLink.attr href:display.craftingUrl
|
||||
@$craftingPlanLink.fadeIn duration:Duration.fast
|
||||
@_imageLoader.load display.iconUrl, @$titleImage
|
||||
@imageLoader.load display.iconUrl, @$titleImage
|
||||
@$name.html display.itemName
|
||||
|
||||
@$el.slideDown duration:Duration.normal
|
||||
@@ -75,6 +81,7 @@ module.exports = class ItemPageController extends BaseController
|
||||
@_refreshByline()
|
||||
@_refreshRecipes()
|
||||
@_refreshSimilarItems()
|
||||
@_refreshUsedAsToolToMake()
|
||||
@_refreshUsedToMake()
|
||||
|
||||
super
|
||||
@@ -88,6 +95,15 @@ module.exports = class ItemPageController extends BaseController
|
||||
|
||||
# Private Methods ##############################################################################
|
||||
|
||||
_refreshUsedAsToolToMake: ->
|
||||
@_usedAsToolToMakeController.title = 'Used as Tool to Make'
|
||||
|
||||
@_usedAsToolToMakeController.model = @model.findToolForRecipes()
|
||||
if @_usedAsToolToMakeController.model?
|
||||
@$usedAsToolToMakeSection.slideDown duration:Duration.normal
|
||||
else
|
||||
@$usedAsToolToMakeSection.slideUp duration:Duration.normal
|
||||
|
||||
_refreshByline: ->
|
||||
mod = @model.item?.modVersion?.mod
|
||||
if mod?.name?.length > 0
|
||||
@@ -117,7 +133,7 @@ module.exports = class ItemPageController extends BaseController
|
||||
for recipe in @model.findRecipes()
|
||||
controller = @_recipeControllers[index]
|
||||
if not controller?
|
||||
controller = new FullRecipeController imageLoader:@_imageLoader, modPack:@_modPack, model:recipe
|
||||
controller = new FullRecipeController imageLoader:@imageLoader, modPack:@modPack, model:recipe
|
||||
@_recipeControllers.push controller
|
||||
controller.render()
|
||||
@$recipeContainer.append controller.$el
|
||||
@@ -145,4 +161,4 @@ module.exports = class ItemPageController extends BaseController
|
||||
@$similarSection.slideUp duration:Duration.normal
|
||||
|
||||
_resolveItemSlug: ->
|
||||
@model.item = @_modPack.findItem @_itemSlug, includeDisabled:true
|
||||
@model.item = @modPack.findItem @_itemSlug, includeDisabled:true
|
||||
|
||||
@@ -21,19 +21,7 @@ module.exports = class ItemPage extends BaseModel
|
||||
# Property Methods #############################################################################
|
||||
|
||||
findComponentInItems: ->
|
||||
return null unless @item?
|
||||
|
||||
result = {}
|
||||
@modPack.eachMod (mod)=>
|
||||
mod.eachRecipe (recipe)=>
|
||||
if recipe.requires @item.slug
|
||||
outputItem = @modPack.findItem recipe.itemSlug, includeDisabled:true
|
||||
result[outputItem.slug] = outputItem
|
||||
|
||||
result = _.values result
|
||||
return null unless result.length > 0
|
||||
|
||||
return result.sort (a, b)-> a.compareTo b
|
||||
return @_findRecipesMatching (recipe)=> recipe.requires @item.slug
|
||||
|
||||
findSimilarItems: ->
|
||||
return null unless @item?.modVersion?
|
||||
@@ -47,3 +35,23 @@ module.exports = class ItemPage extends BaseModel
|
||||
|
||||
findRecipes: ->
|
||||
return @modPack.findRecipes @item?.slug, [], alwaysFromOwningMod:true
|
||||
|
||||
findToolForRecipes: ->
|
||||
return @_findRecipesMatching (recipe)=> recipe.requiresTool @item.slug
|
||||
|
||||
# Private Methods ##############################################################################
|
||||
|
||||
_findRecipesMatching: (callback)->
|
||||
return null unless @item?
|
||||
|
||||
result = {}
|
||||
@modPack.eachMod (mod)=>
|
||||
mod.eachRecipe (recipe)=>
|
||||
if callback(recipe)
|
||||
outputItem = @modPack.findItem recipe.itemSlug, includeDisabled:true
|
||||
result[outputItem.slug] = outputItem
|
||||
|
||||
result = _.values result
|
||||
return null unless result.length > 0
|
||||
|
||||
return result.sort (a, b)-> a.compareTo b
|
||||
@@ -115,6 +115,11 @@ module.exports = class Recipe extends BaseModel
|
||||
return true
|
||||
return false
|
||||
|
||||
requiresTool: (itemSlug)->
|
||||
for stack in @tools
|
||||
if stack.itemSlug.matches itemSlug
|
||||
return true
|
||||
|
||||
# Property Methods #############################################################################
|
||||
|
||||
getSlug: ->
|
||||
|
||||
@@ -20,5 +20,6 @@
|
||||
.panel
|
||||
|
||||
.usedToMake: .view__item_group
|
||||
.usedAsToolToMake: .view__item_group
|
||||
.similar: .view__item_group
|
||||
.plan
|
||||
Reference in New Issue
Block a user