Re-enabled effect marks.

This commit is contained in:
Scott Erickson 2014-09-24 18:42:04 -07:00
parent 91f33e49dc
commit fb30f07f2e
6 changed files with 63 additions and 49 deletions

View file

@ -31,7 +31,6 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
thang: null
camera: null
showInvisible: false
async: true
possessed: false
flipped: false
@ -109,6 +108,7 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
@imageObject = newImageObject
@configureMouse()
@imageObject.on 'animationend', @playNextAction
@trigger 'new-image-object', @imageObject
##################################################
# QUEUEING AND PLAYING ACTIONS
@ -513,24 +513,26 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
createMarks: ->
return unless @options.camera
if @thang
allProps = []
allProps = allProps.concat (@thang.hudProperties ? [])
allProps = allProps.concat (@thang.programmableProperties ? [])
allProps = allProps.concat (@thang.moreProgrammableProperties ? [])
# TODO: Add back ranges
# allProps = []
# allProps = allProps.concat (@thang.hudProperties ? [])
# allProps = allProps.concat (@thang.programmableProperties ? [])
# allProps = allProps.concat (@thang.moreProgrammableProperties ? [])
#
# for property in allProps
# if m = property.match /.*(Range|Distance|Radius)$/
# if @thang[m[0]]? and @thang[m[0]] < 9001
# @ranges.push
# name: m[0]
# radius: @thang[m[0]]
#
# @ranges = _.sortBy @ranges, 'radius'
# @ranges.reverse()
#
# @addMark range.name for range in @ranges
for property in allProps
if m = property.match /.*(Range|Distance|Radius)$/
if @thang[m[0]]? and @thang[m[0]] < 9001
@ranges.push
name: m[0]
radius: @thang[m[0]]
@ranges = _.sortBy @ranges, 'radius'
@ranges.reverse()
@addMark range.name for range in @ranges
@addMark('bounds').toggle true if @thang?.drawsBounds
# TODO: add back bounds
# @addMark('bounds').toggle true if @thang?.drawsBounds
@addMark('shadow').toggle true unless @thangType.get('shadow') is 0
updateMarks: ->
@ -550,30 +552,29 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
@updateEffectMarks() if @thang?.effectNames?.length or @previousEffectNames?.length
updateEffectMarks: ->
# TODO: get effect marks working again
# return if _.isEqual @thang.effectNames, @previousEffectNames
# return if @stopped
# for effect in @thang.effectNames
# mark = @addMark effect, @options.floatingLayer, effect
# mark.statusEffect = true
# mark.toggle 'on'
# mark.show()
#
# if @previousEffectNames
# for effect in @previousEffectNames
# continue if effect in @thang.effectNames
# mark = @marks[effect]
# mark.toggle false
#
# if @thang.effectNames.length > 1 and not @effectInterval
# @rotateEffect()
# @effectInterval = setInterval @rotateEffect, 1500
#
# else if @effectInterval and @thang.effectNames.length <= 1
# clearInterval @effectInterval
# @effectInterval = null
#
# @previousEffectNames = @thang.effectNames
return if _.isEqual @thang.effectNames, @previousEffectNames
return if @stopped
for effect in @thang.effectNames
mark = @addMark effect, @options.floatingLayer, effect
mark.statusEffect = true
mark.toggle 'on'
mark.show()
if @previousEffectNames
for effect in @previousEffectNames
continue if effect in @thang.effectNames
mark = @marks[effect]
mark.toggle false
if @thang.effectNames.length > 1 and not @effectInterval
@rotateEffect()
@effectInterval = setInterval @rotateEffect, 1500
else if @effectInterval and @thang.effectNames.length <= 1
clearInterval @effectInterval
@effectInterval = null
@previousEffectNames = @thang.effectNames
rotateEffect: =>
effects = (m.name for m in _.values(@marks) when m.on and m.statusEffect and m.mark)

View file

@ -57,6 +57,7 @@ module.exports = LayerAdapter = class LayerAdapter extends CocoClass
super()
options ?= {}
@name = options.name ? 'Unnamed'
@defaultSpriteType = if @name is 'Default' then 'segmented' else 'singular'
@customGraphics = {}
@layerPriority = options.layerPriority ? 0
@transformStyle = options.transform ? LayerAdapter.TRANSFORM_CHILD
@ -248,7 +249,7 @@ module.exports = LayerAdapter = class LayerAdapter extends CocoClass
actionNames = (bundle.actionName for bundle in bundleGrouping)
args = [thangType, colorConfig, actionNames, builder]
if thangType.get('raw')
if thangType.get('spriteType') is 'segmented'
if (thangType.get('spriteType') or @defaultSpriteType) is 'segmented'
@renderSegmentedThangType(args...)
else
@renderSingularThangType(args...)

View file

@ -32,6 +32,8 @@ module.exports = class Mark extends CocoClass
onLayerMadeSpriteSheet: ->
return unless @mark
return @update() if @markSprite
# need to update the mark display object manually...
@mark = null
@build()
@layer.addChild @mark
@ -43,8 +45,14 @@ module.exports = class Mark extends CocoClass
@on = to
delete @toggleTo
if @on
if @markSprite
@layer.addCocoSprite(@markSprite)
else
@layer.addChild @mark
@layer.updateLayerOrder()
else
if @markSprite
@layer.removeCocoSprite(@markSprite)
else
@layer.removeChild @mark
if @highlightTween
@ -221,10 +229,11 @@ module.exports = class Mark extends CocoClass
return @listenToOnce(@thangType, 'sync', @onLoadedThangType) if not @thangType.loaded
CocoSprite = require './CocoSprite'
# don't bother with making these render async for now, but maybe later for fun and more complexity of code
markSprite = new CocoSprite @thangType, {async: false}
markSprite = new CocoSprite @thangType
markSprite.queueAction 'idle'
@mark = markSprite.imageObject
@markSprite = markSprite
@listenTo @markSprite, 'new-image-object', (@mark) ->
loadThangType: ->
name = @thangType

View file

@ -2,7 +2,7 @@ SpriteBuilder = require 'lib/sprites/SpriteBuilder'
floors = ['Dungeon Floor', 'Indoor Floor', 'Grass', 'Grass01', 'Grass02', 'Grass03', 'Grass04', 'Grass05', 'Goal Trigger', 'Obstacle']
module.exports = class WebGLSprite extends createjs.Sprite
module.exports = class SingularSprite extends createjs.Sprite
childMovieClips: null
constructor: (@spriteSheet, @thangType, @spriteSheetPrefix, @resolutionFactor=SPRITE_RESOLUTION_FACTOR) ->

File diff suppressed because one or more lines are too long

View file

@ -6,6 +6,7 @@ ThangType = require 'models/ThangType'
treeData = require 'test/app/fixtures/tree1.thang.type'
munchkinData = require 'test/app/fixtures/ogre-munchkin-m.thang.type'
fangriderData = require 'test/app/fixtures/ogre-fangrider.thang.type'
curseData = require 'test/app/fixtures/curse.thang.type'
describe 'SpriteBoss', ->
spriteBoss = null
@ -82,7 +83,7 @@ describe 'SpriteBoss', ->
{id: 'Ogre N', spriteName: 'Segmented Munchkin', exists: true, shape: 'disc', depth: 2, pos: {x:0, y:8, z: 1}, action: 'move', health: 10, maxHealth: 10, rotation: -Math.PI/2, acts: true, scaleFactorX: 1.5, hudProperties: ['health'] }
{id: 'Ogre W', spriteName: 'Segmented Munchkin', exists: true, shape: 'disc', depth: 2, pos: {x:-8, y:0, z: 1}, action: 'move', health: 8, maxHealth: 10, rotation: 0, acts: true, scaleFactorY: 1.5, hudProperties: ['health'] }
{id: 'Ogre E', spriteName: 'Segmented Munchkin', exists: true, shape: 'disc', depth: 2, pos: {x:8, y:0, z: 1}, action: 'move', health: 5, maxHealth: 10, rotation: Math.PI, acts: true, alpha: 0.5, hudProperties: ['health'] }
{id: 'Ogre S', spriteName: 'Segmented Munchkin', exists: true, shape: 'disc', depth: 2, pos: {x:0, y:-8, z: 1}, action: 'move', health: 2, maxHealth: 10, rotation: Math.PI/2, acts: true, hudProperties: ['health'] }
{id: 'Ogre S', spriteName: 'Segmented Munchkin', exists: true, shape: 'disc', depth: 2, pos: {x:0, y:-8, z: 1}, action: 'move', health: 2, maxHealth: 10, rotation: Math.PI/2, acts: true, hudProperties: ['health'], effectNames: ['curse'] }
# Set ogres side by side with different render strategies
{id: 'Singular Ogre', spriteName: 'Singular Munchkin', exists: true, shape: 'disc', depth: 2, pos: {x:-10, y:-8, z: 1}, action: 'move', health: 10, maxHealth: 10, rotation: -Math.PI/2, acts: true, alpha: 0.5 }
@ -101,6 +102,7 @@ describe 'SpriteBoss', ->
_.find(world.thangs, {id: 'Disappearing Tree'}).exists = false
world.thangMap[thang.id] = thang for thang in world.thangs
spriteBoss.update(true)
jasmine.Ajax.requests.sendResponses({'/db/thang.type/curse': curseData})
# Test that the unrendered, animated sprites aren't showing anything
midRenderExpectations.push([spriteBoss.sprites['Segmented Ogre'].imageObject.children.length,10,'animated segmented action'])