Skip to content

Commit

Permalink
feat: added support to color field interpolator to AnimatorFactory (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
RadoslawZambrowski committed Dec 8, 2023
1 parent 1585bb4 commit 85f4382
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/components/animator/AnimatorFactory.brs
@@ -1,5 +1,6 @@
' @import /components/getProperty.brs
' @import /components/rokuComponents/Animation.brs
' @import /components/rokuComponents/ColorFieldInterpolator.brs
' @import /components/rokuComponents/FloatFieldInterpolator.brs
' @import /components/rokuComponents/Vector2DFieldInterpolator.brs

Expand Down Expand Up @@ -65,6 +66,8 @@ function AnimatorFactory() as Object
interpolator = FloatFieldInterpolator()
else if (fieldOptions.type = "vector2d")
interpolator = Vector2DFieldInterpolator()
else if (fieldOptions.type = "color")
interpolator = ColorFieldInterpolator()
else
print "Field ";fieldOptions.field;" cannot be animated. Unsupported type of a field."

Expand Down
12 changes: 10 additions & 2 deletions src/components/animator/_tests/AnimatorFactory.test.brs
@@ -1,5 +1,6 @@
' @import /components/KopytkoTestSuite.brs from @dazn/kopytko-unit-testing-framework
' @mock /components/rokuComponents/Animation.brs
' @mock /components/rokuComponents/ColorFieldInterpolator.brs
' @mock /components/rokuComponents/FloatFieldInterpolator.brs
' @mock /components/rokuComponents/Vector2DFieldInterpolator.brs
function TestSuite__AnimatorFactory() as Object
Expand Down Expand Up @@ -85,6 +86,7 @@ function TestSuite__AnimatorFactory() as Object
end function)

ts.addParameterizedTests([
{ field: "color", key: [0.0, 1.0], keyValue: ["#000000", "#FFFFFF"], type: "color" },
{ field: "opacity", key: [0.0, 1.0], keyValue: [0.0, 1.0], type: "float" },
{ field: "translation", key: [0.0, 1.0], keyValue: [[0.0, 200.0], [400.0, 1200.0]], type: "vector2d" },
], "it appends supported ${type} interpolator", function (ts as Object, params as Object) as String
Expand Down Expand Up @@ -116,13 +118,19 @@ function TestSuite__AnimatorFactory() as Object
return ts.assertEqual(constructedInterpolatorFields, expectedInterpolatorFields, "The interpolator has no expected config")
end function)

ts.addTest("it creates two interpolators", function (ts as Object) as String
ts.addTest("it creates three interpolators", function (ts as Object) as String
' Given
options = {
delay: Csng(0.2),
duration: Csng(20),
easeFunction: "linear",
fields: [
{
field: "color",
key: [0.0, 1.0],
keyValue: ["#000000", "#FFFFFF"],
type: "color",
},
{
field: "opacity",
key: [0.0, 1.0],
Expand All @@ -142,7 +150,7 @@ function TestSuite__AnimatorFactory() as Object

' Then

return ts.assertEqual(2, _animation.getChildCount(), "There is no two interpolators")
return ts.assertEqual(3, _animation.getChildCount(), "There is no three interpolators")
end function)

return ts
Expand Down
5 changes: 5 additions & 0 deletions src/components/rokuComponents/ColorFieldInterpolator.brs
@@ -0,0 +1,5 @@
' Wrapper function for creating native ColorFieldInterpolator component.
' @class
function ColorFieldInterpolator() as Object
return CreateObject("roSGNode", "ColorFieldInterpolator")
end function
@@ -0,0 +1,17 @@
' @import /components/_mocks/Mock.brs from @dazn/kopytko-unit-testing-framework

' @returns {Mock}
function ColorFieldInterpolator() as Object
return Mock({
testComponent: m,
name: "ColorFieldInterpolator",
fields: {
fieldToInterp: "",
key: [],
keyValue: [],
fraction: 0.0,
reverse: false,
__subtype: "ColorFieldInterpolator",
},
})
end function

0 comments on commit 85f4382

Please sign in to comment.