mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-30 19:06:59 -05:00
Fixed a ton more leaks.
This commit is contained in:
parent
ad8a8e00e8
commit
5655084981
17 changed files with 162 additions and 113 deletions
|
@ -131,6 +131,8 @@ module.exports = class God
|
||||||
@dead = true
|
@dead = true
|
||||||
Backbone.Mediator.unsubscribe('tome:cast-spells', @onTomeCast, @)
|
Backbone.Mediator.unsubscribe('tome:cast-spells', @onTomeCast, @)
|
||||||
@goalManager = null
|
@goalManager = null
|
||||||
|
@fillWorkerPool = null
|
||||||
|
@simulateWorld = null
|
||||||
|
|
||||||
#### Bad code for running worlds on main thread (profiling / IE9) ####
|
#### Bad code for running worlds on main thread (profiling / IE9) ####
|
||||||
simulateWorld: =>
|
simulateWorld: =>
|
||||||
|
@ -207,6 +209,7 @@ class Angel
|
||||||
if @worker
|
if @worker
|
||||||
worker = @worker
|
worker = @worker
|
||||||
_.defer -> worker.terminate
|
_.defer -> worker.terminate
|
||||||
|
@worker.removeEventListener 'message', @onWorkerMessage
|
||||||
@worker = null
|
@worker = null
|
||||||
@
|
@
|
||||||
|
|
||||||
|
@ -217,6 +220,7 @@ class Angel
|
||||||
|
|
||||||
terminate: =>
|
terminate: =>
|
||||||
@worker?.terminate()
|
@worker?.terminate()
|
||||||
|
@worker?.removeEventListener 'message', @onWorkerMessage
|
||||||
@worker = null
|
@worker = null
|
||||||
return if @dead
|
return if @dead
|
||||||
@free()
|
@free()
|
||||||
|
@ -225,6 +229,10 @@ class Angel
|
||||||
destroy: ->
|
destroy: ->
|
||||||
@dead = true
|
@dead = true
|
||||||
@abort()
|
@abort()
|
||||||
|
@terminate = null
|
||||||
|
@testWorker = null
|
||||||
|
@condemnWorker = null
|
||||||
|
@onWorkerMessage = null
|
||||||
|
|
||||||
testWorker: =>
|
testWorker: =>
|
||||||
@worker.postMessage {func: 'reportIn'}
|
@worker.postMessage {func: 'reportIn'}
|
||||||
|
@ -235,22 +243,24 @@ class Angel
|
||||||
@abort()
|
@abort()
|
||||||
|
|
||||||
listen: ->
|
listen: ->
|
||||||
@worker.addEventListener 'message', (event) =>
|
@worker.addEventListener 'message', @onWorkerMessage
|
||||||
switch event.data.type
|
|
||||||
when 'new-world'
|
onWorkerMessage: (event) =>
|
||||||
@god.beholdWorld @, event.data.serialized, event.data.goalStates
|
switch event.data.type
|
||||||
when 'world-load-progress-changed'
|
when 'new-world'
|
||||||
Backbone.Mediator.publish 'god:world-load-progress-changed', event.data unless @dead
|
@god.beholdWorld @, event.data.serialized, event.data.goalStates
|
||||||
when 'console-log'
|
when 'world-load-progress-changed'
|
||||||
console.log "|" + @god.id + "'s " + @id + "|", event.data.args...
|
Backbone.Mediator.publish 'god:world-load-progress-changed', event.data unless @dead
|
||||||
when 'user-code-problem'
|
when 'console-log'
|
||||||
@god.angelUserCodeProblem @, event.data.problem
|
console.log "|" + @god.id + "'s " + @id + "|", event.data.args...
|
||||||
when 'abort'
|
when 'user-code-problem'
|
||||||
#console.log @id, "aborted."
|
@god.angelUserCodeProblem @, event.data.problem
|
||||||
clearTimeout @abortTimeout
|
when 'abort'
|
||||||
@free()
|
#console.log @id, "aborted."
|
||||||
@god.angelAborted @
|
clearTimeout @abortTimeout
|
||||||
when 'reportIn'
|
@free()
|
||||||
clearTimeout @condemnTimeout
|
@god.angelAborted @
|
||||||
else
|
when 'reportIn'
|
||||||
console.log "Unsupported message:", event.data
|
clearTimeout @condemnTimeout
|
||||||
|
else
|
||||||
|
console.log "Unsupported message:", event.data
|
||||||
|
|
|
@ -28,7 +28,7 @@ module.exports = class LevelLoader extends CocoClass
|
||||||
@loadLevelModels()
|
@loadLevelModels()
|
||||||
@loadAudio()
|
@loadAudio()
|
||||||
@playJingle()
|
@playJingle()
|
||||||
setTimeout (=> @update()), 1 # lets everything else resolve first
|
_.defer @update # Lets everything else resolve first
|
||||||
|
|
||||||
playJingle: ->
|
playJingle: ->
|
||||||
jingles = ["ident_1", "ident_2"]
|
jingles = ["ident_1", "ident_2"]
|
||||||
|
@ -80,7 +80,7 @@ module.exports = class LevelLoader extends CocoClass
|
||||||
# building = thangType.buildSpriteSheet options
|
# building = thangType.buildSpriteSheet options
|
||||||
# if building
|
# if building
|
||||||
# @spriteSheetsToBuild += 1
|
# @spriteSheetsToBuild += 1
|
||||||
# thangType.on 'build-complete', =>
|
# thangType.once 'build-complete', =>
|
||||||
# @spriteSheetsBuilt += 1
|
# @spriteSheetsBuilt += 1
|
||||||
# @notifyProgress()
|
# @notifyProgress()
|
||||||
|
|
||||||
|
@ -91,7 +91,7 @@ module.exports = class LevelLoader extends CocoClass
|
||||||
|
|
||||||
# Things to do when either the Session or Supermodel load
|
# Things to do when either the Session or Supermodel load
|
||||||
|
|
||||||
update: ->
|
update: =>
|
||||||
@notifyProgress()
|
@notifyProgress()
|
||||||
|
|
||||||
return if @updateCompleted
|
return if @updateCompleted
|
||||||
|
@ -153,7 +153,7 @@ 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.on 'build-complete', =>
|
thangType.once 'build-complete', =>
|
||||||
@spriteSheetsBuilt += 1
|
@spriteSheetsBuilt += 1
|
||||||
@notifyProgress()
|
@notifyProgress()
|
||||||
|
|
||||||
|
@ -208,6 +208,11 @@ module.exports = class LevelLoader extends CocoClass
|
||||||
@trigger 'loaded-all' if @progress() is 1
|
@trigger 'loaded-all' if @progress() is 1
|
||||||
|
|
||||||
destroy: ->
|
destroy: ->
|
||||||
|
super()
|
||||||
@world = null # don't hold onto garbage
|
@world = null # don't hold onto garbage
|
||||||
@supermodel.off 'loaded-one', @onSupermodelLoadedOne
|
@supermodel.off 'loaded-one', @onSupermodelLoadedOne
|
||||||
super()
|
@onSessionLoaded = null
|
||||||
|
@onSupermodelError = null
|
||||||
|
@onSupermodelLoadedOne = null
|
||||||
|
@onSupermodelLoadedAll = null
|
||||||
|
@notifyProgress = null
|
||||||
|
|
|
@ -186,7 +186,7 @@ module.exports = class Camera extends CocoClass
|
||||||
# Target is either just a {x, y} pos or a display object with {x, y} that might change; surface coordinates.
|
# Target is either just a {x, y} pos or a display object with {x, y} that might change; surface coordinates.
|
||||||
time = 0 if @instant
|
time = 0 if @instant
|
||||||
newTarget ?= {x:0, y:0}
|
newTarget ?= {x:0, y:0}
|
||||||
newTarget = (@newTarget or @target) if @locked
|
newTarget = (@newTarget or @target) if @locked
|
||||||
newZoom = Math.min((Math.max @minZoom, newZoom), MAX_ZOOM)
|
newZoom = Math.min((Math.max @minZoom, newZoom), MAX_ZOOM)
|
||||||
return if @zoom is newZoom and newTarget is newTarget.x and newTarget.y is newTarget.y
|
return if @zoom is newZoom and newTarget is newTarget.x and newTarget.y is newTarget.y
|
||||||
|
|
||||||
|
@ -199,15 +199,13 @@ module.exports = class Camera extends CocoClass
|
||||||
@tweenProgress = 0.01
|
@tweenProgress = 0.01
|
||||||
createjs.Tween.get(@)
|
createjs.Tween.get(@)
|
||||||
.to({tweenProgress: 1.0}, time, createjs.Ease.getPowInOut(3))
|
.to({tweenProgress: 1.0}, time, createjs.Ease.getPowInOut(3))
|
||||||
.call @onTweenEnd
|
.call @finishTween
|
||||||
|
|
||||||
else
|
else
|
||||||
@target = newTarget
|
@target = newTarget
|
||||||
@zoom = newZoom
|
@zoom = newZoom
|
||||||
@updateZoom true
|
@updateZoom true
|
||||||
|
|
||||||
onTweenEnd: => @finishTween()
|
|
||||||
|
|
||||||
finishTween: (abort=false) =>
|
finishTween: (abort=false) =>
|
||||||
createjs.Tween.removeTweens(@)
|
createjs.Tween.removeTweens(@)
|
||||||
return unless @newTarget
|
return unless @newTarget
|
||||||
|
@ -263,4 +261,5 @@ module.exports = class Camera extends CocoClass
|
||||||
|
|
||||||
destroy: ->
|
destroy: ->
|
||||||
super()
|
super()
|
||||||
@onTweenEnd = null
|
createjs.Tween.removeTweens @
|
||||||
|
@finishTween = null
|
||||||
|
|
|
@ -80,6 +80,9 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
|
||||||
super()
|
super()
|
||||||
mark.destroy() for name, mark of @marks
|
mark.destroy() for name, mark of @marks
|
||||||
label.destroy() for name, label of @labels
|
label.destroy() for name, label of @labels
|
||||||
|
@imageObject?.off 'animationend', @playNextAction
|
||||||
|
@playNextAction = null
|
||||||
|
@displayObject?.off()
|
||||||
|
|
||||||
toString: -> "<CocoSprite: #{@thang?.id}>"
|
toString: -> "<CocoSprite: #{@thang?.id}>"
|
||||||
|
|
||||||
|
@ -108,7 +111,7 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
|
||||||
@displayObject.sprite = @
|
@displayObject.sprite = @
|
||||||
@displayObject.layerPriority = @thangType.get 'layerPriority'
|
@displayObject.layerPriority = @thangType.get 'layerPriority'
|
||||||
@displayObject.name = @thang?.spriteName or @thangType.get 'name'
|
@displayObject.name = @thang?.spriteName or @thangType.get 'name'
|
||||||
@imageObject.on 'animationend', @onActionEnd
|
@imageObject.on 'animationend', @playNextAction
|
||||||
|
|
||||||
##################################################
|
##################################################
|
||||||
# QUEUEING AND PLAYING ACTIONS
|
# QUEUEING AND PLAYING ACTIONS
|
||||||
|
@ -126,10 +129,9 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
|
||||||
@currentRootAction = action
|
@currentRootAction = action
|
||||||
@playNextAction()
|
@playNextAction()
|
||||||
|
|
||||||
onActionEnd: (e) => @playNextAction()
|
|
||||||
onSurfaceTicked: (e) -> @age += e.dt
|
onSurfaceTicked: (e) -> @age += e.dt
|
||||||
|
|
||||||
playNextAction: ->
|
playNextAction: =>
|
||||||
@playAction(@actionQueue.splice(0,1)[0]) if @actionQueue.length
|
@playAction(@actionQueue.splice(0,1)[0]) if @actionQueue.length
|
||||||
|
|
||||||
playAction: (action) ->
|
playAction: (action) ->
|
||||||
|
@ -411,7 +413,7 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
|
||||||
sound = e.sound ? AudioPlayer.soundForDialogue e.message, @thangType.get 'soundTriggers'
|
sound = e.sound ? AudioPlayer.soundForDialogue e.message, @thangType.get 'soundTriggers'
|
||||||
@instance?.stop()
|
@instance?.stop()
|
||||||
if @instance = @playSound sound, false
|
if @instance = @playSound sound, false
|
||||||
@instance.addEventListener "complete", => Backbone.Mediator.publish 'dialogue-sound-completed'
|
@instance.addEventListener "complete", -> Backbone.Mediator.publish 'dialogue-sound-completed'
|
||||||
@notifySpeechUpdated e
|
@notifySpeechUpdated e
|
||||||
|
|
||||||
onClearDialogue: (e) ->
|
onClearDialogue: (e) ->
|
||||||
|
|
|
@ -7,14 +7,14 @@ CROSSFADE_LENGTH = 1500
|
||||||
module.exports = class MusicPlayer extends CocoClass
|
module.exports = class MusicPlayer extends CocoClass
|
||||||
currentMusic: null
|
currentMusic: null
|
||||||
standingBy: null
|
standingBy: null
|
||||||
|
|
||||||
subscriptions:
|
subscriptions:
|
||||||
'level-play-music': 'onPlayMusic'
|
'level-play-music': 'onPlayMusic'
|
||||||
'audio-player:loaded': 'onAudioLoaded'
|
'audio-player:loaded': 'onAudioLoaded'
|
||||||
|
|
||||||
constructor: ->
|
constructor: ->
|
||||||
super(arguments...)
|
super arguments...
|
||||||
me.on('change:music', @onMusicSettingChanged, @)
|
me.on 'change:music', @onMusicSettingChanged, @
|
||||||
|
|
||||||
onAudioLoaded: ->
|
onAudioLoaded: ->
|
||||||
@onPlayMusic(@standingBy) if @standingBy
|
@onPlayMusic(@standingBy) if @standingBy
|
||||||
|
@ -29,12 +29,12 @@ module.exports = class MusicPlayer extends CocoClass
|
||||||
AudioPlayer.preloadSound(src)
|
AudioPlayer.preloadSound(src)
|
||||||
@standingBy = e
|
@standingBy = e
|
||||||
return
|
return
|
||||||
|
|
||||||
@standingBy = null
|
@standingBy = null
|
||||||
if @currentMusic
|
if @currentMusic
|
||||||
f = -> @stop()
|
f = -> @stop()
|
||||||
createjs.Tween.get(@currentMusic).to({volume:0.0}, CROSSFADE_LENGTH).call(f)
|
createjs.Tween.get(@currentMusic).to({volume:0.0}, CROSSFADE_LENGTH).call(f)
|
||||||
|
|
||||||
@currentMusic = createjs.Sound.play(src, 'none', 0, 0, -1, 0.3) if src and e.play
|
@currentMusic = createjs.Sound.play(src, 'none', 0, 0, -1, 0.3) if src and e.play
|
||||||
return unless @currentMusic
|
return unless @currentMusic
|
||||||
@currentMusic.volume = 0.0
|
@currentMusic.volume = 0.0
|
||||||
|
@ -48,4 +48,7 @@ module.exports = class MusicPlayer extends CocoClass
|
||||||
return unless @currentMusic
|
return unless @currentMusic
|
||||||
createjs.Tween.removeTweens(@currentMusic)
|
createjs.Tween.removeTweens(@currentMusic)
|
||||||
@currentMusic.volume = if me.get('music') then 1.0 else 0.0
|
@currentMusic.volume = if me.get('music') then 1.0 else 0.0
|
||||||
|
|
||||||
|
destroy: ->
|
||||||
|
super()
|
||||||
|
me.off 'change:music', @onMusicSettingChanged, @
|
||||||
|
|
|
@ -90,14 +90,19 @@ module.exports = Surface = class Surface extends CocoClass
|
||||||
@dimmer?.destroy()
|
@dimmer?.destroy()
|
||||||
@stage.clear()
|
@stage.clear()
|
||||||
@musicPlayer?.destroy()
|
@musicPlayer?.destroy()
|
||||||
|
@stage.removeAllChildren()
|
||||||
@stage.removeEventListener 'stagemousemove', @onMouseMove
|
@stage.removeEventListener 'stagemousemove', @onMouseMove
|
||||||
@stage.removeEventListener 'stagemousedown', @onMouseDown
|
@stage.removeEventListener 'stagemousedown', @onMouseDown
|
||||||
@stage.removeAllEventListeners()
|
@stage.removeAllEventListeners()
|
||||||
|
@stage.enableDOMEvents false
|
||||||
|
@stage.enableMouseOver 0
|
||||||
@playScrubbedSounds = null
|
@playScrubbedSounds = null
|
||||||
@onMouseMove = null
|
@onMouseMove = null
|
||||||
@onMouseDown = null
|
@onMouseDown = null
|
||||||
@tick = null
|
@tick = null
|
||||||
|
@canvas.off 'mousewheel', @onMouseWheel
|
||||||
|
@onMouseWheel = null
|
||||||
|
|
||||||
setWorld: (@world) ->
|
setWorld: (@world) ->
|
||||||
@worldLoaded = true
|
@worldLoaded = true
|
||||||
@world.getFrame(Math.min(@getCurrentFrame(), @world.totalFrames - 1)).restoreState() unless @options.choosing
|
@world.getFrame(Math.min(@getCurrentFrame(), @world.totalFrames - 1)).restoreState() unless @options.choosing
|
||||||
|
@ -337,7 +342,7 @@ module.exports = Surface = class Surface extends CocoClass
|
||||||
@stage.enableMouseOver(10)
|
@stage.enableMouseOver(10)
|
||||||
@stage.addEventListener 'stagemousemove', @onMouseMove
|
@stage.addEventListener 'stagemousemove', @onMouseMove
|
||||||
@stage.addEventListener 'stagemousedown', @onMouseDown
|
@stage.addEventListener 'stagemousedown', @onMouseDown
|
||||||
@hookUpZoomControls()
|
@canvas.on 'mousewheel', @onMouseWheel
|
||||||
@hookUpChooseControls() if @options.choosing
|
@hookUpChooseControls() if @options.choosing
|
||||||
console.log "Setting fps", @world.frameRate unless @world.frameRate is 30
|
console.log "Setting fps", @world.frameRate unless @world.frameRate is 30
|
||||||
createjs.Ticker.setFPS @world.frameRate
|
createjs.Ticker.setFPS @world.frameRate
|
||||||
|
@ -436,12 +441,11 @@ module.exports = Surface = class Surface extends CocoClass
|
||||||
onBackground = not @stage.hitTest e.stageX, e.stageY
|
onBackground = not @stage.hitTest e.stageX, e.stageY
|
||||||
Backbone.Mediator.publish 'surface:stage-mouse-down', onBackground: onBackground, x: e.stageX, y: e.stageY, originalEvent: e
|
Backbone.Mediator.publish 'surface:stage-mouse-down', onBackground: onBackground, x: e.stageX, y: e.stageY, originalEvent: e
|
||||||
|
|
||||||
hookUpZoomControls: ->
|
onMouseWheel: (e) =>
|
||||||
@canvas.bind 'mousewheel', (e) =>
|
# https://github.com/brandonaaron/jquery-mousewheel
|
||||||
# https://github.com/brandonaaron/jquery-mousewheel
|
e.preventDefault()
|
||||||
e.preventDefault()
|
return if @disabled
|
||||||
return if @disabled
|
Backbone.Mediator.publish 'surface:mouse-scrolled', deltaX: e.deltaX, deltaY: e.deltaY unless @disabled
|
||||||
Backbone.Mediator.publish 'surface:mouse-scrolled', deltaX: e.deltaX, deltaY: e.deltaY unless @disabled
|
|
||||||
|
|
||||||
hookUpChooseControls: ->
|
hookUpChooseControls: ->
|
||||||
chooserOptions = stage: @stage, surfaceLayer: @surfaceLayer, camera: @camera, restrictRatio: @options.choosing is 'ratio-region'
|
chooserOptions = stage: @stage, surfaceLayer: @surfaceLayer, camera: @camera, restrictRatio: @options.choosing is 'ratio-region'
|
||||||
|
|
|
@ -25,7 +25,7 @@ class CocoModel extends Backbone.Model
|
||||||
@loadSchema()
|
@loadSchema()
|
||||||
@once 'sync', @onLoaded, @
|
@once 'sync', @onLoaded, @
|
||||||
@saveBackup = _.debounce(@saveBackup, 500)
|
@saveBackup = _.debounce(@saveBackup, 500)
|
||||||
|
|
||||||
type: ->
|
type: ->
|
||||||
@constructor.className
|
@constructor.className
|
||||||
|
|
||||||
|
@ -36,18 +36,18 @@ class CocoModel extends Backbone.Model
|
||||||
if @saveBackups
|
if @saveBackups
|
||||||
existing = storage.load @id
|
existing = storage.load @id
|
||||||
if existing
|
if existing
|
||||||
@set(existing, {silent:true})
|
@set(existing, {silent:true})
|
||||||
CocoModel.backedUp[@id] = @
|
CocoModel.backedUp[@id] = @
|
||||||
|
|
||||||
set: ->
|
set: ->
|
||||||
res = super(arguments...)
|
res = super(arguments...)
|
||||||
@saveBackup() if @saveBackups and @loaded and @hasLocalChanges()
|
@saveBackup() if @saveBackups and @loaded and @hasLocalChanges()
|
||||||
res
|
res
|
||||||
|
|
||||||
saveBackup: ->
|
saveBackup: ->
|
||||||
storage.save(@id, @attributes)
|
storage.save(@id, @attributes)
|
||||||
CocoModel.backedUp[@id] = @
|
CocoModel.backedUp[@id] = @
|
||||||
|
|
||||||
@backedUp = {}
|
@backedUp = {}
|
||||||
|
|
||||||
loadSchema: ->
|
loadSchema: ->
|
||||||
|
@ -55,7 +55,7 @@ class CocoModel extends Backbone.Model
|
||||||
@constructor.schema = new CocoSchema(@urlRoot)
|
@constructor.schema = new CocoSchema(@urlRoot)
|
||||||
@constructor.schema.fetch()
|
@constructor.schema.fetch()
|
||||||
|
|
||||||
@constructor.schema.on 'sync', =>
|
@constructor.schema.once 'sync', =>
|
||||||
@constructor.schema.loaded = true
|
@constructor.schema.loaded = true
|
||||||
@addSchemaDefaults()
|
@addSchemaDefaults()
|
||||||
@trigger 'schema-loaded'
|
@trigger 'schema-loaded'
|
||||||
|
@ -90,7 +90,7 @@ class CocoModel extends Backbone.Model
|
||||||
revert: ->
|
revert: ->
|
||||||
@set(@_revertAttributes, {silent: true}) if @_revertAttributes
|
@set(@_revertAttributes, {silent: true}) if @_revertAttributes
|
||||||
@clearBackup()
|
@clearBackup()
|
||||||
|
|
||||||
clearBackup: ->
|
clearBackup: ->
|
||||||
storage.remove @id
|
storage.remove @id
|
||||||
|
|
||||||
|
|
|
@ -8,14 +8,14 @@ class SuperModel
|
||||||
@mustPopulate = model
|
@mustPopulate = model
|
||||||
model.saveBackups = @shouldSaveBackups(model)
|
model.saveBackups = @shouldSaveBackups(model)
|
||||||
model.fetch() unless model.loaded or model.loading
|
model.fetch() unless model.loaded or model.loading
|
||||||
model.on('sync', @modelLoaded) unless model.loaded
|
model.once('sync', @modelLoaded) unless model.loaded
|
||||||
model.once('error', @modelErrored) unless model.loaded
|
model.once('error', @modelErrored) unless model.loaded
|
||||||
url = model.url()
|
url = model.url()
|
||||||
@models[url] = model unless @models[url]?
|
@models[url] = model unless @models[url]?
|
||||||
@modelLoaded(model) if model.loaded
|
@modelLoaded(model) if model.loaded
|
||||||
|
|
||||||
# replace or overwrite
|
# replace or overwrite
|
||||||
shouldPopulate: (url) -> return true
|
shouldPopulate: (url) -> return true
|
||||||
shouldSaveBackups: (model) -> return false
|
shouldSaveBackups: (model) -> return false
|
||||||
|
|
||||||
modelErrored: (model) =>
|
modelErrored: (model) =>
|
||||||
|
@ -23,7 +23,7 @@ class SuperModel
|
||||||
|
|
||||||
modelLoaded: (model) =>
|
modelLoaded: (model) =>
|
||||||
schema = model.schema()
|
schema = model.schema()
|
||||||
return schema.on('sync', => @modelLoaded(model)) unless schema.loaded
|
return schema.once('sync', => @modelLoaded(model)) unless schema.loaded
|
||||||
refs = model.getReferencedModels(model.attributes, schema.attributes)
|
refs = model.getReferencedModels(model.attributes, schema.attributes)
|
||||||
refs = [] unless @mustPopulate is model or @shouldPopulate(model)
|
refs = [] unless @mustPopulate is model or @shouldPopulate(model)
|
||||||
# console.log 'Loaded', model.get('name')
|
# console.log 'Loaded', model.get('name')
|
||||||
|
@ -33,7 +33,7 @@ class SuperModel
|
||||||
continue if @models[refURL]
|
continue if @models[refURL]
|
||||||
@models[refURL] = ref
|
@models[refURL] = ref
|
||||||
ref.fetch()
|
ref.fetch()
|
||||||
ref.on 'sync', @modelLoaded
|
ref.once 'sync', @modelLoaded
|
||||||
|
|
||||||
@trigger 'loaded-one', model: model
|
@trigger 'loaded-one', model: model
|
||||||
@trigger 'loaded-all' if @finished()
|
@trigger 'loaded-all' if @finished()
|
||||||
|
|
|
@ -28,7 +28,6 @@ module.exports = class User extends CocoModel
|
||||||
profileUrl = "#{GRAVATAR_URL}#{emailHash}.json?callback=#{functionName}"
|
profileUrl = "#{GRAVATAR_URL}#{emailHash}.json?callback=#{functionName}"
|
||||||
script = $("<script src='#{profileUrl}' type='text/javascript'></script>")
|
script = $("<script src='#{profileUrl}' type='text/javascript'></script>")
|
||||||
$('head').append(script)
|
$('head').append(script)
|
||||||
$('body').on('load',(e)->console.log('we did it!', e))
|
|
||||||
window[functionName] = (profile) =>
|
window[functionName] = (profile) =>
|
||||||
@gravatarProfile = profile
|
@gravatarProfile = profile
|
||||||
@trigger('change', @)
|
@trigger('change', @)
|
||||||
|
|
|
@ -42,6 +42,7 @@ module.exports = class CocoView extends Backbone.View
|
||||||
@undelegateEvents() # removes both events and subs
|
@undelegateEvents() # removes both events and subs
|
||||||
view.destroy() for id, view of @subviews
|
view.destroy() for id, view of @subviews
|
||||||
@modalClosed = null
|
@modalClosed = null
|
||||||
|
$('#modal-wrapper .modal').off 'hidden.bs.modal', @modalClosed
|
||||||
|
|
||||||
afterInsert: ->
|
afterInsert: ->
|
||||||
|
|
||||||
|
@ -85,14 +86,14 @@ module.exports = class CocoView extends Backbone.View
|
||||||
|
|
||||||
# Modals
|
# Modals
|
||||||
|
|
||||||
toggleModal: (e) ->
|
toggleModal: (e) ->
|
||||||
if $(e.currentTarget).prop('target') is '_blank'
|
if $(e.currentTarget).prop('target') is '_blank'
|
||||||
return true
|
return true
|
||||||
# special handler for opening modals that are dynamically loaded, rather than static in the page. It works (or should work) like Bootstrap's modals, except use coco-modal for the data-toggle value.
|
# special handler for opening modals that are dynamically loaded, rather than static in the page. It works (or should work) like Bootstrap's modals, except use coco-modal for the data-toggle value.
|
||||||
elem = $(e.target)
|
elem = $(e.target)
|
||||||
return unless elem.data('toggle') is 'coco-modal'
|
return unless elem.data('toggle') is 'coco-modal'
|
||||||
target = elem.data('target')
|
target = elem.data('target')
|
||||||
view = application.router.getView(target, '_modal') # could set up a system for loading cached modals, if told to
|
view = application.router.getView(target, '_modal') # could set up a system for loading cached modals, if told to
|
||||||
@openModalView(view)
|
@openModalView(view)
|
||||||
|
|
||||||
openModalView: (modalView) ->
|
openModalView: (modalView) ->
|
||||||
|
@ -101,12 +102,12 @@ module.exports = class CocoView extends Backbone.View
|
||||||
waitingModal = modalView
|
waitingModal = modalView
|
||||||
visibleModal.hide()
|
visibleModal.hide()
|
||||||
return
|
return
|
||||||
modalView.render()
|
modalView.render()
|
||||||
$('#modal-wrapper').empty().append modalView.el
|
$('#modal-wrapper').empty().append modalView.el
|
||||||
modalView.afterInsert()
|
modalView.afterInsert()
|
||||||
visibleModal = modalView
|
visibleModal = modalView
|
||||||
modalOptions = {show: true, backdrop: if modalView.closesOnClickOutside then true else 'static'}
|
modalOptions = {show: true, backdrop: if modalView.closesOnClickOutside then true else 'static'}
|
||||||
$('#modal-wrapper .modal').modal(modalOptions).on('hidden.bs.modal', @modalClosed)
|
$('#modal-wrapper .modal').modal(modalOptions).on 'hidden.bs.modal', @modalClosed
|
||||||
window.currentModal = modalView
|
window.currentModal = modalView
|
||||||
@getRootView().stopListeningToShortcuts(true)
|
@getRootView().stopListeningToShortcuts(true)
|
||||||
|
|
||||||
|
@ -114,7 +115,8 @@ module.exports = class CocoView extends Backbone.View
|
||||||
visibleModal.willDisappear() if visibleModal
|
visibleModal.willDisappear() if visibleModal
|
||||||
visibleModal.destroy()
|
visibleModal.destroy()
|
||||||
visibleModal = null
|
visibleModal = null
|
||||||
if waitingModal
|
$('#modal-wrapper .modal').off 'hidden.bs.modal', @modalClosed
|
||||||
|
if waitingModal
|
||||||
wm = waitingModal
|
wm = waitingModal
|
||||||
waitingModal = null
|
waitingModal = null
|
||||||
@openModalView(wm)
|
@openModalView(wm)
|
||||||
|
@ -212,8 +214,8 @@ module.exports = class CocoView extends Backbone.View
|
||||||
slider.on('slide',changeCallback)
|
slider.on('slide',changeCallback)
|
||||||
slider.on('slidechange',changeCallback)
|
slider.on('slidechange',changeCallback)
|
||||||
slider
|
slider
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
mobileRELong = /(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i
|
mobileRELong = /(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i
|
||||||
mobileREShort = /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i
|
mobileREShort = /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i
|
||||||
|
|
|
@ -37,6 +37,7 @@ module.exports = class ControlBarView extends View
|
||||||
setBus: (@bus) ->
|
setBus: (@bus) ->
|
||||||
|
|
||||||
onPlayerStatesChanged: (e) ->
|
onPlayerStatesChanged: (e) ->
|
||||||
|
# TODO: this doesn't fire any more. Replacement?
|
||||||
return unless @bus is e.bus
|
return unless @bus is e.bus
|
||||||
numPlayers = _.keys(e.players).length
|
numPlayers = _.keys(e.players).length
|
||||||
return if numPlayers is @numPlayers
|
return if numPlayers is @numPlayers
|
||||||
|
|
|
@ -11,6 +11,8 @@ module.exports = class CastButtonView extends View
|
||||||
'tome:cast-spells': 'onCastSpells'
|
'tome:cast-spells': 'onCastSpells'
|
||||||
'god:world-load-progress-changed': 'onWorldLoadProgressChanged'
|
'god:world-load-progress-changed': 'onWorldLoadProgressChanged'
|
||||||
'god:new-world-created': 'onNewWorld'
|
'god:new-world-created': 'onNewWorld'
|
||||||
|
'click .cast-button': -> Backbone.Mediator.publish 'tome:manual-cast', {}
|
||||||
|
'click .cast-options a': 'onCastOptionsClick'
|
||||||
|
|
||||||
constructor: (options) ->
|
constructor: (options) ->
|
||||||
super options
|
super options
|
||||||
|
@ -26,8 +28,10 @@ module.exports = class CastButtonView extends View
|
||||||
|
|
||||||
afterRender: ->
|
afterRender: ->
|
||||||
super()
|
super()
|
||||||
|
@castButton = $('.cast-button', @$el)
|
||||||
|
@castButtonGroup = $('.cast-button-group', @$el)
|
||||||
|
@castOptions = $('.autocast-delays', @$el)
|
||||||
# TODO: use a User setting instead of localStorage
|
# TODO: use a User setting instead of localStorage
|
||||||
@hookUpButtons()
|
|
||||||
delay = localStorage.getItem 'autocastDelay'
|
delay = localStorage.getItem 'autocastDelay'
|
||||||
delay ?= 5000
|
delay ?= 5000
|
||||||
@setAutocastDelay delay
|
@setAutocastDelay delay
|
||||||
|
@ -35,19 +39,11 @@ module.exports = class CastButtonView extends View
|
||||||
attachTo: (spellView) ->
|
attachTo: (spellView) ->
|
||||||
@$el.detach().prependTo(spellView.toolbarView.$el).show()
|
@$el.detach().prependTo(spellView.toolbarView.$el).show()
|
||||||
|
|
||||||
hookUpButtons: ->
|
onCastOptionsClick: (e) ->
|
||||||
# hook up cast button callbacks
|
Backbone.Mediator.publish 'focus-editor'
|
||||||
@castButton = $('.cast-button', @$el)
|
@castButtonGroup.removeClass 'open'
|
||||||
@castButtonGroup = $('.cast-button-group', @$el)
|
@setAutocastDelay $(e.target).attr 'data-delay'
|
||||||
@castOptions = $('.autocast-delays', @$el)
|
false
|
||||||
|
|
||||||
@castButton.click (e) =>
|
|
||||||
Backbone.Mediator.publish 'tome:manual-cast', {}
|
|
||||||
@castOptions.find('a').click (e) =>
|
|
||||||
Backbone.Mediator.publish 'focus-editor'
|
|
||||||
@castButtonGroup.removeClass 'open'
|
|
||||||
@setAutocastDelay $(e.target).attr 'data-delay'
|
|
||||||
false
|
|
||||||
|
|
||||||
onSpellChanged: (e) ->
|
onSpellChanged: (e) ->
|
||||||
@updateCastButton()
|
@updateCastButton()
|
||||||
|
|
|
@ -60,7 +60,7 @@ module.exports = class DebugView extends View
|
||||||
@variableChain = @markerRange = null
|
@variableChain = @markerRange = null
|
||||||
@update()
|
@update()
|
||||||
|
|
||||||
onMouseOut: (e) =>
|
onMouseOut: (e) ->
|
||||||
@variableChain = @markerRange = null
|
@variableChain = @markerRange = null
|
||||||
@update()
|
@update()
|
||||||
|
|
||||||
|
@ -138,3 +138,4 @@ module.exports = class DebugView extends View
|
||||||
destroy: ->
|
destroy: ->
|
||||||
super()
|
super()
|
||||||
@ace?.removeEventListener "mousemove", @onMouseMove
|
@ace?.removeEventListener "mousemove", @onMouseMove
|
||||||
|
@onMouseMove = null
|
||||||
|
|
|
@ -60,3 +60,4 @@ module.exports = class SpellPaletteView extends View
|
||||||
destroy: ->
|
destroy: ->
|
||||||
super()
|
super()
|
||||||
entry.destroy() for entry in @entries
|
entry.destroy() for entry in @entries
|
||||||
|
@toggleBackground = null
|
||||||
|
|
|
@ -74,47 +74,51 @@ module.exports = class SpellView extends View
|
||||||
$(@ace.container).find('.ace_gutter').on 'click', '.ace_error, .ace_warning, .ace_info', @onAnnotationClick
|
$(@ace.container).find('.ace_gutter').on 'click', '.ace_error, .ace_warning, .ace_info', @onAnnotationClick
|
||||||
|
|
||||||
createACEShortcuts: ->
|
createACEShortcuts: ->
|
||||||
@ace.commands.addCommand
|
@aceCommands = []
|
||||||
|
addCommand = (c) =>
|
||||||
|
@ace.commands.addCommand c
|
||||||
|
@aceCommands.push c.name
|
||||||
|
addCommand
|
||||||
name: 'run-code'
|
name: 'run-code'
|
||||||
bindKey: {win: 'Shift-Enter|Ctrl-Enter|Ctrl-S', mac: 'Shift-Enter|Command-Enter|Ctrl-Enter|Command-S|Ctrl-S'}
|
bindKey: {win: 'Shift-Enter|Ctrl-Enter|Ctrl-S', mac: 'Shift-Enter|Command-Enter|Ctrl-Enter|Command-S|Ctrl-S'}
|
||||||
exec: (e) => @recompile()
|
exec: (e) => @recompile()
|
||||||
@ace.commands.addCommand
|
addCommand
|
||||||
name: 'toggle-playing'
|
name: 'toggle-playing'
|
||||||
bindKey: {win: 'Ctrl-P', mac: 'Command-P|Ctrl-P'}
|
bindKey: {win: 'Ctrl-P', mac: 'Command-P|Ctrl-P'}
|
||||||
exec: -> Backbone.Mediator.publish 'level-toggle-playing'
|
exec: -> Backbone.Mediator.publish 'level-toggle-playing'
|
||||||
@ace.commands.addCommand
|
addCommand
|
||||||
name: 'end-current-script'
|
name: 'end-current-script'
|
||||||
bindKey: {win: 'Shift-Space', mac: 'Shift-Space'}
|
bindKey: {win: 'Shift-Space', mac: 'Shift-Space'}
|
||||||
exec: -> Backbone.Mediator.publish 'level:shift-space-pressed'
|
exec: -> Backbone.Mediator.publish 'level:shift-space-pressed'
|
||||||
@ace.commands.addCommand
|
addCommand
|
||||||
name: 'end-all-scripts'
|
name: 'end-all-scripts'
|
||||||
bindKey: {win: 'Escape', mac: 'Escape'}
|
bindKey: {win: 'Escape', mac: 'Escape'}
|
||||||
exec: -> Backbone.Mediator.publish 'level:escape-pressed'
|
exec: -> Backbone.Mediator.publish 'level:escape-pressed'
|
||||||
@ace.commands.addCommand
|
addCommand
|
||||||
name: 'toggle-grid'
|
name: 'toggle-grid'
|
||||||
bindKey: {win: 'Ctrl-G', mac: 'Command-G|Ctrl-G'}
|
bindKey: {win: 'Ctrl-G', mac: 'Command-G|Ctrl-G'}
|
||||||
exec: -> Backbone.Mediator.publish 'level-toggle-grid'
|
exec: -> Backbone.Mediator.publish 'level-toggle-grid'
|
||||||
@ace.commands.addCommand
|
addCommand
|
||||||
name: 'toggle-debug'
|
name: 'toggle-debug'
|
||||||
bindKey: {win: 'Ctrl-\\', mac: 'Command-\\|Ctrl-\\'}
|
bindKey: {win: 'Ctrl-\\', mac: 'Command-\\|Ctrl-\\'}
|
||||||
exec: -> Backbone.Mediator.publish 'level-toggle-debug'
|
exec: -> Backbone.Mediator.publish 'level-toggle-debug'
|
||||||
@ace.commands.addCommand
|
addCommand
|
||||||
name: 'toggle-pathfinding'
|
name: 'toggle-pathfinding'
|
||||||
bindKey: {win: 'Ctrl-O', mac: 'Command-O|Ctrl-O'}
|
bindKey: {win: 'Ctrl-O', mac: 'Command-O|Ctrl-O'}
|
||||||
exec: -> Backbone.Mediator.publish 'level-toggle-pathfinding'
|
exec: -> Backbone.Mediator.publish 'level-toggle-pathfinding'
|
||||||
@ace.commands.addCommand
|
addCommand
|
||||||
name: 'level-scrub-forward'
|
name: 'level-scrub-forward'
|
||||||
bindKey: {win: 'Ctrl-]', mac: 'Command-]|Ctrl-]'}
|
bindKey: {win: 'Ctrl-]', mac: 'Command-]|Ctrl-]'}
|
||||||
exec: -> Backbone.Mediator.publish 'level-scrub-forward'
|
exec: -> Backbone.Mediator.publish 'level-scrub-forward'
|
||||||
@ace.commands.addCommand
|
addCommand
|
||||||
name: 'level-scrub-back'
|
name: 'level-scrub-back'
|
||||||
bindKey: {win: 'Ctrl-[', mac: 'Command-[|Ctrl-]'}
|
bindKey: {win: 'Ctrl-[', mac: 'Command-[|Ctrl-]'}
|
||||||
exec: -> Backbone.Mediator.publish 'level-scrub-back'
|
exec: -> Backbone.Mediator.publish 'level-scrub-back'
|
||||||
@ace.commands.addCommand
|
addCommand
|
||||||
name: 'spell-step-forward'
|
name: 'spell-step-forward'
|
||||||
bindKey: {win: 'Ctrl-Alt-]', mac: 'Command-Alt-]|Ctrl-Alt-]'}
|
bindKey: {win: 'Ctrl-Alt-]', mac: 'Command-Alt-]|Ctrl-Alt-]'}
|
||||||
exec: -> Backbone.Mediator.publish 'spell-step-forward'
|
exec: -> Backbone.Mediator.publish 'spell-step-forward'
|
||||||
@ace.commands.addCommand
|
addCommand
|
||||||
name: 'spell-step-backward'
|
name: 'spell-step-backward'
|
||||||
bindKey: {win: 'Ctrl-Alt-[', mac: 'Command-Alt-[|Ctrl-Alt-]'}
|
bindKey: {win: 'Ctrl-Alt-[', mac: 'Command-Alt-[|Ctrl-Alt-]'}
|
||||||
exec: -> Backbone.Mediator.publish 'spell-step-backward'
|
exec: -> Backbone.Mediator.publish 'spell-step-backward'
|
||||||
|
@ -212,6 +216,9 @@ module.exports = class SpellView extends View
|
||||||
@updateACEText @spell.originalSource
|
@updateACEText @spell.originalSource
|
||||||
@recompile cast
|
@recompile cast
|
||||||
|
|
||||||
|
recompileIfNeeded: =>
|
||||||
|
@recompile() if @recompileNeeded
|
||||||
|
|
||||||
recompile: (cast=true) =>
|
recompile: (cast=true) =>
|
||||||
@setRecompileNeeded false
|
@setRecompileNeeded false
|
||||||
return if @spell.source is @getSource()
|
return if @spell.source is @getSource()
|
||||||
|
@ -238,7 +245,7 @@ module.exports = class SpellView extends View
|
||||||
autocastDelay = @autocastDelay ? 3000
|
autocastDelay = @autocastDelay ? 3000
|
||||||
onSignificantChange = [
|
onSignificantChange = [
|
||||||
_.debounce @setRecompileNeeded, autocastDelay - 100
|
_.debounce @setRecompileNeeded, autocastDelay - 100
|
||||||
@currentAutocastHandler = _.debounce (=> @recompile() if @recompileNeeded), autocastDelay
|
@currentAutocastHandler = _.debounce @recompileIfNeeded, autocastDelay
|
||||||
]
|
]
|
||||||
onAnyChange = [
|
onAnyChange = [
|
||||||
_.debounce @updateAether, 500
|
_.debounce @updateAether, 500
|
||||||
|
@ -500,9 +507,17 @@ module.exports = class SpellView extends View
|
||||||
|
|
||||||
destroy: ->
|
destroy: ->
|
||||||
super()
|
super()
|
||||||
|
$(@ace?.container).find('.ace_gutter').off 'click', '.ace_error, .ace_warning, .ace_info', @onAnnotationClick
|
||||||
@firepad?.dispose()
|
@firepad?.dispose()
|
||||||
@ace.destroy()
|
@ace?.commands.removeCommand command for command in @aceCommands
|
||||||
|
@ace?.destroy()
|
||||||
@ace = null
|
@ace = null
|
||||||
|
@aceDoc?.off 'change', @onCodeChangeMetaHandler
|
||||||
|
@aceDoc = null
|
||||||
|
@aceSession?.selection.off 'changeCursor', @onCursorActivity
|
||||||
|
@aceSession = null
|
||||||
@debugView?.destroy()
|
@debugView?.destroy()
|
||||||
@spell = null
|
@spell = null
|
||||||
@session.off 'change:multiplayer', @onMultiplayerChanged, @
|
@session.off 'change:multiplayer', @onMultiplayerChanged, @
|
||||||
|
for fat in ['notifySpellChanged', 'notifyEditingEnded', 'notifyEditingBegan', 'onFirepadLoaded', 'onLoaded', 'recompile', 'toggleBackground', 'setRecompileNeeded', 'onCursorActivity', 'highlightCurrentLine', 'updateAether', 'onCodeChangeMetaHandler', 'recompileIfNeeded', 'currentAutocastHandler']
|
||||||
|
@[fat] = null
|
||||||
|
|
|
@ -97,12 +97,12 @@ module.exports = class ThangListEntryView extends View
|
||||||
@$el.popover('setContent').popover('show')
|
@$el.popover('setContent').popover('show')
|
||||||
@$el.parent().parent().parent().i18n()
|
@$el.parent().parent().parent().i18n()
|
||||||
clearTimeout @hideSpellsTimeout if @hideSpellsTimeout
|
clearTimeout @hideSpellsTimeout if @hideSpellsTimeout
|
||||||
popover = @$el.parent().parent().parent().find('.popover')
|
@popover = @$el.parent().parent().parent().find('.popover')
|
||||||
popover.off 'mouseenter mouseleave'
|
@popover.off 'mouseenter mouseleave'
|
||||||
popover.mouseenter (e) => @onMouseEnter()
|
@popover.mouseenter (e) => @onMouseEnter()
|
||||||
popover.mouseleave (e) => @onMouseLeave()
|
@popover.mouseleave (e) => @onMouseLeave()
|
||||||
thangID = @thang.id
|
thangID = @thang.id
|
||||||
popover.find('code').click (e) ->
|
@popover.find('code').click (e) ->
|
||||||
Backbone.Mediator.publish "level-select-sprite", thangID: thangID, spellName: $(@).data 'spell-name'
|
Backbone.Mediator.publish "level-select-sprite", thangID: thangID, spellName: $(@).data 'spell-name'
|
||||||
|
|
||||||
hideSpells: =>
|
hideSpells: =>
|
||||||
|
@ -139,3 +139,5 @@ module.exports = class ThangListEntryView extends View
|
||||||
destroy: ->
|
destroy: ->
|
||||||
super()
|
super()
|
||||||
@avatar?.destroy()
|
@avatar?.destroy()
|
||||||
|
@popover?.off 'mouseenter mouseleave'
|
||||||
|
@popover?.find('code').off 'click'
|
||||||
|
|
|
@ -76,9 +76,7 @@ module.exports = class PlayLevelView extends View
|
||||||
@sessionID = @getQueryVariable 'session'
|
@sessionID = @getQueryVariable 'session'
|
||||||
|
|
||||||
$(window).on('resize', @onWindowResize)
|
$(window).on('resize', @onWindowResize)
|
||||||
@supermodel.once 'error', =>
|
@supermodel.once 'error', @onLevelLoadError
|
||||||
msg = $.i18n.t('play_level.level_load_error', defaultValue: "Level could not be loaded.")
|
|
||||||
@$el.html('<div class="alert">' + msg + '</div>')
|
|
||||||
@saveScreenshot = _.throttle @saveScreenshot, 30000
|
@saveScreenshot = _.throttle @saveScreenshot, 30000
|
||||||
|
|
||||||
if @isEditorPreview
|
if @isEditorPreview
|
||||||
|
@ -94,6 +92,10 @@ module.exports = class PlayLevelView extends View
|
||||||
if localStorage?
|
if localStorage?
|
||||||
localStorage["lastLevel"] = @levelID
|
localStorage["lastLevel"] = @levelID
|
||||||
|
|
||||||
|
onLevelLoadError: (e) =>
|
||||||
|
msg = $.i18n.t('play_level.level_load_error', defaultValue: "Level could not be loaded.")
|
||||||
|
@$el.html('<div class="alert">' + msg + '</div>')
|
||||||
|
|
||||||
setLevel: (@level, @supermodel) ->
|
setLevel: (@level, @supermodel) ->
|
||||||
@god?.level = @level.serialize @supermodel
|
@god?.level = @level.serialize @supermodel
|
||||||
if @world
|
if @world
|
||||||
|
@ -181,21 +183,21 @@ module.exports = class PlayLevelView extends View
|
||||||
onWindowResize: (s...) ->
|
onWindowResize: (s...) ->
|
||||||
$('#pointer').css('opacity', 0.0)
|
$('#pointer').css('opacity', 0.0)
|
||||||
|
|
||||||
onDisableControls: (e) =>
|
onDisableControls: (e) ->
|
||||||
return if e.controls and not ('level' in e.controls)
|
return if e.controls and not ('level' in e.controls)
|
||||||
@shortcutsEnabled = false
|
@shortcutsEnabled = false
|
||||||
@wasFocusedOn = document.activeElement
|
@wasFocusedOn = document.activeElement
|
||||||
$('body').focus()
|
$('body').focus()
|
||||||
|
|
||||||
onEnableControls: (e) =>
|
onEnableControls: (e) ->
|
||||||
return if e.controls? and not ('level' in e.controls)
|
return if e.controls? and not ('level' in e.controls)
|
||||||
@shortcutsEnabled = true
|
@shortcutsEnabled = true
|
||||||
$(@wasFocusedOn).focus() if @wasFocusedOn
|
$(@wasFocusedOn).focus() if @wasFocusedOn
|
||||||
@wasFocusedOn = null
|
@wasFocusedOn = null
|
||||||
|
|
||||||
onDonePressed: => @showVictory()
|
onDonePressed: -> @showVictory()
|
||||||
|
|
||||||
onShowVictory: (e) =>
|
onShowVictory: (e) ->
|
||||||
console.log 'show vict', e
|
console.log 'show vict', e
|
||||||
$('#level-done-button').show()
|
$('#level-done-button').show()
|
||||||
@showVictory() if e.showModal
|
@showVictory() if e.showModal
|
||||||
|
@ -221,7 +223,7 @@ module.exports = class PlayLevelView extends View
|
||||||
@openModalView new InfiniteLoopModal()
|
@openModalView new InfiniteLoopModal()
|
||||||
window.tracker?.trackEvent 'Saw Initial Infinite Loop', level: @world.name, label: @world.name
|
window.tracker?.trackEvent 'Saw Initial Infinite Loop', level: @world.name, label: @world.name
|
||||||
|
|
||||||
onPlayNextLevel: =>
|
onPlayNextLevel: ->
|
||||||
nextLevel = @getNextLevel()
|
nextLevel = @getNextLevel()
|
||||||
nextLevelID = nextLevel.get('slug') or nextLevel.id
|
nextLevelID = nextLevel.get('slug') or nextLevel.id
|
||||||
url = "/play/level/#{nextLevelID}"
|
url = "/play/level/#{nextLevelID}"
|
||||||
|
@ -235,7 +237,7 @@ module.exports = class PlayLevelView extends View
|
||||||
levels = @supermodel.getModels(Level)
|
levels = @supermodel.getModels(Level)
|
||||||
return l for l in levels when l.get('original') is nextLevelOriginal
|
return l for l in levels when l.get('original') is nextLevelOriginal
|
||||||
|
|
||||||
onHighlightDom: (e) =>
|
onHighlightDom: (e) ->
|
||||||
if e.delay
|
if e.delay
|
||||||
delay = e.delay
|
delay = e.delay
|
||||||
delete e.delay
|
delete e.delay
|
||||||
|
@ -289,16 +291,16 @@ module.exports = class PlayLevelView extends View
|
||||||
), 1)
|
), 1)
|
||||||
|
|
||||||
|
|
||||||
animatePointer: =>
|
animatePointer: ->
|
||||||
pointer = $('#pointer')
|
pointer = $('#pointer')
|
||||||
pointer.css('transition', 'all 0.6s ease-out')
|
pointer.css('transition', 'all 0.6s ease-out')
|
||||||
pointer.css('transform', "rotate(#{@pointerRotation}rad) translate(-3px, #{@pointerRadialDistance-50}px)")
|
pointer.css('transform', "rotate(#{@pointerRotation}rad) translate(-3px, #{@pointerRadialDistance-50}px)")
|
||||||
setTimeout((=>
|
setTimeout((=>
|
||||||
pointer.css('transform', "rotate(#{@pointerRotation}rad) translate(-3px, #{@pointerRadialDistance}px)").css('transition', 'all 0.4s ease-in')), 800)
|
pointer.css('transform', "rotate(#{@pointerRotation}rad) translate(-3px, #{@pointerRadialDistance}px)").css('transition', 'all 0.4s ease-in')), 800)
|
||||||
|
|
||||||
onFocusDom: (e) => $(e.selector).focus()
|
onFocusDom: (e) -> $(e.selector).focus()
|
||||||
|
|
||||||
onEndHighlight: =>
|
onEndHighlight: ->
|
||||||
$('#pointer').css('opacity', 0.0)
|
$('#pointer').css('opacity', 0.0)
|
||||||
clearInterval(@pointerInterval)
|
clearInterval(@pointerInterval)
|
||||||
|
|
||||||
|
@ -380,6 +382,8 @@ module.exports = class PlayLevelView extends View
|
||||||
|
|
||||||
destroy: ->
|
destroy: ->
|
||||||
super()
|
super()
|
||||||
|
@supermodel.off 'error', @onLevelLoadError
|
||||||
|
@levelLoader?.off 'loaded-all', @onLevelLoaderLoaded
|
||||||
@levelLoader?.destroy()
|
@levelLoader?.destroy()
|
||||||
@surface?.destroy()
|
@surface?.destroy()
|
||||||
@god?.destroy()
|
@god?.destroy()
|
||||||
|
@ -393,3 +397,8 @@ module.exports = class PlayLevelView extends View
|
||||||
#@instance.save() unless @instance.loading
|
#@instance.save() unless @instance.loading
|
||||||
console.profileEnd?() if PROFILE_ME
|
console.profileEnd?() if PROFILE_ME
|
||||||
@session.off 'change:multiplayer', @onMultiplayerChanged, @
|
@session.off 'change:multiplayer', @onMultiplayerChanged, @
|
||||||
|
@onLevelLoadError = null
|
||||||
|
@onLevelLoaderLoaded = null
|
||||||
|
@onSupermodelLoadedOne = null
|
||||||
|
@preloadNextLevel = null
|
||||||
|
@saveScreenshot = null
|
||||||
|
|
Loading…
Reference in a new issue