Skip to content

Commit

Permalink
stateCycle() now takes any amount of arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
emilwidlund committed May 9, 2018
1 parent 09d17f5 commit fc89fdc
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 24 deletions.
13 changes: 12 additions & 1 deletion debug/app.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,22 @@ new Model
rotationZ: 180
z: 0
rotationY: 0
options:
curve: 'easeInOutQuart'
testX:
x: 0
rotationZ: 0
z: 300
rotationY: 84
options:
curve: 'easeInOutQuart'
textS:
x: 62
rotationZ: 92
z: -100
rotationY: 230
options:
curve: 'easeInOutQuart'

scene.onClick ->
model.stateCycle()
model.stateCycle('test', 'testX', 'textS')
20 changes: 13 additions & 7 deletions form/Light.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,19 @@ class exports.Light extends BaseClass

stateCycle: (stateA, stateB) ->
if arguments.length
# Check if stateA or stateB already is the current state on model
if @states.current == @states[stateA] || @states.current == @states[stateB]
if @states.current == @states[stateA] then @animate stateB
else if @states.current == @states[stateB] then @animate stateA
else
# If neither are current, animate to stateA
@animate stateA

for s, i in arguments
if _.isEqual @states[s], @states.current
if i == (arguments.length - 1)
nextState = 0
else
nextState = i + 1

if nextState == undefined
nextState = 0

@animate arguments[nextState]

else
states = Object.keys(@states)
states.splice(1, 1)
Expand Down
22 changes: 14 additions & 8 deletions form/Model.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -206,15 +206,21 @@ class exports.Model extends BaseClass
Object.keys(@states.current).map (pk) =>
@[pk] = @states.current[pk]

stateCycle: (stateA, stateB) ->
stateCycle: () ->
if arguments.length
# Check if stateA or stateB already is the current state on model
if @states.current == @states[stateA] || @states.current == @states[stateB]
if @states.current == @states[stateA] then @animate stateB
else if @states.current == @states[stateB] then @animate stateA
else
# If neither are current, animate to stateA
@animate stateA

for s, i in arguments
if _.isEqual @states[s], @states.current
if i == (arguments.length - 1)
nextState = 0
else
nextState = i + 1

if nextState == undefined
nextState = 0

@animate arguments[nextState]

else
states = Object.keys(@states)
states.splice(1, 1)
Expand Down
22 changes: 14 additions & 8 deletions form/_Camera.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,21 @@ class exports.Camera extends BaseClass
Object.keys(@states.current).map (pk) =>
@[pk] = @states.current[pk]

stateCycle: (stateA, stateB) ->
stateCycle: () ->
if arguments.length
# Check if stateA or stateB already is the current state on model
if @states.current == @states[stateA] || @states.current == @states[stateB]
if @states.current == @states[stateA] then @animate stateB
else if @states.current == @states[stateB] then @animate stateA
else
# If neither are current, animate to stateA
@animate stateA

for s, i in arguments
if _.isEqual @states[s], @states.current
if i == (arguments.length - 1)
nextState = 0
else
nextState = i + 1

if nextState == undefined
nextState = 0

@animate arguments[nextState]

else
states = Object.keys(@states)
states.splice(1, 1)
Expand Down

0 comments on commit fc89fdc

Please sign in to comment.