2014-05-12 20:16:31 -04:00
|
|
|
do (setupLodash = this) ->
|
|
|
|
GLOBAL._ = require 'lodash'
|
|
|
|
_.str = require 'underscore.string'
|
|
|
|
_.mixin _.str.exports()
|
|
|
|
Aether = require "aether"
|
|
|
|
async = require 'async'
|
|
|
|
|
|
|
|
serverSetup = require '../server_setup'
|
2014-06-19 11:47:31 -04:00
|
|
|
Level = require '../server/levels/Level'
|
|
|
|
LevelSession = require '../server/levels/sessions/LevelSession'
|
2014-05-12 20:16:31 -04:00
|
|
|
|
|
|
|
Aether.addGlobal 'Vector', require '../app/lib/world/vector'
|
|
|
|
Aether.addGlobal '_', _
|
2014-06-05 19:48:31 -04:00
|
|
|
i = 0
|
2014-05-12 20:16:31 -04:00
|
|
|
transpileLevelSession = (sessionID, cb) ->
|
2014-06-05 19:48:31 -04:00
|
|
|
query = LevelSession.findOne("_id": sessionID).select("team teamSpells submittedCode submittedCodeLanguage").lean()
|
2014-05-12 20:16:31 -04:00
|
|
|
query.exec (err, session) ->
|
|
|
|
if err then return cb err
|
|
|
|
submittedCode = session.submittedCode
|
2014-06-05 17:06:28 -04:00
|
|
|
unless session.submittedCodeLanguage
|
|
|
|
throw "SUBMITTED CODE LANGUAGE DOESN'T EXIST"
|
|
|
|
else
|
2014-06-05 19:48:31 -04:00
|
|
|
console.log "Transpiling code for session #{i++} #{session._id} in language #{session.submittedCodeLanguage}"
|
2014-05-12 20:16:31 -04:00
|
|
|
transpiledCode = {}
|
2014-06-05 17:06:28 -04:00
|
|
|
#console.log "Updating session #{sessionID}"
|
2014-05-12 20:16:31 -04:00
|
|
|
for thang, spells of submittedCode
|
|
|
|
transpiledCode[thang] = {}
|
|
|
|
for spellID, spell of spells
|
2014-06-05 19:48:31 -04:00
|
|
|
spellName = thang + "/" + spellID
|
2014-05-25 15:15:32 -04:00
|
|
|
|
2014-06-05 19:48:31 -04:00
|
|
|
if session.teamSpells and not (spellName in session.teamSpells[session.team]) then continue
|
|
|
|
#console.log "Transpiling spell #{spellName}"
|
2014-05-12 20:16:31 -04:00
|
|
|
aetherOptions =
|
|
|
|
problems: {}
|
2014-06-05 19:48:31 -04:00
|
|
|
language: session.submittedCodeLanguage
|
2014-05-12 20:16:31 -04:00
|
|
|
functionName: spellID
|
2014-05-13 13:27:44 -04:00
|
|
|
functionParameters: []
|
2014-05-12 20:16:31 -04:00
|
|
|
yieldConditionally: spellID is "plan"
|
|
|
|
globals: ['Vector', '_']
|
|
|
|
protectAPI: true
|
|
|
|
includeFlow: false
|
2014-05-25 15:15:32 -04:00
|
|
|
executionLimit: 1 * 1000 * 1000
|
2014-05-14 13:14:18 -04:00
|
|
|
if spellID is "hear" then aetherOptions["functionParameters"] = ["speaker","message","data"]
|
2014-05-25 15:15:32 -04:00
|
|
|
|
2014-05-12 20:16:31 -04:00
|
|
|
aether = new Aether aetherOptions
|
|
|
|
transpiledCode[thang][spellID] = aether.transpile spell
|
2014-05-25 15:15:32 -04:00
|
|
|
conditions =
|
2014-05-13 13:27:44 -04:00
|
|
|
"_id": sessionID
|
2014-05-25 15:15:32 -04:00
|
|
|
update =
|
2014-05-14 13:14:18 -04:00
|
|
|
"transpiledCode": transpiledCode
|
|
|
|
query = LevelSession.update(conditions,update)
|
2014-05-25 15:15:32 -04:00
|
|
|
|
2014-05-14 13:14:18 -04:00
|
|
|
query.exec (err, numUpdated) -> cb err
|
2014-05-12 20:16:31 -04:00
|
|
|
|
|
|
|
findLadderLevelSessions = (levelID, cb) ->
|
2014-05-25 15:15:32 -04:00
|
|
|
queryParameters =
|
2014-05-13 13:27:44 -04:00
|
|
|
"level.original": levelID + ""
|
2014-05-12 20:16:31 -04:00
|
|
|
submitted: true
|
2014-05-25 15:15:32 -04:00
|
|
|
|
2014-05-12 20:16:31 -04:00
|
|
|
selectString = "_id"
|
2014-05-14 13:14:18 -04:00
|
|
|
query = LevelSession.find(queryParameters).select(selectString).lean()
|
2014-05-25 15:15:32 -04:00
|
|
|
|
2014-05-12 20:16:31 -04:00
|
|
|
query.exec (err, levelSessions) ->
|
|
|
|
if err then return cb err
|
|
|
|
levelSessionIDs = _.pluck levelSessions, "_id"
|
2014-05-14 13:14:18 -04:00
|
|
|
async.eachSeries levelSessionIDs, transpileLevelSession, (err) ->
|
|
|
|
if err then return cb err
|
2014-06-05 19:48:31 -04:00
|
|
|
return cb null
|
2014-05-25 15:15:32 -04:00
|
|
|
|
|
|
|
|
2014-05-12 20:16:31 -04:00
|
|
|
transpileLadderSessions = ->
|
2014-05-25 15:15:32 -04:00
|
|
|
queryParameters =
|
2014-05-12 20:16:31 -04:00
|
|
|
type: "ladder"
|
2014-05-13 13:27:44 -04:00
|
|
|
"version.isLatestMajor": true
|
|
|
|
"version.isLatestMinor": true
|
2014-05-12 20:16:31 -04:00
|
|
|
selectString = "original"
|
2014-05-14 13:14:18 -04:00
|
|
|
query = Level.find(queryParameters).select(selectString).lean()
|
2014-05-25 15:15:32 -04:00
|
|
|
|
2014-05-12 20:16:31 -04:00
|
|
|
query.exec (err, ladderLevels) ->
|
|
|
|
throw err if err
|
|
|
|
ladderLevels = _.pluck ladderLevels, "original"
|
2014-05-14 13:14:18 -04:00
|
|
|
async.eachSeries ladderLevels, findLadderLevelSessions, (err) ->
|
2014-05-12 20:16:31 -04:00
|
|
|
throw err if err
|
2014-05-14 13:14:18 -04:00
|
|
|
|
2014-05-12 20:16:31 -04:00
|
|
|
serverSetup.connectToDatabase()
|
2014-06-19 11:47:31 -04:00
|
|
|
transpileLadderSessions()
|