Avoid opening InventoryModal or ChooseHeroesModal until the session is loaded.

This commit is contained in:
Nick Winter 2014-12-04 13:18:00 -08:00
parent 0edf4e0ca1
commit c0842959e8
3 changed files with 18 additions and 6 deletions

View file

@ -20,13 +20,14 @@ module.exports = class LevelSetupManager extends CocoClass
@fillSessionWithDefaults()
else
@loadSession()
@loadModals()
#@loadModals()
loadSession: ->
url = "/db/level/#{@options.levelID}/session"
#url += "?team=#{@team}" if @options.team # TODO: figure out how to get the teams for multiplayer PVP hero style
@session = new LevelSession().setURL url
onSessionSync = ->
return if @destroyed
@session.url = -> '/db/level.session/' + @id
@fillSessionWithDefaults()
@listenToOnce @session, 'sync', onSessionSync
@ -37,6 +38,7 @@ module.exports = class LevelSetupManager extends CocoClass
fillSessionWithDefaults: ->
heroConfig = _.merge {}, me.get('heroConfig'), @session.get('heroConfig')
@session.set('heroConfig', heroConfig)
@loadModals()
loadModals: ->
# build modals and prevent them from disappearing.
@ -49,8 +51,13 @@ module.exports = class LevelSetupManager extends CocoClass
@listenToOnce @heroesModal, 'hero-loaded', @onceHeroLoaded
@listenTo @inventoryModal, 'choose-hero-click', @onChooseHeroClicked
@listenTo @inventoryModal, 'play-click', @onInventoryModalPlayClicked
@modalsLoaded = true
if @waitingToOpen
@waitingToOpen = false
@open()
open: ->
return @waitingToOpen = true unless @modalsLoaded
firstModal = if @options.hadEverChosenHero then @inventoryModal else @heroesModal
if (not _.isEqual(lastHeroesEarned, me.get('earned')?.heroes ? []) or
not _.isEqual(lastHeroesPurchased, me.get('purchased')?.heroes ? []))
@ -70,7 +77,7 @@ module.exports = class LevelSetupManager extends CocoClass
#- Modal events
onceHeroLoaded: (e) ->
@inventoryModal.setHero(e.hero)
@inventoryModal.setHero(e.hero) if window.currentModal is @inventoryModal
onHeroesModalConfirmClicked: (e) ->
@options.parent.openModalView(@inventoryModal)
@ -99,6 +106,6 @@ module.exports = class LevelSetupManager extends CocoClass
}
destroy: ->
@heroesModalDestroy.call @heroesModal unless @heroesModal.destroyed
@inventoryModalDestroy.call @inventoryModal unless @inventoryModal.destroyed
@heroesModalDestroy?.call @heroesModal unless @heroesModal?.destroyed
@inventoryModalDestroy?.call @inventoryModal unless @inventoryModal?.destroyed
super()

View file

@ -173,3 +173,5 @@ module.exports =
'level:hero-selection-updated': c.object {required: ['hero']},
hero: {type: 'object'}
'level:subscription-required': c.object {}

View file

@ -363,7 +363,7 @@ module.exports = class InventoryModal extends ModalView
@remainingRequiredEquipment = []
@$el.find('.should-equip').removeClass('should-equip')
inWorldMap = $('#world-map-view').length
if heroClass = @selectedHero?.get('heroClass')
if @supermodel.finished() and heroClass = @selectedHero?.get('heroClass')
for slot, item of _.clone equipment
itemModel = @items.findWhere original: item
unless itemModel and heroClass in itemModel.classes
@ -528,10 +528,11 @@ module.exports = class InventoryModal extends ModalView
#- Paper doll equipment updating
onEquipmentChanged: ->
equipment = @getCurrentEquipmentConfig()
return unless _.size(equipment) and @supermodel.finished()
@removeDollImages()
heroClass = @selectedHero?.get('heroClass') ? 'Warrior'
gender = if @selectedHero?.get('slug') in heroGenders.male then 'male' else 'female'
equipment = @getCurrentEquipmentConfig()
slotsWithImages = []
for slot, original of equipment
item = _.find @items.models, (item) -> item.get('original') is original
@ -542,6 +543,8 @@ module.exports = class InventoryModal extends ModalView
@$el.find('#hero-image-hair').toggle not ('head' in slotsWithImages)
@$el.find('#hero-image-thumb').toggle not ('gloves' in slotsWithImages)
@equipment = @options.equipment = equipment
removeDollImages: ->
@$el.find('.doll-image').remove()