codecombat/app/views/play/level/modal/multiplayer_modal.coffee

98 lines
3.1 KiB
CoffeeScript
Raw Normal View History

2014-01-03 13:32:13 -05:00
View = require 'views/kinds/ModalView'
template = require 'templates/play/level/modal/multiplayer'
2014-02-06 20:31:08 -05:00
{me} = require('lib/auth')
2014-01-03 13:32:13 -05:00
module.exports = class MultiplayerModal extends View
id: 'level-multiplayer-modal'
template: template
events:
'click textarea': 'onClickLink'
'change #multiplayer': 'updateLinkSection'
'click .rank-game-button': 'onRankGame'
2014-01-03 13:32:13 -05:00
constructor: (options) ->
super(options)
@session = options.session
@level = options.level
2014-03-24 12:58:34 -04:00
@listenTo(@session, 'change:multiplayer', @updateLinkSection)
2014-02-06 20:31:08 -05:00
@playableTeams = options.playableTeams
2014-01-03 13:32:13 -05:00
getRenderData: ->
c = super()
c.joinLink = (document.location.href.replace(/\?.*/, '').replace('#', '') +
'?session=' +
@session.id)
c.multiplayer = @session.get 'multiplayer'
c.team = @session.get 'team'
c.levelSlug = @level?.get 'slug'
2014-02-06 20:31:08 -05:00
c.playableTeams = @playableTeams
# For now, ladderGame will disallow multiplayer, because session code combining doesn't play nice yet.
if @level?.get('type') is 'ladder'
c.ladderGame = true
c.readyToRank = @session?.readyToRank()
2014-01-03 13:32:13 -05:00
c
2014-01-03 13:32:13 -05:00
afterRender: ->
super()
@updateLinkSection()
2014-02-06 20:31:08 -05:00
onClickLink: (e) ->
2014-01-03 13:32:13 -05:00
e.target.select()
2014-02-11 18:38:36 -05:00
updateLinkSection: ->
multiplayer = @$el.find('#multiplayer').prop('checked')
2014-01-03 13:32:13 -05:00
la = @$el.find('#link-area')
la.toggle Boolean(multiplayer)
true
2014-01-03 13:32:13 -05:00
onHidden: ->
multiplayer = Boolean(@$el.find('#multiplayer').prop('checked'))
@session.set('multiplayer', multiplayer)
2014-02-11 18:38:36 -05:00
onRankGame: (e) ->
button = @$el.find('.rank-game-button')
button.text($.i18n.t('play_level.victory_ranking_game', defaultValue: 'Submitting...'))
button.prop 'disabled', true
2014-05-14 18:45:38 -04:00
ajaxData =
session: @session.id
levelID: @level.id
originalLevelID: @level.get('original')
levelMajorVersion: @level.get('version').major
transpiledCode: @transpileSession(@session)
ladderURL = "/play/ladder/#{@level.get('slug')}#my-matches"
goToLadder = -> Backbone.Mediator.publish 'router:navigate', route: ladderURL
$.ajax '/queue/scoring',
type: 'POST'
data: ajaxData
success: goToLadder
failure: (response) ->
console.error "Couldn't submit game for ranking:", response
goToLadder()
2014-05-14 18:45:38 -04:00
transpileSession: (session) ->
submittedCode = session.get('code')
transpiledCode = {}
for thang, spells of submittedCode
transpiledCode[thang] = {}
for spellID, spell of spells
unless _.contains(session.get('teamSpells')[session.get('team')], thang + "/" + spellID) then continue
2014-05-14 18:45:38 -04:00
#DRY this
aetherOptions =
problems: {}
language: "javascript"
functionName: spellID
functionParameters: []
yieldConditionally: spellID is "plan"
globals: ['Vector', '_']
protectAPI: true
includeFlow: false
if spellID is "hear" then aetherOptions["functionParameters"] = ["speaker","message","data"]
2014-05-14 18:45:38 -04:00
aether = new Aether aetherOptions
transpiledCode[thang][spellID] = aether.transpile spell
transpiledCode
2014-02-11 18:38:36 -05:00
destroy: ->
super()