Skip to content
Permalink
Browse files

Fix stateCycle() and states.next() when not providing options

  • Loading branch information
nvh committed Oct 5, 2016
1 parent 2a7ad6c commit 1f18a6cb612e5e9b90e36fef0615f0c411348adb
@@ -928,11 +928,12 @@ class exports.Layer extends BaseClass

return animation

stateCycle: (args..., options={}) ->
states = []
states = _.flatten(args) if args.length
@animate(@states.machine.next(states), options)
stateCycle: (args...) ->
states = _.flatten(args)
if _.isObject(_.last(states))
options = states.pop()

@animate(@states.machine.next(states), options)
stateSwitch: (stateName, options={}) ->
return @animate(stateName, options) if options.animate is true
return @animate(stateName, _.defaults({}, options, {instant:true}))
@@ -54,10 +54,10 @@ class LayerStates
stateProperties = {}

for k, v of properties

if k in LayerStatesIgnoredKeys
continue

if Color.isValidColorProperty(k, v)
stateProperties[k] = new Color(v)
continue
@@ -124,8 +124,9 @@ class LayerStates
keys = _.union(keys, _.keys(state))
return keys

next: (options) ->
next: (options...) ->
deprecatedWarning("next", "layer.stateCycle()")
options = _.flatten(options)
@machine.layer.stateCycle(options)

last: (options) ->
@@ -80,6 +80,32 @@ describe "LayerStates Backwards compatibility", ->
done()
layer.states.next()

it "should still support layer.states.next with string arguments", (done) ->
layer = new Layer
layer.states =
stateA: x: 200
stateB: scale: 0.5
layer.once Events.StateSwitchEnd, ->
layer.states.current.name.should.equal "stateB"
layer.once Events.StateSwitchEnd, ->
layer.states.current.name.should.equal "stateA"
done()
layer.states.next("stateB", "stateA")
layer.states.next("stateB", "stateA")

it "should still support layer.states.next with list arguments", (done) ->
layer = new Layer
layer.states =
stateA: x: 200
stateB: scale: 0.5
layer.once Events.StateSwitchEnd, ->
layer.states.current.name.should.equal "stateB"
layer.once Events.StateSwitchEnd, ->
layer.states.current.name.should.equal "stateA"
done()
layer.states.next ["stateB", "stateA"]
layer.states.next ["stateB", "stateA"]

it "should still support layer.states.last", (done) ->
layer = new Layer
layer.states =
@@ -88,7 +88,7 @@ describe "LayerStates", ->
describe "Adding", ->

describe "when setting multiple states", ->

it "should override existing states", ->
layer = new Layer
layer.states.test = x: 100
@@ -514,6 +514,33 @@ describe "LayerStates", ->
layer.states.current.name.should.equal "testA"
done()

it "should cycle list without options", (done) ->
layer = new Layer
layer.animationOptions.time = 0.1
layer.states.testA = {x: 200}
layer.states.testB = {x: 400}
layer.once Events.StateSwitchEnd, ->
layer.states.current.name.should.equal "testB"
layer.once Events.StateSwitchEnd, ->
layer.states.current.name.should.equal "testA"
done()
layer.stateCycle ["testB", "testA"]
layer.stateCycle ["testB", "testA"]

it "should cycle multiple arguments without options", (done) ->
layer = new Layer
layer.animationOptions.time = 0.1
layer.states.testA = {x: 200}
layer.states.testB = {x: 400}
layer.once Events.StateSwitchEnd, ->
layer.states.current.name.should.equal "testB"
layer.once Events.StateSwitchEnd, ->
layer.states.current.name.should.equal "testA"
done()
layer.stateCycle "testB", "testA"
layer.stateCycle "testB", "testA"


it "should cycle two out of three in arguments", (done) ->
layer = new Layer
layer.animationOptions.time = 0.1

0 comments on commit 1f18a6c

Please sign in to comment.
You can’t perform that action at this time.