This commit is contained in:
Glen De Cauwsemaecker 2014-04-15 02:05:38 +02:00
commit 1354bc3d59
6 changed files with 48 additions and 28 deletions

View file

@ -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

View file

@ -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"

View file

@ -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

View file

@ -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'

View file

@ -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

View file

@ -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'
@ -242,22 +242,24 @@ LevelHandler = class LevelHandler extends Handler
majorVersion: level.version.major
submitted:true
query = Session
.find(sessionsQueryParameters)
.select('team')
.lean()
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
query.exec (err, resultSessions) =>
return @sendDatabaseError res, err if err? or not resultSessions
teamSessions = _.groupBy resultSessions, 'team'
async.map teams, findTop20Players.bind(@, sessionsQueryParameters), (err, map) =>
if err? then return @sendDatabaseError(res, err)
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!"
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