Skip to content

Commit fc89fdc

Browse files
committed
stateCycle() now takes any amount of arguments
1 parent 09d17f5 commit fc89fdc

File tree

4 files changed

+53
-24
lines changed

4 files changed

+53
-24
lines changed

debug/app.coffee

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,22 @@ new Model
2828
rotationZ: 180
2929
z: 0
3030
rotationY: 0
31+
options:
32+
curve: 'easeInOutQuart'
3133
testX:
3234
x: 0
3335
rotationZ: 0
3436
z: 300
3537
rotationY: 84
38+
options:
39+
curve: 'easeInOutQuart'
40+
textS:
41+
x: 62
42+
rotationZ: 92
43+
z: -100
44+
rotationY: 230
45+
options:
46+
curve: 'easeInOutQuart'
3647

3748
scene.onClick ->
38-
model.stateCycle()
49+
model.stateCycle('test', 'testX', 'textS')

form/Light.coffee

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,19 @@ class exports.Light extends BaseClass
107107

108108
stateCycle: (stateA, stateB) ->
109109
if arguments.length
110-
# Check if stateA or stateB already is the current state on model
111-
if @states.current == @states[stateA] || @states.current == @states[stateB]
112-
if @states.current == @states[stateA] then @animate stateB
113-
else if @states.current == @states[stateB] then @animate stateA
114-
else
115-
# If neither are current, animate to stateA
116-
@animate stateA
110+
111+
for s, i in arguments
112+
if _.isEqual @states[s], @states.current
113+
if i == (arguments.length - 1)
114+
nextState = 0
115+
else
116+
nextState = i + 1
117+
118+
if nextState == undefined
119+
nextState = 0
120+
121+
@animate arguments[nextState]
122+
117123
else
118124
states = Object.keys(@states)
119125
states.splice(1, 1)

form/Model.coffee

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -206,15 +206,21 @@ class exports.Model extends BaseClass
206206
Object.keys(@states.current).map (pk) =>
207207
@[pk] = @states.current[pk]
208208

209-
stateCycle: (stateA, stateB) ->
209+
stateCycle: () ->
210210
if arguments.length
211-
# Check if stateA or stateB already is the current state on model
212-
if @states.current == @states[stateA] || @states.current == @states[stateB]
213-
if @states.current == @states[stateA] then @animate stateB
214-
else if @states.current == @states[stateB] then @animate stateA
215-
else
216-
# If neither are current, animate to stateA
217-
@animate stateA
211+
212+
for s, i in arguments
213+
if _.isEqual @states[s], @states.current
214+
if i == (arguments.length - 1)
215+
nextState = 0
216+
else
217+
nextState = i + 1
218+
219+
if nextState == undefined
220+
nextState = 0
221+
222+
@animate arguments[nextState]
223+
218224
else
219225
states = Object.keys(@states)
220226
states.splice(1, 1)

form/_Camera.coffee

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,21 @@ class exports.Camera extends BaseClass
9999
Object.keys(@states.current).map (pk) =>
100100
@[pk] = @states.current[pk]
101101

102-
stateCycle: (stateA, stateB) ->
102+
stateCycle: () ->
103103
if arguments.length
104-
# Check if stateA or stateB already is the current state on model
105-
if @states.current == @states[stateA] || @states.current == @states[stateB]
106-
if @states.current == @states[stateA] then @animate stateB
107-
else if @states.current == @states[stateB] then @animate stateA
108-
else
109-
# If neither are current, animate to stateA
110-
@animate stateA
104+
105+
for s, i in arguments
106+
if _.isEqual @states[s], @states.current
107+
if i == (arguments.length - 1)
108+
nextState = 0
109+
else
110+
nextState = i + 1
111+
112+
if nextState == undefined
113+
nextState = 0
114+
115+
@animate arguments[nextState]
116+
111117
else
112118
states = Object.keys(@states)
113119
states.splice(1, 1)

0 commit comments

Comments
 (0)