2014-09-19 14:03:38 -04:00
|
|
|
ModalView = require 'views/kinds/ModalView'
|
|
|
|
template = require 'templates/play/modal/play-level-modal'
|
|
|
|
ChooseHeroView = require 'views/game-menu/ChooseHeroView'
|
|
|
|
InventoryView = require 'views/game-menu/InventoryView'
|
2014-09-20 18:18:21 -04:00
|
|
|
PlayLevelView = require 'views/play/level/PlayLevelView'
|
2014-09-25 03:02:53 -04:00
|
|
|
LadderView = require 'views/play/ladder/LadderView'
|
2014-09-20 18:18:21 -04:00
|
|
|
LevelSession = require 'models/LevelSession'
|
2014-09-19 14:03:38 -04:00
|
|
|
|
2014-10-13 20:40:16 -04:00
|
|
|
hasGoneFullScreenOnce = false
|
|
|
|
|
2014-09-19 14:03:38 -04:00
|
|
|
module.exports = class PlayLevelModal extends ModalView
|
|
|
|
className: 'modal fade play-modal'
|
|
|
|
template: template
|
|
|
|
id: 'play-level-modal'
|
|
|
|
|
2014-09-20 01:15:58 -04:00
|
|
|
events:
|
|
|
|
'click #choose-inventory-button': 'onClickChooseInventory'
|
|
|
|
'click #choose-hero-button': 'onClickChooseHero'
|
|
|
|
'click #play-level-button': 'onClickPlayLevel'
|
|
|
|
|
2014-09-21 02:06:28 -04:00
|
|
|
shortcuts:
|
|
|
|
'enter': 'onEnterPressed'
|
|
|
|
|
2014-09-19 14:03:38 -04:00
|
|
|
constructor: (options) ->
|
|
|
|
super options
|
|
|
|
@options.showDevBits = true
|
2014-09-20 18:18:21 -04:00
|
|
|
@loadSession()
|
|
|
|
|
|
|
|
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
|
|
|
|
@session = @supermodel.loadModel(session, 'level_session').model
|
|
|
|
@options.session = @session
|
2014-09-19 14:03:38 -04:00
|
|
|
|
|
|
|
getRenderData: (context={}) ->
|
|
|
|
context = super(context)
|
|
|
|
context.levelID = @options.levelID
|
|
|
|
context.levelPath = @options.levelPath
|
|
|
|
context.levelName = @options.levelName
|
|
|
|
context
|
|
|
|
|
|
|
|
afterRender: ->
|
|
|
|
super()
|
|
|
|
return unless @supermodel.finished()
|
2014-09-20 18:18:21 -04:00
|
|
|
@session.url = -> '/db/level.session/' + @id
|
2014-09-19 14:03:38 -04:00
|
|
|
Backbone.Mediator.publish 'audio-player:play-sound', trigger: 'game-menu-open', volume: 1
|
2014-09-20 01:15:58 -04:00
|
|
|
@insertSubView @chooseHeroView = new ChooseHeroView @options
|
|
|
|
@insertSubView @inventoryView = new InventoryView @options
|
2014-10-02 14:18:43 -04:00
|
|
|
if @options.hadEverChosenHero
|
|
|
|
@$el.find('.choose-hero-active').add(@chooseHeroView.$el).addClass 'secret'
|
|
|
|
@$el.find('.choose-inventory-active').removeClass 'secret'
|
|
|
|
@inventoryView.onShown()
|
|
|
|
else
|
|
|
|
@$el.find('.choose-inventory-active').add(@inventoryView.$el).addClass 'secret'
|
|
|
|
@$el.find('.choose-hero-active').removeClass 'secret'
|
|
|
|
@chooseHeroView.onShown()
|
2014-09-19 14:03:38 -04:00
|
|
|
|
|
|
|
onHidden: ->
|
2014-09-20 18:18:21 -04:00
|
|
|
unless @navigatingToPlay
|
|
|
|
skipSessionSave = not @options.session.get('levelName')? # Has to have been already started.
|
2014-09-20 19:04:13 -04:00
|
|
|
@updateConfig null, skipSessionSave
|
2014-09-19 14:03:38 -04:00
|
|
|
Backbone.Mediator.publish 'audio-player:play-sound', trigger: 'game-menu-close', volume: 1
|
2014-09-20 18:18:21 -04:00
|
|
|
super()
|
|
|
|
|
2014-09-20 19:04:13 -04:00
|
|
|
updateConfig: (callback, skipSessionSave) ->
|
2014-09-20 18:18:21 -04:00
|
|
|
sessionHeroConfig = @options.session.get('heroConfig') ? {}
|
|
|
|
lastHeroConfig = me.get('heroConfig') ? {}
|
2014-10-09 18:54:18 -04:00
|
|
|
thangType = @subviews.choose_hero_view.selectedHero?.get('original') ? sessionHeroConfig.thangType ? lastHeroConfig.thangType
|
2014-09-20 18:18:21 -04:00
|
|
|
inventory = @subviews.inventory_view.getCurrentEquipmentConfig()
|
|
|
|
patchSession = patchMe = false
|
|
|
|
props = thangType: thangType, inventory: inventory
|
|
|
|
for key, val of props when val
|
|
|
|
patchSession ||= not _.isEqual val, sessionHeroConfig[key]
|
|
|
|
patchMe ||= not _.isEqual val, lastHeroConfig[key]
|
|
|
|
sessionHeroConfig[key] = val
|
|
|
|
lastHeroConfig[key] = val
|
2014-09-20 19:04:13 -04:00
|
|
|
if (codeLanguage = @subviews.choose_hero_view.codeLanguage) and @subviews.choose_hero_view.codeLanguageChanged
|
|
|
|
patchSession ||= codeLanguage isnt @options.session.get('codeLanguage')
|
|
|
|
patchMe ||= codeLanguage isnt me.get('aceConfig')?.language
|
|
|
|
@options.session.set 'codeLanguage', codeLanguage
|
|
|
|
aceConfig = me.get('aceConfig', true) ? {}
|
|
|
|
aceConfig.language = codeLanguage
|
|
|
|
me.set 'aceConfig', aceConfig
|
2014-09-20 18:18:21 -04:00
|
|
|
if patchMe
|
2014-10-21 16:57:49 -04:00
|
|
|
console.log 'setting me.heroConfig to', lastHeroConfig
|
2014-09-20 18:18:21 -04:00
|
|
|
me.set 'heroConfig', lastHeroConfig
|
|
|
|
me.patch()
|
|
|
|
if patchSession
|
2014-10-21 16:57:49 -04:00
|
|
|
console.log 'setting session.heroConfig to', sessionHeroConfig
|
2014-09-20 18:18:21 -04:00
|
|
|
@options.session.set 'heroConfig', sessionHeroConfig
|
|
|
|
@options.session.patch success: callback unless skipSessionSave
|
|
|
|
else
|
|
|
|
callback?()
|
2014-09-19 14:03:38 -04:00
|
|
|
|
2014-09-20 01:15:58 -04:00
|
|
|
onClickChooseInventory: (e) ->
|
|
|
|
@chooseHeroView.$el.add('#choose-inventory-button, #choose-hero-header').addClass 'secret'
|
|
|
|
@inventoryView.$el.add('#choose-hero-button, #play-level-button, #choose-inventory-header').removeClass 'secret'
|
2014-09-21 02:06:28 -04:00
|
|
|
@inventoryView.selectedHero = @chooseHeroView.selectedHero
|
|
|
|
@inventoryView.onShown()
|
2014-10-21 19:49:25 -04:00
|
|
|
window.tracker?.trackEvent 'Play Level Modal', Action: 'Choose Inventory'
|
2014-09-20 01:15:58 -04:00
|
|
|
|
|
|
|
onClickChooseHero: (e) ->
|
|
|
|
@chooseHeroView.$el.add('#choose-inventory-button, #choose-hero-header').removeClass 'secret'
|
|
|
|
@inventoryView.$el.add('#choose-hero-button, #play-level-button, #choose-inventory-header').addClass 'secret'
|
2014-09-21 02:06:28 -04:00
|
|
|
@chooseHeroView.onShown()
|
2014-10-15 13:33:33 -04:00
|
|
|
@inventoryView.endHighlight()
|
2014-10-21 19:49:25 -04:00
|
|
|
window.tracker?.trackEvent 'Play Level Modal', Action: 'Choose Hero'
|
2014-09-20 01:15:58 -04:00
|
|
|
|
|
|
|
onClickPlayLevel: (e) ->
|
2014-10-09 18:54:18 -04:00
|
|
|
return if @$el.find('#play-level-button').prop 'disabled'
|
2014-09-20 18:18:21 -04:00
|
|
|
@showLoading()
|
2014-10-13 20:40:16 -04:00
|
|
|
ua = navigator.userAgent.toLowerCase()
|
2014-10-15 13:28:29 -04:00
|
|
|
unless hasGoneFullScreenOnce or (/safari/.test(ua) and not /chrome/.test(ua)) or $(window).height() >= 658 # Min vertical resolution needed at 1366px wide
|
2014-10-13 20:40:16 -04:00
|
|
|
@toggleFullscreen()
|
|
|
|
hasGoneFullScreenOnce = true
|
2014-09-20 19:04:13 -04:00
|
|
|
@updateConfig =>
|
2014-09-20 18:18:21 -04:00
|
|
|
@navigatingToPlay = true
|
2014-09-25 03:02:53 -04:00
|
|
|
viewClass = if @options.levelPath is 'ladder' then LadderView else PlayLevelView
|
2014-09-20 18:18:21 -04:00
|
|
|
Backbone.Mediator.publish 'router:navigate', {
|
2014-09-25 03:02:53 -04:00
|
|
|
route: "/play/#{@options.levelPath || 'level'}/#{@options.levelID}"
|
|
|
|
viewClass: viewClass
|
|
|
|
viewArgs: [{supermodel: @supermodel}, @options.levelID]
|
|
|
|
}
|
2014-10-21 19:49:25 -04:00
|
|
|
window.tracker?.trackEvent 'Play Level Modal', Action: 'Play'
|
2014-09-21 02:06:28 -04:00
|
|
|
|
|
|
|
onEnterPressed: (e) ->
|
|
|
|
(if @chooseHeroView.$el.hasClass('secret') then @onClickPlayLevel else @onClickChooseInventory).apply @
|