2014-11-28 20:49:41 -05:00
|
|
|
CocoView = require 'views/core/CocoView'
|
2014-08-23 22:00:35 -04:00
|
|
|
template = require 'templates/play/level/level-flags-view'
|
2014-11-28 20:49:41 -05:00
|
|
|
{me} = require 'core/auth'
|
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-08-23 22:00:35 -04:00
|
|
|
|
2014-09-04 23:10:04 -04:00
|
|
|
multiplayerFlagDelay = 0.5 # Long, static second delay for now; should be more than enough.
|
|
|
|
|
2014-08-23 22:00:35 -04:00
|
|
|
module.exports = class LevelFlagsView extends CocoView
|
|
|
|
id: 'level-flags-view'
|
|
|
|
template: template
|
2014-09-22 01:10:52 -04:00
|
|
|
className: 'secret'
|
2014-08-23 22:00:35 -04:00
|
|
|
|
|
|
|
subscriptions:
|
|
|
|
'playback:real-time-playback-started': 'onRealTimePlaybackStarted'
|
|
|
|
'playback:real-time-playback-ended': 'onRealTimePlaybackEnded'
|
|
|
|
'surface:stage-mouse-down': 'onStageMouseDown'
|
|
|
|
'god:new-world-created': 'onNewWorld'
|
|
|
|
'god:streaming-world-updated': 'onNewWorld'
|
2014-08-24 19:09:06 -04:00
|
|
|
'surface:remove-flag': 'onRemoveFlag'
|
2014-08-29 18:10:04 -04:00
|
|
|
'real-time-multiplayer:joined-game': 'onJoinedMultiplayerGame'
|
2014-08-23 22:00:35 -04:00
|
|
|
|
|
|
|
events:
|
|
|
|
'click .green-flag': -> @onFlagSelected color: 'green', source: 'button'
|
|
|
|
'click .black-flag': -> @onFlagSelected color: 'black', source: 'button'
|
|
|
|
'click .violet-flag': -> @onFlagSelected color: 'violet', source: 'button'
|
|
|
|
|
|
|
|
shortcuts:
|
|
|
|
'g': -> @onFlagSelected color: 'green', source: 'shortcut'
|
|
|
|
'b': -> @onFlagSelected color: 'black', source: 'shortcut'
|
|
|
|
'v': -> @onFlagSelected color: 'violet', source: 'shortcut'
|
|
|
|
'esc': -> @onFlagSelected color: null, source: 'shortcut'
|
2014-08-24 19:09:06 -04:00
|
|
|
'delete, del, backspace': 'onDeletePressed'
|
2014-08-23 22:00:35 -04:00
|
|
|
|
|
|
|
constructor: (options) ->
|
|
|
|
super options
|
2014-11-23 20:15:59 -05:00
|
|
|
@levelID = options.levelID
|
2014-08-23 22:00:35 -04:00
|
|
|
@world = options.world
|
|
|
|
|
|
|
|
onRealTimePlaybackStarted: (e) ->
|
|
|
|
@realTime = true
|
|
|
|
@$el.show()
|
|
|
|
@flags = {}
|
|
|
|
@flagHistory = []
|
|
|
|
|
|
|
|
onRealTimePlaybackEnded: (e) ->
|
2014-08-24 19:48:59 -04:00
|
|
|
@onFlagSelected color: null
|
2014-08-25 00:39:34 -04:00
|
|
|
@realTime = false
|
2014-08-23 22:00:35 -04:00
|
|
|
@$el.hide()
|
|
|
|
|
|
|
|
onFlagSelected: (e) ->
|
2014-08-25 00:39:34 -04:00
|
|
|
return unless @realTime
|
2014-11-26 09:58:23 -05:00
|
|
|
@playSound 'menu-button-click' if e.color
|
2014-08-25 17:02:23 -04:00
|
|
|
color = if e.color is @flagColor then null else e.color
|
2014-08-23 22:00:35 -04:00
|
|
|
@flagColor = color
|
2014-08-24 19:09:06 -04:00
|
|
|
Backbone.Mediator.publish 'level:flag-color-selected', color: color
|
2014-08-23 22:00:35 -04:00
|
|
|
@$el.find('.flag-button').removeClass('active')
|
|
|
|
@$el.find(".#{color}-flag").addClass('active') if color
|
|
|
|
|
|
|
|
onStageMouseDown: (e) ->
|
|
|
|
return unless @flagColor and @realTime
|
2014-11-26 09:58:23 -05:00
|
|
|
@playSound 'menu-button-click' # TODO: different flag placement sound?
|
2014-08-23 22:00:35 -04:00
|
|
|
pos = x: e.worldPos.x, y: e.worldPos.y
|
2014-09-04 23:10:04 -04:00
|
|
|
delay = if @realTimeFlags then multiplayerFlagDelay else 0
|
|
|
|
now = @world.dt * @world.frames.length
|
2014-11-15 19:56:18 -05:00
|
|
|
flag = player: me.id, team: me.team, color: @flagColor, pos: pos, time: now + delay, active: true, source: 'click'
|
2014-08-23 22:00:35 -04:00
|
|
|
@flags[@flagColor] = flag
|
|
|
|
@flagHistory.push flag
|
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
|
|
|
@realTimeFlags?.create flag
|
2014-08-23 22:00:35 -04:00
|
|
|
Backbone.Mediator.publish 'level:flag-updated', flag
|
2014-08-24 19:09:06 -04:00
|
|
|
#console.log 'trying to place flag at', @world.age, 'and think it will happen by', flag.time
|
2014-08-23 22:00:35 -04:00
|
|
|
|
2014-08-24 19:09:06 -04:00
|
|
|
onDeletePressed: (e) ->
|
|
|
|
return unless @realTime
|
|
|
|
Backbone.Mediator.publish 'surface:remove-selected-flag', {}
|
|
|
|
|
|
|
|
onRemoveFlag: (e) ->
|
2014-08-23 22:00:35 -04:00
|
|
|
delete @flags[e.color]
|
2014-09-04 23:10:04 -04:00
|
|
|
delay = if @realTimeFlags then multiplayerFlagDelay else 0
|
|
|
|
now = @world.dt * @world.frames.length
|
2014-11-15 19:56:18 -05:00
|
|
|
flag = player: me.id, team: me.team, color: e.color, time: now + delay, active: false, source: 'click'
|
2014-08-23 22:00:35 -04:00
|
|
|
@flagHistory.push flag
|
|
|
|
Backbone.Mediator.publish 'level:flag-updated', flag
|
2014-08-24 19:09:06 -04:00
|
|
|
#console.log e.color, 'deleted at time', flag.time
|
2014-08-23 22:00:35 -04:00
|
|
|
|
|
|
|
onNewWorld: (event) ->
|
|
|
|
return unless event.world.name is @world.name
|
2014-08-25 00:39:34 -04:00
|
|
|
@world = @options.world = event.world
|
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
|
|
|
onJoinedMultiplayerGame: (e) ->
|
2014-11-23 20:15:59 -05:00
|
|
|
@realTimeFlags = new RealTimeCollection("multiplayer_level_sessions/#{@levelID}/#{e.realTimeSessionID}/flagHistory")
|
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
|
|
|
@realTimeFlags.on 'add', @onRealTimeMultiplayerFlagAdded
|
2014-09-04 23:10:04 -04:00
|
|
|
@realTimeFlags.on 'remove', @onRealTimeMultiplayerFlagRemoved
|
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
|
|
|
onLeftMultiplayerGame: (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
|
|
|
if @realTimeFlags
|
2014-11-17 18:07:10 -05:00
|
|
|
@realTimeFlags.off 'add', @onRealTimeMultiplayerFlagAdded
|
|
|
|
@realTimeFlags.off 'remove', @onRealTimeMultiplayerFlagRemoved
|
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
|
|
|
@realTimeFlags = null
|
|
|
|
|
|
|
|
onRealTimeMultiplayerFlagAdded: (e) =>
|
|
|
|
if e.get('player') != me.id
|
|
|
|
# TODO: what is @flags used for?
|
|
|
|
# Build local flag from Backbone.Model flag
|
|
|
|
flag =
|
|
|
|
player: e.get('player')
|
|
|
|
team: e.get('team')
|
|
|
|
color: e.get('color')
|
|
|
|
pos: e.get('pos')
|
|
|
|
time: e.get('time')
|
|
|
|
active: e.get('active')
|
2014-11-15 19:56:18 -05:00
|
|
|
#source: 'click'? e.get('source')? nothing?
|
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
|
|
|
@flagHistory.push flag
|
|
|
|
Backbone.Mediator.publish 'level:flag-updated', flag
|
2014-09-04 23:10:04 -04:00
|
|
|
|
|
|
|
onRealTimeMultiplayerFlagRemoved: (e) =>
|