Adjust animations, fix bugs, and tweak a few algos
* Adjust page change animations to slide the page closed and then open again. * Add Railcraft to the standard set of mods * Change every controller which uses an `ImageLoader` to only accept it from a parent controller (with the router creating the one shared instance). * Fix several places where controllers need to refresh when the mod pack changes * Fix a few places which should be using the `ImageLoader` but were not. * Remove a number of animations which caused performance issues (esp. animating individual items in item group views). * Fix a bug where changing the current version of a mod didn't cause the current crafting plan to be re-evaluated * Simplify the name finder to allow regular expressions instead of the current algorithm
This commit is contained in:
@@ -21,10 +21,10 @@ ItemPage = require '../models/item_page'
|
||||
module.exports = class ItemPageController extends BaseController
|
||||
|
||||
constructor: (options={})->
|
||||
if not options.modPack? then throw new Error 'options.modPack is required'
|
||||
if not options.itemSlug? then throw new Error 'options.itemSlug is required'
|
||||
if not options.imageLoader? then throw new Error 'options.imageLoader is required'
|
||||
if not options.modPack? then throw new Error 'options.modPack is required'
|
||||
|
||||
options.imageLoader ?= new ImageLoader defaultUrl:'/images/unknown.png'
|
||||
options.model ?= new ItemPage modPack:options.modPack
|
||||
options.templateName ?= 'item_page'
|
||||
|
||||
@@ -34,23 +34,27 @@ module.exports = class ItemPageController extends BaseController
|
||||
@_itemSlug = options.itemSlug
|
||||
@_modPack = options.modPack
|
||||
|
||||
@_modPack.on Event.change, => @refresh()
|
||||
@_modPack.on Event.change, => @tryRefresh()
|
||||
|
||||
# BaseController Overrides #####################################################################
|
||||
|
||||
onDidRender: ->
|
||||
@_similarItemsController = @addChild ItemGroupController, '.similar .view__item_group', modPack:@_modPack
|
||||
@_usedToMakeController = @addChild ItemGroupController, '.usedToMake .view__item_group', modPack:@_modPack
|
||||
@_similarItemsController = @addChild ItemGroupController, '.similar .view__item_group',
|
||||
imageLoader: @_imageLoader
|
||||
modPack: @_modPack
|
||||
@_usedToMakeController = @addChild ItemGroupController, '.usedToMake .view__item_group',
|
||||
imageLoader: @_imageLoader
|
||||
modPack: @_modPack
|
||||
|
||||
@$byline = @$('.byline')
|
||||
@$bylineLink = @$('.byline a')
|
||||
@$craftingPlanLink = @$('a.craftingPlan')
|
||||
@$name = @$('h1.name')
|
||||
@$recipeContainer = @$('.recipes .panel')
|
||||
@$recipesSection = @$('.recipes')
|
||||
@$similarContainer = @$('.similar')
|
||||
@$titleImage = @$('.titleImage img')
|
||||
@$usedToMakeContainer = @$('.usedToMake')
|
||||
@$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: ->
|
||||
@@ -60,13 +64,13 @@ module.exports = class ItemPageController extends BaseController
|
||||
if @model.item?
|
||||
display = @_modPack.findItemDisplay @model.item.slug
|
||||
@$craftingPlanLink.attr href:display.craftingUrl
|
||||
@$craftingPlanLink.fadeIn duration:Duration.normal
|
||||
@$craftingPlanLink.fadeIn duration:Duration.fast
|
||||
@_imageLoader.load display.iconUrl, @$titleImage
|
||||
@$name.html display.itemName
|
||||
|
||||
@$el.slideDown duration:Duration.normal
|
||||
else
|
||||
@$craftingPlanLink.fadeOut duration:Duration.normal
|
||||
@$titleImage.removeAttr 'src'
|
||||
@$name.html ''
|
||||
@$el.slideUp duration:Duration.normal
|
||||
|
||||
@_refreshByline()
|
||||
@_refreshRecipes()
|
||||
@@ -89,18 +93,18 @@ module.exports = class ItemPageController extends BaseController
|
||||
if mod?.name?.length > 0
|
||||
@$bylineLink.attr 'href', Url.mod modSlug:mod.slug
|
||||
@$bylineLink.html mod.name
|
||||
@$byline.fadeIn duration:Duration.normal
|
||||
@$byline.fadeIn duration:Duration.fast
|
||||
else
|
||||
@$byline.fadeOut duration:Duration.normal
|
||||
@$byline.fadeOut duration:Duration.fast
|
||||
|
||||
_refreshUsedToMake: ->
|
||||
@_usedToMakeController.title = 'Used to Make'
|
||||
|
||||
@_usedToMakeController.model = @model.findComponentInItems()
|
||||
if @_usedToMakeController.model?
|
||||
@$usedToMakeContainer.fadeIn duration:Duration.normal
|
||||
@$usedToMakeSection.slideDown duration:Duration.normal
|
||||
else
|
||||
@$usedToMakeContainer.fadeOut duration:Duration.normal
|
||||
@$usedToMakeSection.slideUp duration:Duration.normal
|
||||
|
||||
_refreshRecipes: ->
|
||||
@_recipeControllers ?= []
|
||||
@@ -108,26 +112,24 @@ module.exports = class ItemPageController extends BaseController
|
||||
|
||||
recipes = @model.findRecipes()
|
||||
if recipes?
|
||||
@$recipesSection.fadeIn duration:Duration.normal
|
||||
@$recipesSection.slideDown duration:Duration.normal
|
||||
|
||||
for recipe in @model.findRecipes()
|
||||
controller = @_recipeControllers[index]
|
||||
if not controller?
|
||||
controller = new FullRecipeController modPack:@_modPack, model:recipe
|
||||
controller = new FullRecipeController imageLoader:@_imageLoader, modPack:@_modPack, model:recipe
|
||||
@_recipeControllers.push controller
|
||||
controller.render()
|
||||
controller.$el.hide()
|
||||
@$recipeContainer.append controller.$el
|
||||
controller.$el.fadeIn duration:Duration.normal
|
||||
else
|
||||
controller.model = recipe
|
||||
index++
|
||||
else
|
||||
@$recipesSection.fadeOut duration:Duration.normal
|
||||
@$recipesSection.slideUp duration:Duration.normal
|
||||
|
||||
while @_recipeControllers.length > index
|
||||
controller = @_recipeControllers.pop()
|
||||
controller.fadeOut duration:Duration.normal, complete:-> controller.$el.remove()
|
||||
controller.$el.slideUp duration:Duration.normal, complete:-> controller.$el.remove()
|
||||
|
||||
_refreshSimilarItems: ->
|
||||
group = @model.item?.group
|
||||
@@ -138,9 +140,9 @@ module.exports = class ItemPageController extends BaseController
|
||||
@_similarItemsController.model = null
|
||||
|
||||
if @_similarItemsController.model?
|
||||
@$similarContainer.fadeIn duration:Duration.normal
|
||||
@$similarSection.slideDown duration:Duration.normal
|
||||
else
|
||||
@$similarContainer.fadeOut duration:Duration.normal
|
||||
@$similarSection.slideUp duration:Duration.normal
|
||||
|
||||
_resolveItemSlug: ->
|
||||
@model.item = @_modPack.findItem @_itemSlug, includeDisabled:true
|
||||
|
||||
Reference in New Issue
Block a user