mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-27 17:45:40 -05:00
Preloaded previous/next heroes in ChooseHeroView.
This commit is contained in:
parent
a786b1e096
commit
53ddf0159d
1 changed files with 27 additions and 11 deletions
|
@ -17,8 +17,8 @@ module.exports = class ChooseHeroView extends CocoView
|
|||
'change #option-code-language': 'onCodeLanguageChanged'
|
||||
|
||||
shortcuts:
|
||||
'left': -> @$el.find('#hero-carousel').carousel('prev') unless @$el.hasClass 'secret'
|
||||
'right': -> @$el.find('#hero-carousel').carousel('next') unless @$el.hasClass 'secret'
|
||||
'left': -> @$el.find('#hero-carousel').carousel('prev') if @heroes.models.length and not @$el.hasClass 'secret'
|
||||
'right': -> @$el.find('#hero-carousel').carousel('next') if @heroes.models.length and not @$el.hasClass 'secret'
|
||||
|
||||
constructor: (options) ->
|
||||
super options
|
||||
|
@ -69,6 +69,7 @@ module.exports = class ChooseHeroView extends CocoView
|
|||
direction = e.direction # 'left' or 'right'
|
||||
heroItem = $(e.relatedTarget)
|
||||
hero = _.find @heroes.models, (hero) -> hero.get('original') is heroItem.data('hero-id')
|
||||
return console.error "Couldn't find hero from heroItem:", heroItem unless hero
|
||||
heroIndex = heroItem.index()
|
||||
@$el.find('.hero-indicator').each ->
|
||||
distance = Math.min 3, Math.abs $(@).index() - heroIndex
|
||||
|
@ -77,19 +78,33 @@ module.exports = class ChooseHeroView extends CocoView
|
|||
heroInfo = temporaryHeroInfo[hero.get('slug')]
|
||||
locked = heroInfo.status is 'Locked'
|
||||
hero = @loadHero hero, heroIndex
|
||||
@preloadHero heroIndex + 1
|
||||
@preloadHero heroIndex - 1
|
||||
@selectedHero = hero unless locked
|
||||
Backbone.Mediator.publish 'level:hero-selection-updated', hero: @selectedHero
|
||||
$('#choose-inventory-button').prop 'disabled', locked
|
||||
|
||||
loadHero: (hero, heroIndex) ->
|
||||
getFullHero: (original) ->
|
||||
url = "/db/thang.type/#{original}/version"
|
||||
if fullHero = @supermodel.getModel url
|
||||
return fullHero
|
||||
fullHero = new ThangType()
|
||||
fullHero.setURL url
|
||||
fullHero = (@supermodel.loadModel fullHero, 'thang').model
|
||||
fullHero
|
||||
|
||||
preloadHero: (heroIndex) ->
|
||||
return unless hero = @heroes.models[heroIndex]
|
||||
@loadHero hero, heroIndex, true
|
||||
|
||||
loadHero: (hero, heroIndex, preloading=false) ->
|
||||
createjs.Ticker.removeEventListener 'tick', stage for stage in _.values @stages
|
||||
if stage = @stages[heroIndex]
|
||||
createjs.Ticker.addEventListener 'tick', stage
|
||||
@playSelectionSound hero
|
||||
unless preloading
|
||||
_.defer -> createjs.Ticker.addEventListener 'tick', stage # Deferred, otherwise it won't start updating for some reason.
|
||||
@playSelectionSound hero
|
||||
return hero
|
||||
fullHero = new ThangType()
|
||||
fullHero.setURL "/db/thang.type/#{hero.get('original')}/version"
|
||||
fullHero = (@supermodel.loadModel fullHero, 'thang').model
|
||||
fullHero = @getFullHero hero.get 'original'
|
||||
onLoaded = =>
|
||||
return unless canvas = $(".hero-item[data-hero-id='#{fullHero.get('original')}'] canvas")
|
||||
canvas.prop width: @canvasWidth, height: @canvasHeight
|
||||
|
@ -104,12 +119,13 @@ module.exports = class ChooseHeroView extends CocoView
|
|||
movieClip.x = canvas.prop('width') * 0.5
|
||||
movieClip.y = canvas.prop('height') * 0.925 # This is where the feet go.
|
||||
stage = new createjs.Stage(canvas[0])
|
||||
@stages[heroIndex] = stage
|
||||
stage.addChild movieClip
|
||||
stage.update()
|
||||
createjs.Ticker.addEventListener 'tick', stage
|
||||
movieClip.gotoAndPlay 0
|
||||
@stages[heroIndex] = stage
|
||||
@playSelectionSound hero
|
||||
unless preloading
|
||||
createjs.Ticker.addEventListener 'tick', stage
|
||||
@playSelectionSound hero
|
||||
if fullHero.loaded
|
||||
_.defer onLoaded
|
||||
else
|
||||
|
|
Loading…
Reference in a new issue