mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-12-12 00:31:21 -05:00
Merge branch 'master' into production
This commit is contained in:
commit
b2d2e6b525
3 changed files with 26 additions and 16 deletions
|
@ -25,7 +25,7 @@ elementAcceptsKeystrokes = (el) ->
|
||||||
# not radio, checkbox, range, or color
|
# 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)
|
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) ->
|
preload = (arrayOfImages) ->
|
||||||
$(arrayOfImages).each ->
|
$(arrayOfImages).each ->
|
||||||
$('<img/>')[0].src = @
|
$('<img/>')[0].src = @
|
||||||
|
|
|
@ -20,7 +20,6 @@ module.exports = class SpriteBoss extends CocoClass
|
||||||
'level-lock-select': 'onSetLockSelect'
|
'level-lock-select': 'onSetLockSelect'
|
||||||
'level:restarted': 'onLevelRestarted'
|
'level:restarted': 'onLevelRestarted'
|
||||||
'god:new-world-created': 'onNewWorld'
|
'god:new-world-created': 'onNewWorld'
|
||||||
'tome:cast-spells': 'onCastSpells'
|
|
||||||
'camera:dragged': 'onCameraDragged'
|
'camera:dragged': 'onCameraDragged'
|
||||||
'sprite:loaded': -> @update(true)
|
'sprite:loaded': -> @update(true)
|
||||||
|
|
||||||
|
@ -216,9 +215,6 @@ module.exports = class SpriteBoss extends CocoClass
|
||||||
|
|
||||||
onNewWorld: (e) ->
|
onNewWorld: (e) ->
|
||||||
@world = @options.world = e.world
|
@world = @options.world = e.world
|
||||||
@play()
|
|
||||||
|
|
||||||
onCastSpells: (e) -> @stop() unless e.preload
|
|
||||||
|
|
||||||
play: ->
|
play: ->
|
||||||
sprite.play() for sprite in @spriteArray
|
sprite.play() for sprite in @spriteArray
|
||||||
|
|
|
@ -66,6 +66,7 @@ module.exports = Surface = class Surface extends CocoClass
|
||||||
'tome:cast-spells': 'onCastSpells'
|
'tome:cast-spells': 'onCastSpells'
|
||||||
'level-set-letterbox': 'onSetLetterbox'
|
'level-set-letterbox': 'onSetLetterbox'
|
||||||
'application:idle-changed': 'onIdleChanged'
|
'application:idle-changed': 'onIdleChanged'
|
||||||
|
'camera:zoom-updated': 'onZoomUpdated'
|
||||||
|
|
||||||
shortcuts:
|
shortcuts:
|
||||||
'ctrl+\\, ⌘+\\': 'onToggleDebug'
|
'ctrl+\\, ⌘+\\': 'onToggleDebug'
|
||||||
|
@ -105,6 +106,8 @@ module.exports = Surface = class Surface extends CocoClass
|
||||||
@stage.enableMouseOver 0
|
@stage.enableMouseOver 0
|
||||||
@canvas.off 'mousewheel', @onMouseWheel
|
@canvas.off 'mousewheel', @onMouseWheel
|
||||||
$(window).off 'resize', @onResize
|
$(window).off 'resize', @onResize
|
||||||
|
clearTimeout @surfacePauseTimeout if @surfacePauseTimeout
|
||||||
|
clearTimeout @surfaceZoomPauseTimeout if @surfaceZoomPauseTimeout
|
||||||
super()
|
super()
|
||||||
|
|
||||||
setWorld: (@world) ->
|
setWorld: (@world) ->
|
||||||
|
@ -253,6 +256,11 @@ module.exports = Surface = class Surface extends CocoClass
|
||||||
@cameraBorder.updateBounds @camera.bounds
|
@cameraBorder.updateBounds @camera.bounds
|
||||||
@camera.zoomTo target, e.zoom, e.duration # TODO: SurfaceScriptModule perhaps shouldn't assign e.zoom if not set
|
@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) ->
|
setDisabled: (@disabled) ->
|
||||||
@spriteBoss.disabled = @disabled
|
@spriteBoss.disabled = @disabled
|
||||||
|
|
||||||
|
@ -305,14 +313,10 @@ module.exports = Surface = class Surface extends CocoClass
|
||||||
)
|
)
|
||||||
|
|
||||||
if @lastFrame < @world.totalFrames and @currentFrame >= @world.totalFrames - 1
|
if @lastFrame < @world.totalFrames and @currentFrame >= @world.totalFrames - 1
|
||||||
@spriteBoss.stop()
|
|
||||||
@playbackOverScreen.show()
|
|
||||||
@ended = true
|
@ended = true
|
||||||
@setPaused true
|
@setPaused true
|
||||||
Backbone.Mediator.publish 'surface:playback-ended'
|
Backbone.Mediator.publish 'surface:playback-ended'
|
||||||
else if @currentFrame < @world.totalFrames and @ended
|
else if @currentFrame < @world.totalFrames and @ended
|
||||||
@spriteBoss.play()
|
|
||||||
@playbackOverScreen.hide()
|
|
||||||
@ended = false
|
@ended = false
|
||||||
@setPaused false
|
@setPaused false
|
||||||
Backbone.Mediator.publish 'surface:playback-restarted'
|
Backbone.Mediator.publish 'surface:playback-restarted'
|
||||||
|
@ -322,20 +326,27 @@ module.exports = Surface = class Surface extends CocoClass
|
||||||
onIdleChanged: (e) ->
|
onIdleChanged: (e) ->
|
||||||
@setPaused e.idle unless @ended
|
@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.
|
# 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.
|
# If pausing, though, we want to give it enough time to finish any tweens.
|
||||||
performToggle = =>
|
performToggle = =>
|
||||||
createjs.Ticker.setFPS if to then 1 else @options.frameRate
|
createjs.Ticker.setFPS if paused then 1 else @options.frameRate
|
||||||
@surfacePauseInterval = null
|
@surfacePauseTimeout = null
|
||||||
clearTimeout @surfacePauseInterval if @surfacePauseInterval
|
clearTimeout @surfacePauseTimeout if @surfacePauseTimeout
|
||||||
if to
|
clearTimeout @surfaceZoomPauseTimeout if @surfaceZoomPauseTimeout
|
||||||
@surfacePauseInterval = _.delay performToggle, 2000
|
@surfacePauseTimeout = @surfaceZoomPauseTimeout = null
|
||||||
|
if paused
|
||||||
|
@surfacePauseTimeout = _.delay performToggle, 2000
|
||||||
|
@spriteBoss.stop()
|
||||||
|
@playbackOverScreen.show()
|
||||||
else
|
else
|
||||||
performToggle()
|
performToggle()
|
||||||
|
@spriteBoss.play()
|
||||||
|
@playbackOverScreen.hide()
|
||||||
|
|
||||||
onCastSpells: (e) ->
|
onCastSpells: (e) ->
|
||||||
return if e.preload
|
return if e.preload
|
||||||
|
@setPaused false if @ended
|
||||||
@casting = true
|
@casting = true
|
||||||
@wasPlayingWhenCastingBegan = @playing
|
@wasPlayingWhenCastingBegan = @playing
|
||||||
Backbone.Mediator.publish 'level-set-playing', { playing: false }
|
Backbone.Mediator.publish 'level-set-playing', { playing: false }
|
||||||
|
@ -350,6 +361,10 @@ module.exports = Surface = class Surface extends CocoClass
|
||||||
onNewWorld: (event) ->
|
onNewWorld: (event) ->
|
||||||
return unless event.world.name is @world.name
|
return unless event.world.name is @world.name
|
||||||
@casting = false
|
@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
|
# 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.
|
# 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
|
oldHeight = parseInt @canvas.attr('height'), 10
|
||||||
newWidth = @canvas.width()
|
newWidth = @canvas.width()
|
||||||
newHeight = @canvas.height()
|
newHeight = @canvas.height()
|
||||||
console.log "had size", oldWidth, oldHeight, "moving to", newWidth, newHeight
|
|
||||||
@canvas.attr width: newWidth, height: newHeight
|
@canvas.attr width: newWidth, height: newHeight
|
||||||
@stage.scaleX *= newWidth / oldWidth
|
@stage.scaleX *= newWidth / oldWidth
|
||||||
@stage.scaleY *= newHeight / oldHeight
|
@stage.scaleY *= newHeight / oldHeight
|
||||||
|
|
Loading…
Reference in a new issue