-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Parallel animation added #25
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
' @import /components/animator/AnimatorFactory.brs | ||
' @import /components/getProperty.brs | ||
' @import /components/rokuComponents/ParallelAnimation.brs | ||
|
||
' @class | ||
function ParallelAnimationFactory() as Object | ||
prototype = {} | ||
|
||
' Creates ParallelAnimation component with one or more Animations. | ||
' @param {String} name | ||
' @param {Object} [options={}] | ||
' @param {Float} options.delay | ||
' @param {Boolean} options.repeat | ||
' @param {Object.<string, AnimatorFactory~Options>} options.animations | ||
' @param {Node} element | ||
' @returns {Object} - ParallelAnimation component | ||
prototype.createAnimation = function(name as String, options = {} as Object) as Object | ||
parallelAnimationNode = ParallelAnimation() | ||
parallelAnimationNode.setFields({ | ||
id: name, | ||
delay: getProperty(options, "delay", 0.001), | ||
repeat: getProperty(options, "repeat", false), | ||
}) | ||
|
||
factory = AnimatorFactory() | ||
for each animationOption in options.animations.items() | ||
parallelAnimationNode.appendChild(factory.createAnimation(animationOption.key, animationOption.value)) | ||
end for | ||
|
||
return parallelAnimationNode | ||
end function | ||
|
||
return prototype | ||
end function |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
' @import /components/KopytkoTestSuite.brs from @dazn/kopytko-unit-testing-framework | ||
' @import /components/rokuComponents/Animation.brs | ||
' @mock /components/animator/AnimatorFactory.brs | ||
function TestSuite__ParallelAnimationFactory() as Object | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A unit test testing multiple elements is missing |
||
ts = KopytkoTestSuite() | ||
ts.name = "ParallelAnimatorFactory" | ||
|
||
ts.setBeforeEach(sub (ts as Object) | ||
m.__parallelAnimationFactory = ParallelAnimationFactory() | ||
|
||
m.__mocks.animatorFactory = { | ||
createAnimation: { | ||
calls: [], | ||
returnValue: Animation(), | ||
}, | ||
} | ||
end sub) | ||
|
||
ts.addTest("it creates animation object with given config", function (ts as Object) as String | ||
' Given | ||
options = { | ||
delay: Csng(0.2), | ||
repeat: true, | ||
animations: { | ||
elementOne: { | ||
delay: Csng(0.2), | ||
duration: Csng(20), | ||
easeFunction: "linear", | ||
easeInPercent: 0.1, | ||
easeOutPercent: 0.2, | ||
optional: false, | ||
repeat: false, | ||
Comment on lines
+19
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand, aren't |
||
}, | ||
}, | ||
} | ||
|
||
' When | ||
_animation = m.__parallelAnimationFactory.createAnimation("testElement", options) | ||
|
||
' Then | ||
expectedConfig = { | ||
id: "testElement", | ||
delay: options.delay, | ||
repeat: options.repeat, | ||
type: "ParallelAnimation", | ||
} | ||
constructedConfig = { | ||
id: _animation.id, | ||
delay: Csng(_animation.delay), | ||
repeat: _animation.repeat, | ||
type: _animation.subType(), | ||
} | ||
|
||
return ts.assertEqual(expectedConfig, constructedConfig, "Animation config is wrong") | ||
end function) | ||
|
||
ts.addTest("it creates child animation object", function (ts as Object) as String | ||
' Given | ||
options = { | ||
delay: Csng(0.2), | ||
repeat: true, | ||
animations: { | ||
elementOne: { | ||
delay: Csng(0.2), | ||
duration: Csng(20), | ||
easeFunction: "linear", | ||
easeInPercent: 0.1, | ||
easeOutPercent: 0.2, | ||
optional: false, | ||
repeat: false, | ||
fields: [ | ||
{ field: "opacity", type: "float" } | ||
{ field: "translation", type: "vector2d" } | ||
], | ||
}, | ||
}, | ||
} | ||
|
||
' When | ||
_animation = m.__parallelAnimationFactory.createAnimation("testElement", options) | ||
|
||
' Then | ||
expectedConfig = { | ||
name: "elementone", | ||
options: { | ||
delay: options.animations.elementOne.delay, | ||
duration: options.animations.elementOne.duration, | ||
easeFunction: options.animations.elementOne.easeFunction, | ||
easeInPercent: options.animations.elementOne.easeInPercent, | ||
easeOutPercent: options.animations.elementOne.easeOutPercent, | ||
optional: options.animations.elementOne.optional, | ||
repeat: options.animations.elementOne.repeat, | ||
fields: options.animations.elementOne.fields, | ||
}, | ||
} | ||
|
||
return ts.assertMethodWasCalled("AnimatorFactory.createAnimation", expectedConfig) | ||
end function) | ||
|
||
ts.addTest("it creates 2 child animation objects", function (ts as Object) as String | ||
' Given | ||
options = { | ||
delay: Csng(0.2), | ||
repeat: true, | ||
animations: { | ||
elementOne: { | ||
delay: Csng(0.2), | ||
duration: Csng(20), | ||
easeFunction: "linear", | ||
easeInPercent: 0.1, | ||
easeOutPercent: 0.2, | ||
optional: false, | ||
repeat: false, | ||
fields: [ | ||
{ field: "opacity", type: "float" } | ||
{ field: "translation", type: "vector2d" } | ||
], | ||
}, | ||
elementTwo: { | ||
delay: Csng(122), | ||
duration: Csng(20), | ||
easeFunction: "outExpo", | ||
easeInPercent: 0.1, | ||
easeOutPercent: 0.2, | ||
optional: false, | ||
repeat: false, | ||
fields: [ | ||
{ field: "color", type: "color" } | ||
], | ||
}, | ||
}, | ||
} | ||
|
||
' When | ||
m.__parallelAnimationFactory.createAnimation("testElement", options) | ||
|
||
' Then | ||
return ts.assertEqual(m.__mocks.animatorFactory.createAnimation.calls.count(), 2) | ||
end function) | ||
tomek-r marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return ts | ||
end function |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
' Wrapper function for creating native ParallelAnimation component. | ||
' @class | ||
function ParallelAnimation() as Object | ||
return CreateObject("roSGNode", "ParallelAnimation") | ||
end function |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AnimatorFactory.createAnimation
has such an interface:function (name as String, options = {} as Object, element = Invalid as Object)
So if you implement my suggestion (https://github.com/getndazn/kopytko-utils/pull/25/files#r1378563587) you could iterate through options.animations objects and code would look clearer:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the definition point of view clearer is:
vs
Less code and more compact imho.