mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-28 01:55:38 -05:00
This commit is contained in:
commit
1354bc3d59
6 changed files with 48 additions and 28 deletions
|
@ -104,7 +104,7 @@ module.exports = class LevelLoader extends CocoClass
|
||||||
|
|
||||||
onSupermodelLoadedOne: (e) ->
|
onSupermodelLoadedOne: (e) ->
|
||||||
@buildSpriteSheetsForThangType e.model if not @headless and e.model instanceof ThangType
|
@buildSpriteSheetsForThangType e.model if not @headless and e.model instanceof ThangType
|
||||||
@update()
|
@update() unless @destroyed
|
||||||
|
|
||||||
# Things to do when either the Session or Supermodel load
|
# Things to do when either the Session or Supermodel load
|
||||||
|
|
||||||
|
@ -160,7 +160,7 @@ module.exports = class LevelLoader extends CocoClass
|
||||||
buildSpriteSheetsForThangType: (thangType) ->
|
buildSpriteSheetsForThangType: (thangType) ->
|
||||||
@grabThangTypeTeams() unless @thangTypeTeams
|
@grabThangTypeTeams() unless @thangTypeTeams
|
||||||
for team in @thangTypeTeams[thangType.get('original')] ? [null]
|
for team in @thangTypeTeams[thangType.get('original')] ? [null]
|
||||||
spriteOptions = {resolutionFactor: 4, async: true}
|
spriteOptions = {resolutionFactor: 4, async: false}
|
||||||
if thangType.get('kind') is 'Floor'
|
if thangType.get('kind') is 'Floor'
|
||||||
spriteOptions.resolutionFactor = 2
|
spriteOptions.resolutionFactor = 2
|
||||||
if team and color = @teamConfigs[team]?.color
|
if team and color = @teamConfigs[team]?.color
|
||||||
|
@ -174,10 +174,14 @@ module.exports = class LevelLoader extends CocoClass
|
||||||
return unless building
|
return unless building
|
||||||
#console.log 'Building:', thangType.get('name'), options
|
#console.log 'Building:', thangType.get('name'), options
|
||||||
@spriteSheetsToBuild += 1
|
@spriteSheetsToBuild += 1
|
||||||
thangType.once 'build-complete', =>
|
onBuildComplete = =>
|
||||||
return if @destroyed
|
return if @destroyed
|
||||||
@spriteSheetsBuilt += 1
|
@spriteSheetsBuilt += 1
|
||||||
@notifyProgress()
|
@notifyProgress()
|
||||||
|
if options.async
|
||||||
|
thangType.once 'build-complete', onBuildComplete
|
||||||
|
else
|
||||||
|
onBuildComplete()
|
||||||
|
|
||||||
# World init
|
# World init
|
||||||
|
|
||||||
|
|
|
@ -291,6 +291,9 @@
|
||||||
time_current: "Now:"
|
time_current: "Now:"
|
||||||
time_total: "Max:"
|
time_total: "Max:"
|
||||||
time_goto: "Go to:"
|
time_goto: "Go to:"
|
||||||
|
infinite_loop_try_again: "Try Again"
|
||||||
|
infinite_loop_reset_level: "Reset Level"
|
||||||
|
infinite_loop_comment_out: "Comment Out My Code"
|
||||||
|
|
||||||
admin:
|
admin:
|
||||||
av_title: "Admin Views"
|
av_title: "Admin Views"
|
||||||
|
|
|
@ -8,5 +8,6 @@ block modal-body-content
|
||||||
p(data-i18n="play_level.infinite_loop_explanation") The initial code to build the world never finished running. It's probably either really slow or has an infinite loop. Or there might be a bug. You can either try running this code again or reset the code to the default state. If that doesn't fix it, please let us know.
|
p(data-i18n="play_level.infinite_loop_explanation") The initial code to build the world never finished running. It's probably either really slow or has an infinite loop. Or there might be a bug. You can either try running this code again or reset the code to the default state. If that doesn't fix it, please let us know.
|
||||||
|
|
||||||
block modal-footer-content
|
block modal-footer-content
|
||||||
a(href='#', data-dismiss="modal", aria-hidden="true", data-i18n="play_level.infinite_loop_wait").btn#restart-level-infinite-loop-retry-button Try Again
|
a(href='#', data-dismiss="modal", aria-hidden="true", data-i18n="play_level.infinite_loop_try_again").btn#restart-level-infinite-loop-retry-button Try Again
|
||||||
a(href='#', data-dismiss="modal", aria-hidden="true", data-i18n="play_level.infinite_loop_reload").btn.btn-primary#restart-level-infinite-loop-confirm-button Reset Level
|
a(href='#', data-dismiss="modal", aria-hidden="true", data-i18n="play_level.infinite_loop_reset_level").btn.btn-danger#restart-level-infinite-loop-confirm-button Reset Level
|
||||||
|
a(href='#', data-dismiss="modal", aria-hidden="true", data-i18n="play_level.infinite_loop_comment_out").btn.btn-primary#restart-level-infinite-loop-comment-button Comment Out My Code
|
||||||
|
|
|
@ -8,3 +8,4 @@ module.exports = class InfiniteLoopModal extends View
|
||||||
events:
|
events:
|
||||||
'click #restart-level-infinite-loop-retry-button': -> Backbone.Mediator.publish 'tome:cast-spell'
|
'click #restart-level-infinite-loop-retry-button': -> Backbone.Mediator.publish 'tome:cast-spell'
|
||||||
'click #restart-level-infinite-loop-confirm-button': -> Backbone.Mediator.publish 'restart-level'
|
'click #restart-level-infinite-loop-confirm-button': -> Backbone.Mediator.publish 'restart-level'
|
||||||
|
'click #restart-level-infinite-loop-comment-button': -> Backbone.Mediator.publish 'tome:comment-my-code'
|
||||||
|
|
|
@ -51,6 +51,7 @@ module.exports = class TomeView extends View
|
||||||
'tome:change-language': 'updateLanguageForAllSpells'
|
'tome:change-language': 'updateLanguageForAllSpells'
|
||||||
'surface:sprite-selected': 'onSpriteSelected'
|
'surface:sprite-selected': 'onSpriteSelected'
|
||||||
'god:new-world-created': 'onNewWorld'
|
'god:new-world-created': 'onNewWorld'
|
||||||
|
'tome:comment-my-code': 'onCommentMyCode'
|
||||||
|
|
||||||
events:
|
events:
|
||||||
'click #spell-view': 'onSpellViewClick'
|
'click #spell-view': 'onSpellViewClick'
|
||||||
|
@ -78,6 +79,14 @@ module.exports = class TomeView extends View
|
||||||
@thangList.adjustThangs @spells, thangs
|
@thangList.adjustThangs @spells, thangs
|
||||||
@spellList.adjustSpells @spells
|
@spellList.adjustSpells @spells
|
||||||
|
|
||||||
|
onCommentMyCode: (e) ->
|
||||||
|
for spellKey, spell of @spells when spell.canWrite()
|
||||||
|
console.log "Commenting out", spellKey
|
||||||
|
commentedSource = 'return; // Commented out to stop infinite loop.\n' + spell.getSource()
|
||||||
|
spell.view.updateACEText commentedSource
|
||||||
|
spell.view.recompile false
|
||||||
|
@cast()
|
||||||
|
|
||||||
createWorker: ->
|
createWorker: ->
|
||||||
return
|
return
|
||||||
# In progress
|
# In progress
|
||||||
|
|
|
@ -5,7 +5,7 @@ SessionHandler = require('./sessions/level_session_handler')
|
||||||
Feedback = require('./feedbacks/LevelFeedback')
|
Feedback = require('./feedbacks/LevelFeedback')
|
||||||
Handler = require('../commons/Handler')
|
Handler = require('../commons/Handler')
|
||||||
mongoose = require('mongoose')
|
mongoose = require('mongoose')
|
||||||
|
async = require 'async'
|
||||||
LevelHandler = class LevelHandler extends Handler
|
LevelHandler = class LevelHandler extends Handler
|
||||||
modelClass: Level
|
modelClass: Level
|
||||||
jsonSchema: require '../../app/schemas/models/level'
|
jsonSchema: require '../../app/schemas/models/level'
|
||||||
|
@ -220,7 +220,7 @@ LevelHandler = class LevelHandler extends Handler
|
||||||
userMap[u._id] = u[serviceProperty] for u in userResults
|
userMap[u._id] = u[serviceProperty] for u in userResults
|
||||||
session[serviceProperty] = userMap[session.creator] for session in sessionResults
|
session[serviceProperty] = userMap[session.creator] for session in sessionResults
|
||||||
res.send(sessionResults)
|
res.send(sessionResults)
|
||||||
|
|
||||||
getRandomSessionPair: (req, res, slugOrID) ->
|
getRandomSessionPair: (req, res, slugOrID) ->
|
||||||
findParameters = {}
|
findParameters = {}
|
||||||
if Handler.isID slugOrID
|
if Handler.isID slugOrID
|
||||||
|
@ -235,32 +235,34 @@ LevelHandler = class LevelHandler extends Handler
|
||||||
query.exec (err, level) =>
|
query.exec (err, level) =>
|
||||||
return @sendDatabaseError(res, err) if err
|
return @sendDatabaseError(res, err) if err
|
||||||
return @sendNotFoundError(res) unless level?
|
return @sendNotFoundError(res) unless level?
|
||||||
|
|
||||||
sessionsQueryParameters =
|
sessionsQueryParameters =
|
||||||
level:
|
level:
|
||||||
original: level.original.toString()
|
original: level.original.toString()
|
||||||
majorVersion: level.version.major
|
majorVersion: level.version.major
|
||||||
submitted:true
|
submitted:true
|
||||||
|
|
||||||
query = Session
|
query = Session.find(sessionsQueryParameters).distinct("team")
|
||||||
.find(sessionsQueryParameters)
|
query.exec (err, teams) =>
|
||||||
.select('team')
|
return @sendDatabaseError res, err if err? or not teams
|
||||||
.lean()
|
findTop20Players = (sessionQueryParams, team, cb) ->
|
||||||
|
sessionQueryParams["team"] = team
|
||||||
query.exec (err, resultSessions) =>
|
Session.aggregate [
|
||||||
return @sendDatabaseError res, err if err? or not resultSessions
|
{$match: sessionQueryParams}
|
||||||
|
{$project: {"totalScore":1}}
|
||||||
teamSessions = _.groupBy resultSessions, 'team'
|
{$sort: {"totalScore":-1}}
|
||||||
sessions = []
|
{$limit: 20}
|
||||||
numberOfTeams = 0
|
], cb
|
||||||
for team of teamSessions
|
|
||||||
numberOfTeams += 1
|
async.map teams, findTop20Players.bind(@, sessionsQueryParameters), (err, map) =>
|
||||||
sessions.push _.sample(teamSessions[team])
|
if err? then return @sendDatabaseError(res, err)
|
||||||
if numberOfTeams != 2 then return @sendDatabaseError res, "There aren't sessions of 2 teams, so cannot choose random opponents!"
|
sessions = []
|
||||||
|
for mapItem in map
|
||||||
@sendSuccess res, sessions
|
sessions.push _.sample(mapItem)
|
||||||
|
if map.length != 2 then return @sendDatabaseError res, "There aren't sessions of 2 teams, so cannot choose random opponents!"
|
||||||
|
@sendSuccess res, sessions
|
||||||
|
|
||||||
|
|
||||||
getFeedback: (req, res, id) ->
|
getFeedback: (req, res, id) ->
|
||||||
return @sendNotFoundError(res) unless req.user
|
return @sendNotFoundError(res) unless req.user
|
||||||
@fetchLevelByIDAndHandleErrors id, req, res, (err, level) =>
|
@fetchLevelByIDAndHandleErrors id, req, res, (err, level) =>
|
||||||
|
|
Loading…
Reference in a new issue