lottie/slot: Support overriding plural sids

Previously, slot overriding only works in single sid, the others are ignored.

This patch enables slot overriding for all sids within a single slot.
This commit is contained in:
Jinny You 2024-03-12 11:12:04 +09:00 committed by Hermet Park
parent 78e6606b05
commit 8146a6ef25
3 changed files with 19 additions and 16 deletions

View file

@ -309,21 +309,22 @@ bool LottieLoader::override(const char* slot)
//parsing slot json //parsing slot json
LottieParser parser(temp, dirName); LottieParser parser(temp, dirName);
auto sid = parser.sid();
if (!sid) { auto idx = 0;
free(temp); auto success = true;
return false; while (auto sid = parser.sid(idx == 0)) {
for (auto s = comp->slots.begin(); s < comp->slots.end(); ++s) {
if (strcmp((*s)->sid, sid)) continue;
if (!parser.parse(*s)) success = false;
break;
}
++idx;
} }
bool ret = false; if (idx < 1) success = false;
for (auto s = comp->slots.begin(); s < comp->slots.end(); ++s) {
if (strcmp((*s)->sid, sid)) continue;
ret = parser.parse(*s);
break;
}
free(temp); free(temp);
return ret; return success;
} }

View file

@ -1238,11 +1238,13 @@ void LottieParser::postProcess(Array<LottieGlyph*>& glyphes)
/* External Class Implementation */ /* External Class Implementation */
/************************************************************************/ /************************************************************************/
const char* LottieParser::sid() const char* LottieParser::sid(bool first)
{ {
//verify json if (first) {
if (!parseNext()) return nullptr; //verify json
enterObject(); if (!parseNext()) return nullptr;
enterObject();
}
return nextObjectKey(); return nextObjectKey();
} }

View file

@ -37,7 +37,7 @@ public:
bool parse(); bool parse();
bool parse(LottieSlot* slot); bool parse(LottieSlot* slot);
const char* sid(); const char* sid(bool first = false);
LottieComposition* comp = nullptr; LottieComposition* comp = nullptr;
const char* dirName = nullptr; //base resource directory const char* dirName = nullptr; //base resource directory