Merge pull request #820 from codecombat/master

Master into production
This commit is contained in:
Michael Schmatz 2014-04-11 17:13:02 -07:00
commit a56b1d6ade
8 changed files with 45 additions and 31 deletions

View file

@ -102,6 +102,7 @@ module.exports = class Simulator extends CocoClass
sendResultsBackToServer: (results) =>
@trigger 'statusUpdate', 'Simulation completed, sending results back to server!'
console.log "Sending result back to server!"
$.ajax
url: "/queue/scoring"
data: results
@ -217,7 +218,11 @@ module.exports = class Simulator extends CocoClass
createSpellThang: (thang, method, spellKey) ->
@spells[spellKey].thangs ?= {}
@spells[spellKey].thangs[thang.id] ?= {}
@spells[spellKey].thangs[thang.id].aether = @createAether @spells[spellKey].name, method
spellTeam = @task.getSpellKeyToTeamMap()[spellKey]
playerTeams = @task.getPlayerTeams()
useProtectAPI = true
if spellTeam not in playerTeams then useProtectAPI = false
@spells[spellKey].thangs[thang.id].aether = @createAether @spells[spellKey].name, method, useProtectAPI
transpileSpell: (thang, spellKey, methodName) ->
slugifiedThangID = _.string.slugify thang.id
@ -229,10 +234,10 @@ module.exports = class Simulator extends CocoClass
console.log "Couldn't transpile #{spellKey}:\n#{source}\n", e
aether.transpile ''
createAether: (methodName, method) ->
createAether: (methodName, method, useProtectAPI) ->
aetherOptions =
functionName: methodName
protectAPI: true
protectAPI: useProtectAPI
includeFlow: false
requiresThis: true
yieldConditionally: false
@ -249,6 +254,7 @@ module.exports = class Simulator extends CocoClass
class SimulationTask
constructor: (@rawData) ->
console.log 'Simulating sessions', (session for session in @getSessions())
@spellKeyToTeamMap = {}
getLevelName: ->
levelName = @rawData.sessions?[0]?.levelID
@ -273,21 +279,31 @@ class SimulationTask
getReceiptHandle: -> @rawData.receiptHandle
getSessions: -> @rawData.sessions
getSpellKeyToTeamMap: -> @spellKeyToTeamMap
getPlayerTeams: -> _.pluck @rawData.sessions, 'team'
generateSpellKeyToSourceMap: ->
playerTeams = _.pluck @rawData.sessions, 'team'
spellKeyToSourceMap = {}
for session in @rawData.sessions
teamSpells = session.teamSpells[session.team]
allTeams = _.keys session.teamSpells
nonPlayerTeams = _.difference allTeams, playerTeams
for team in allTeams
for spell in session.teamSpells[team]
@spellKeyToTeamMap[spell] = team
for nonPlayerTeam in nonPlayerTeams
teamSpells = teamSpells.concat(session.teamSpells[nonPlayerTeam])
teamCode = {}
for thangName, thangSpells of session.code
for spellName, spell of thangSpells
fullSpellName = [thangName,spellName].join '/'
if _.contains(teamSpells, fullSpellName)
teamCode[fullSpellName]=spell
_.merge spellKeyToSourceMap, teamCode
commonSpells = session.teamSpells["common"]
_.merge spellKeyToSourceMap, _.pick(session.code, commonSpells) if commonSpells?
spellKeyToSourceMap

View file

@ -1,6 +1,9 @@
@import "app/styles/bootstrap/mixins"
@import "app/styles/mixins"
body.is-playing
background-color: black
#level-view
margin: 0 auto
@include user-select(none)

View file

@ -1,16 +1,9 @@
@import "app/styles/bootstrap/mixins"
@import "app/styles/mixins"
@mixin sky-background($url: '', $backgroundPosition: left)
$top: #95D9EF
$mid: #FFFFFF
$bot: #8EC643
$stop: 99.6%
background: $mid
background-image: url($url) // fallback
background-image: url($url), -webkit-linear-gradient(top, $top, $mid $stop, $bot)
background-image: url($url), -ms-linear-gradient(top, $top, $mid $stop, $bot)
background-image: url($url), linear-gradient(to bottom, $top, $mid $stop, $bot)
@mixin wing-background($url: '', $backgroundPosition: left)
background: black
background-image: url($url)
background-repeat: no-repeat
background-position: top $backgroundPosition
background-size: contain
@ -69,11 +62,11 @@
position: absolute
.left-wing
@include sky-background('/images/level/loading_left_wing.png', right)
@include wing-background('/images/level/loading_left_wing.png', right)
left: -50%
transition: all $UNVEIL_TIME ease
.right-wing
@include sky-background('/images/level/loading_right_wing.png', left)
@include wing-background('/images/level/loading_right_wing.png', left)
right: -50%
transition: all $UNVEIL_TIME ease

View file

@ -48,6 +48,7 @@ module.exports = class RootView extends CocoView
afterRender: ->
super(arguments...)
@chooseTab(location.hash.replace('#','')) if location.hash
$('body').removeClass('is-playing')
chooseTab: (category) ->
$("a[href='##{category}']", @$el).tab('show')

View file

@ -126,6 +126,7 @@ module.exports = class PlayLevelView extends View
@insertSubView @loadingView = new LoadingView {}
@$el.find('#level-done-button').hide()
super()
$('body').addClass('is-playing')
onLevelLoaderProgressChanged: ->
return if @seenDocs

View file

@ -119,6 +119,7 @@ module.exports = class SpectateLevelView extends View
@insertSubView @loadingView = new LoadingView {}
@$el.find('#level-done-button').hide()
super()
$('body').addClass('is-playing')
onLevelLoaderProgressChanged: ->
return if @seenDocs

View file

@ -240,9 +240,6 @@ LevelHandler = class LevelHandler extends Handler
original: level.original.toString()
majorVersion: level.version.major
submitted:true
console.log sessionsQueryParameters
query = Session
.find(sessionsQueryParameters)
@ -253,7 +250,6 @@ LevelHandler = class LevelHandler extends Handler
return @sendDatabaseError res, err if err? or not resultSessions
teamSessions = _.groupBy resultSessions, 'team'
console.log teamSessions
sessions = []
numberOfTeams = 0
for team of teamSessions

View file

@ -36,7 +36,7 @@ module.exports.messagesInQueueCount = (req, res) ->
module.exports.addPairwiseTaskToQueueFromRequest = (req, res) ->
taskPair = req.body.sessions
addPairwiseTaskToQueue req.body.sessions (err, success) ->
addPairwiseTaskToQueue req.body.sessions, (err, success) ->
if err? then return errors.serverError res, "There was an error adding pairwise tasks: #{err}"
sendResponseObject req, res, {"message":"All task pairs were succesfully sent to the queue"}
@ -113,7 +113,6 @@ module.exports.createNewTask = (req, res) ->
updateSessionToSubmit
fetchInitialSessionsToRankAgainst.bind(@, requestLevelMajorVersion, originalLevelID)
generateAndSendTaskPairsToTheQueue
], (err, successMessageObject) ->
if err? then return errors.serverError res, "There was an error submitting the game to the queue:#{err}"
sendResponseObject req, res, successMessageObject
@ -188,15 +187,16 @@ fetchInitialSessionsToRankAgainst = (levelMajorVersion, levelID, submittedSessio
submittedCode:
$exists: true
team: opposingTeam
sortParameters =
totalScore: 1
limitNumber = 1
query = LevelSession.find(findParameters)
.sort(sortParameters)
.limit(limitNumber)
query = LevelSession.aggregate [
{$match: findParameters}
{$sort: sortParameters}
{$limit: limitNumber}
]
query.exec (err, sessionToRankAgainst) ->
callback err, sessionToRankAgainst, submittedSession
@ -206,6 +206,8 @@ generateAndSendTaskPairsToTheQueue = (sessionToRankAgainst,submittedSession, cal
taskPairs = generateTaskPairs(sessionToRankAgainst, submittedSession)
sendEachTaskPairToTheQueue taskPairs, (taskPairError) ->
if taskPairError? then return callback taskPairError
console.log "Sent task pairs to the queue!"
console.log taskPairs
callback null, {"message": "All task pairs were succesfully sent to the queue"}
@ -580,7 +582,8 @@ sendEachTaskPairToTheQueue = (taskPairs, callback) -> async.each taskPairs, send
generateTaskPairs = (submittedSessions, sessionToScore) ->
taskPairs = []
for session in submittedSessions
session = session.toObject()
if session.toObject?
session = session.toObject()
teams = ['ogres','humans']
opposingTeams = _.pull teams, sessionToScore.team
if String(session._id) isnt String(sessionToScore._id) and session.team in opposingTeams