1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-14 10:12:59 +02:00

Initialize submods / mods settings on new mod install

This commit is contained in:
Ivan Savenko 2024-10-16 19:17:21 +00:00
parent 915bd0bd35
commit 9742f3a110
3 changed files with 22 additions and 2 deletions

View File

@ -65,13 +65,13 @@ QString detectModArchive(QString path, QString modName, std::vector<std::string>
CModManager::CModManager(CModList * modList)
: modList(modList)
{
modSettings = std::make_shared<ModSettingsStorage>();
loadMods();
loadModSettings();
}
void CModManager::loadModSettings()
{
modSettings = std::make_shared<ModSettingsStorage>();
modList->setModSettings(modSettings);
}
@ -116,7 +116,9 @@ void CModManager::loadMods()
json["storedLocally"].Bool() = true;
mod = JsonUtils::toVariant(json);
localMods.insert(QString::fromUtf8(modname.c_str()).toLower(), mod);
QString modNameQt = QString::fromUtf8(modname.c_str()).toLower();
localMods.insert(modNameQt, mod);
modSettings->registerNewMod(modNameQt, json["keepDisabled"].Bool());
}
}
modList->setLocalModList(localMods);

View File

@ -110,6 +110,22 @@ void ModSettingsStorage::setRootModActive(const QString & modName, bool on)
JsonUtils::JsonToFile(settingsPath(), config);
}
void ModSettingsStorage::registerNewMod(const QString & modName, bool keepDisabled)
{
if (!modName.contains('.'))
return;
QString rootModName = modName.section('.', 0, 0);
QString settingName = modName.section('.', 1);
QVariantMap modSettings = getModSettings(rootModName);
if (modSettings.contains(settingName))
return;
setModSettingActive(modName, !keepDisabled);
}
void ModSettingsStorage::setModSettingActive(const QString & modName, bool on)
{
QString presetName = getActivePreset();

View File

@ -30,6 +30,8 @@ class ModSettingsStorage
public:
ModSettingsStorage();
void registerNewMod(const QString & modName, bool keepDisabled);
void setModActive(const QString & modName, bool on);
void setActivePreset(const QString & presetName);