2014-11-28 20:49:41 -05:00
|
|
|
CocoView = require 'views/core/CocoView'
|
2016-07-28 16:39:58 -04:00
|
|
|
template = require 'templates/play/level/control-bar-view'
|
2014-11-28 20:49:41 -05:00
|
|
|
{me} = require 'core/auth'
|
2014-01-03 13:32:13 -05:00
|
|
|
|
2016-06-26 16:51:14 -04:00
|
|
|
Campaign = require 'models/Campaign'
|
|
|
|
Classroom = require 'models/Classroom'
|
|
|
|
Course = require 'models/Course'
|
|
|
|
CourseInstance = require 'models/CourseInstance'
|
2014-11-29 15:46:04 -05:00
|
|
|
GameMenuModal = require 'views/play/menu/GameMenuModal'
|
2014-11-07 11:54:22 -05:00
|
|
|
LevelSetupManager = require 'lib/LevelSetupManager'
|
2014-01-03 13:32:13 -05:00
|
|
|
|
2014-07-17 20:20:11 -04:00
|
|
|
module.exports = class ControlBarView extends CocoView
|
2014-06-30 22:16:26 -04:00
|
|
|
id: 'control-bar-view'
|
2014-01-03 13:32:13 -05:00
|
|
|
template: template
|
|
|
|
|
|
|
|
subscriptions:
|
2014-11-08 11:58:36 -05:00
|
|
|
'level:disable-controls': 'onDisableControls'
|
|
|
|
'level:enable-controls': 'onEnableControls'
|
2014-11-18 14:21:29 -05:00
|
|
|
'ipad:memory-warning': 'onIPadMemoryWarning'
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
events:
|
2014-08-27 15:24:03 -04:00
|
|
|
'click #next-game-button': -> Backbone.Mediator.publish 'level:next-game-pressed', {}
|
2014-08-26 01:05:24 -04:00
|
|
|
'click #game-menu-button': 'showGameMenuModal'
|
|
|
|
'click': -> Backbone.Mediator.publish 'tome:focus-editor', {}
|
2014-11-20 14:11:27 -05:00
|
|
|
'click .levels-link-area': 'onClickHome'
|
2014-09-25 03:02:53 -04:00
|
|
|
'click .home a': 'onClickHome'
|
2014-12-08 01:44:20 -05:00
|
|
|
'click #control-bar-sign-up-button': 'onClickSignupButton'
|
2014-09-25 03:02:53 -04:00
|
|
|
|
2014-01-03 13:32:13 -05:00
|
|
|
constructor: (options) ->
|
2016-06-26 16:51:14 -04:00
|
|
|
@supermodel = options.supermodel
|
2015-11-12 12:57:34 -05:00
|
|
|
@courseID = options.courseID
|
|
|
|
@courseInstanceID = options.courseInstanceID
|
2015-09-24 20:12:18 -04:00
|
|
|
|
2014-01-03 13:32:13 -05:00
|
|
|
@worldName = options.worldName
|
|
|
|
@session = options.session
|
|
|
|
@level = options.level
|
2016-06-08 09:24:59 -04:00
|
|
|
@levelSlug = @level.get('slug')
|
|
|
|
@levelID = @levelSlug or @level.id
|
2014-03-12 20:51:09 -04:00
|
|
|
@spectateGame = options.spectateGame ? false
|
2015-01-31 13:04:02 -05:00
|
|
|
@observing = options.session.get('creator') isnt me.id
|
2016-06-26 16:51:14 -04:00
|
|
|
|
|
|
|
@levelNumber = ''
|
2016-07-14 12:38:45 -04:00
|
|
|
if @level.isType('course', 'game-dev', 'web-dev') and @level.get('campaignIndex')?
|
2016-06-26 16:51:14 -04:00
|
|
|
@levelNumber = @level.get('campaignIndex') + 1
|
|
|
|
if @courseInstanceID
|
|
|
|
@courseInstance = new CourseInstance(_id: @courseInstanceID)
|
|
|
|
jqxhr = @courseInstance.fetch()
|
|
|
|
@supermodel.trackRequest(jqxhr)
|
|
|
|
new Promise(jqxhr.then).then(=>
|
|
|
|
@classroom = new Classroom(_id: @courseInstance.get('classroomID'))
|
|
|
|
@supermodel.trackRequest @classroom.fetch()
|
|
|
|
)
|
|
|
|
else if @courseID
|
|
|
|
@course = new Course(_id: @courseID)
|
|
|
|
jqxhr = @course.fetch()
|
|
|
|
@supermodel.trackRequest(jqxhr)
|
|
|
|
new Promise(jqxhr.then).then(=>
|
|
|
|
@campaign = new Campaign(_id: @course.get('campaignID'))
|
|
|
|
@supermodel.trackRequest(@campaign.fetch())
|
|
|
|
)
|
2014-01-03 13:32:13 -05:00
|
|
|
super options
|
2015-01-16 15:50:10 -05:00
|
|
|
if @level.get 'replayable'
|
|
|
|
@listenTo @session, 'change-difficulty', @onSessionDifficultyChanged
|
2014-01-03 13:32:13 -05:00
|
|
|
|
2016-06-26 16:51:14 -04:00
|
|
|
onLoaded: ->
|
|
|
|
if @classroom
|
|
|
|
@levelNumber = @classroom.getLevelNumber(@level.get('original'), @levelNumber)
|
|
|
|
else if @campaign
|
|
|
|
@levelNumber = @campaign.getLevelNumber(@level.get('original'), @levelNumber)
|
|
|
|
super()
|
|
|
|
|
2014-01-03 13:32:13 -05:00
|
|
|
setBus: (@bus) ->
|
|
|
|
|
2014-02-26 21:58:25 -05:00
|
|
|
getRenderData: (c={}) ->
|
|
|
|
super c
|
|
|
|
c.worldName = @worldName
|
2016-07-14 11:58:43 -04:00
|
|
|
c.ladderGame = @level.isType('ladder', 'hero-ladder', 'course-ladder')
|
2015-01-16 15:50:10 -05:00
|
|
|
if @level.get 'replayable'
|
|
|
|
c.levelDifficulty = @session.get('state')?.difficulty ? 0
|
2015-02-04 14:31:43 -05:00
|
|
|
if @observing
|
|
|
|
c.levelDifficulty = Math.max 0, c.levelDifficulty - 1 # Show the difficulty they won, not the next one.
|
2015-01-16 15:50:10 -05:00
|
|
|
c.difficultyTitle = "#{$.i18n.t 'play.level_difficulty'}#{c.levelDifficulty}"
|
|
|
|
@lastDifficulty = c.levelDifficulty
|
2014-03-12 20:51:09 -04:00
|
|
|
c.spectateGame = @spectateGame
|
2015-01-31 13:04:02 -05:00
|
|
|
c.observing = @observing
|
2014-11-18 14:21:29 -05:00
|
|
|
@homeViewArgs = [{supermodel: if @hasReceivedMemoryWarning then null else @supermodel}]
|
2016-04-15 13:58:52 -04:00
|
|
|
if me.isSessionless()
|
2016-04-08 15:59:10 -04:00
|
|
|
@homeLink = "/teachers/courses"
|
|
|
|
@homeViewClass = "views/courses/TeacherCoursesView"
|
2016-07-14 11:58:43 -04:00
|
|
|
else if @level.isType('ladder', 'ladder-tutorial', 'hero-ladder', 'course-ladder')
|
2015-09-02 17:54:44 -04:00
|
|
|
levelID = @level.get('slug')?.replace(/\-tutorial$/, '') or @level.id
|
2016-09-01 19:38:02 -04:00
|
|
|
@homeLink = "/play/ladder/#{levelID}"
|
2014-11-29 19:46:36 -05:00
|
|
|
@homeViewClass = 'views/ladder/LadderView'
|
2014-09-25 03:02:53 -04:00
|
|
|
@homeViewArgs.push levelID
|
2016-09-01 19:38:02 -04:00
|
|
|
if leagueID = @getQueryVariable('league') or @getQueryVariable('course-instance')
|
2016-07-14 11:58:43 -04:00
|
|
|
leagueType = if @level.isType('course-ladder') then 'course' else 'clan'
|
2015-09-04 19:21:35 -04:00
|
|
|
@homeViewArgs.push leagueType
|
|
|
|
@homeViewArgs.push leagueID
|
|
|
|
@homeLink += "/#{leagueType}/#{leagueID}"
|
2016-07-15 19:57:39 -04:00
|
|
|
else if @level.isType('course') or @courseID
|
2015-09-24 20:12:18 -04:00
|
|
|
@homeLink = '/courses'
|
|
|
|
@homeViewClass = 'views/courses/CoursesView'
|
|
|
|
if @courseID
|
|
|
|
@homeLink += "/#{@courseID}"
|
|
|
|
@homeViewArgs.push @courseID
|
|
|
|
@homeViewClass = 'views/courses/CourseDetailsView'
|
|
|
|
if @courseInstanceID
|
2015-09-24 20:52:00 -04:00
|
|
|
@homeLink += "/#{@courseInstanceID}"
|
2015-09-24 20:12:18 -04:00
|
|
|
@homeViewArgs.push @courseInstanceID
|
2016-07-15 19:57:39 -04:00
|
|
|
else if @level.isType('hero', 'hero-coop', 'game-dev', 'web-dev') or window.serverConfig.picoCTF
|
|
|
|
@homeLink = '/play'
|
|
|
|
@homeViewClass = 'views/play/CampaignView'
|
|
|
|
campaign = @level.get 'campaign'
|
|
|
|
@homeLink += '/' + campaign
|
|
|
|
@homeViewArgs.push campaign
|
2014-05-05 18:33:08 -04:00
|
|
|
else
|
2015-07-24 20:37:42 -04:00
|
|
|
@homeLink = '/'
|
2014-11-29 19:46:36 -05:00
|
|
|
@homeViewClass = 'views/HomeView'
|
2015-09-02 17:54:44 -04:00
|
|
|
c.editorLink = "/editor/level/#{@level.get('slug') or @level.id}"
|
2014-11-11 19:36:44 -05:00
|
|
|
c.homeLink = @homeLink
|
2014-02-26 21:58:25 -05:00
|
|
|
c
|
2014-01-03 13:32:13 -05:00
|
|
|
|
2015-08-13 14:09:26 -04:00
|
|
|
showGameMenuModal: (e, tab=null) ->
|
2015-08-13 08:58:37 -04:00
|
|
|
gameMenuModal = new GameMenuModal level: @level, session: @session, supermodel: @supermodel, showTab: tab
|
2014-11-07 11:54:22 -05:00
|
|
|
@openModalView gameMenuModal
|
|
|
|
@listenToOnce gameMenuModal, 'change-hero', ->
|
2014-11-09 19:19:18 -05:00
|
|
|
@setupManager?.destroy()
|
2015-11-12 14:00:54 -05:00
|
|
|
@setupManager = new LevelSetupManager({supermodel: @supermodel, level: @level, levelID: @levelID, parent: @, session: @session, courseID: @courseID, courseInstanceID: @courseInstanceID})
|
2014-11-09 19:19:18 -05:00
|
|
|
@setupManager.open()
|
Real-time multiplayer initial commit
Simple matchmaking, synchronous multiplayer PVP, flags!
Rough matchmaking is under the game menu multiplayer tab, for ladder
games only. After creating a 2-person game there, you can exit that
modal and real-time cast to play against each other.
If you’re the first person to cast, you’ll sit at the real-time level
playback view waiting until the other player casts. When they do, you
both should start the real-time playback (and start placing flags like
crazy people).
If in a multiplayer session, the real-time simulation runs the players’
code against each other. Your multiplayer opponent’s name should be up
near the level name.
Multiplayer sessions are stored completely in Firebase for now, and
removed if both players leave the game. There’s plenty of bugs,
synchronization issues, and minimal polish to add before we push it to
master.
2014-08-29 02:34:07 -04:00
|
|
|
|
2014-09-25 03:02:53 -04:00
|
|
|
onClickHome: (e) ->
|
2016-07-14 11:58:43 -04:00
|
|
|
if @level.isType('course')
|
2016-06-08 09:24:59 -04:00
|
|
|
category = if me.isTeacher() then 'Teachers' else 'Students'
|
|
|
|
window.tracker?.trackEvent 'Play Level Back To Levels', category: category, levelSlug: @levelSlug, ['Mixpanel']
|
2014-09-25 03:02:53 -04:00
|
|
|
e.preventDefault()
|
|
|
|
e.stopImmediatePropagation()
|
|
|
|
Backbone.Mediator.publish 'router:navigate', route: @homeLink, viewClass: @homeViewClass, viewArgs: @homeViewArgs
|
2014-11-08 11:58:36 -05:00
|
|
|
|
2015-08-13 14:09:26 -04:00
|
|
|
onClickSignupButton: (e) ->
|
2014-12-08 01:44:20 -05:00
|
|
|
window.tracker?.trackEvent 'Started Signup', category: 'Play Level', label: 'Control Bar', level: @levelID
|
|
|
|
|
2014-11-08 11:58:36 -05:00
|
|
|
onDisableControls: (e) -> @toggleControls e, false
|
|
|
|
onEnableControls: (e) -> @toggleControls e, true
|
|
|
|
toggleControls: (e, enabled) ->
|
|
|
|
return if e.controls and not ('level' in e.controls)
|
|
|
|
return if enabled is @controlsEnabled
|
|
|
|
@controlsEnabled = enabled
|
|
|
|
@$el.toggleClass 'controls-disabled', not enabled
|
2014-11-09 19:19:18 -05:00
|
|
|
|
2014-11-18 14:21:29 -05:00
|
|
|
onIPadMemoryWarning: (e) ->
|
|
|
|
@hasReceivedMemoryWarning = true
|
|
|
|
|
2015-01-16 15:50:10 -05:00
|
|
|
onSessionDifficultyChanged: ->
|
|
|
|
return if @session.get('state')?.difficulty is @lastDifficulty
|
|
|
|
@render()
|
|
|
|
|
2014-11-09 19:19:18 -05:00
|
|
|
destroy: ->
|
|
|
|
@setupManager?.destroy()
|
|
|
|
super()
|