mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-23 15:48:11 -05:00
Fixed some tests broken from the refactoring.
This commit is contained in:
parent
f081d9ed4b
commit
b65b553f2d
5 changed files with 66 additions and 68 deletions
|
@ -334,7 +334,6 @@ module.exports = LayerAdapter = class LayerAdapter extends CocoClass
|
|||
#- Rendering containers for segmented thang types
|
||||
|
||||
renderSegmentedThangType: (thangType, colorConfig, actionNames, spriteSheetBuilder) ->
|
||||
console.log 'rendering segmented thang type'
|
||||
containersToRender = {}
|
||||
for actionName in actionNames
|
||||
action = _.find(thangType.getActions(), {name: actionName})
|
||||
|
@ -365,7 +364,6 @@ module.exports = LayerAdapter = class LayerAdapter extends CocoClass
|
|||
#- Rendering sprite sheets for singular thang types
|
||||
|
||||
renderSingularThangType: (thangType, colorConfig, actionNames, spriteSheetBuilder) ->
|
||||
console.log 'rendering singular thang type'
|
||||
actionObjects = _.values(thangType.getActions())
|
||||
animationActions = []
|
||||
for a in actionObjects
|
||||
|
|
|
@ -69,11 +69,11 @@ describe 'LankBoss', ->
|
|||
lankBoss.update(true)
|
||||
|
||||
# Test that the unrendered, static sprites aren't showing anything
|
||||
midRenderExpectations.push([lankBoss.lanks['Segmented Tree'].imageObject.children.length,1,'static segmented action'])
|
||||
midRenderExpectations.push([lankBoss.lanks['Segmented Tree'].imageObject.children[0].currentFrame,0,'static segmented action'])
|
||||
midRenderExpectations.push([lankBoss.lanks['Segmented Tree'].imageObject.children[0].paused,true,'static segmented action'])
|
||||
midRenderExpectations.push([lankBoss.lanks['Singular Tree'].imageObject.currentFrame,0,'static singular action'])
|
||||
midRenderExpectations.push([lankBoss.lanks['Singular Tree'].imageObject.paused,true,'static singular action'])
|
||||
midRenderExpectations.push([lankBoss.lanks['Segmented Tree'].sprite.children.length,1,'static segmented action'])
|
||||
midRenderExpectations.push([lankBoss.lanks['Segmented Tree'].sprite.children[0].currentFrame,0,'static segmented action'])
|
||||
midRenderExpectations.push([lankBoss.lanks['Segmented Tree'].sprite.children[0].paused,true,'static segmented action'])
|
||||
midRenderExpectations.push([lankBoss.lanks['Singular Tree'].sprite.currentFrame,0,'static singular action'])
|
||||
midRenderExpectations.push([lankBoss.lanks['Singular Tree'].sprite.paused,true,'static singular action'])
|
||||
|
||||
defaultLayer.once 'new-spritesheet', ->
|
||||
|
||||
|
@ -105,11 +105,11 @@ describe 'LankBoss', ->
|
|||
jasmine.Ajax.requests.sendResponses({'/db/thang.type/curse': curseData})
|
||||
|
||||
# Test that the unrendered, animated sprites aren't showing anything
|
||||
midRenderExpectations.push([lankBoss.lanks['Segmented Ogre'].imageObject.children.length,10,'animated segmented action'])
|
||||
for child in lankBoss.lanks['Segmented Ogre'].imageObject.children
|
||||
midRenderExpectations.push([lankBoss.lanks['Segmented Ogre'].sprite.children.length,10,'animated segmented action'])
|
||||
for child in lankBoss.lanks['Segmented Ogre'].sprite.children
|
||||
midRenderExpectations.push([child.children[0].currentFrame, 0, 'animated segmented action'])
|
||||
midRenderExpectations.push([lankBoss.lanks['Singular Ogre'].imageObject.currentFrame,0,'animated singular action'])
|
||||
midRenderExpectations.push([lankBoss.lanks['Singular Ogre'].imageObject.paused,true,'animated singular action'])
|
||||
midRenderExpectations.push([lankBoss.lanks['Singular Ogre'].sprite.currentFrame,0,'animated singular action'])
|
||||
midRenderExpectations.push([lankBoss.lanks['Singular Ogre'].sprite.paused,true,'animated singular action'])
|
||||
|
||||
defaultLayer.once 'new-spritesheet', ->
|
||||
# showMe() # Uncomment to display this world when you run any of these tests.
|
||||
|
@ -140,30 +140,30 @@ describe 'LankBoss', ->
|
|||
expect(expectation[0]).toBe(expectation[1])
|
||||
|
||||
it 'rotates and animates sprites according to thang rotation', ->
|
||||
expect(lankBoss.lanks['Ogre N'].imageObject.currentAnimation).toBe('move_fore')
|
||||
expect(lankBoss.lanks['Ogre E'].imageObject.currentAnimation).toBe('move_side')
|
||||
expect(lankBoss.lanks['Ogre W'].imageObject.currentAnimation).toBe('move_side')
|
||||
expect(lankBoss.lanks['Ogre S'].imageObject.currentAnimation).toBe('move_back')
|
||||
expect(lankBoss.lanks['Ogre N'].sprite.currentAnimation).toBe('move_fore')
|
||||
expect(lankBoss.lanks['Ogre E'].sprite.currentAnimation).toBe('move_side')
|
||||
expect(lankBoss.lanks['Ogre W'].sprite.currentAnimation).toBe('move_side')
|
||||
expect(lankBoss.lanks['Ogre S'].sprite.currentAnimation).toBe('move_back')
|
||||
|
||||
expect(lankBoss.lanks['Ogre E'].imageObject.scaleX).toBeLessThan(0)
|
||||
expect(lankBoss.lanks['Ogre W'].imageObject.scaleX).toBeGreaterThan(0)
|
||||
expect(lankBoss.lanks['Ogre E'].sprite.scaleX).toBeLessThan(0)
|
||||
expect(lankBoss.lanks['Ogre W'].sprite.scaleX).toBeGreaterThan(0)
|
||||
|
||||
it 'positions sprites according to thang pos', ->
|
||||
expect(lankBoss.lanks['Ogre N'].imageObject.x).toBe(0)
|
||||
expect(lankBoss.lanks['Ogre N'].imageObject.y).toBeCloseTo(-60)
|
||||
expect(lankBoss.lanks['Ogre E'].imageObject.x).toBeCloseTo(80)
|
||||
expect(lankBoss.lanks['Ogre E'].imageObject.y).toBe(0)
|
||||
expect(lankBoss.lanks['Ogre W'].imageObject.x).toBe(-80)
|
||||
expect(lankBoss.lanks['Ogre W'].imageObject.y).toBeCloseTo(0)
|
||||
expect(lankBoss.lanks['Ogre S'].imageObject.x).toBe(0)
|
||||
expect(lankBoss.lanks['Ogre S'].imageObject.y).toBeCloseTo(60)
|
||||
expect(lankBoss.lanks['Ogre N'].sprite.x).toBe(0)
|
||||
expect(lankBoss.lanks['Ogre N'].sprite.y).toBeCloseTo(-60)
|
||||
expect(lankBoss.lanks['Ogre E'].sprite.x).toBeCloseTo(80)
|
||||
expect(lankBoss.lanks['Ogre E'].sprite.y).toBe(0)
|
||||
expect(lankBoss.lanks['Ogre W'].sprite.x).toBe(-80)
|
||||
expect(lankBoss.lanks['Ogre W'].sprite.y).toBeCloseTo(0)
|
||||
expect(lankBoss.lanks['Ogre S'].sprite.x).toBe(0)
|
||||
expect(lankBoss.lanks['Ogre S'].sprite.y).toBeCloseTo(60)
|
||||
|
||||
it 'scales sprites according to thang scaleFactorX and scaleFactorY', ->
|
||||
expect(lankBoss.lanks['Ogre N'].imageObject.scaleX).toBe(lankBoss.lanks['Ogre N'].imageObject.baseScaleX * 1.5)
|
||||
expect(lankBoss.lanks['Ogre W'].imageObject.scaleY).toBe(lankBoss.lanks['Ogre N'].imageObject.baseScaleY * 1.5)
|
||||
expect(lankBoss.lanks['Ogre N'].sprite.scaleX).toBe(lankBoss.lanks['Ogre N'].sprite.baseScaleX * 1.5)
|
||||
expect(lankBoss.lanks['Ogre W'].sprite.scaleY).toBe(lankBoss.lanks['Ogre N'].sprite.baseScaleY * 1.5)
|
||||
|
||||
it 'sets alpha based on thang alpha', ->
|
||||
expect(lankBoss.lanks['Ogre E'].imageObject.alpha).toBe(0.5)
|
||||
expect(lankBoss.lanks['Ogre E'].sprite.alpha).toBe(0.5)
|
||||
|
||||
it 'orders sprites in the layer based on thang pos.y\'s', ->
|
||||
container = lankBoss.layerAdapters.Default.container
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
LayerAdapter = require 'lib/surface/LayerAdapter'
|
||||
CocoSprite = require 'lib/surface/CocoSprite'
|
||||
Lank = require 'lib/surface/Lank'
|
||||
ThangType = require 'models/ThangType'
|
||||
treeThangType = new ThangType(require 'test/app/fixtures/tree1.thang.type')
|
||||
ogreMunchkinThangType = new ThangType(require 'test/app/fixtures/ogre-munchkin-m.thang.type')
|
||||
|
@ -15,16 +15,16 @@ describe 'LayerAdapter', ->
|
|||
it 'creates containers for animated actions if set to spriteType=segmented', ->
|
||||
ogreMunchkinThangType.set('spriteType', 'segmented')
|
||||
colorConfig = {team: {hue: 0, saturation: 1, lightness: 0.5}}
|
||||
sprite = new CocoSprite(ogreMunchkinThangType, {colorConfig: colorConfig})
|
||||
layer.addCocoSprite(sprite)
|
||||
sprite = new Lank(ogreMunchkinThangType, {colorConfig: colorConfig})
|
||||
layer.addLank(sprite)
|
||||
sheet = layer.renderNewSpriteSheet()
|
||||
key = layer.renderGroupingKey(ogreMunchkinThangType, 'head', colorConfig)
|
||||
expect(key in sheet.getAnimations()).toBe(true)
|
||||
|
||||
it 'creates the container for static actions if set to spriteType=segmented', ->
|
||||
treeThangType.set('spriteType', 'segmented')
|
||||
sprite = new CocoSprite(treeThangType)
|
||||
layer.addCocoSprite(sprite)
|
||||
sprite = new Lank(treeThangType)
|
||||
layer.addLank(sprite)
|
||||
sheet = layer.renderNewSpriteSheet()
|
||||
key = layer.renderGroupingKey(treeThangType, 'Tree_4')
|
||||
expect(key in sheet.getAnimations()).toBe(true)
|
||||
|
@ -32,16 +32,16 @@ describe 'LayerAdapter', ->
|
|||
it 'creates animations for animated actions if set to spriteType=singular', ->
|
||||
ogreMunchkinThangType.set('spriteType', 'singular')
|
||||
colorConfig = {team: {hue: 0, saturation: 1, lightness: 0.5}}
|
||||
sprite = new CocoSprite(ogreMunchkinThangType, {colorConfig: colorConfig})
|
||||
layer.addCocoSprite(sprite)
|
||||
sprite = new Lank(ogreMunchkinThangType, {colorConfig: colorConfig})
|
||||
layer.addLank(sprite)
|
||||
sheet = layer.renderNewSpriteSheet()
|
||||
key = layer.renderGroupingKey(ogreMunchkinThangType, 'idle', colorConfig)
|
||||
expect(key in sheet.getAnimations()).toBe(true)
|
||||
|
||||
it 'creates animations for static actions if set to spriteType=singular', ->
|
||||
treeThangType.set('spriteType', 'singular')
|
||||
sprite = new CocoSprite(treeThangType)
|
||||
layer.addCocoSprite(sprite)
|
||||
sprite = new Lank(treeThangType)
|
||||
layer.addLank(sprite)
|
||||
sheet = layer.renderNewSpriteSheet()
|
||||
key = layer.renderGroupingKey(treeThangType, 'idle')
|
||||
expect(key in sheet.getAnimations()).toBe(true)
|
||||
|
@ -50,8 +50,8 @@ describe 'LayerAdapter', ->
|
|||
layer.defaultActions = ['idle'] # uses the move side animation
|
||||
ogreMunchkinThangType.set('spriteType', 'singular')
|
||||
colorConfig = {team: {hue: 0, saturation: 1, lightness: 0.5}}
|
||||
sprite = new CocoSprite(ogreMunchkinThangType, {colorConfig: colorConfig})
|
||||
layer.addCocoSprite(sprite)
|
||||
sprite = new Lank(ogreMunchkinThangType, {colorConfig: colorConfig})
|
||||
layer.addLank(sprite)
|
||||
sheet = layer.renderNewSpriteSheet()
|
||||
key = layer.renderGroupingKey(ogreMunchkinThangType, 'idle', colorConfig)
|
||||
animations = sheet.getAnimations()
|
||||
|
@ -63,8 +63,8 @@ describe 'LayerAdapter', ->
|
|||
bootsThangType = new ThangType(require 'test/app/fixtures/leather-boots.thang.type')
|
||||
bootsThangType.loadRasterImage()
|
||||
bootsThangType.once('raster-image-loaded', ->
|
||||
sprite = new CocoSprite(bootsThangType)
|
||||
layer.addCocoSprite(sprite)
|
||||
sprite = new Lank(bootsThangType)
|
||||
layer.addLank(sprite)
|
||||
sheet = layer.renderNewSpriteSheet()
|
||||
key = layer.renderGroupingKey(bootsThangType)
|
||||
expect(key in sheet.getAnimations()).toBe(true)
|
||||
|
@ -76,18 +76,18 @@ describe 'LayerAdapter', ->
|
|||
done()
|
||||
)
|
||||
|
||||
it 'loads ThangTypes for CocoSprites that are added to it and need to be loaded', ->
|
||||
it 'loads ThangTypes for Lanks that are added to it and need to be loaded', ->
|
||||
thangType = new ThangType({_id: 1})
|
||||
sprite = new CocoSprite(thangType)
|
||||
layer.addCocoSprite(sprite)
|
||||
sprite = new Lank(thangType)
|
||||
layer.addLank(sprite)
|
||||
expect(layer.numThingsLoading).toBe(1)
|
||||
expect(jasmine.Ajax.requests.count()).toBe(1)
|
||||
|
||||
it 'loads raster images for ThangType', ->
|
||||
bootsThangTypeData = require 'test/app/fixtures/leather-boots.thang.type'
|
||||
thangType = new ThangType({_id: 1})
|
||||
sprite = new CocoSprite(thangType)
|
||||
layer.addCocoSprite(sprite)
|
||||
sprite = new Lank(thangType)
|
||||
layer.addLank(sprite)
|
||||
expect(layer.numThingsLoading).toBe(1)
|
||||
spyOn(thangType, 'loadRasterImage')
|
||||
jasmine.Ajax.requests.sendResponses({'/db/thang.type/1': bootsThangTypeData})
|
||||
|
@ -103,9 +103,9 @@ describe 'LayerAdapter', ->
|
|||
bootsThangTypeData = require 'test/app/fixtures/leather-boots.thang.type'
|
||||
thangType1 = new ThangType({_id: 1})
|
||||
thangType2 = new ThangType({_id: 2})
|
||||
layer.addCocoSprite(new CocoSprite(thangType1))
|
||||
layer.addLank(new Lank(thangType1))
|
||||
expect(layer.numThingsLoading).toBe(1)
|
||||
layer.addCocoSprite(new CocoSprite(thangType2))
|
||||
layer.addLank(new Lank(thangType2))
|
||||
expect(layer.numThingsLoading).toBe(2)
|
||||
spyOn(thangType2, 'loadRasterImage')
|
||||
spyOn layer, '_renderNewSpriteSheet'
|
||||
|
@ -122,8 +122,8 @@ describe 'LayerAdapter', ->
|
|||
|
||||
it 'recycles *containers* from previous sprite sheets, rather than building repeatedly from raw vector data', ->
|
||||
treeThangType.set('spriteType', 'segmented')
|
||||
sprite = new CocoSprite(treeThangType)
|
||||
layer.addCocoSprite(sprite)
|
||||
sprite = new Lank(treeThangType)
|
||||
layer.addLank(sprite)
|
||||
spyOn(SpriteBuilder.prototype, 'buildContainerFromStore').and.callThrough()
|
||||
for i in _.range(2)
|
||||
sheet = layer.renderNewSpriteSheet()
|
||||
|
@ -131,8 +131,8 @@ describe 'LayerAdapter', ->
|
|||
|
||||
it '*does not* recycle *containers* from previous sprite sheets when the resolutionFactor has changed', ->
|
||||
treeThangType.set('spriteType', 'segmented')
|
||||
sprite = new CocoSprite(treeThangType)
|
||||
layer.addCocoSprite(sprite)
|
||||
sprite = new Lank(treeThangType)
|
||||
layer.addLank(sprite)
|
||||
spyOn(SpriteBuilder.prototype, 'buildContainerFromStore').and.callThrough()
|
||||
for i in _.range(2)
|
||||
layer.resolutionFactor *= 1.1
|
||||
|
@ -141,8 +141,8 @@ describe 'LayerAdapter', ->
|
|||
|
||||
it 'recycles *animations* from previous sprite sheets, rather than building repeatedly from raw vector data', ->
|
||||
ogreMunchkinThangType.set('spriteType', 'singular')
|
||||
sprite = new CocoSprite(ogreMunchkinThangType)
|
||||
layer.addCocoSprite(sprite)
|
||||
sprite = new Lank(ogreMunchkinThangType)
|
||||
layer.addLank(sprite)
|
||||
numFrameses = []
|
||||
spyOn(SpriteBuilder.prototype, 'buildMovieClip').and.callThrough()
|
||||
for i in _.range(2)
|
||||
|
@ -157,8 +157,8 @@ describe 'LayerAdapter', ->
|
|||
|
||||
it '*does not* recycles *animations* from previous sprite sheets when the resolutionFactor has changed', ->
|
||||
ogreMunchkinThangType.set('spriteType', 'singular')
|
||||
sprite = new CocoSprite(ogreMunchkinThangType)
|
||||
layer.addCocoSprite(sprite)
|
||||
sprite = new Lank(ogreMunchkinThangType)
|
||||
layer.addLank(sprite)
|
||||
spyOn(SpriteBuilder.prototype, 'buildMovieClip').and.callThrough()
|
||||
for i in _.range(2)
|
||||
layer.resolutionFactor *= 1.1
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
LayerAdapter = require 'lib/surface/LayerAdapter'
|
||||
SegmentedSprite = require 'lib/surface/SegmentedSprite'
|
||||
CocoSprite = require 'lib/surface/CocoSprite'
|
||||
Lank = require 'lib/surface/Lank'
|
||||
ThangType = require 'models/ThangType'
|
||||
SpriteBuilder = require 'lib/sprites/SpriteBuilder'
|
||||
ogreMunchkinThangType = new ThangType(require 'test/app/fixtures/ogre-munchkin-m.thang.type')
|
||||
|
@ -40,8 +40,8 @@ describe 'SegmentedSprite', ->
|
|||
layer.buildAsync = false
|
||||
treeThangType.markToRevert()
|
||||
treeThangType.set('spriteType', 'segmented')
|
||||
sprite = new CocoSprite(treeThangType)
|
||||
layer.addCocoSprite(sprite)
|
||||
sprite = new Lank(treeThangType)
|
||||
layer.addLank(sprite)
|
||||
sheet = layer.renderNewSpriteSheet()
|
||||
prefix = layer.renderGroupingKey(treeThangType) + '.'
|
||||
window.segmentedSprite = segmentedSprite = new SegmentedSprite(sheet, treeThangType, prefix)
|
||||
|
@ -103,8 +103,8 @@ describe 'SegmentedSprite', ->
|
|||
actions.head = {container:'head', name:'head'}
|
||||
|
||||
colorConfig = {team: {hue: 0, saturation: 1, lightness: 0.5}}
|
||||
sprite = new CocoSprite(ogreMunchkinThangType, {colorConfig: colorConfig})
|
||||
layer.addCocoSprite(sprite)
|
||||
sprite = new Lank(ogreMunchkinThangType, {colorConfig: colorConfig})
|
||||
layer.addLank(sprite)
|
||||
sheet = layer.renderNewSpriteSheet()
|
||||
prefix = layer.renderGroupingKey(ogreMunchkinThangType, null, colorConfig) + '.'
|
||||
window.segmentedSprite = segmentedSprite = new SegmentedSprite(sheet, ogreMunchkinThangType, prefix)
|
||||
|
@ -195,8 +195,8 @@ describe 'SegmentedSprite', ->
|
|||
ogreFangriderThangType.markToRevert()
|
||||
ogreFangriderThangType.set('spriteType', 'segmented')
|
||||
colorConfig = {team: {hue: 0, saturation: 1, lightness: 0.5}}
|
||||
sprite = new CocoSprite(ogreFangriderThangType, {colorConfig: colorConfig})
|
||||
layer.addCocoSprite(sprite)
|
||||
sprite = new Lank(ogreFangriderThangType, {colorConfig: colorConfig})
|
||||
layer.addLank(sprite)
|
||||
sheet = layer.renderNewSpriteSheet()
|
||||
prefix = layer.renderGroupingKey(ogreFangriderThangType, null, colorConfig) + '.'
|
||||
window.segmentedSprite = segmentedSprite = new SegmentedSprite(sheet, ogreFangriderThangType, prefix)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
LayerAdapter = require 'lib/surface/LayerAdapter'
|
||||
SingularSprite = require 'lib/surface/SingularSprite'
|
||||
CocoSprite = require 'lib/surface/CocoSprite'
|
||||
Lank = require 'lib/surface/Lank'
|
||||
SpriteBuilder = require 'lib/sprites/SpriteBuilder'
|
||||
ThangType = require 'models/ThangType'
|
||||
ogreMunchkinThangType = new ThangType(require 'test/app/fixtures/ogre-munchkin-m.thang.type')
|
||||
|
@ -45,8 +45,8 @@ describe 'SingularSprite', ->
|
|||
layer.buildAsync = false
|
||||
treeThangType.markToRevert()
|
||||
treeThangType.set('spriteType', 'singular')
|
||||
sprite = new CocoSprite(treeThangType)
|
||||
layer.addCocoSprite(sprite)
|
||||
sprite = new Lank(treeThangType)
|
||||
layer.addLank(sprite)
|
||||
sheet = layer.renderNewSpriteSheet()
|
||||
prefix = layer.renderGroupingKey(treeThangType) + '.'
|
||||
window.singularSprite = singularSprite = new SingularSprite(sheet, treeThangType, prefix)
|
||||
|
@ -98,8 +98,8 @@ describe 'SingularSprite', ->
|
|||
actions = ogreMunchkinThangType.getActions()
|
||||
|
||||
colorConfig = {team: {hue: 0, saturation: 1, lightness: 0.5}}
|
||||
sprite = new CocoSprite(ogreMunchkinThangType, {colorConfig: colorConfig})
|
||||
layer.addCocoSprite(sprite)
|
||||
sprite = new Lank(ogreMunchkinThangType, {colorConfig: colorConfig})
|
||||
layer.addLank(sprite)
|
||||
sheet = layer.renderNewSpriteSheet()
|
||||
prefix = layer.renderGroupingKey(ogreMunchkinThangType, null, colorConfig) + '.'
|
||||
window.singularSprite = singularSprite = new SingularSprite(sheet, ogreMunchkinThangType, prefix)
|
||||
|
|
Loading…
Reference in a new issue