1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-30 04:30:42 +02:00

Fixed detection of campaign format

This commit is contained in:
Ivan Savenko 2023-05-24 22:02:03 +03:00
parent 029322f8bb
commit b3ca6c8cee

View File

@ -118,8 +118,7 @@ std::unique_ptr<CCampaign> CCampaignHandler::getCampaign( const std::string & na
std::vector<std::vector<ui8>> files = getFile(std::move(fileStream), false); std::vector<std::vector<ui8>> files = getFile(std::move(fileStream), false);
JsonNode jsonCampaign((const char*)files[0].data(), files[0].size()); if (files[0].front() < uint8_t(' ')) // binary format
if(jsonCampaign.isNull())
{ {
CMemoryStream stream(files[0].data(), files[0].size()); CMemoryStream stream(files[0].data(), files[0].size());
CBinaryReader reader(&stream); CBinaryReader reader(&stream);
@ -128,8 +127,9 @@ std::unique_ptr<CCampaign> CCampaignHandler::getCampaign( const std::string & na
for(int g = 0; g < ret->header.numberOfScenarios; ++g) for(int g = 0; g < ret->header.numberOfScenarios; ++g)
ret->scenarios.emplace_back(readScenarioFromMemory(reader, ret->header)); ret->scenarios.emplace_back(readScenarioFromMemory(reader, ret->header));
} }
else else // text format (json)
{ {
JsonNode jsonCampaign((const char*)files[0].data(), files[0].size());
ret->header = readHeaderFromJson(jsonCampaign, resourceID.getName(), modName, encoding); ret->header = readHeaderFromJson(jsonCampaign, resourceID.getName(), modName, encoding);
for(auto & scenario : jsonCampaign["scenarios"].Vector()) for(auto & scenario : jsonCampaign["scenarios"].Vector())
ret->scenarios.emplace_back(readScenarioFromJson(scenario)); ret->scenarios.emplace_back(readScenarioFromJson(scenario));