2014-07-17 20:20:11 -04:00
|
|
|
CocoView = require 'views/kinds/CocoView'
|
2014-01-03 13:32:13 -05:00
|
|
|
template = require 'templates/play/level/control_bar'
|
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
|
|
|
{me} = require 'lib/auth'
|
2014-01-03 13:32:13 -05:00
|
|
|
|
2014-07-29 13:45:01 -04:00
|
|
|
LevelGuideModal = require './modal/LevelGuideModal'
|
2014-08-08 14:36:41 -04:00
|
|
|
GameMenuModal = require 'views/game-menu/GameMenuModal'
|
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
|
|
|
RealTimeCollection = require 'collections/RealTimeCollection'
|
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:
|
|
|
|
'bus:player-states-changed': 'onPlayerStatesChanged'
|
2014-08-29 18:10:04 -04:00
|
|
|
'real-time-multiplayer:joined-game': 'onJoinedRealTimeMultiplayerGame'
|
|
|
|
'real-time-multiplayer:left-game': 'onLeftRealTimeMultiplayerGame'
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
events:
|
|
|
|
'click #docs-button': ->
|
2014-05-16 20:38:33 -04:00
|
|
|
window.tracker?.trackEvent 'Clicked Docs', level: @level.get('name'), label: @level.get('name')
|
2014-01-03 13:32:13 -05:00
|
|
|
@showGuideModal()
|
|
|
|
|
2014-08-27 15:24:03 -04:00
|
|
|
'click #next-game-button': -> Backbone.Mediator.publish 'level:next-game-pressed', {}
|
2014-01-03 13:32:13 -05:00
|
|
|
|
2014-08-26 01:05:24 -04:00
|
|
|
'click #game-menu-button': 'showGameMenuModal'
|
2014-08-08 14:36:41 -04:00
|
|
|
|
2014-08-26 01:05:24 -04:00
|
|
|
'click': -> Backbone.Mediator.publish 'tome:focus-editor', {}
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
constructor: (options) ->
|
|
|
|
@worldName = options.worldName
|
|
|
|
@session = options.session
|
|
|
|
@level = options.level
|
2014-03-12 20:51:09 -04:00
|
|
|
@spectateGame = options.spectateGame ? false
|
2014-01-03 13:32:13 -05:00
|
|
|
super options
|
|
|
|
|
|
|
|
setBus: (@bus) ->
|
|
|
|
|
|
|
|
onPlayerStatesChanged: (e) ->
|
2014-02-12 15:41:41 -05:00
|
|
|
# TODO: this doesn't fire any more. Replacement?
|
2014-01-03 13:32:13 -05:00
|
|
|
return unless @bus is e.bus
|
|
|
|
numPlayers = _.keys(e.players).length
|
|
|
|
return if numPlayers is @numPlayers
|
|
|
|
@numPlayers = numPlayers
|
|
|
|
text = 'Multiplayer'
|
|
|
|
text += " (#{numPlayers})" if numPlayers > 1
|
|
|
|
$('#multiplayer-button', @$el).text(text)
|
|
|
|
|
2014-02-26 21:58:25 -05:00
|
|
|
getRenderData: (c={}) ->
|
|
|
|
super c
|
|
|
|
c.worldName = @worldName
|
|
|
|
c.multiplayerEnabled = @session.get('multiplayer')
|
2014-05-05 18:33:08 -04:00
|
|
|
c.ladderGame = @level.get('type') is 'ladder'
|
2014-03-12 20:51:09 -04:00
|
|
|
c.spectateGame = @spectateGame
|
2014-09-22 17:05:13 -04:00
|
|
|
if @level.get('type', true) in ['ladder', 'ladder-tutorial']
|
2014-05-05 18:33:08 -04:00
|
|
|
c.homeLink = '/play/ladder/' + @level.get('slug').replace /\-tutorial$/, ''
|
2014-09-22 17:05:13 -04:00
|
|
|
else if @level.get('type', true) is 'hero'
|
|
|
|
c.homeLink = '/play-hero'
|
2014-05-05 18:33:08 -04:00
|
|
|
else
|
|
|
|
c.homeLink = '/'
|
2014-08-19 00:49:58 -04:00
|
|
|
c.editorLink = "/editor/level/#{@level.get('slug')}"
|
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
|
|
|
c.multiplayerSession = @multiplayerSession if @multiplayerSession
|
|
|
|
c.multiplayerPlayers = @multiplayerPlayers if @multiplayerPlayers
|
|
|
|
c.meID = me.id
|
2014-02-26 21:58:25 -05:00
|
|
|
c
|
2014-01-03 13:32:13 -05:00
|
|
|
|
2014-03-28 15:22:53 -04:00
|
|
|
afterRender: ->
|
|
|
|
super()
|
|
|
|
@guideHighlightInterval ?= setInterval @onGuideHighlight, 5 * 60 * 1000
|
|
|
|
|
|
|
|
destroy: ->
|
|
|
|
clearInterval @guideHighlightInterval if @guideHighlightInterval
|
|
|
|
super()
|
|
|
|
|
|
|
|
onGuideHighlight: =>
|
|
|
|
return if @destroyed or @guideShownOnce
|
|
|
|
@$el.find('#docs-button').hide().show('highlight', 4000)
|
|
|
|
|
2014-01-03 13:32:13 -05:00
|
|
|
showGuideModal: ->
|
|
|
|
options = {docs: @level.get('documentation'), supermodel: @supermodel}
|
2014-07-29 13:45:01 -04:00
|
|
|
@openModalView(new LevelGuideModal(options))
|
2014-03-28 15:22:53 -04:00
|
|
|
clearInterval @guideHighlightInterval
|
|
|
|
@guideHighlightInterval = null
|
2014-01-03 13:32:13 -05:00
|
|
|
|
2014-08-08 14:36:41 -04:00
|
|
|
showGameMenuModal: ->
|
2014-09-21 23:19:27 -04:00
|
|
|
@openModalView new GameMenuModal level: @level, session: @session
|
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-08-29 18:10:04 -04:00
|
|
|
onJoinedRealTimeMultiplayerGame: (e) ->
|
|
|
|
@multiplayerSession = e.session
|
|
|
|
@multiplayerPlayers = new RealTimeCollection('multiplayer_level_sessions/' + @multiplayerSession.id + '/players')
|
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
|
|
|
@multiplayerPlayers.on 'add', @onRealTimeMultiplayerPlayerAdded
|
|
|
|
@multiplayerPlayers.on 'remove', @onRealTimeMultiplayerPlayerRemoved
|
|
|
|
@render()
|
|
|
|
|
2014-08-29 18:10:04 -04:00
|
|
|
onLeftRealTimeMultiplayerGame: (e) ->
|
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
|
|
|
@multiplayerSession = null
|
|
|
|
@multiplayerPlayers.off()
|
|
|
|
@multiplayerPlayers = null
|
|
|
|
@render()
|
|
|
|
|
|
|
|
onRealTimeMultiplayerPlayerAdded: (e) =>
|
2014-09-03 19:14:33 -04:00
|
|
|
@render() unless @destroyed
|
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
|
|
|
|
|
|
|
onRealTimeMultiplayerPlayerRemoved: (e) =>
|
2014-09-03 19:14:33 -04:00
|
|
|
@render() unless @destroyed
|