mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-02-17 00:40:56 -05:00
The whole WebGL system now dynamically renders needed frames when actions it doesn't support get activated.
This commit is contained in:
parent
0404b94e5e
commit
c7279e68a8
4 changed files with 18 additions and 5 deletions
|
@ -47,6 +47,7 @@ module.exports = class WebGLLayer extends CocoClass
|
|||
|
||||
cocoSprite.layer = @
|
||||
cocoSprite.updateBaseScale()
|
||||
@listenTo(cocoSprite, 'action-needs-render', @onActionNeedsRender)
|
||||
@cocoSprites.push cocoSprite
|
||||
@loadThangType(cocoSprite.thangType)
|
||||
@addDefaultActionsToRender(cocoSprite)
|
||||
|
@ -54,9 +55,13 @@ module.exports = class WebGLLayer extends CocoClass
|
|||
# TODO: actually add it as a child
|
||||
|
||||
removeCocoSprite: (cocoSprite) ->
|
||||
@stopListening(cocoSprite)
|
||||
cocoSprite.imageObject.parent.removeChild cocoSprite.imageObject
|
||||
@cocoSprites = _.without @cocoSprites, cocoSprite
|
||||
|
||||
onActionNeedsRender: (cocoSprite, action) ->
|
||||
@upsertActionToRender(cocoSprite.thangType, action.name, cocoSprite.options.colorConfig)
|
||||
|
||||
loadThangType: (thangType) ->
|
||||
if not thangType.isFullyLoaded()
|
||||
thangType.setProjection null
|
||||
|
|
|
@ -49,6 +49,7 @@ module.exports = class WebGLSprite extends createjs.SpriteContainer
|
|||
animationName = @spriteSheetPrefix + actionName
|
||||
if not (animationName in @spriteSheet.getAnimations())
|
||||
@singleChildSprite.gotoAndStop(0)
|
||||
@notifyActionNeedsRender(action)
|
||||
return
|
||||
@singleChildSprite[func](animationName)
|
||||
@singleChildSprite.framerate = action.framerate or 20
|
||||
|
@ -63,6 +64,7 @@ module.exports = class WebGLSprite extends createjs.SpriteContainer
|
|||
@baseMovieClip = @buildMovieClip(action.animation)
|
||||
if not @baseMovieClip
|
||||
@children = []
|
||||
@notifyActionNeedsRender(action)
|
||||
return
|
||||
@children = @baseMovieClip.children
|
||||
@frames = action.frames
|
||||
|
@ -81,6 +83,7 @@ module.exports = class WebGLSprite extends createjs.SpriteContainer
|
|||
animationName = @spriteSheetPrefix + actionName
|
||||
if not (animationName in @spriteSheet.getAnimations())
|
||||
@singleChildSprite.gotoAndStop(0)
|
||||
@notifyActionNeedsRender(action)
|
||||
return
|
||||
@singleChildSprite.gotoAndStop(animationName)
|
||||
|
||||
|
@ -91,6 +94,7 @@ module.exports = class WebGLSprite extends createjs.SpriteContainer
|
|||
containerName = @spriteSheetPrefix + action.container
|
||||
if not (containerName in @spriteSheet.getAnimations())
|
||||
@children = []
|
||||
@notifyActionNeedsRender(action)
|
||||
return
|
||||
sprite = new createjs.Sprite(@spriteSheet)
|
||||
sprite.gotoAndStop(containerName)
|
||||
|
@ -98,6 +102,9 @@ module.exports = class WebGLSprite extends createjs.SpriteContainer
|
|||
@children = [sprite]
|
||||
|
||||
return
|
||||
|
||||
notifyActionNeedsRender: (action) ->
|
||||
@sprite.trigger('action-needs-render', @sprite, action)
|
||||
|
||||
buildMovieClip: (animationName, mode, startPosition, loops) ->
|
||||
raw = @thangType.get('raw')
|
||||
|
|
|
@ -59,10 +59,11 @@ describe 'SpriteBoss', ->
|
|||
|
||||
defaultLayer = spriteBoss.spriteLayers.Default
|
||||
defaultLayer.buildAsync = false # cause faster
|
||||
|
||||
# Don't have the layer automatically draw for move_fore, instead have it notified from WebGLSprites that
|
||||
# this animation or its containers are needed.
|
||||
defaultLayer.setDefaultActions(_.without defaultLayer.defaultActions, 'move_fore')
|
||||
|
||||
# Sort of an implicit test. By default, all the default actions are always rendered,
|
||||
# but I want to make sure the system can dynamically hear about actions it needs to render for
|
||||
# as they are used.
|
||||
defaultLayer.setDefaultActions(['idle'])
|
||||
|
||||
# Render the simple world with just trees
|
||||
spriteBoss.update(true)
|
||||
|
|
|
@ -56,7 +56,7 @@ describe 'WebGLLayer', ->
|
|||
animations = sheet.getAnimations()
|
||||
expect(animations.length).toBe(1)
|
||||
expect(animations[0]).toBe(key)
|
||||
expect(sheet.getNumFrames()).toBe(1)
|
||||
expect(sheet.getNumFrames()).toBe(2) # one idle frame, and the emptiness frame
|
||||
|
||||
it 'renders a raster image onto a sheet', (done) ->
|
||||
bootsThangType = new ThangType(require 'test/app/fixtures/leather-boots.thang.type')
|
||||
|
|
Loading…
Reference in a new issue