From c16b0f97bf9e1de582c972744daa75ba054bb80f Mon Sep 17 00:00:00 2001 From: Matt Lott Date: Sat, 22 Nov 2014 20:48:04 -0800 Subject: [PATCH] Update sync PVP to use transpiledCode --- app/views/play/level/PlayLevelView.coffee | 47 +++++++++++++++------- app/views/play/level/tome/Spell.coffee | 1 - server/levels/sessions/LevelSession.coffee | 2 +- 3 files changed, 33 insertions(+), 17 deletions(-) diff --git a/app/views/play/level/PlayLevelView.coffee b/app/views/play/level/PlayLevelView.coffee index 3f0b759ae..df2d4e9e1 100644 --- a/app/views/play/level/PlayLevelView.coffee +++ b/app/views/play/level/PlayLevelView.coffee @@ -4,6 +4,7 @@ template = require 'templates/play/level' ThangType = require 'models/ThangType' utils = require 'lib/utils' storage = require 'lib/storage' +{createAetherOptions} = require 'lib/aether_utils' # tools Surface = require 'lib/surface/Surface' @@ -217,8 +218,7 @@ module.exports = class PlayLevelView extends RootView opponentSpells = opponentSpells.concat spells if (not @session.get('teamSpells')) and @otherSession?.get('teamSpells') @session.set('teamSpells', @otherSession.get('teamSpells')) - # hero-ladder levels use code instead of transpiledCode - opponentCode = @otherSession?.get('transpiledCode') or @otherSession?.get('code') or {} + opponentCode = @otherSession?.get('transpiledCode') or {} myCode = @session.get('code') or {} for spell in opponentSpells [thang, spell] = spell.split '/' @@ -571,7 +571,20 @@ module.exports = class PlayLevelView extends RootView @onRealTimeMultiplayerLevelUnloaded() super() - # Real-time Multiplayer ###################################################### + onIPadMemoryWarning: (e) -> + @hasReceivedMemoryWarning = true + + onItemPurchased: (e) -> + heroConfig = @session.get('heroConfig') ? {} + inventory = heroConfig.inventory ? {} + slot = e.item.getAllowedSlots()[0] + if slot and not inventory[slot] + # Open up the inventory modal so they can equip the new item + @setupManager?.destroy() + @setupManager = new LevelSetupManager({supermodel: @supermodel, levelID: @levelID, parent: @, session: @session, hadEverChosenHero: true}) + @setupManager.open() + + # Start Real-time Multiplayer ###################################################### # # This view acts as a hub for the real-time multiplayer session for the current level. # @@ -800,6 +813,21 @@ module.exports = class PlayLevelView extends RootView opponentPlayer = player if myPlayer console.info 'Submitting my code' + # Transpile code + # Copied from scripts/transpile.coffee + # TODO: Should this live somewhere else? + transpiledCode = {} + for thang, spells of @session.get('code') + transpiledCode[thang] = {} + for spellID, spell of spells + spellName = thang + '/' + spellID + continue if @session.get('teamSpells') and not (spellName in @session.get('teamSpells')[@session.get('team')]) + # console.log "PlayLevelView Transpiling spell #{spellName}" + aetherOptions = createAetherOptions functionName: spellID, codeLanguage: @session.get('submittedCodeLanguage') + aether = new Aether aetherOptions + transpiledCode[thang][spellID] = aether.transpile spell + # console.log "PlayLevelView transpiled code", transpiledCode + @session.set 'transpiledCode', transpiledCode @session.patch() myPlayer.set 'state', 'submitted' else @@ -904,15 +932,4 @@ module.exports = class PlayLevelView extends RootView # TODO: Don't hardcode spellName Backbone.Mediator.publish 'level:select-sprite', thangID: sessionState.selected, spellName: 'plan' - onIPadMemoryWarning: (e) -> - @hasReceivedMemoryWarning = true - - onItemPurchased: (e) -> - heroConfig = @session.get('heroConfig') ? {} - inventory = heroConfig.inventory ? {} - slot = e.item.getAllowedSlots()[0] - if slot and not inventory[slot] - # Open up the inventory modal so they can equip the new item - @setupManager?.destroy() - @setupManager = new LevelSetupManager({supermodel: @supermodel, levelID: @levelID, parent: @, session: @session, hadEverChosenHero: true}) - @setupManager.open() +# End Real-time Multiplayer ###################################################### diff --git a/app/views/play/level/tome/Spell.coffee b/app/views/play/level/tome/Spell.coffee index 1d7acdcd9..98e713dc3 100644 --- a/app/views/play/level/tome/Spell.coffee +++ b/app/views/play/level/tome/Spell.coffee @@ -185,7 +185,6 @@ module.exports = class Spell shouldUseTranspiledCode: -> # Determine whether this code has already been transpiled, or whether it's raw source needing transpilation. - return false if @levelType is 'hero-ladder' return true if @spectateView # Use transpiled code for both teams if we're just spectating. return true if @isEnemySpell() # Use transpiled for enemy spells. # Players without permissions can't view the raw code. diff --git a/server/levels/sessions/LevelSession.coffee b/server/levels/sessions/LevelSession.coffee index 80f511a9c..46beecef2 100644 --- a/server/levels/sessions/LevelSession.coffee +++ b/server/levels/sessions/LevelSession.coffee @@ -39,7 +39,7 @@ LevelSessionSchema.statics.privateProperties = ['code', 'submittedCode', 'unsubs LevelSessionSchema.statics.editableProperties = ['multiplayer', 'players', 'code', 'codeLanguage', 'completed', 'state', 'levelName', 'creatorName', 'levelID', 'screenshot', 'chat', 'teamSpells', 'submitted', 'submittedCodeLanguage', - 'unsubscribed', 'playtime', 'heroConfig', 'team'] + 'unsubscribed', 'playtime', 'heroConfig', 'team', 'transpiledCode'] LevelSessionSchema.statics.jsonSchema = jsonschema LevelSessionSchema.index {user: 1, changed: -1}, {sparse: true, name: 'last played index'}