Merge branch 'master' into production

This commit is contained in:
Nick Winter 2014-05-12 19:21:48 -07:00
commit b2d2e6b525
3 changed files with 26 additions and 16 deletions

View file

@ -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 ->
$('<img/>')[0].src = @

View file

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

View file

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