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 946d934827
commit 7f2cd1090c
3 changed files with 19 additions and 16 deletions

View file

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

View file

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

View file

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