diff --git a/src/loaders/lottie/tvgLottieExpressions.cpp b/src/loaders/lottie/tvgLottieExpressions.cpp index 6714b128..93477fc0 100644 --- a/src/loaders/lottie/tvgLottieExpressions.cpp +++ b/src/loaders/lottie/tvgLottieExpressions.cpp @@ -317,7 +317,7 @@ static void _buildLayer(jerry_value_t context, float frameNo, LottieLayer* layer static jerry_value_t _value(float frameNo, LottieExpression* exp) { - switch (exp->type) { + switch (exp->property->type) { case LottieProperty::Type::Point: { auto value = jerry_object(); auto pos = (*static_cast(exp->property))(frameNo); @@ -352,7 +352,7 @@ static jerry_value_t _value(float frameNo, LottieExpression* exp) return value; } default: { - TVGERR("LOTTIE", "Non supported type for value? = %d", (int) exp->type); + TVGERR("LOTTIE", "Non supported type for value? = %d", (int) exp->property->type); } } return jerry_undefined(); @@ -735,7 +735,7 @@ static jerry_value_t _velocityAtTime(const jerry_call_info_t* info, const jerry_ Point cur, prv; //compute the velocity - switch (exp->type) { + switch (exp->property->type) { case LottieProperty::Type::Point: { prv = (*static_cast(exp->property))(pframe); cur = (*static_cast(exp->property))(cframe); @@ -779,7 +779,7 @@ static jerry_value_t _speedAtTime(const jerry_call_info_t* info, const jerry_val Point cur, prv; //compute the velocity - switch (exp->type) { + switch (exp->property->type) { case LottieProperty::Type::Point: { prv = (*static_cast(exp->property))(pframe); cur = (*static_cast(exp->property))(cframe); @@ -1307,7 +1307,7 @@ jerry_value_t LottieExpressions::evaluate(float frameNo, LottieExpression* exp) jerry_object_set_native_ptr(thisProperty, nullptr, exp->property); _buildProperty(frameNo, global, exp); - if (exp->type == LottieProperty::Type::PathSet) _buildPath(thisProperty, exp); + if (exp->property->type == LottieProperty::Type::PathSet) _buildPath(thisProperty, exp); if (exp->object->type == LottieObject::Transform) _buildTransform(global, frameNo, static_cast(exp->object)); //evaluate the code diff --git a/src/loaders/lottie/tvgLottieParser.cpp b/src/loaders/lottie/tvgLottieParser.cpp index 34b1ea7a..9a9fb2be 100644 --- a/src/loaders/lottie/tvgLottieParser.cpp +++ b/src/loaders/lottie/tvgLottieParser.cpp @@ -34,7 +34,7 @@ #define KEY_AS(name) !strcmp(key, name) -static LottieExpression* _expression(char* code, LottieComposition* comp, LottieLayer* layer, LottieObject* object, LottieProperty* property, LottieProperty::Type type) +static LottieExpression* _expression(char* code, LottieComposition* comp, LottieLayer* layer, LottieObject* object, LottieProperty* property) { if (!comp->expressions) comp->expressions = true; @@ -44,7 +44,6 @@ static LottieExpression* _expression(char* code, LottieComposition* comp, Lottie inst->layer = layer; inst->object = object; inst->property = property; - inst->type = type; inst->enabled = true; return inst; @@ -509,14 +508,14 @@ void LottieParser::parseProperty(T& prop, LottieObject* obj) for (auto slot = comp->slots.begin(); slot < comp->slots.end(); ++slot) { if (strcmp((*slot)->sid, sid)) continue; (*slot)->pairs.push({obj}); - return; + break; } comp->slots.push(new LottieSlot(sid, obj, type)); - } else if (!strcmp(key, "x")) { - prop.exp = _expression(getStringCopy(), comp, context.layer, context.parent, &prop, type); - } - else skip(key); + } else if (KEY_AS("x")) { + prop.exp = _expression(getStringCopy(), comp, context.layer, context.parent, &prop); + } else skip(key); } + prop.type = type; } @@ -603,9 +602,10 @@ LottieTransform* LottieParser::parseTransform(bool ddd) //check separateCoord to figure out whether "x(expression)" / "x(coord)" else if (transform->coords && KEY_AS("x")) parseProperty(transform->coords->x); else if (transform->coords && KEY_AS("y")) parseProperty(transform->coords->y); - else if (KEY_AS("x")) transform->position.exp = _expression(getStringCopy(), comp, context.layer, context.parent, &transform->position, LottieProperty::Type::Position); + else if (KEY_AS("x")) transform->position.exp = _expression(getStringCopy(), comp, context.layer, context.parent, &transform->position); else skip(key); } + transform->position.type = LottieProperty::Type::Position; } else if (KEY_AS("a")) parseProperty(transform->anchor); else if (KEY_AS("s")) parseProperty(transform->scale); @@ -696,10 +696,11 @@ void LottieParser::getPathSet(LottiePathSet& path) } else { getValue(path.value); } - } else if (!strcmp(key, "x")) { - path.exp = _expression(getStringCopy(), comp, context.layer, context.parent, &path, LottieProperty::Type::PathSet); + } else if (KEY_AS("x")) { + path.exp = _expression(getStringCopy(), comp, context.layer, context.parent, &path); } else skip(key); } + path.type = LottieProperty::Type::PathSet; } diff --git a/src/loaders/lottie/tvgLottieProperty.h b/src/loaders/lottie/tvgLottieProperty.h index efed0585..137c46b0 100644 --- a/src/loaders/lottie/tvgLottieProperty.h +++ b/src/loaders/lottie/tvgLottieProperty.h @@ -176,9 +176,11 @@ struct LottieVectorFrame struct LottieProperty { enum class Type : uint8_t { Point = 0, Float, Opacity, Color, PathSet, ColorStop, Position, TextDoc, Invalid }; - virtual ~LottieProperty() {} LottieExpression* exp = nullptr; + Type type; + + virtual ~LottieProperty() {} //TODO: Apply common bodies? virtual uint32_t frameCnt() = 0; @@ -196,7 +198,6 @@ struct LottieExpression LottieLayer* layer; LottieObject* object; LottieProperty* property; - LottieProperty::Type type; bool enabled;