lottie: ++slot overriding

Keep trying overriding even if the given sid is invalid.

issue: https://github.com/thorvg/thorvg/issues/2969
This commit is contained in:
Hermet Park 2024-11-18 19:24:38 +09:00
parent 80815b269b
commit ed07a151c9

View file

@ -294,8 +294,6 @@ bool LottieLoader::override(const char* slots, bool byDefault)
{ {
if (!ready() || comp->slots.count == 0) return false; if (!ready() || comp->slots.count == 0) return false;
auto success = true;
//override slots //override slots
if (slots) { if (slots) {
//Copy the input data because the JSON parser will encode the data immediately. //Copy the input data because the JSON parser will encode the data immediately.
@ -306,18 +304,21 @@ bool LottieLoader::override(const char* slots, bool byDefault)
parser.comp = comp; parser.comp = comp;
auto idx = 0; auto idx = 0;
auto succeed = false;
while (auto sid = parser.sid(idx == 0)) { while (auto sid = parser.sid(idx == 0)) {
auto applied = false;
for (auto s = comp->slots.begin(); s < comp->slots.end(); ++s) { for (auto s = comp->slots.begin(); s < comp->slots.end(); ++s) {
if (strcmp((*s)->sid, sid)) continue; if (strcmp((*s)->sid, sid)) continue;
if (!parser.apply(*s, byDefault)) success = false; if (parser.apply(*s, byDefault)) succeed = applied = true;
break; break;
} }
if (!applied) parser.skip(sid);
++idx; ++idx;
} }
if (idx < 1) success = false;
free((char*)temp); free((char*)temp);
rebuild = overridden = success; rebuild = succeed;
overridden |= succeed;
return rebuild;
//reset slots //reset slots
} else if (overridden) { } else if (overridden) {
for (auto s = comp->slots.begin(); s < comp->slots.end(); ++s) { for (auto s = comp->slots.begin(); s < comp->slots.end(); ++s) {
@ -326,7 +327,7 @@ bool LottieLoader::override(const char* slots, bool byDefault)
overridden = false; overridden = false;
rebuild = true; rebuild = true;
} }
return success; return true;
} }