mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-12 02:28:11 +02:00
Restored mod list display functionality in launcher
This commit is contained in:
parent
f8724b9558
commit
06ce71087e
@ -37,8 +37,14 @@
|
|||||||
|
|
||||||
void CModListView::setupModModel()
|
void CModListView::setupModModel()
|
||||||
{
|
{
|
||||||
|
static const QString repositoryCachePath = CLauncherDirs::downloadsPath() + "/repositoryCache.json";
|
||||||
|
const auto &cachedRepositoryData = JsonUtils::jsonFromFile(repositoryCachePath);
|
||||||
|
|
||||||
modStateModel = std::make_shared<ModStateModel>();
|
modStateModel = std::make_shared<ModStateModel>();
|
||||||
modModel = new ModStateItemModel(this);
|
if (!cachedRepositoryData.isNull())
|
||||||
|
modStateModel->appendRepositories(cachedRepositoryData);
|
||||||
|
|
||||||
|
modModel = new ModStateItemModel(modStateModel, this);
|
||||||
manager = std::make_unique<ModStateController>(modStateModel);
|
manager = std::make_unique<ModStateController>(modStateModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -248,6 +254,14 @@ QStringList CModListView::getModNames(QStringList input)
|
|||||||
|
|
||||||
for(const auto & modID : input)
|
for(const auto & modID : input)
|
||||||
{
|
{
|
||||||
|
// Missing mod - use mod ID
|
||||||
|
// TODO: for submods show parent ID instead
|
||||||
|
if (!modStateModel->isModExists(modID))
|
||||||
|
{
|
||||||
|
result += modID;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
auto mod = modStateModel->getMod(modID);
|
auto mod = modStateModel->getMod(modID);
|
||||||
|
|
||||||
QString displayName = mod.getName();
|
QString displayName = mod.getName();
|
||||||
@ -298,10 +312,10 @@ QString CModListView::genModInfoText(ModState & mod)
|
|||||||
|
|
||||||
result += replaceIfNotEmpty(mod.getAuthors(), lineTemplate.arg(tr("Authors")));
|
result += replaceIfNotEmpty(mod.getAuthors(), lineTemplate.arg(tr("Authors")));
|
||||||
|
|
||||||
if(mod.getLicenseName().isEmpty())
|
if(!mod.getLicenseName().isEmpty())
|
||||||
result += urlTemplate.arg(tr("License")).arg(mod.getLicenseUrl()).arg(mod.getLicenseName());
|
result += urlTemplate.arg(tr("License")).arg(mod.getLicenseUrl()).arg(mod.getLicenseName());
|
||||||
|
|
||||||
if(mod.getContact().isEmpty())
|
if(!mod.getContact().isEmpty())
|
||||||
result += urlTemplate.arg(tr("Contact")).arg(mod.getContact()).arg(mod.getContact());
|
result += urlTemplate.arg(tr("Contact")).arg(mod.getContact()).arg(mod.getContact());
|
||||||
|
|
||||||
//compatibility info
|
//compatibility info
|
||||||
@ -357,12 +371,12 @@ QString CModListView::genModInfoText(ModState & mod)
|
|||||||
|
|
||||||
QString notes;
|
QString notes;
|
||||||
|
|
||||||
notes += replaceIfNotEmpty(getModNames(findInvalidDependencies(mod.getName())), listTemplate.arg(unknownDeps));
|
notes += replaceIfNotEmpty(getModNames(findInvalidDependencies(mod.getID())), listTemplate.arg(unknownDeps));
|
||||||
notes += replaceIfNotEmpty(getModNames(findBlockingMods(mod.getName())), listTemplate.arg(blockingMods));
|
notes += replaceIfNotEmpty(getModNames(findBlockingMods(mod.getID())), listTemplate.arg(blockingMods));
|
||||||
if(mod.isEnabled())
|
if(mod.isEnabled())
|
||||||
notes += replaceIfNotEmpty(getModNames(findDependentMods(mod.getName(), true)), listTemplate.arg(hasActiveDependentMods));
|
notes += replaceIfNotEmpty(getModNames(findDependentMods(mod.getID(), true)), listTemplate.arg(hasActiveDependentMods));
|
||||||
if(mod.isInstalled())
|
if(mod.isInstalled())
|
||||||
notes += replaceIfNotEmpty(getModNames(findDependentMods(mod.getName(), false)), listTemplate.arg(hasDependentMods));
|
notes += replaceIfNotEmpty(getModNames(findDependentMods(mod.getID(), false)), listTemplate.arg(hasDependentMods));
|
||||||
|
|
||||||
if(mod.isSubmod())
|
if(mod.isSubmod())
|
||||||
notes += noteTemplate.arg(thisIsSubmod);
|
notes += noteTemplate.arg(thisIsSubmod);
|
||||||
@ -463,7 +477,7 @@ QStringList CModListView::findInvalidDependencies(QString mod)
|
|||||||
QStringList ret;
|
QStringList ret;
|
||||||
for(QString requirement : modStateModel->getMod(mod).getDependencies())
|
for(QString requirement : modStateModel->getMod(mod).getDependencies())
|
||||||
{
|
{
|
||||||
if(!modStateModel->isModExists(requirement) && !modStateModel->isModExists(modStateModel->getMod(requirement).getTopParentID()))
|
if(!modStateModel->isModExists(requirement))
|
||||||
ret += requirement;
|
ret += requirement;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
@ -776,7 +790,7 @@ void CModListView::installFiles(QStringList files)
|
|||||||
QStringList maps;
|
QStringList maps;
|
||||||
QStringList images;
|
QStringList images;
|
||||||
QStringList exe;
|
QStringList exe;
|
||||||
QVector<QVariantMap> repositories;
|
JsonNode repository;
|
||||||
|
|
||||||
// TODO: some better way to separate zip's with mods and downloaded repository files
|
// TODO: some better way to separate zip's with mods and downloaded repository files
|
||||||
for(QString filename : files)
|
for(QString filename : files)
|
||||||
@ -790,33 +804,40 @@ void CModListView::installFiles(QStringList files)
|
|||||||
else if(filename.endsWith(".json", Qt::CaseInsensitive))
|
else if(filename.endsWith(".json", Qt::CaseInsensitive))
|
||||||
{
|
{
|
||||||
//download and merge additional files
|
//download and merge additional files
|
||||||
auto repoData = JsonUtils::JsonFromFile(filename).toMap();
|
const auto &repoData = JsonUtils::jsonFromFile(filename);
|
||||||
if(repoData.value("name").isNull())
|
if(repoData["name"].isNull())
|
||||||
{
|
{
|
||||||
for(const auto & key : repoData.keys())
|
// This is main repository index. Download all referenced mods
|
||||||
|
for(const auto & [modName, modJson] : repoData.Struct())
|
||||||
{
|
{
|
||||||
auto modjson = repoData[key].toMap().value("mod");
|
auto modNameLower = boost::algorithm::to_lower_copy(modName);
|
||||||
if(!modjson.isNull())
|
auto modJsonUrl = modJson["mod"];
|
||||||
{
|
if(!modJsonUrl.isNull())
|
||||||
downloadFile(key + ".json", modjson.toString(), tr("mods repository index"));
|
downloadFile(QString::fromStdString(modName + ".json"), QString::fromStdString(modJsonUrl.String()), tr("mods repository index"));
|
||||||
}
|
|
||||||
|
repository[modNameLower] = repoData;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
auto modn = QFileInfo(filename).baseName();
|
// This is json of a single mod. Extract name of mod and add it to repo
|
||||||
QVariantMap temp;
|
auto modName = QFileInfo(filename).baseName().toStdString();
|
||||||
temp[modn] = repoData;
|
auto modNameLower = boost::algorithm::to_lower_copy(modName);
|
||||||
repoData = temp;
|
repository[modNameLower] = repoData;
|
||||||
}
|
}
|
||||||
repositories.push_back(repoData);
|
|
||||||
}
|
}
|
||||||
else if(filename.endsWith(".png", Qt::CaseInsensitive))
|
else if(filename.endsWith(".png", Qt::CaseInsensitive))
|
||||||
images.push_back(filename);
|
images.push_back(filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (!repositories.empty())
|
if (!repository.isNull())
|
||||||
// manager->loadRepositories(repositories);
|
{
|
||||||
|
manager->appendRepositories(repository);
|
||||||
|
modModel->reloadRepositories();
|
||||||
|
|
||||||
|
static const QString repositoryCachePath = CLauncherDirs::downloadsPath() + "/repositoryCache.json";
|
||||||
|
JsonUtils::jsonToFile(repositoryCachePath, modStateModel->getRepositoryData());
|
||||||
|
}
|
||||||
|
|
||||||
if(!mods.empty())
|
if(!mods.empty())
|
||||||
installMods(mods);
|
installMods(mods);
|
||||||
|
@ -120,7 +120,7 @@ QString ModState::getLocalSizeFormatted() const
|
|||||||
|
|
||||||
QString ModState::getAuthors() const
|
QString ModState::getAuthors() const
|
||||||
{
|
{
|
||||||
return QString::fromStdString(impl.getValue("authors").String());
|
return QString::fromStdString(impl.getValue("author").String());
|
||||||
}
|
}
|
||||||
|
|
||||||
QString ModState::getContact() const
|
QString ModState::getContact() const
|
||||||
@ -130,7 +130,7 @@ QString ModState::getContact() const
|
|||||||
|
|
||||||
QString ModState::getLicenseUrl() const
|
QString ModState::getLicenseUrl() const
|
||||||
{
|
{
|
||||||
return QString::fromStdString(impl.getValue("licenseUrl").String());
|
return QString::fromStdString(impl.getValue("licenseURL").String());
|
||||||
}
|
}
|
||||||
|
|
||||||
QString ModState::getLicenseName() const
|
QString ModState::getLicenseName() const
|
||||||
@ -173,7 +173,7 @@ bool ModState::isHidden() const
|
|||||||
if (isTranslation() && !isInstalled())
|
if (isTranslation() && !isInstalled())
|
||||||
return impl.getBaseLanguage() == CGeneralTextHandler::getPreferredLanguage();
|
return impl.getBaseLanguage() == CGeneralTextHandler::getPreferredLanguage();
|
||||||
|
|
||||||
return isCompatibility() || getID() == "vcmi";
|
return isCompatibility() || getID() == "vcmi" || getID() == "core";
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ModState::isDisabled() const
|
bool ModState::isDisabled() const
|
||||||
@ -198,7 +198,7 @@ bool ModState::isInstalled() const
|
|||||||
|
|
||||||
bool ModState::isUpdateAvailable() const
|
bool ModState::isUpdateAvailable() const
|
||||||
{
|
{
|
||||||
return getInstalledVersion() != getRepositoryVersion() && !getRepositoryVersion().isEmpty();
|
return getInstalledVersion() != getRepositoryVersion() && !getRepositoryVersion().isEmpty() && !getInstalledVersion().isEmpty();;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ModState::isCompatible() const
|
bool ModState::isCompatible() const
|
||||||
|
@ -71,9 +71,9 @@ ModStateController::ModStateController(std::shared_ptr<ModStateModel> modList)
|
|||||||
|
|
||||||
ModStateController::~ModStateController() = default;
|
ModStateController::~ModStateController() = default;
|
||||||
|
|
||||||
void ModStateController::loadRepositories(QVector<JsonNode> repomap)
|
void ModStateController::appendRepositories(const JsonNode & repomap)
|
||||||
{
|
{
|
||||||
modList->setRepositories(repomap);
|
modList->appendRepositories(repomap);
|
||||||
}
|
}
|
||||||
|
|
||||||
//void ModStateController::loadMods()
|
//void ModStateController::loadMods()
|
||||||
|
@ -38,7 +38,7 @@ public:
|
|||||||
ModStateController(std::shared_ptr<ModStateModel> modList);
|
ModStateController(std::shared_ptr<ModStateModel> modList);
|
||||||
~ModStateController();
|
~ModStateController();
|
||||||
|
|
||||||
void loadRepositories(QVector<JsonNode> repositoriesList);
|
void appendRepositories(const JsonNode & repositoriesList);
|
||||||
|
|
||||||
QStringList getErrors();
|
QStringList getErrors();
|
||||||
|
|
||||||
|
@ -25,8 +25,9 @@ static const QString iconEnabledSubmod = ":/icons/submod-enabled.png";
|
|||||||
static const QString iconUpdate = ":/icons/mod-update.png";
|
static const QString iconUpdate = ":/icons/mod-update.png";
|
||||||
}
|
}
|
||||||
|
|
||||||
ModStateItemModel::ModStateItemModel(QObject * parent)
|
ModStateItemModel::ModStateItemModel(std::shared_ptr<ModStateModel> model, QObject * parent)
|
||||||
: QAbstractItemModel(parent)
|
: QAbstractItemModel(parent)
|
||||||
|
, model(model)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -164,7 +165,7 @@ QVariant ModStateItemModel::data(const QModelIndex & index, int role) const
|
|||||||
case ModRoles::ValueRole:
|
case ModRoles::ValueRole:
|
||||||
return getValue(mod, index.column());
|
return getValue(mod, index.column());
|
||||||
case ModRoles::ModNameRole:
|
case ModRoles::ModNameRole:
|
||||||
return mod.getName();
|
return mod.getID();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return QVariant();
|
return QVariant();
|
||||||
@ -280,7 +281,7 @@ bool CModFilterModel::filterAcceptsRow(int source_row, const QModelIndex & sourc
|
|||||||
{
|
{
|
||||||
QModelIndex index = base->index(source_row, 0, source_parent);
|
QModelIndex index = base->index(source_row, 0, source_parent);
|
||||||
QString modID = index.data(ModRoles::ModNameRole).toString();
|
QString modID = index.data(ModRoles::ModNameRole).toString();
|
||||||
if (base->model->isModVisible(modID))
|
if (base->model->getMod(modID).isHidden())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if(filterMatchesThis(index))
|
if(filterMatchesThis(index))
|
||||||
|
@ -46,7 +46,7 @@ enum EModRoles
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
class ModStateItemModel : public QAbstractItemModel
|
class ModStateItemModel : public QAbstractItemModel
|
||||||
{
|
{
|
||||||
friend class CModFilterModel;
|
friend class CModFilterModel;
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -69,7 +69,7 @@ class ModStateItemModel : public QAbstractItemModel
|
|||||||
QVariant getIcon(const ModState & mod, int field) const;
|
QVariant getIcon(const ModState & mod, int field) const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit ModStateItemModel(QObject * parent = nullptr);
|
explicit ModStateItemModel(std::shared_ptr<ModStateModel> model, QObject * parent = nullptr);
|
||||||
|
|
||||||
/// CModListContainer overrides
|
/// CModListContainer overrides
|
||||||
void reloadRepositories();
|
void reloadRepositories();
|
||||||
|
@ -11,20 +11,31 @@
|
|||||||
#include "modstatemodel.h"
|
#include "modstatemodel.h"
|
||||||
|
|
||||||
#include "../../lib/modding/ModManager.h"
|
#include "../../lib/modding/ModManager.h"
|
||||||
|
#include "../../lib/json/JsonUtils.h"
|
||||||
|
|
||||||
ModStateModel::ModStateModel()
|
ModStateModel::ModStateModel()
|
||||||
:modManager(std::make_unique<ModManager>())
|
: repositoryData(std::make_unique<JsonNode>())
|
||||||
{}
|
, modManager(std::make_unique<ModManager>())
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
ModStateModel::~ModStateModel() = default;
|
ModStateModel::~ModStateModel() = default;
|
||||||
|
|
||||||
void ModStateModel::setRepositories(QVector<JsonNode> repositoriesList)
|
void ModStateModel::appendRepositories(const JsonNode & repositoriesList)
|
||||||
{
|
{
|
||||||
//TODO
|
JsonUtils::mergeCopy(*repositoryData, repositoriesList);
|
||||||
|
|
||||||
|
modManager = std::make_unique<ModManager>(*repositoryData);
|
||||||
|
}
|
||||||
|
|
||||||
|
const JsonNode & ModStateModel::getRepositoryData() const
|
||||||
|
{
|
||||||
|
return *repositoryData;
|
||||||
}
|
}
|
||||||
|
|
||||||
ModState ModStateModel::getMod(QString modName) const
|
ModState ModStateModel::getMod(QString modName) const
|
||||||
{
|
{
|
||||||
|
assert(modName.toLower() == modName);
|
||||||
return ModState(modManager->getModDescription(modName.toStdString()));
|
return ModState(modManager->getModDescription(modName.toStdString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,7 +50,7 @@ QStringList stringListStdToQt(const Container & container)
|
|||||||
|
|
||||||
QStringList ModStateModel::getAllMods() const
|
QStringList ModStateModel::getAllMods() const
|
||||||
{
|
{
|
||||||
return stringListStdToQt(modManager->getActiveMods());
|
return stringListStdToQt(modManager->getAllMods());
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList ModStateModel::getSubmods(QString modName) const
|
QStringList ModStateModel::getSubmods(QString modName) const
|
||||||
|
@ -20,13 +20,15 @@ VCMI_LIB_NAMESPACE_END
|
|||||||
/// Provides Qt-based interface to library class ModManager
|
/// Provides Qt-based interface to library class ModManager
|
||||||
class ModStateModel
|
class ModStateModel
|
||||||
{
|
{
|
||||||
|
std::unique_ptr<JsonNode> repositoryData;
|
||||||
std::unique_ptr<ModManager> modManager;
|
std::unique_ptr<ModManager> modManager;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ModStateModel();
|
ModStateModel();
|
||||||
~ModStateModel();
|
~ModStateModel();
|
||||||
|
|
||||||
void setRepositories(QVector<JsonNode> repositoriesList);
|
void appendRepositories(const JsonNode & repositoriesList);
|
||||||
|
const JsonNode & getRepositoryData() const;
|
||||||
|
|
||||||
ModState getMod(QString modName) const;
|
ModState getMod(QString modName) const;
|
||||||
QStringList getAllMods() const;
|
QStringList getAllMods() const;
|
||||||
|
@ -17,12 +17,13 @@
|
|||||||
|
|
||||||
VCMI_LIB_NAMESPACE_BEGIN
|
VCMI_LIB_NAMESPACE_BEGIN
|
||||||
|
|
||||||
ModDescription::ModDescription(const TModID & fullID, const JsonNode & config)
|
ModDescription::ModDescription(const TModID & fullID, const JsonNode & localConfig, const JsonNode & repositoryConfig)
|
||||||
: identifier(fullID)
|
: identifier(fullID)
|
||||||
, localConfig(std::make_unique<JsonNode>(config))
|
, localConfig(std::make_unique<JsonNode>(localConfig))
|
||||||
, dependencies(loadModList(config["depends"]))
|
, repositoryConfig(std::make_unique<JsonNode>(repositoryConfig))
|
||||||
, softDependencies(loadModList(config["softDepends"]))
|
, dependencies(loadModList(getValue("depends")))
|
||||||
, conflicts(loadModList(config["conflicts"]))
|
, softDependencies(loadModList(getValue("softDepends")))
|
||||||
|
, conflicts(loadModList(getValue("conflicts")))
|
||||||
{
|
{
|
||||||
if(getID() != "core")
|
if(getID() != "core")
|
||||||
dependencies.insert("core");
|
dependencies.insert("core");
|
||||||
@ -72,17 +73,17 @@ const std::string & ModDescription::getBaseLanguage() const
|
|||||||
{
|
{
|
||||||
static const std::string defaultLanguage = "english";
|
static const std::string defaultLanguage = "english";
|
||||||
|
|
||||||
return getLocalConfig()["language"].isString() ? getLocalConfig()["language"].String() : defaultLanguage;
|
return getValue("language").isString() ? getValue("language").String() : defaultLanguage;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string & ModDescription::getName() const
|
const std::string & ModDescription::getName() const
|
||||||
{
|
{
|
||||||
return getLocalConfig()["name"].String();
|
return getValue("name").String();
|
||||||
}
|
}
|
||||||
|
|
||||||
const JsonNode & ModDescription::getFilesystemConfig() const
|
const JsonNode & ModDescription::getFilesystemConfig() const
|
||||||
{
|
{
|
||||||
return getLocalConfig()["filesystem"];
|
return getLocalValue("filesystem");
|
||||||
}
|
}
|
||||||
|
|
||||||
const JsonNode & ModDescription::getLocalConfig() const
|
const JsonNode & ModDescription::getLocalConfig() const
|
||||||
@ -92,7 +93,11 @@ const JsonNode & ModDescription::getLocalConfig() const
|
|||||||
|
|
||||||
const JsonNode & ModDescription::getValue(const std::string & keyName) const
|
const JsonNode & ModDescription::getValue(const std::string & keyName) const
|
||||||
{
|
{
|
||||||
return getLocalConfig()[keyName];
|
const JsonNode & localValue = getLocalValue(keyName);
|
||||||
|
if (localValue.isNull())
|
||||||
|
return getRepositoryValue(keyName);
|
||||||
|
else
|
||||||
|
return getLocalValue(keyName);
|
||||||
}
|
}
|
||||||
|
|
||||||
const JsonNode & ModDescription::getLocalValue(const std::string & keyName) const
|
const JsonNode & ModDescription::getLocalValue(const std::string & keyName) const
|
||||||
@ -107,7 +112,7 @@ const JsonNode & ModDescription::getRepositoryValue(const std::string & keyName)
|
|||||||
|
|
||||||
CModVersion ModDescription::getVersion() const
|
CModVersion ModDescription::getVersion() const
|
||||||
{
|
{
|
||||||
return CModVersion::fromString(getLocalConfig()["version"].String());
|
return CModVersion::fromString(getValue("version").String());
|
||||||
}
|
}
|
||||||
|
|
||||||
ModVerificationInfo ModDescription::getVerificationInfo() const
|
ModVerificationInfo ModDescription::getVerificationInfo() const
|
||||||
@ -123,17 +128,17 @@ ModVerificationInfo ModDescription::getVerificationInfo() const
|
|||||||
|
|
||||||
bool ModDescription::isCompatibility() const
|
bool ModDescription::isCompatibility() const
|
||||||
{
|
{
|
||||||
return getLocalConfig()["modType"].String() == "Compatibility";
|
return getValue("modType").String() == "Compatibility";
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ModDescription::isTranslation() const
|
bool ModDescription::isTranslation() const
|
||||||
{
|
{
|
||||||
return getLocalConfig()["modType"].String() == "Translation";
|
return getValue("modType").String() == "Translation";
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ModDescription::keepDisabled() const
|
bool ModDescription::keepDisabled() const
|
||||||
{
|
{
|
||||||
return getLocalConfig()["keepDisabled"].Bool();
|
return getValue("keepDisabled").Bool();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ModDescription::isInstalled() const
|
bool ModDescription::isInstalled() const
|
||||||
|
@ -21,18 +21,17 @@ using TModSet = std::set<TModID>;
|
|||||||
|
|
||||||
class DLL_LINKAGE ModDescription : boost::noncopyable
|
class DLL_LINKAGE ModDescription : boost::noncopyable
|
||||||
{
|
{
|
||||||
|
std::unique_ptr<JsonNode> localConfig;
|
||||||
|
std::unique_ptr<JsonNode> repositoryConfig;
|
||||||
|
|
||||||
TModID identifier;
|
TModID identifier;
|
||||||
TModSet dependencies;
|
TModSet dependencies;
|
||||||
TModSet softDependencies;
|
TModSet softDependencies;
|
||||||
TModSet conflicts;
|
TModSet conflicts;
|
||||||
|
|
||||||
std::unique_ptr<JsonNode> localConfig;
|
|
||||||
std::unique_ptr<JsonNode> repositoryConfig;
|
|
||||||
|
|
||||||
TModSet loadModList(const JsonNode & configNode) const;
|
TModSet loadModList(const JsonNode & configNode) const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ModDescription(const TModID & fullID, const JsonNode & localConfig);
|
|
||||||
ModDescription(const TModID & fullID, const JsonNode & localConfig, const JsonNode & repositoryConfig);
|
ModDescription(const TModID & fullID, const JsonNode & localConfig, const JsonNode & repositoryConfig);
|
||||||
~ModDescription();
|
~ModDescription();
|
||||||
|
|
||||||
|
@ -212,11 +212,11 @@ std::vector<TModID> ModsPresetState::getActiveMods() const
|
|||||||
return allActiveMods;
|
return allActiveMods;
|
||||||
}
|
}
|
||||||
|
|
||||||
ModsStorage::ModsStorage(const std::vector<TModID> & modsToLoad, const std::vector<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"));
|
||||||
coreModConfig.setModScope(ModScope::scopeBuiltin());
|
coreModConfig.setModScope(ModScope::scopeBuiltin());
|
||||||
mods.try_emplace(ModScope::scopeBuiltin(), ModScope::scopeBuiltin(), coreModConfig);
|
mods.try_emplace(ModScope::scopeBuiltin(), ModScope::scopeBuiltin(), coreModConfig, JsonNode());
|
||||||
|
|
||||||
for(auto modID : modsToLoad)
|
for(auto modID : modsToLoad)
|
||||||
{
|
{
|
||||||
@ -235,7 +235,18 @@ ModsStorage::ModsStorage(const std::vector<TModID> & modsToLoad, const std::vect
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
mods.try_emplace(modID, modID, modConfig);
|
mods.try_emplace(modID, modID, modConfig, repositoryList[modID]);
|
||||||
|
}
|
||||||
|
|
||||||
|
for(const auto & mod : repositoryList.Struct())
|
||||||
|
{
|
||||||
|
if (vstd::contains(modsToLoad, mod.first))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (mod.second["modType"].isNull() || mod.second["name"].isNull())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
mods.try_emplace(mod.first, mod.first, JsonNode(), mod.second);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -244,12 +255,21 @@ const ModDescription & ModsStorage::getMod(const TModID & fullID) const
|
|||||||
return mods.at(fullID);
|
return mods.at(fullID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TModList ModsStorage::getAllMods() const
|
||||||
|
{
|
||||||
|
TModList result;
|
||||||
|
for (const auto & mod : mods)
|
||||||
|
result.push_back(mod.first);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
ModManager::ModManager()
|
ModManager::ModManager()
|
||||||
:ModManager(std::vector<JsonNode>())
|
:ModManager(JsonNode())
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
ModManager::ModManager(const std::vector<JsonNode> & repositoryList)
|
ModManager::ModManager(const JsonNode & repositoryList)
|
||||||
: modsState(std::make_unique<ModsState>())
|
: modsState(std::make_unique<ModsState>())
|
||||||
, modsPreset(std::make_unique<ModsPresetState>())
|
, modsPreset(std::make_unique<ModsPresetState>())
|
||||||
{
|
{
|
||||||
@ -267,6 +287,7 @@ ModManager::~ModManager() = default;
|
|||||||
|
|
||||||
const ModDescription & ModManager::getModDescription(const TModID & modID) const
|
const ModDescription & ModManager::getModDescription(const TModID & modID) const
|
||||||
{
|
{
|
||||||
|
assert(boost::to_lower_copy(modID) == modID);
|
||||||
return modsStorage->getMod(modID);
|
return modsStorage->getMod(modID);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -280,9 +301,9 @@ const TModList & ModManager::getActiveMods() const
|
|||||||
return activeMods;
|
return activeMods;
|
||||||
}
|
}
|
||||||
|
|
||||||
const TModList & ModManager::getAllMods() const
|
TModList ModManager::getAllMods() const
|
||||||
{
|
{
|
||||||
return activeMods; //TODO
|
return modsStorage->getAllMods();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModManager::eraseMissingModsFromPreset()
|
void ModManager::eraseMissingModsFromPreset()
|
||||||
|
@ -69,9 +69,11 @@ class ModsStorage : boost::noncopyable
|
|||||||
std::map<TModID, ModDescription> mods;
|
std::map<TModID, ModDescription> mods;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ModsStorage(const TModList & modsToLoad, const std::vector<JsonNode> & repositoryList);
|
ModsStorage(const TModList & modsToLoad, const JsonNode & repositoryList);
|
||||||
|
|
||||||
const ModDescription & getMod(const TModID & fullID) const;
|
const ModDescription & getMod(const TModID & fullID) const;
|
||||||
|
|
||||||
|
TModList getAllMods() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Provides public interface to access mod state
|
/// Provides public interface to access mod state
|
||||||
@ -92,13 +94,13 @@ class DLL_LINKAGE ModManager : boost::noncopyable
|
|||||||
void addNewModsToPreset();
|
void addNewModsToPreset();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ModManager(const std::vector<JsonNode> & repositoryList);
|
ModManager(const JsonNode & repositoryList);
|
||||||
ModManager();
|
ModManager();
|
||||||
~ModManager();
|
~ModManager();
|
||||||
|
|
||||||
const ModDescription & getModDescription(const TModID & modID) const;
|
const ModDescription & getModDescription(const TModID & modID) const;
|
||||||
const TModList & getActiveMods() const;
|
const TModList & getActiveMods() const;
|
||||||
const TModList & getAllMods() const;
|
TModList getAllMods() const;
|
||||||
bool isModActive(const TModID & modID) const;
|
bool isModActive(const TModID & modID) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ QVariant toVariant(const JsonNode & node)
|
|||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant JsonFromFile(QString filename)
|
JsonNode jsonFromFile(QString filename)
|
||||||
{
|
{
|
||||||
QFile file(filename);
|
QFile file(filename);
|
||||||
if(!file.open(QFile::ReadOnly))
|
if(!file.open(QFile::ReadOnly))
|
||||||
@ -90,7 +90,7 @@ QVariant JsonFromFile(QString filename)
|
|||||||
|
|
||||||
const auto data = file.readAll();
|
const auto data = file.readAll();
|
||||||
JsonNode node(reinterpret_cast<const std::byte*>(data.data()), data.size(), filename.toStdString());
|
JsonNode node(reinterpret_cast<const std::byte*>(data.data()), data.size(), filename.toStdString());
|
||||||
return toVariant(node);
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonNode toJson(QVariant object)
|
JsonNode toJson(QVariant object)
|
||||||
@ -113,10 +113,10 @@ JsonNode toJson(QVariant object)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void JsonToFile(QString filename, QVariant object)
|
void jsonToFile(QString filename, const JsonNode & object)
|
||||||
{
|
{
|
||||||
std::fstream file(qstringToPath(filename).c_str(), std::ios::out | std::ios_base::binary);
|
std::fstream file(qstringToPath(filename).c_str(), std::ios::out | std::ios_base::binary);
|
||||||
file << toJson(object).toString();
|
file << object.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -20,10 +20,10 @@ class JsonNode;
|
|||||||
namespace JsonUtils
|
namespace JsonUtils
|
||||||
{
|
{
|
||||||
VCMIQT_LINKAGE QVariant toVariant(const JsonNode & node);
|
VCMIQT_LINKAGE QVariant toVariant(const JsonNode & node);
|
||||||
VCMIQT_LINKAGE QVariant JsonFromFile(QString filename);
|
VCMIQT_LINKAGE JsonNode jsonFromFile(QString filename);
|
||||||
|
|
||||||
VCMIQT_LINKAGE JsonNode toJson(QVariant object);
|
VCMIQT_LINKAGE JsonNode toJson(QVariant object);
|
||||||
VCMIQT_LINKAGE void JsonToFile(QString filename, QVariant object);
|
VCMIQT_LINKAGE void jsonToFile(QString filename, const JsonNode & object);
|
||||||
}
|
}
|
||||||
|
|
||||||
VCMI_LIB_NAMESPACE_END
|
VCMI_LIB_NAMESPACE_END
|
||||||
|
Loading…
Reference in New Issue
Block a user