From dbfbddeb5dfbf3ce340060b81d5e843165acf99c Mon Sep 17 00:00:00 2001 From: Scott Erickson Date: Wed, 17 Sep 2014 16:06:23 -0700 Subject: [PATCH] Added a test to make sure the WebGLLayer ended up with the right number of children after multiple renderings. Fixed something that was breaking WebGLLayer and WebGLSprite tests. --- app/lib/surface/WebGLLayer.coffee | 3 +- test/app/lib/surface/SpriteBoss.spec.coffee | 42 +++++++++++++-------- 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/app/lib/surface/WebGLLayer.coffee b/app/lib/surface/WebGLLayer.coffee index 230487080..49151df57 100644 --- a/app/lib/surface/WebGLLayer.coffee +++ b/app/lib/surface/WebGLLayer.coffee @@ -21,6 +21,7 @@ module.exports = class WebGLLayer extends CocoClass spriteContainer: null constructor: (@layerOptions) -> + @layerOptions ?= {} super() @initializing = true @spriteSheet = @_renderNewSpriteSheet(false) # builds an empty spritesheet @@ -131,7 +132,7 @@ module.exports = class WebGLLayer extends CocoClass index = parent.getChildIndex(oldLayer) parent.removeChildAt(index) parent.addChildAt(@spriteContainer, index) - @layerOptions.camera.updateZoom(true) + @layerOptions.camera?.updateZoom(true) @spriteContainer.updateLayerOrder() @trigger 'new-spritesheet' diff --git a/test/app/lib/surface/SpriteBoss.spec.coffee b/test/app/lib/surface/SpriteBoss.spec.coffee index aff07cbca..65fc5553a 100644 --- a/test/app/lib/surface/SpriteBoss.spec.coffee +++ b/test/app/lib/surface/SpriteBoss.spec.coffee @@ -23,20 +23,6 @@ describe 'SpriteBoss', -> world = new World() world.thangs = [ - - # four cardinal ogres - {id: 'Ogre N', spriteName: 'Ogre Munchkin M', exists: true, pos: {x:0, y:8}, action: 'move', health: 10, maxHealth: 10, rotation: -Math.PI/2, acts: true, scaleFactorX: 2 } - {id: 'Ogre W', spriteName: 'Ogre Munchkin M', exists: true, pos: {x:-8, y:0}, action: 'move', health: 5, maxHealth: 10, rotation: 0, acts: true, scaleFactorY: 2 } - {id: 'Ogre E', spriteName: 'Ogre Munchkin M', exists: true, pos: {x:8, y:0}, action: 'move', health: 5, maxHealth: 10, rotation: Math.PI, acts: true, alpha: 0.5, scaleFactorY: 3, scaleFactorX: 3 } - {id: 'Ogre S', spriteName: 'Ogre Munchkin M', exists: true, pos: {x:0, y:-8}, action: 'move', health: 5, maxHealth: 10, rotation: Math.PI/2, acts: true } - - # ogres overlapping - {id: 'Ogre 1', spriteName: 'Ogre Munchkin M', exists: true, pos: {x:-14, y:0}, action: 'die', health: 5, maxHealth: 10, rotation: 0, acts: true } - {id: 'Ogre 2', spriteName: 'Ogre Munchkin M', exists: true, pos: {x:-13.5, y:1}, action: 'die', health: 5, maxHealth: 10, rotation: 0, acts: true } - {id: 'Ogre 3', spriteName: 'Ogre Munchkin M', exists: true, pos: {x:-13, y:2}, action: 'die', health: 5, maxHealth: 10, rotation: 0, acts: true } - {id: 'Ogre 4', spriteName: 'Ogre Munchkin M', exists: true, pos: {x:-12.5, y:3}, action: 'die', health: 5, maxHealth: 10, rotation: 0, acts: true } - - {id: 'Fangrider 1', spriteName: 'Ogre Fangrider', exists: true, pos: {x:8, y:8}, action: 'move', health: 20, maxHealth: 20, rotation: 0, acts: true } {id: 'Tree 1', spriteName: 'Tree 1', exists: true, pos: {x:4, y:0}, action: 'idle', health: 20, maxHealth: 20, rotation: Math.PI/2, acts: true } ] world.thangMap = {} @@ -62,8 +48,27 @@ describe 'SpriteBoss', -> defaultLayer.buildAsync = false # cause faster spriteBoss.update(true) - defaultLayer.once 'new-spritesheet', -> done() -# showMe() + defaultLayer.once 'new-spritesheet', -> + world.thangs = world.thangs.concat [ + # four cardinal ogres + {id: 'Ogre N', spriteName: 'Ogre Munchkin M', exists: true, pos: {x:0, y:8}, action: 'move', health: 10, maxHealth: 10, rotation: -Math.PI/2, acts: true, scaleFactorX: 2 } + {id: 'Ogre W', spriteName: 'Ogre Munchkin M', exists: true, pos: {x:-8, y:0}, action: 'move', health: 5, maxHealth: 10, rotation: 0, acts: true, scaleFactorY: 2 } + {id: 'Ogre E', spriteName: 'Ogre Munchkin M', exists: true, pos: {x:8, y:0}, action: 'move', health: 5, maxHealth: 10, rotation: Math.PI, acts: true, alpha: 0.5, scaleFactorY: 3, scaleFactorX: 3 } + {id: 'Ogre S', spriteName: 'Ogre Munchkin M', exists: true, pos: {x:0, y:-8}, action: 'move', health: 5, maxHealth: 10, rotation: Math.PI/2, acts: true } + + # ogres overlapping + {id: 'Ogre 1', spriteName: 'Ogre Munchkin M', exists: true, pos: {x:-14, y:0}, action: 'die', health: 5, maxHealth: 10, rotation: 0, acts: true } + {id: 'Ogre 2', spriteName: 'Ogre Munchkin M', exists: true, pos: {x:-13.5, y:1}, action: 'die', health: 5, maxHealth: 10, rotation: 0, acts: true } + {id: 'Ogre 3', spriteName: 'Ogre Munchkin M', exists: true, pos: {x:-13, y:2}, action: 'die', health: 5, maxHealth: 10, rotation: 0, acts: true } + {id: 'Ogre 4', spriteName: 'Ogre Munchkin M', exists: true, pos: {x:-12.5, y:3}, action: 'die', health: 5, maxHealth: 10, rotation: 0, acts: true } + + {id: 'Fangrider 1', spriteName: 'Ogre Fangrider', exists: true, pos: {x:8, y:8}, action: 'move', health: 20, maxHealth: 20, rotation: 0, acts: true } + ] + world.thangMap[thang.id] = thang for thang in world.thangs + spriteBoss.update(true) + defaultLayer.once 'new-spritesheet', -> + done() +# showMe() beforeEach (done) -> init(done) @@ -118,3 +123,8 @@ describe 'SpriteBoss', -> expect(i1).toBeGreaterThan(i2) expect(i2).toBeGreaterThan(i3) expect(i3).toBeGreaterThan(i4) + + it 'only contains children Sprites and SpriteContainers whose spritesheet matches the Layer', -> + defaultLayerContainer = spriteBoss.spriteLayers.Default.spriteContainer + for c in defaultLayerContainer.children + expect(c.spriteSheet).toBe(defaultLayerContainer.spriteSheet)