55 * found in the LICENSE file.
66 */
77
8- #include " SkottieAnimator.h"
9-
108#include " SkCubicMap.h"
119#include " SkottieJson.h"
10+ #include " SkottiePriv.h"
1211#include " SkottieValue.h"
12+ #include " SkSGScene.h"
1313#include " SkString.h"
1414#include " SkTArray.h"
1515
@@ -68,9 +68,9 @@ class KeyframeAnimatorBase : public sksg::Animator {
6868 : SkTPin (fCubicMaps [rec.cmidx ].computeYFromX (lt), 0 .0f , 1 .0f );
6969 }
7070
71- virtual int parseValue (const skjson::Value&) = 0;
71+ virtual int parseValue (const skjson::Value&, const AnimationBuilder* abuilder ) = 0;
7272
73- void parseKeyFrames (const skjson::ArrayValue& jframes) {
73+ void parseKeyFrames (const skjson::ArrayValue& jframes, const AnimationBuilder* abuilder ) {
7474 for (const skjson::ObjectValue* jframe : jframes) {
7575 if (!jframe) continue ;
7676
@@ -88,7 +88,7 @@ class KeyframeAnimatorBase : public sksg::Animator {
8888 fRecs .back ().t1 = t0;
8989 }
9090
91- const auto vidx0 = this ->parseValue ((*jframe)[" s" ]);
91+ const auto vidx0 = this ->parseValue ((*jframe)[" s" ], abuilder );
9292 if (vidx0 < 0 )
9393 continue ;
9494
@@ -97,7 +97,7 @@ class KeyframeAnimatorBase : public sksg::Animator {
9797
9898 if (!ParseDefault<bool >((*jframe)[" h" ], false )) {
9999 // Regular frame, requires an end value.
100- vidx1 = this ->parseValue ((*jframe)[" e" ]);
100+ vidx1 = this ->parseValue ((*jframe)[" e" ], abuilder );
101101 if (vidx1 < 0 )
102102 continue ;
103103
@@ -176,10 +176,12 @@ template <typename T>
176176class KeyframeAnimator final : public KeyframeAnimatorBase {
177177public:
178178 static std::unique_ptr<KeyframeAnimator> Make (const skjson::ArrayValue* jv,
179+ const AnimationBuilder* abuilder,
179180 std::function<void (const T&)>&& apply) {
180181 if (!jv) return nullptr ;
181182
182- std::unique_ptr<KeyframeAnimator> animator (new KeyframeAnimator (*jv, std::move (apply)));
183+ std::unique_ptr<KeyframeAnimator> animator (
184+ new KeyframeAnimator (*jv, abuilder, std::move (apply)));
183185 if (!animator->count ())
184186 return nullptr ;
185187
@@ -193,14 +195,16 @@ class KeyframeAnimator final : public KeyframeAnimatorBase {
193195
194196private:
195197 KeyframeAnimator (const skjson::ArrayValue& jframes,
198+ const AnimationBuilder* abuilder,
196199 std::function<void (const T&)>&& apply)
197200 : fApplyFunc (std::move(apply)) {
198- this ->parseKeyFrames (jframes);
201+ this ->parseKeyFrames (jframes, abuilder );
199202 }
200203
201- int parseValue (const skjson::Value& jv) override {
204+ int parseValue (const skjson::Value& jv, const AnimationBuilder* abuilder ) override {
202205 T val;
203- if (!Parse<T>(jv, &val) || (!fVs .empty () && !ValueTraits<T>::CanLerp (val, fVs .back ()))) {
206+ if (!ValueTraits<T>::FromJSON (jv, abuilder, &val) ||
207+ (!fVs .empty () && !ValueTraits<T>::CanLerp (val, fVs .back ()))) {
204208 return -1 ;
205209 }
206210
@@ -241,7 +245,8 @@ class KeyframeAnimator final : public KeyframeAnimatorBase {
241245
242246template <typename T>
243247static inline bool BindPropertyImpl (const skjson::ObjectValue* jprop,
244- sksg::AnimatorList* animators,
248+ const AnimationBuilder* abuilder,
249+ AnimatorScope* ascope,
245250 std::function<void (const T&)>&& apply,
246251 const T* noop = nullptr) {
247252 if (!jprop) return false ;
@@ -257,7 +262,7 @@ static inline bool BindPropertyImpl(const skjson::ObjectValue* jprop,
257262 // For those, we attempt to parse both ways.
258263 if (!ParseDefault<bool >(jpropA, false )) {
259264 T val;
260- if (Parse <T>(jpropK, &val)) {
265+ if (ValueTraits <T>:: FromJSON (jpropK, abuilder , &val)) {
261266 // Static property.
262267 if (noop && val == *noop)
263268 return false ;
@@ -272,20 +277,21 @@ static inline bool BindPropertyImpl(const skjson::ObjectValue* jprop,
272277 }
273278
274279 // Keyframe property.
275- auto animator = KeyframeAnimator<T>::Make (jpropK, std::move (apply));
280+ auto animator = KeyframeAnimator<T>::Make (jpropK, abuilder, std::move (apply));
276281
277282 if (!animator) {
278283 return LogFail (*jprop, " Could not parse keyframed property" );
279284 }
280285
281- animators ->push_back (std::move (animator));
286+ ascope ->push_back (std::move (animator));
282287
283288 return true ;
284289}
285290
286291class SplitPointAnimator final : public sksg::Animator {
287292public:
288293 static std::unique_ptr<SplitPointAnimator> Make (const skjson::ObjectValue* jprop,
294+ const AnimationBuilder* abuilder,
289295 std::function<void (const VectorValue&)>&& apply,
290296 const VectorValue*) {
291297 if (!jprop) return nullptr ;
@@ -297,9 +303,9 @@ class SplitPointAnimator final : public sksg::Animator {
297303 // the object itself, so the scope is bound to the life time of the object.
298304 auto * split_animator_ptr = split_animator.get ();
299305
300- if (!BindPropertyImpl<ScalarValue>((*jprop)[" x" ], &split_animator->fAnimators ,
306+ if (!BindPropertyImpl<ScalarValue>((*jprop)[" x" ], abuilder, &split_animator->fAnimators ,
301307 [split_animator_ptr](const ScalarValue& x) { split_animator_ptr->setX (x); }) ||
302- !BindPropertyImpl<ScalarValue>((*jprop)[" y" ], &split_animator->fAnimators ,
308+ !BindPropertyImpl<ScalarValue>((*jprop)[" y" ], abuilder, &split_animator->fAnimators ,
303309 [split_animator_ptr](const ScalarValue& y) { split_animator_ptr->setY (y); })) {
304310 LogFail (*jprop, " Could not parse split property" );
305311 return nullptr ;
@@ -340,11 +346,12 @@ class SplitPointAnimator final : public sksg::Animator {
340346};
341347
342348bool BindSplitPositionProperty (const skjson::Value& jv,
343- sksg::AnimatorList* animators,
349+ const AnimationBuilder* abuilder,
350+ AnimatorScope* ascope,
344351 std::function<void (const VectorValue&)>&& apply,
345352 const VectorValue* noop) {
346- if (auto split_animator = SplitPointAnimator::Make (jv, std::move (apply), noop)) {
347- animators ->push_back (std::unique_ptr<sksg::Animator>(split_animator.release ()));
353+ if (auto split_animator = SplitPointAnimator::Make (jv, abuilder, std::move (apply), noop)) {
354+ ascope ->push_back (std::unique_ptr<sksg::Animator>(split_animator.release ()));
348355 return true ;
349356 }
350357
@@ -354,32 +361,32 @@ bool BindSplitPositionProperty(const skjson::Value& jv,
354361} // namespace
355362
356363template <>
357- bool BindProperty (const skjson::Value& jv,
364+ bool AnimationBuilder::bindProperty (const skjson::Value& jv,
358365 AnimatorScope* ascope,
359366 std::function<void (const ScalarValue&)>&& apply,
360- const ScalarValue* noop) {
361- return BindPropertyImpl (jv, ascope, std::move (apply), noop);
367+ const ScalarValue* noop) const {
368+ return BindPropertyImpl (jv, this , ascope, std::move (apply), noop);
362369}
363370
364371template <>
365- bool BindProperty (const skjson::Value& jv,
372+ bool AnimationBuilder::bindProperty (const skjson::Value& jv,
366373 AnimatorScope* ascope,
367374 std::function<void (const VectorValue&)>&& apply,
368- const VectorValue* noop) {
375+ const VectorValue* noop) const {
369376 if (!jv.is <skjson::ObjectValue>())
370377 return false ;
371378
372379 return ParseDefault<bool >(jv.as <skjson::ObjectValue>()[" s" ], false )
373- ? BindSplitPositionProperty (jv, ascope, std::move (apply), noop)
374- : BindPropertyImpl (jv, ascope, std::move (apply), noop);
380+ ? BindSplitPositionProperty (jv, this , ascope, std::move (apply), noop)
381+ : BindPropertyImpl (jv, this , ascope, std::move (apply), noop);
375382}
376383
377384template <>
378- bool BindProperty (const skjson::Value& jv,
385+ bool AnimationBuilder::bindProperty (const skjson::Value& jv,
379386 AnimatorScope* ascope,
380387 std::function<void (const ShapeValue&)>&& apply,
381- const ShapeValue* noop) {
382- return BindPropertyImpl (jv, ascope, std::move (apply), noop);
388+ const ShapeValue* noop) const {
389+ return BindPropertyImpl (jv, this , ascope, std::move (apply), noop);
383390}
384391
385392} // namespace internal
0 commit comments