mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-29 23:07:48 +02:00
Restored mod list display functionality in launcher
This commit is contained in:
@@ -17,12 +17,13 @@
|
||||
|
||||
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)
|
||||
, localConfig(std::make_unique<JsonNode>(config))
|
||||
, dependencies(loadModList(config["depends"]))
|
||||
, softDependencies(loadModList(config["softDepends"]))
|
||||
, conflicts(loadModList(config["conflicts"]))
|
||||
, localConfig(std::make_unique<JsonNode>(localConfig))
|
||||
, repositoryConfig(std::make_unique<JsonNode>(repositoryConfig))
|
||||
, dependencies(loadModList(getValue("depends")))
|
||||
, softDependencies(loadModList(getValue("softDepends")))
|
||||
, conflicts(loadModList(getValue("conflicts")))
|
||||
{
|
||||
if(getID() != "core")
|
||||
dependencies.insert("core");
|
||||
@@ -72,17 +73,17 @@ const std::string & ModDescription::getBaseLanguage() const
|
||||
{
|
||||
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
|
||||
{
|
||||
return getLocalConfig()["name"].String();
|
||||
return getValue("name").String();
|
||||
}
|
||||
|
||||
const JsonNode & ModDescription::getFilesystemConfig() const
|
||||
{
|
||||
return getLocalConfig()["filesystem"];
|
||||
return getLocalValue("filesystem");
|
||||
}
|
||||
|
||||
const JsonNode & ModDescription::getLocalConfig() const
|
||||
@@ -92,7 +93,11 @@ const JsonNode & ModDescription::getLocalConfig() 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
|
||||
@@ -107,7 +112,7 @@ const JsonNode & ModDescription::getRepositoryValue(const std::string & keyName)
|
||||
|
||||
CModVersion ModDescription::getVersion() const
|
||||
{
|
||||
return CModVersion::fromString(getLocalConfig()["version"].String());
|
||||
return CModVersion::fromString(getValue("version").String());
|
||||
}
|
||||
|
||||
ModVerificationInfo ModDescription::getVerificationInfo() const
|
||||
@@ -123,17 +128,17 @@ ModVerificationInfo ModDescription::getVerificationInfo() const
|
||||
|
||||
bool ModDescription::isCompatibility() const
|
||||
{
|
||||
return getLocalConfig()["modType"].String() == "Compatibility";
|
||||
return getValue("modType").String() == "Compatibility";
|
||||
}
|
||||
|
||||
bool ModDescription::isTranslation() const
|
||||
{
|
||||
return getLocalConfig()["modType"].String() == "Translation";
|
||||
return getValue("modType").String() == "Translation";
|
||||
}
|
||||
|
||||
bool ModDescription::keepDisabled() const
|
||||
{
|
||||
return getLocalConfig()["keepDisabled"].Bool();
|
||||
return getValue("keepDisabled").Bool();
|
||||
}
|
||||
|
||||
bool ModDescription::isInstalled() const
|
||||
|
||||
@@ -21,18 +21,17 @@ using TModSet = std::set<TModID>;
|
||||
|
||||
class DLL_LINKAGE ModDescription : boost::noncopyable
|
||||
{
|
||||
std::unique_ptr<JsonNode> localConfig;
|
||||
std::unique_ptr<JsonNode> repositoryConfig;
|
||||
|
||||
TModID identifier;
|
||||
TModSet dependencies;
|
||||
TModSet softDependencies;
|
||||
TModSet conflicts;
|
||||
|
||||
std::unique_ptr<JsonNode> localConfig;
|
||||
std::unique_ptr<JsonNode> repositoryConfig;
|
||||
|
||||
TModSet loadModList(const JsonNode & configNode) const;
|
||||
|
||||
public:
|
||||
ModDescription(const TModID & fullID, const JsonNode & localConfig);
|
||||
ModDescription(const TModID & fullID, const JsonNode & localConfig, const JsonNode & repositoryConfig);
|
||||
~ModDescription();
|
||||
|
||||
|
||||
@@ -212,11 +212,11 @@ std::vector<TModID> ModsPresetState::getActiveMods() const
|
||||
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"));
|
||||
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)
|
||||
{
|
||||
@@ -235,7 +235,18 @@ ModsStorage::ModsStorage(const std::vector<TModID> & modsToLoad, const std::vect
|
||||
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);
|
||||
}
|
||||
|
||||
TModList ModsStorage::getAllMods() const
|
||||
{
|
||||
TModList result;
|
||||
for (const auto & mod : mods)
|
||||
result.push_back(mod.first);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
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>())
|
||||
, modsPreset(std::make_unique<ModsPresetState>())
|
||||
{
|
||||
@@ -267,6 +287,7 @@ ModManager::~ModManager() = default;
|
||||
|
||||
const ModDescription & ModManager::getModDescription(const TModID & modID) const
|
||||
{
|
||||
assert(boost::to_lower_copy(modID) == modID);
|
||||
return modsStorage->getMod(modID);
|
||||
}
|
||||
|
||||
@@ -280,9 +301,9 @@ const TModList & ModManager::getActiveMods() const
|
||||
return activeMods;
|
||||
}
|
||||
|
||||
const TModList & ModManager::getAllMods() const
|
||||
TModList ModManager::getAllMods() const
|
||||
{
|
||||
return activeMods; //TODO
|
||||
return modsStorage->getAllMods();
|
||||
}
|
||||
|
||||
void ModManager::eraseMissingModsFromPreset()
|
||||
|
||||
@@ -69,9 +69,11 @@ class ModsStorage : boost::noncopyable
|
||||
std::map<TModID, ModDescription> mods;
|
||||
|
||||
public:
|
||||
ModsStorage(const TModList & modsToLoad, const std::vector<JsonNode> & repositoryList);
|
||||
ModsStorage(const TModList & modsToLoad, const JsonNode & repositoryList);
|
||||
|
||||
const ModDescription & getMod(const TModID & fullID) const;
|
||||
|
||||
TModList getAllMods() const;
|
||||
};
|
||||
|
||||
/// Provides public interface to access mod state
|
||||
@@ -92,13 +94,13 @@ class DLL_LINKAGE ModManager : boost::noncopyable
|
||||
void addNewModsToPreset();
|
||||
|
||||
public:
|
||||
ModManager(const std::vector<JsonNode> & repositoryList);
|
||||
ModManager(const JsonNode & repositoryList);
|
||||
ModManager();
|
||||
~ModManager();
|
||||
|
||||
const ModDescription & getModDescription(const TModID & modID) const;
|
||||
const TModList & getActiveMods() const;
|
||||
const TModList & getAllMods() const;
|
||||
TModList getAllMods() const;
|
||||
bool isModActive(const TModID & modID) const;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user