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'
|
|
|
|
Level = require '../server/levels/Level.coffee'
|
|
|
|
LevelSession = require '../server/levels/sessions/LevelSession.coffee'
|
|
|
|
|
|
|
|
Aether.addGlobal 'Vector', require '../app/lib/world/vector'
|
|
|
|
Aether.addGlobal '_', _
|
|
|
|
|
|
|
|
transpileLevelSession = (sessionID, cb) ->
|
2014-05-14 13:14:18 -04:00
|
|
|
query = LevelSession.findOne("_id": sessionID).select("submittedCode").lean()
|
2014-05-12 20:16:31 -04:00
|
|
|
query.exec (err, session) ->
|
|
|
|
if err then return cb err
|
|
|
|
submittedCode = session.submittedCode
|
|
|
|
transpiledCode = {}
|
2014-05-14 13:14:18 -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-05-25 15:15:32 -04:00
|
|
|
|
2014-05-12 20:16:31 -04:00
|
|
|
aetherOptions =
|
|
|
|
problems: {}
|
|
|
|
language: "javascript"
|
|
|
|
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
|
|
|
|
"submittedCodeLanguage": "javascript"
|
|
|
|
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
|
|
|
|
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()
|
|
|
|
transpileLadderSessions()
|