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) ->
|
||||
@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
|
||||
|
||||
|
@ -160,7 +160,7 @@ module.exports = class LevelLoader extends CocoClass
|
|||
buildSpriteSheetsForThangType: (thangType) ->
|
||||
@grabThangTypeTeams() unless @thangTypeTeams
|
||||
for team in @thangTypeTeams[thangType.get('original')] ? [null]
|
||||
spriteOptions = {resolutionFactor: 4, async: true}
|
||||
spriteOptions = {resolutionFactor: 4, async: false}
|
||||
if thangType.get('kind') is 'Floor'
|
||||
spriteOptions.resolutionFactor = 2
|
||||
if team and color = @teamConfigs[team]?.color
|
||||
|
@ -174,10 +174,14 @@ module.exports = class LevelLoader extends CocoClass
|
|||
return unless building
|
||||
#console.log 'Building:', thangType.get('name'), options
|
||||
@spriteSheetsToBuild += 1
|
||||
thangType.once 'build-complete', =>
|
||||
onBuildComplete = =>
|
||||
return if @destroyed
|
||||
@spriteSheetsBuilt += 1
|
||||
@notifyProgress()
|
||||
if options.async
|
||||
thangType.once 'build-complete', onBuildComplete
|
||||
else
|
||||
onBuildComplete()
|
||||
|
||||
# World init
|
||||
|
||||
|
|
|
@ -291,6 +291,9 @@
|
|||
time_current: "Now:"
|
||||
time_total: "Max:"
|
||||
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:
|
||||
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.
|
||||
|
||||
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_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_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_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:
|
||||
'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-comment-button': -> Backbone.Mediator.publish 'tome:comment-my-code'
|
||||
|
|
|
@ -51,6 +51,7 @@ module.exports = class TomeView extends View
|
|||
'tome:change-language': 'updateLanguageForAllSpells'
|
||||
'surface:sprite-selected': 'onSpriteSelected'
|
||||
'god:new-world-created': 'onNewWorld'
|
||||
'tome:comment-my-code': 'onCommentMyCode'
|
||||
|
||||
events:
|
||||
'click #spell-view': 'onSpellViewClick'
|
||||
|
@ -78,6 +79,14 @@ module.exports = class TomeView extends View
|
|||
@thangList.adjustThangs @spells, thangs
|
||||
@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: ->
|
||||
return
|
||||
# In progress
|
||||
|
|
|
@ -5,7 +5,7 @@ SessionHandler = require('./sessions/level_session_handler')
|
|||
Feedback = require('./feedbacks/LevelFeedback')
|
||||
Handler = require('../commons/Handler')
|
||||
mongoose = require('mongoose')
|
||||
|
||||
async = require 'async'
|
||||
LevelHandler = class LevelHandler extends Handler
|
||||
modelClass: 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
|
||||
session[serviceProperty] = userMap[session.creator] for session in sessionResults
|
||||
res.send(sessionResults)
|
||||
|
||||
|
||||
getRandomSessionPair: (req, res, slugOrID) ->
|
||||
findParameters = {}
|
||||
if Handler.isID slugOrID
|
||||
|
@ -235,32 +235,34 @@ LevelHandler = class LevelHandler extends Handler
|
|||
query.exec (err, level) =>
|
||||
return @sendDatabaseError(res, err) if err
|
||||
return @sendNotFoundError(res) unless level?
|
||||
|
||||
|
||||
sessionsQueryParameters =
|
||||
level:
|
||||
original: level.original.toString()
|
||||
majorVersion: level.version.major
|
||||
submitted:true
|
||||
|
||||
query = Session
|
||||
.find(sessionsQueryParameters)
|
||||
.select('team')
|
||||
.lean()
|
||||
|
||||
query.exec (err, resultSessions) =>
|
||||
return @sendDatabaseError res, err if err? or not resultSessions
|
||||
|
||||
teamSessions = _.groupBy resultSessions, 'team'
|
||||
sessions = []
|
||||
numberOfTeams = 0
|
||||
for team of teamSessions
|
||||
numberOfTeams += 1
|
||||
sessions.push _.sample(teamSessions[team])
|
||||
if numberOfTeams != 2 then return @sendDatabaseError res, "There aren't sessions of 2 teams, so cannot choose random opponents!"
|
||||
|
||||
@sendSuccess res, sessions
|
||||
|
||||
|
||||
|
||||
query = Session.find(sessionsQueryParameters).distinct("team")
|
||||
query.exec (err, teams) =>
|
||||
return @sendDatabaseError res, err if err? or not teams
|
||||
findTop20Players = (sessionQueryParams, team, cb) ->
|
||||
sessionQueryParams["team"] = team
|
||||
Session.aggregate [
|
||||
{$match: sessionQueryParams}
|
||||
{$project: {"totalScore":1}}
|
||||
{$sort: {"totalScore":-1}}
|
||||
{$limit: 20}
|
||||
], cb
|
||||
|
||||
async.map teams, findTop20Players.bind(@, sessionsQueryParameters), (err, map) =>
|
||||
if err? then return @sendDatabaseError(res, err)
|
||||
sessions = []
|
||||
for mapItem in map
|
||||
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) ->
|
||||
return @sendNotFoundError(res) unless req.user
|
||||
@fetchLevelByIDAndHandleErrors id, req, res, (err, level) =>
|
||||
|
|
Loading…
Reference in a new issue