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/tome/cast_button'
|
|
|
|
{me} = require 'lib/auth'
|
|
|
|
|
2014-07-17 20:20:11 -04:00
|
|
|
module.exports = class CastButtonView extends CocoView
|
2014-01-03 13:32:13 -05:00
|
|
|
id: 'cast-button-view'
|
|
|
|
template: template
|
|
|
|
|
2014-03-24 13:11:27 -04:00
|
|
|
events:
|
|
|
|
'click .cast-button': 'onCastButtonClick'
|
2014-08-23 17:31:38 -04:00
|
|
|
'click .cast-real-time-button': 'onCastRealTimeButtonClick'
|
2014-03-24 13:11:27 -04:00
|
|
|
|
2014-01-03 13:32:13 -05:00
|
|
|
subscriptions:
|
2014-06-30 22:16:26 -04:00
|
|
|
'tome:spell-changed': 'onSpellChanged'
|
2014-01-03 13:32:13 -05:00
|
|
|
'tome:cast-spells': 'onCastSpells'
|
|
|
|
'god:world-load-progress-changed': 'onWorldLoadProgressChanged'
|
|
|
|
'god:new-world-created': 'onNewWorld'
|
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
|
|
|
|
|
|
|
constructor: (options) ->
|
|
|
|
super options
|
|
|
|
@spells = options.spells
|
2014-02-19 17:00:54 -05:00
|
|
|
@levelID = options.levelID
|
2014-06-30 22:16:26 -04:00
|
|
|
@castShortcut = '⇧↵'
|
2014-01-03 13:32:13 -05:00
|
|
|
|
2014-02-11 17:58:45 -05:00
|
|
|
getRenderData: (context={}) ->
|
2014-01-03 13:32:13 -05:00
|
|
|
context = super context
|
2014-08-25 00:39:34 -04:00
|
|
|
shift = $.i18n.t 'keyboard_shortcuts.shift'
|
|
|
|
enter = $.i18n.t 'keyboard_shortcuts.enter'
|
|
|
|
castShortcutVerbose = "#{shift}+#{enter}"
|
|
|
|
castRealTimeShortcutVerbose = (if @isMac() then 'Cmd' else 'Ctrl') + '+' + castShortcutVerbose
|
|
|
|
context.castVerbose = castShortcutVerbose + ': ' + $.i18n.t('keyboard_shortcuts.cast_spell')
|
|
|
|
context.castRealTimeVerbose = castRealTimeShortcutVerbose + ': ' + $.i18n.t('keyboard_shortcuts.run_real_time')
|
2014-01-03 13:32:13 -05:00
|
|
|
context
|
|
|
|
|
|
|
|
afterRender: ->
|
|
|
|
super()
|
2014-02-12 15:41:41 -05:00
|
|
|
@castButton = $('.cast-button', @$el)
|
|
|
|
@castButtonGroup = $('.cast-button-group', @$el)
|
|
|
|
@castOptions = $('.autocast-delays', @$el)
|
2014-03-21 16:04:16 -04:00
|
|
|
delay = me.get('autocastDelay')
|
2014-08-23 17:31:38 -04:00
|
|
|
delay ?= 90019001
|
2014-01-03 13:32:13 -05:00
|
|
|
@setAutocastDelay delay
|
|
|
|
|
2014-01-25 18:11:29 -05:00
|
|
|
attachTo: (spellView) ->
|
|
|
|
@$el.detach().prependTo(spellView.toolbarView.$el).show()
|
|
|
|
|
2014-02-12 23:45:29 -05:00
|
|
|
onCastButtonClick: (e) ->
|
|
|
|
Backbone.Mediator.publish 'tome:manual-cast', {}
|
|
|
|
|
2014-08-23 17:31:38 -04:00
|
|
|
onCastRealTimeButtonClick: (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 @multiplayerSession
|
2014-08-29 18:10:04 -04:00
|
|
|
Backbone.Mediator.publish 'real-time-multiplayer:manual-cast', {}
|
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
|
|
|
# Wait for multiplayer session to be up and running
|
|
|
|
@multiplayerSession.on 'change', (e) =>
|
|
|
|
if @multiplayerSession.get('state') is 'running'
|
|
|
|
# Real-time multiplayer session is ready to go, so resume normal cast
|
|
|
|
@multiplayerSession.off()
|
|
|
|
Backbone.Mediator.publish 'tome:manual-cast', {realTime: true}
|
|
|
|
else
|
|
|
|
Backbone.Mediator.publish 'tome:manual-cast', {realTime: true}
|
2014-08-23 17:31:38 -04:00
|
|
|
|
2014-02-13 20:43:42 -05:00
|
|
|
onCastOptionsClick: (e) =>
|
2014-08-27 15:24:03 -04:00
|
|
|
Backbone.Mediator.publish 'tome:focus-editor', {}
|
2014-02-12 15:41:41 -05:00
|
|
|
@castButtonGroup.removeClass 'open'
|
|
|
|
@setAutocastDelay $(e.target).attr 'data-delay'
|
|
|
|
false
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
onSpellChanged: (e) ->
|
|
|
|
@updateCastButton()
|
|
|
|
|
|
|
|
onCastSpells: (e) ->
|
2014-05-11 20:42:32 -04:00
|
|
|
return if e.preload
|
2014-01-03 13:32:13 -05:00
|
|
|
@casting = true
|
2014-05-20 00:53:14 -04:00
|
|
|
if @hasStartedCastingOnce # Don't play this sound the first time
|
2014-08-27 15:24:03 -04:00
|
|
|
Backbone.Mediator.publish 'audio-player:play-sound', trigger: 'cast', volume: 0.5
|
2014-05-20 00:53:14 -04:00
|
|
|
@hasStartedCastingOnce = true
|
2014-01-03 13:32:13 -05:00
|
|
|
@updateCastButton()
|
2014-02-19 21:04:37 -05:00
|
|
|
@onWorldLoadProgressChanged progress: 0
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
onWorldLoadProgressChanged: (e) ->
|
2014-02-28 14:05:41 -05:00
|
|
|
return # trying out showing progress on the canvas instead
|
2014-01-03 13:32:13 -05:00
|
|
|
overlay = @castButtonGroup.find '.button-progress-overlay'
|
2014-02-22 20:50:45 -05:00
|
|
|
overlay.css 'width', e.progress * @castButton.outerWidth() + 1
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
onNewWorld: (e) ->
|
|
|
|
@casting = false
|
2014-05-20 00:53:14 -04:00
|
|
|
if @hasCastOnce # Don't play this sound the first time
|
2014-08-27 15:24:03 -04:00
|
|
|
Backbone.Mediator.publish 'audio-player:play-sound', trigger: 'cast-end', volume: 0.5
|
2014-05-20 00:53:14 -04:00
|
|
|
@hasCastOnce = true
|
2014-01-03 13:32:13 -05:00
|
|
|
@updateCastButton()
|
|
|
|
|
|
|
|
updateCastButton: ->
|
|
|
|
return if _.some @spells, (spell) => not spell.loaded
|
2014-04-22 14:04:56 -04:00
|
|
|
|
2014-04-22 11:54:35 -04:00
|
|
|
async.some _.values(@spells), (spell, callback) =>
|
|
|
|
spell.hasChangedSignificantly spell.getSource(), null, callback
|
|
|
|
, (castable) =>
|
2014-05-19 13:08:12 -04:00
|
|
|
Backbone.Mediator.publish 'tome:spell-has-changed-significantly-calculation', hasChangedSignificantly: castable
|
2014-04-22 11:54:35 -04:00
|
|
|
@castButtonGroup.toggleClass('castable', castable).toggleClass('casting', @casting)
|
|
|
|
if @casting
|
2014-06-30 22:16:26 -04:00
|
|
|
s = $.i18n.t('play_level.tome_cast_button_casting', defaultValue: 'Casting')
|
2014-04-22 11:54:35 -04:00
|
|
|
else if castable
|
2014-06-30 22:16:26 -04:00
|
|
|
s = $.i18n.t('play_level.tome_cast_button_castable', defaultValue: 'Cast Spell') + ' ' + @castShortcut
|
2014-04-22 11:54:35 -04:00
|
|
|
else
|
2014-06-30 22:16:26 -04:00
|
|
|
s = $.i18n.t('play_level.tome_cast_button_cast', defaultValue: 'Spell Cast')
|
2014-04-22 11:54:35 -04:00
|
|
|
@castButton.text s
|
|
|
|
@castButton.prop 'disabled', not castable
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
setAutocastDelay: (delay) ->
|
2014-06-30 22:16:26 -04:00
|
|
|
#console.log 'Set autocast delay to', delay
|
2014-01-03 13:32:13 -05:00
|
|
|
return unless delay
|
|
|
|
@autocastDelay = delay = parseInt delay
|
2014-03-21 16:04:16 -04:00
|
|
|
me.set('autocastDelay', delay)
|
2014-06-11 17:17:31 -04:00
|
|
|
me.patch()
|
2014-08-25 00:39:34 -04:00
|
|
|
spell.view?.setAutocastDelay delay for spellKey, spell of @spells
|
2014-01-03 13:32:13 -05:00
|
|
|
@castOptions.find('a').each ->
|
|
|
|
$(@).toggleClass('selected', parseInt($(@).attr('data-delay')) is delay)
|
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
|
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
|
|
|
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
|
|
|
if @multiplayerSession
|
|
|
|
@multiplayerSession.off()
|
|
|
|
@multiplayerSession = null
|