From 2eefdef1917affe72c322b72c14a10f64807b469 Mon Sep 17 00:00:00 2001 From: Nick Winter Date: Mon, 12 May 2014 15:54:07 -0700 Subject: [PATCH 1/2] Working on matching Surface paused state to the pause screen. --- app/lib/surface/SpriteBoss.coffee | 4 ---- app/lib/surface/Surface.coffee | 36 +++++++++++++++++++++---------- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/app/lib/surface/SpriteBoss.coffee b/app/lib/surface/SpriteBoss.coffee index b325596f4..df3642e83 100644 --- a/app/lib/surface/SpriteBoss.coffee +++ b/app/lib/surface/SpriteBoss.coffee @@ -20,7 +20,6 @@ module.exports = class SpriteBoss extends CocoClass 'level-lock-select': 'onSetLockSelect' 'level:restarted': 'onLevelRestarted' 'god:new-world-created': 'onNewWorld' - 'tome:cast-spells': 'onCastSpells' 'camera:dragged': 'onCameraDragged' 'sprite:loaded': -> @update(true) @@ -216,9 +215,6 @@ module.exports = class SpriteBoss extends CocoClass onNewWorld: (e) -> @world = @options.world = e.world - @play() - - onCastSpells: (e) -> @stop() unless e.preload play: -> sprite.play() for sprite in @spriteArray diff --git a/app/lib/surface/Surface.coffee b/app/lib/surface/Surface.coffee index a45fdafec..506626c51 100644 --- a/app/lib/surface/Surface.coffee +++ b/app/lib/surface/Surface.coffee @@ -66,6 +66,7 @@ module.exports = Surface = class Surface extends CocoClass 'tome:cast-spells': 'onCastSpells' 'level-set-letterbox': 'onSetLetterbox' 'application:idle-changed': 'onIdleChanged' + 'camera:zoom-updated': 'onZoomUpdated' shortcuts: 'ctrl+\\, ⌘+\\': 'onToggleDebug' @@ -105,6 +106,8 @@ module.exports = Surface = class Surface extends CocoClass @stage.enableMouseOver 0 @canvas.off 'mousewheel', @onMouseWheel $(window).off 'resize', @onResize + clearTimeout @surfacePauseTimeout if @surfacePauseTimeout + clearTimeout @surfaceZoomPauseTimeout if @surfaceZoomPauseTimeout super() setWorld: (@world) -> @@ -253,6 +256,11 @@ module.exports = Surface = class Surface extends CocoClass @cameraBorder.updateBounds @camera.bounds @camera.zoomTo target, e.zoom, e.duration # TODO: SurfaceScriptModule perhaps shouldn't assign e.zoom if not set + onZoomUpdated: (e) -> + if @ended + @setPaused false + @surfaceZoomPauseTimeout = _.delay (=> @setPaused true), 3000 + setDisabled: (@disabled) -> @spriteBoss.disabled = @disabled @@ -305,14 +313,10 @@ module.exports = Surface = class Surface extends CocoClass ) if @lastFrame < @world.totalFrames and @currentFrame >= @world.totalFrames - 1 - @spriteBoss.stop() - @playbackOverScreen.show() @ended = true @setPaused true Backbone.Mediator.publish 'surface:playback-ended' else if @currentFrame < @world.totalFrames and @ended - @spriteBoss.play() - @playbackOverScreen.hide() @ended = false @setPaused false Backbone.Mediator.publish 'surface:playback-restarted' @@ -322,20 +326,27 @@ module.exports = Surface = class Surface extends CocoClass onIdleChanged: (e) -> @setPaused e.idle unless @ended - setPaused: (to) -> + setPaused: (paused) -> # We want to be able to essentially stop rendering the surface if it doesn't need to animate anything. # If pausing, though, we want to give it enough time to finish any tweens. performToggle = => - createjs.Ticker.setFPS if to then 1 else @options.frameRate - @surfacePauseInterval = null - clearTimeout @surfacePauseInterval if @surfacePauseInterval - if to - @surfacePauseInterval = _.delay performToggle, 2000 + createjs.Ticker.setFPS if paused then 1 else @options.frameRate + @surfacePauseTimeout = null + clearTimeout @surfacePauseTimeout if @surfacePauseTimeout + clearTimeout @surfaceZoomPauseTimeout if @surfaceZoomPauseTimeout + @surfacePauseTimeout = @surfaceZoomPauseTimeout = null + if paused + @surfacePauseTimeout = _.delay performToggle, 2000 + @spriteBoss.stop() + @playbackOverScreen.show() else performToggle() + @spriteBoss.play() + @playbackOverScreen.hide() onCastSpells: (e) -> return if e.preload + @setPaused false if @ended @casting = true @wasPlayingWhenCastingBegan = @playing Backbone.Mediator.publish 'level-set-playing', { playing: false } @@ -350,6 +361,10 @@ module.exports = Surface = class Surface extends CocoClass onNewWorld: (event) -> return unless event.world.name is @world.name @casting = false + if @ended and not @wasPlayingWhenCastingBegan + @setPaused true + else + @spriteBoss.play() # This has a tendency to break scripts that are waiting for playback to change when the level is loaded # so only run it after the first world is created. @@ -408,7 +423,6 @@ module.exports = Surface = class Surface extends CocoClass oldHeight = parseInt @canvas.attr('height'), 10 newWidth = @canvas.width() newHeight = @canvas.height() - console.log "had size", oldWidth, oldHeight, "moving to", newWidth, newHeight @canvas.attr width: newWidth, height: newHeight @stage.scaleX *= newWidth / oldWidth @stage.scaleY *= newHeight / oldHeight From 4a151d3b72f26e356bcc544d3e6fbccfca777eb9 Mon Sep 17 00:00:00 2001 From: Nick Winter Date: Mon, 12 May 2014 16:45:12 -0700 Subject: [PATCH 2/2] Improving #671. --- app/application.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/application.coffee b/app/application.coffee index 77c1a568b..ec6580b65 100644 --- a/app/application.coffee +++ b/app/application.coffee @@ -25,7 +25,7 @@ elementAcceptsKeystrokes = (el) -> # not radio, checkbox, range, or color return (tag is 'textarea' or (tag is 'input' and type in textInputTypes) or el.contentEditable in ["", "true"]) and not (el.readOnly or el.disabled) -COMMON_FILES = ['/images/pages/base/modal_background.png', '/images/level/code_palette_background.png'] +COMMON_FILES = ['/images/pages/base/modal_background.png', '/images/level/code_palette_background.png', '/images/level/popover_background.png', '/images/level/code_editor_background.png'] preload = (arrayOfImages) -> $(arrayOfImages).each -> $('')[0].src = @