mirror of
https://github.com/vcmi/vcmi.git
synced 2025-03-27 21:49:10 +02:00
It is now possible to export or import mod preset to/from clipboard
This commit is contained in:
parent
a9dfd9b7f4
commit
a983b5c7d7
launcher
modManager
startGame
lib/modding
@ -1143,3 +1143,14 @@ QString CModListView::getActivePreset() const
|
|||||||
{
|
{
|
||||||
return modStateModel->getActivePreset();
|
return modStateModel->getActivePreset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JsonNode CModListView::exportCurrentPreset() const
|
||||||
|
{
|
||||||
|
return modStateModel->exportCurrentPreset();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CModListView::importPreset(const JsonNode & data)
|
||||||
|
{
|
||||||
|
modStateModel->importPreset(data);
|
||||||
|
modStateModel->reloadLocalState();
|
||||||
|
}
|
||||||
|
@ -97,17 +97,16 @@ public:
|
|||||||
QStringList getUpdateableMods();
|
QStringList getUpdateableMods();
|
||||||
|
|
||||||
void createNewPreset(const QString & presetName);
|
void createNewPreset(const QString & presetName);
|
||||||
|
|
||||||
void deletePreset(const QString & presetName);
|
void deletePreset(const QString & presetName);
|
||||||
|
|
||||||
void activatePreset(const QString & presetName);
|
void activatePreset(const QString & presetName);
|
||||||
|
|
||||||
void renamePreset(const QString & oldPresetName, const QString & newPresetName);
|
void renamePreset(const QString & oldPresetName, const QString & newPresetName);
|
||||||
|
|
||||||
QStringList getAllPresets() const;
|
QStringList getAllPresets() const;
|
||||||
|
|
||||||
QString getActivePreset() const;
|
QString getActivePreset() const;
|
||||||
|
|
||||||
|
JsonNode exportCurrentPreset() const;
|
||||||
|
void importPreset(const JsonNode & data);
|
||||||
|
|
||||||
/// returns true if mod is currently enabled
|
/// returns true if mod is currently enabled
|
||||||
bool isModEnabled(const QString & modName);
|
bool isModEnabled(const QString & modName);
|
||||||
|
|
||||||
|
@ -157,3 +157,13 @@ QString ModStateModel::getActivePreset() const
|
|||||||
{
|
{
|
||||||
return QString::fromStdString(modManager->getActivePreset());
|
return QString::fromStdString(modManager->getActivePreset());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JsonNode ModStateModel::exportCurrentPreset() const
|
||||||
|
{
|
||||||
|
return modManager->exportCurrentPreset();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ModStateModel::importPreset(const JsonNode & data)
|
||||||
|
{
|
||||||
|
modManager->importPreset(data);
|
||||||
|
}
|
||||||
|
@ -57,4 +57,7 @@ public:
|
|||||||
|
|
||||||
QStringList getAllPresets() const;
|
QStringList getAllPresets() const;
|
||||||
QString getActivePreset() const;
|
QString getActivePreset() const;
|
||||||
|
|
||||||
|
JsonNode exportCurrentPreset() const;
|
||||||
|
void importPreset(const JsonNode & data);
|
||||||
};
|
};
|
||||||
|
@ -44,8 +44,6 @@ StartGameTab::StartGameTab(QWidget * parent)
|
|||||||
refreshState();
|
refreshState();
|
||||||
|
|
||||||
ui->buttonGameResume->setVisible(false); // TODO: implement
|
ui->buttonGameResume->setVisible(false); // TODO: implement
|
||||||
ui->buttonPresetExport->setVisible(false); // TODO: implement
|
|
||||||
ui->buttonPresetImport->setVisible(false); // TODO: implement
|
|
||||||
|
|
||||||
#ifndef ENABLE_EDITOR
|
#ifndef ENABLE_EDITOR
|
||||||
ui->buttonGameEditor->hide();
|
ui->buttonGameEditor->hide();
|
||||||
@ -360,12 +358,20 @@ void StartGameTab::on_buttonMissingCampaignsHelp_clicked()
|
|||||||
|
|
||||||
void StartGameTab::on_buttonPresetExport_clicked()
|
void StartGameTab::on_buttonPresetExport_clicked()
|
||||||
{
|
{
|
||||||
// TODO
|
JsonNode presetJson = getMainWindow()->getModView()->exportCurrentPreset();
|
||||||
|
QString presetString = QString::fromStdString(presetJson.toCompactString());
|
||||||
|
QGuiApplication::clipboard()->setText(presetString);
|
||||||
}
|
}
|
||||||
|
|
||||||
void StartGameTab::on_buttonPresetImport_clicked()
|
void StartGameTab::on_buttonPresetImport_clicked()
|
||||||
{
|
{
|
||||||
// TODO
|
QString presetString = QGuiApplication::clipboard()->text();
|
||||||
|
QByteArray presetBytes(presetString.toUtf8());
|
||||||
|
JsonNode presetJson(reinterpret_cast<const std::byte*>(presetBytes.data()), presetBytes.size(), "imported preset");
|
||||||
|
|
||||||
|
getMainWindow()->getModView()->importPreset(presetJson);
|
||||||
|
getMainWindow()->switchToModsTab();
|
||||||
|
refreshPresets();
|
||||||
}
|
}
|
||||||
|
|
||||||
void StartGameTab::on_buttonPresetNew_clicked()
|
void StartGameTab::on_buttonPresetNew_clicked()
|
||||||
|
@ -385,6 +385,31 @@ std::string ModsPresetState::getActivePreset() const
|
|||||||
return modConfig["activePreset"].String();
|
return modConfig["activePreset"].String();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JsonNode ModsPresetState::exportCurrentPreset() const
|
||||||
|
{
|
||||||
|
JsonNode data = getActivePresetConfig();
|
||||||
|
std::string presetName = getActivePreset();
|
||||||
|
|
||||||
|
data["name"] = JsonNode(presetName);
|
||||||
|
|
||||||
|
vstd::erase_if(data["settings"].Struct(), [&](const auto & pair){
|
||||||
|
return !vstd::contains(data["mods"].Vector(), JsonNode(pair.first));
|
||||||
|
});
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ModsPresetState::importPreset(const JsonNode & newConfig)
|
||||||
|
{
|
||||||
|
std::string importedPresetName = newConfig["name"].String();
|
||||||
|
|
||||||
|
if (importedPresetName.empty())
|
||||||
|
throw std::runtime_error("Attempt to import invalid preset");
|
||||||
|
|
||||||
|
modConfig["presets"][importedPresetName] = newConfig;
|
||||||
|
modConfig["presets"][importedPresetName].Struct().erase("name");
|
||||||
|
}
|
||||||
|
|
||||||
ModsStorage::ModsStorage(const std::vector<TModID> & modsToLoad, const JsonNode & repositoryList)
|
ModsStorage::ModsStorage(const std::vector<TModID> & modsToLoad, const JsonNode & repositoryList)
|
||||||
{
|
{
|
||||||
JsonNode coreModConfig(JsonPath::builtin("config/gameConfig.json"));
|
JsonNode coreModConfig(JsonPath::builtin("config/gameConfig.json"));
|
||||||
@ -796,4 +821,15 @@ std::string ModManager::getActivePreset() const
|
|||||||
return modsPreset->getActivePreset();
|
return modsPreset->getActivePreset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JsonNode ModManager::exportCurrentPreset() const
|
||||||
|
{
|
||||||
|
return modsPreset->exportCurrentPreset();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ModManager::importPreset(const JsonNode & data)
|
||||||
|
{
|
||||||
|
modsPreset->importPreset(data);
|
||||||
|
modsPreset->saveConfigurationState();
|
||||||
|
}
|
||||||
|
|
||||||
VCMI_LIB_NAMESPACE_END
|
VCMI_LIB_NAMESPACE_END
|
||||||
|
@ -58,6 +58,9 @@ public:
|
|||||||
std::vector<std::string> getAllPresets() const;
|
std::vector<std::string> getAllPresets() const;
|
||||||
std::string getActivePreset() const;
|
std::string getActivePreset() const;
|
||||||
|
|
||||||
|
JsonNode exportCurrentPreset() const;
|
||||||
|
void importPreset(const JsonNode & data);
|
||||||
|
|
||||||
void setModActive(const TModID & modName, bool isActive);
|
void setModActive(const TModID & modName, bool isActive);
|
||||||
|
|
||||||
void addRootMod(const TModID & modName);
|
void addRootMod(const TModID & modName);
|
||||||
@ -155,6 +158,9 @@ public:
|
|||||||
|
|
||||||
std::vector<std::string> getAllPresets() const;
|
std::vector<std::string> getAllPresets() const;
|
||||||
std::string getActivePreset() const;
|
std::string getActivePreset() const;
|
||||||
|
|
||||||
|
JsonNode exportCurrentPreset() const;
|
||||||
|
void importPreset(const JsonNode & data);
|
||||||
};
|
};
|
||||||
|
|
||||||
VCMI_LIB_NAMESPACE_END
|
VCMI_LIB_NAMESPACE_END
|
||||||
|
Loading…
x
Reference in New Issue
Block a user