Improve slow level loading on CampaignView

* Fix LevelSetupManager to call onLevelSync asynchronously if level is not loaded on init
* Show a progress bar in level-info-container while level is loading asynchronously
This commit is contained in:
Scott Erickson 2015-12-04 10:26:09 -08:00
parent 6a48f3697a
commit 97c28e1c8a
3 changed files with 14 additions and 7 deletions

View file

@ -26,12 +26,13 @@ module.exports = class LevelSetupManager extends CocoClass
levelURL = "/db/level/#{@options.levelID}"
@level = new Level().setURL levelURL
@level = @supermodel.loadModel(@level, 'level').model
onLevelSync = ->
return if @destroyed
if @waitingToLoadModals
@waitingToLoadModals = false
@loadModals()
onLevelSync.call @ if @level.loaded
if @level.loaded then @onLevelSync() else @listenToOnce @level, 'sync', @onLevelSync
onLevelSync: ->
return if @destroyed
if @waitingToLoadModals
@waitingToLoadModals = false
@loadModals()
loadSession: ->
sessionURL = "/db/level/#{@options.levelID}/session"
@ -104,6 +105,7 @@ module.exports = class LevelSetupManager extends CocoClass
lastHeroesPurchased = me.get('purchased')?.heroes ? []
@options.parent.openModalView(firstModal)
@trigger 'open'
# @inventoryModal.onShown() # replace?
#- Modal events

View file

@ -28,6 +28,8 @@ if campaign
div(style="left: #{level.position.x}%; bottom: #{level.position.y}%", class="level-shadow" + (level.next ? " next" : "") + " " + (levelStatusMap[level.slug] || ""))
.level-info-container(data-level-slug=level.slug, data-level-path=level.levelPath || 'level', data-level-name=level.name)
- var playCount = levelPlayCountMap[level.slug]
.progress.progress-striped.active.hide
.progress-bar(style="width: 100%")
div(class="level-info " + (levelStatusMap[level.slug] || "") + (level.requiresSubscription ? " premium" : ""))
.level-status
h3= i18n(level, 'name') + (level.disabled ? " (Coming soon!)" : (level.locked ? " (Locked)" : ""))

View file

@ -499,8 +499,11 @@ module.exports = class CampaignView extends RootView
levelSlug = levelElement.data 'level-slug'
session = @preloadedSession if @preloadedSession?.loaded and @preloadedSession.levelSlug is levelSlug
@setupManager = new LevelSetupManager supermodel: @supermodel, levelID: levelSlug, levelPath: levelElement.data('level-path'), levelName: levelElement.data('level-name'), hadEverChosenHero: @hadEverChosenHero, parent: @, session: session
@$levelInfo.find('.level-info, .progress').toggleClass('hide')
@listenToOnce @setupManager, 'open', ->
@$levelInfo.find('.level-info, .progress').toggleClass('hide')
@$levelInfo?.hide()
@setupManager.open()
@$levelInfo?.hide()
onClickViewSolutions: (e) ->
levelElement = $(e.target).parents('.level-info-container')