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

View file

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

View file

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