From fc89fdcf5587470f33e4130a8159e66edecb219b Mon Sep 17 00:00:00 2001 From: Emil Widlund Date: Wed, 9 May 2018 08:09:56 +0200 Subject: [PATCH] stateCycle() now takes any amount of arguments --- debug/app.coffee | 13 ++++++++++++- form/Light.coffee | 20 +++++++++++++------- form/Model.coffee | 22 ++++++++++++++-------- form/_Camera.coffee | 22 ++++++++++++++-------- 4 files changed, 53 insertions(+), 24 deletions(-) diff --git a/debug/app.coffee b/debug/app.coffee index d73c018..7dcc6d4 100644 --- a/debug/app.coffee +++ b/debug/app.coffee @@ -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() \ No newline at end of file + model.stateCycle('test', 'testX', 'textS') \ No newline at end of file diff --git a/form/Light.coffee b/form/Light.coffee index 7971086..6ae922d 100644 --- a/form/Light.coffee +++ b/form/Light.coffee @@ -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) diff --git a/form/Model.coffee b/form/Model.coffee index 9f979f1..398698e 100644 --- a/form/Model.coffee +++ b/form/Model.coffee @@ -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) diff --git a/form/_Camera.coffee b/form/_Camera.coffee index 3ae5166..1de0445 100644 --- a/form/_Camera.coffee +++ b/form/_Camera.coffee @@ -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)