1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-22 22:13:35 +02:00

Merge pull request #4100 from IvanSavenko/launcher_fix_drag_lag

Fix lag on dragging mod list in Launcher on Android
This commit is contained in:
Ivan Savenko 2024-06-08 16:56:38 +03:00 committed by GitHub
commit a33a37b1a4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 25 additions and 3 deletions

View File

@ -226,11 +226,13 @@ QVariantMap CModList::copyField(QVariantMap data, QString from, QString to) cons
void CModList::reloadRepositories() void CModList::reloadRepositories()
{ {
cachedMods.clear();
} }
void CModList::resetRepositories() void CModList::resetRepositories()
{ {
repositories.clear(); repositories.clear();
cachedMods.clear();
} }
void CModList::addRepository(QVariantMap data) void CModList::addRepository(QVariantMap data)
@ -238,20 +240,25 @@ void CModList::addRepository(QVariantMap data)
for(auto & key : data.keys()) for(auto & key : data.keys())
data[key.toLower()] = data.take(key); data[key.toLower()] = data.take(key);
repositories.push_back(copyField(data, "version", "latestVersion")); repositories.push_back(copyField(data, "version", "latestVersion"));
cachedMods.clear();
} }
void CModList::setLocalModList(QVariantMap data) void CModList::setLocalModList(QVariantMap data)
{ {
localModList = copyField(data, "version", "installedVersion"); localModList = copyField(data, "version", "installedVersion");
cachedMods.clear();
} }
void CModList::setModSettings(QVariant data) void CModList::setModSettings(QVariant data)
{ {
modSettings = data.toMap(); modSettings = data.toMap();
cachedMods.clear();
} }
void CModList::modChanged(QString modID) void CModList::modChanged(QString modID)
{ {
cachedMods.clear();
} }
static QVariant getValue(QVariant input, QString path) static QVariant getValue(QVariant input, QString path)
@ -270,9 +277,21 @@ static QVariant getValue(QVariant input, QString path)
} }
} }
CModEntry CModList::getMod(QString modname) const const CModEntry & CModList::getMod(QString modName) const
{
modName = modName.toLower();
auto it = cachedMods.find(modName);
if (it != cachedMods.end())
return it.value();
auto itNew = cachedMods.insert(modName, getModUncached(modName));
return *itNew;
}
CModEntry CModList::getModUncached(QString modname) const
{ {
modname = modname.toLower();
QVariantMap repo; QVariantMap repo;
QVariantMap local = localModList[modname].toMap(); QVariantMap local = localModList[modname].toMap();
QVariantMap settings; QVariantMap settings;

View File

@ -82,8 +82,11 @@ class CModList
QVariantMap localModList; QVariantMap localModList;
QVariantMap modSettings; QVariantMap modSettings;
mutable QMap<QString, CModEntry> cachedMods;
QVariantMap copyField(QVariantMap data, QString from, QString to) const; QVariantMap copyField(QVariantMap data, QString from, QString to) const;
CModEntry getModUncached(QString modname) const;
public: public:
virtual void resetRepositories(); virtual void resetRepositories();
virtual void reloadRepositories(); virtual void reloadRepositories();
@ -93,7 +96,7 @@ public:
virtual void modChanged(QString modID); virtual void modChanged(QString modID);
// returns mod by name. Note: mod MUST exist // returns mod by name. Note: mod MUST exist
CModEntry getMod(QString modname) const; const CModEntry & getMod(QString modname) const;
// returns list of all mods necessary to run selected one, including mod itself // returns list of all mods necessary to run selected one, including mod itself
// order is: first mods in list don't have any dependencies, last mod is modname // order is: first mods in list don't have any dependencies, last mod is modname