mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-25 22:42:04 +02:00
Load map and campaign overrides once
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
#include "../mapping/CMapService.h"
|
||||
#include "../mapping/CMapInfo.h"
|
||||
#include "../mapping/CMap.h"
|
||||
#include "../mapping/MapFormatSettings.h"
|
||||
#include "../mapObjects/CGHeroInstance.h"
|
||||
#include "../serializer/JsonDeserializer.h"
|
||||
#include "../serializer/JsonSerializer.h"
|
||||
@@ -377,34 +378,29 @@ std::set<CampaignScenarioID> Campaign::allScenarios() const
|
||||
|
||||
void Campaign::overrideCampaign()
|
||||
{
|
||||
const JsonNode node = JsonUtils::assembleFromFiles("config/campaignOverrides.json");
|
||||
for (auto & entry : node.Struct())
|
||||
if(filename == entry.first)
|
||||
{
|
||||
if(!entry.second["regions"].isNull())
|
||||
campaignRegions = CampaignRegions(entry.second["regions"]);
|
||||
if (!entry.second["scenarioCount"].isNull())
|
||||
numberOfScenarios = entry.second["scenarioCount"].Integer();
|
||||
if(!entry.second["loadingBackground"].isNull())
|
||||
loadingBackground = ImagePath::builtin(entry.second["loadingBackground"].String());
|
||||
if(!entry.second["videoRim"].isNull())
|
||||
videoRim = ImagePath::builtin(entry.second["videoRim"].String());
|
||||
if(!entry.second["introVideo"].isNull())
|
||||
introVideo = VideoPath::builtin(entry.second["introVideo"].String());
|
||||
if(!entry.second["outroVideo"].isNull())
|
||||
outroVideo = VideoPath::builtin(entry.second["outroVideo"].String());
|
||||
}
|
||||
const JsonNode & overrides = LIBRARY->mapFormat->campaignOverrides(filename);
|
||||
|
||||
if(!overrides["regions"].isNull())
|
||||
campaignRegions = CampaignRegions(overrides["regions"]);
|
||||
if (!overrides["scenarioCount"].isNull())
|
||||
numberOfScenarios = overrides["scenarioCount"].Integer();
|
||||
if(!overrides["loadingBackground"].isNull())
|
||||
loadingBackground = ImagePath::builtin(overrides["loadingBackground"].String());
|
||||
if(!overrides["videoRim"].isNull())
|
||||
videoRim = ImagePath::builtin(overrides["videoRim"].String());
|
||||
if(!overrides["introVideo"].isNull())
|
||||
introVideo = VideoPath::builtin(overrides["introVideo"].String());
|
||||
if(!overrides["outroVideo"].isNull())
|
||||
outroVideo = VideoPath::builtin(overrides["outroVideo"].String());
|
||||
}
|
||||
|
||||
void Campaign::overrideCampaignScenarios()
|
||||
{
|
||||
const JsonNode node = JsonUtils::assembleFromFiles("config/campaignOverrides.json");
|
||||
for (auto & entry : node.Struct())
|
||||
if(filename == entry.first)
|
||||
const JsonNode & overrides = LIBRARY->mapFormat->campaignOverrides(filename);
|
||||
|
||||
if(!overrides["scenarios"].isNull())
|
||||
{
|
||||
if(!entry.second["scenarios"].isNull())
|
||||
{
|
||||
auto sc = entry.second["scenarios"].Vector();
|
||||
auto sc = overrides["scenarios"].Vector();
|
||||
for(int i = 0; i < sc.size(); i++)
|
||||
{
|
||||
auto it = scenarios.begin();
|
||||
@@ -416,7 +412,6 @@ void Campaign::overrideCampaignScenarios()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int Campaign::scenariosCount() const
|
||||
{
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
#include "StdInc.h"
|
||||
#include "CMapService.h"
|
||||
|
||||
#include "MapFormatSettings.h"
|
||||
|
||||
#include "../json/JsonUtils.h"
|
||||
#include "../filesystem/Filesystem.h"
|
||||
#include "../filesystem/CBinaryReader.h"
|
||||
@@ -163,23 +165,11 @@ std::unique_ptr<IMapLoader> CMapService::getMapLoader(std::unique_ptr<CInputStre
|
||||
}
|
||||
}
|
||||
|
||||
static JsonNode loadPatches(const std::string & path)
|
||||
{
|
||||
JsonNode node = JsonUtils::assembleFromFiles(path);
|
||||
for (auto & entry : node.Struct())
|
||||
JsonUtils::validate(entry.second, "vcmi:mapHeader", "patch for " + entry.first);
|
||||
|
||||
node.setModScope(ModScope::scopeMap());
|
||||
return node;
|
||||
}
|
||||
|
||||
std::unique_ptr<IMapPatcher> CMapService::getMapPatcher(std::string scenarioName)
|
||||
{
|
||||
static const JsonNode node = loadPatches("config/mapOverrides.json");
|
||||
|
||||
boost::to_lower(scenarioName);
|
||||
logGlobal->debug("Request to patch map %s", scenarioName);
|
||||
return std::unique_ptr<IMapPatcher>(new CMapPatcher(node[scenarioName]));
|
||||
return std::unique_ptr<IMapPatcher>(new CMapPatcher(LIBRARY->mapFormat->mapOverrides(scenarioName)));
|
||||
}
|
||||
|
||||
VCMI_LIB_NAMESPACE_END
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include "../GameLibrary.h"
|
||||
#include "../IGameSettings.h"
|
||||
#include "../json/JsonUtils.h"
|
||||
#include "../modding/ModScope.h"
|
||||
|
||||
MapIdentifiersH3M MapFormatSettings::generateMapping(EMapFormat format)
|
||||
{
|
||||
@@ -83,6 +84,10 @@ MapFormatSettings::MapFormatSettings()
|
||||
, campaignOverridesConfig(JsonUtils::assembleFromFiles("config/campaignOverrides.json"))
|
||||
, mapOverridesConfig(JsonUtils::assembleFromFiles("config/mapOverrides.json"))
|
||||
{
|
||||
for (auto & entry : mapOverridesConfig.Struct())
|
||||
JsonUtils::validate(entry.second, "vcmi:mapHeader", "patch for " + entry.first);
|
||||
|
||||
mapOverridesConfig.setModScope(ModScope::scopeMap());
|
||||
}
|
||||
|
||||
VCMI_LIB_NAMESPACE_END
|
||||
|
||||
Reference in New Issue
Block a user