mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-03-26 21:02:02 -04:00
Fixed #2597: press escape to abort simulation now, if your code is going to be slow.
This commit is contained in:
parent
ea54c4a8e3
commit
a0057910ac
2 changed files with 9 additions and 2 deletions
app
|
@ -16,6 +16,7 @@ module.exports = class Angel extends CocoClass
|
|||
subscriptions:
|
||||
'level:flag-updated': 'onFlagEvent'
|
||||
'playback:stop-real-time-playback': 'onStopRealTimePlayback'
|
||||
'level:escape-pressed': 'onEscapePressed'
|
||||
|
||||
constructor: (@shared) ->
|
||||
super()
|
||||
|
@ -165,10 +166,11 @@ module.exports = class Angel extends CocoClass
|
|||
@worker.postMessage func: 'finalizePreload'
|
||||
@work.preload = false
|
||||
|
||||
infinitelyLooped: =>
|
||||
infinitelyLooped: (escaped=false) =>
|
||||
@say 'On infinitely looped! Aborting?', @aborting
|
||||
return if @aborting
|
||||
problem = type: 'runtime', level: 'error', id: 'runtime_InfiniteLoop', message: 'Code never finished. It\'s either really slow or has an infinite loop.'
|
||||
problem.message = 'Escape pressed; code aborted.' if escaped
|
||||
Backbone.Mediator.publish 'god:user-code-problem', problem: problem
|
||||
Backbone.Mediator.publish 'god:infinite-loop', firstWorld: @shared.firstWorld
|
||||
@fireWorker()
|
||||
|
@ -239,8 +241,14 @@ module.exports = class Angel extends CocoClass
|
|||
onStopRealTimePlayback: (e) ->
|
||||
return unless @running and @work.realTime
|
||||
@work.realTime = false
|
||||
@lastRealTimeWork = new Date()
|
||||
@worker.postMessage func: 'stopRealTimePlayback'
|
||||
|
||||
onEscapePressed: (e) ->
|
||||
return unless @running and not @work.realTime
|
||||
return if (new Date() - @lastRealTimeWork) < 1000 # Fires right after onStopRealTimePlayback
|
||||
@infinitelyLooped true
|
||||
|
||||
#### Synchronous code for running worlds on main thread (profiling / IE9) ####
|
||||
simulateSync: (work) =>
|
||||
console?.profile? "World Generation #{(Math.random() * 1000).toFixed(0)}" if imitateIE9?
|
||||
|
|
|
@ -153,7 +153,6 @@ module.exports = class SpellView extends CocoView
|
|||
bindKey: {win: 'Escape', mac: 'Escape'}
|
||||
readOnly: true
|
||||
exec: ->
|
||||
console.log 'esc pressed'
|
||||
Backbone.Mediator.publish 'level:escape-pressed', {}
|
||||
addCommand
|
||||
name: 'toggle-grid'
|
||||
|
|
Loading…
Add table
Reference in a new issue