diff --git a/config/campaignOverrides.json b/config/campaignOverrides.json new file mode 100644 index 000000000..abc3cff2e --- /dev/null +++ b/config/campaignOverrides.json @@ -0,0 +1,22 @@ +{ + "MAPS/HC1_MAIN" : { // Heroes Chronicles 1 + "regions": + { + "background": "Hc1_CamBkHc", + "prefix": "Hc1_HcSc", + "suffix": ["_1", "_2", "_3"], + "color_suffix_length": 0, + "desc": [ + { "infix": "1", "x": 27, "y": 43 }, + { "infix": "2", "x": 225, "y": 43 }, + { "infix": "3", "x": 27, "y": 173 }, + { "infix": "4", "x": 225, "y": 173 }, + { "infix": "5", "x": 27, "y": 303 }, + { "infix": "6", "x": 225, "y": 303 }, + { "infix": "7", "x": 27, "y": 433 }, + { "infix": "8", "x": 225, "y": 433 } + ] + }, + "scenarioCount": 8 + } +} diff --git a/launcher/modManager/chroniclesextractor.cpp b/launcher/modManager/chroniclesextractor.cpp index 6d2d63b78..44bb993a6 100644 --- a/launcher/modManager/chroniclesextractor.cpp +++ b/launcher/modManager/chroniclesextractor.cpp @@ -203,7 +203,7 @@ void ChroniclesExtractor::extractFiles(int no) auto rename = [tmpDir, no](QDir dest){ dest.refresh(); for(auto & entry : dest.entryList()) - if(!entry.startsWith("Hc")) + if(!entry.startsWith("Hc" + QString::number(no) + "_")) dest.rename(entry, "Hc" + QString::number(no) + "_" + entry); }; diff --git a/lib/campaign/CampaignHandler.cpp b/lib/campaign/CampaignHandler.cpp index d811f6008..6d5f0ae39 100644 --- a/lib/campaign/CampaignHandler.cpp +++ b/lib/campaign/CampaignHandler.cpp @@ -38,6 +38,7 @@ void CampaignHandler::readCampaign(Campaign * ret, const std::vector & inpu CBinaryReader reader(&stream); readHeaderFromMemory(*ret, reader, filename, modName, encoding); + ret->overrideCampaign(); for(int g = 0; g < ret->numberOfScenarios; ++g) { diff --git a/lib/campaign/CampaignState.cpp b/lib/campaign/CampaignState.cpp index d8236746a..b3180e207 100644 --- a/lib/campaign/CampaignState.cpp +++ b/lib/campaign/CampaignState.cpp @@ -20,6 +20,7 @@ #include "../mapObjects/CGHeroInstance.h" #include "../serializer/JsonDeserializer.h" #include "../serializer/JsonSerializer.h" +#include "../json/JsonUtils.h" VCMI_LIB_NAMESPACE_BEGIN @@ -138,6 +139,20 @@ void CampaignHeader::loadLegacyData(ui8 campId) numberOfScenarios = VLC->generaltexth->getCampaignLength(campId); } +void CampaignHeader::loadLegacyData(CampaignRegions regions, int numOfScenario) +{ + campaignRegions = regions; + numberOfScenarios = numOfScenario; +} + +void CampaignHeader::overrideCampaign() +{ + JsonNode node = JsonUtils::assembleFromFiles("config/campaignOverrides.json"); + for (auto & entry : node.Struct()) + if(filename == entry.first && !entry.second["regions"].isNull() && !entry.second["scenarioCount"].isNull()) + loadLegacyData(CampaignRegions::fromJson(entry.second["regions"]), entry.second["scenarioCount"].Integer()); +} + bool CampaignHeader::playerSelectedDifficulty() const { return difficultyChosenByPlayer; diff --git a/lib/campaign/CampaignState.h b/lib/campaign/CampaignState.h index 17d91e528..950f32910 100644 --- a/lib/campaign/CampaignState.h +++ b/lib/campaign/CampaignState.h @@ -101,6 +101,7 @@ class DLL_LINKAGE CampaignHeader : public boost::noncopyable bool difficultyChosenByPlayer = false; void loadLegacyData(ui8 campId); + void loadLegacyData(CampaignRegions regions, int numOfScenario); TextContainerRegistrable textContainer; @@ -122,6 +123,8 @@ public: const CampaignRegions & getRegions() const; TextContainerRegistrable & getTexts(); + void overrideCampaign(); + template void serialize(Handler &h) { h & version;