MapFormatJson.cpp 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337
  1. /*
  2. * MapFormatJson.cpp, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #include "StdInc.h"
  11. #include "MapFormatJson.h"
  12. #include "../filesystem/CInputStream.h"
  13. #include "../filesystem/COutputStream.h"
  14. #include "../json/JsonWriter.h"
  15. #include "CMap.h"
  16. #include "MapFormat.h"
  17. #include "../ArtifactUtils.h"
  18. #include "../GameLibrary.h"
  19. #include "../RiverHandler.h"
  20. #include "../RoadHandler.h"
  21. #include "../TerrainHandler.h"
  22. #include "../entities/faction/CTownHandler.h"
  23. #include "../entities/hero/CHeroHandler.h"
  24. #include "../mapObjectConstructors/AObjectTypeHandler.h"
  25. #include "../mapObjectConstructors/CObjectClassesHandler.h"
  26. #include "../mapObjects/ObjectTemplate.h"
  27. #include "../mapObjects/CGHeroInstance.h"
  28. #include "../mapObjects/CGTownInstance.h"
  29. #include "../mapObjects/MiscObjects.h"
  30. #include "../modding/ModScope.h"
  31. #include "../modding/ModUtility.h"
  32. #include "../spells/CSpellHandler.h"
  33. #include "../CSkillHandler.h"
  34. #include "../constants/StringConstants.h"
  35. #include "../serializer/JsonDeserializer.h"
  36. #include "../serializer/JsonSerializer.h"
  37. #include "../texts/Languages.h"
  38. VCMI_LIB_NAMESPACE_BEGIN
  39. class MapObjectResolver: public IInstanceResolver
  40. {
  41. public:
  42. MapObjectResolver(const CMapFormatJson * owner_);
  43. si32 decode (const std::string & identifier) const override;
  44. std::string encode(si32 identifier) const override;
  45. private:
  46. const CMapFormatJson * owner;
  47. };
  48. MapObjectResolver::MapObjectResolver(const CMapFormatJson * owner_):
  49. owner(owner_)
  50. {
  51. }
  52. si32 MapObjectResolver::decode(const std::string & identifier) const
  53. {
  54. //always decode as ObjectInstanceID
  55. auto it = owner->map->instanceNames.find(identifier);
  56. if(it != owner->map->instanceNames.end())
  57. {
  58. return (*it).second->id.getNum();
  59. }
  60. else
  61. {
  62. logGlobal->error("Object not found: %s", identifier);
  63. return -1;
  64. }
  65. }
  66. std::string MapObjectResolver::encode(si32 identifier) const
  67. {
  68. ObjectInstanceID id(identifier);
  69. auto object = owner->map->getObject(id);
  70. if(!object)
  71. {
  72. logGlobal->error("Cannot get object with id %d", id.getNum());
  73. return "";
  74. }
  75. return object->instanceName;
  76. }
  77. namespace HeaderDetail
  78. {
  79. static const std::vector<std::string> difficultyMap =
  80. {
  81. "EASY",
  82. "NORMAL",
  83. "HARD",
  84. "EXPERT",
  85. "IMPOSSIBLE"
  86. };
  87. enum class ECanPlay
  88. {
  89. NONE = 0,
  90. PLAYER_OR_AI = 1,
  91. PLAYER_ONLY = 2,
  92. AI_ONLY = 3
  93. };
  94. static const std::vector<std::string> canPlayMap =
  95. {
  96. "",
  97. "PlayerOrAI",
  98. "PlayerOnly",
  99. "AIOnly"
  100. };
  101. }
  102. namespace TriggeredEventsDetail
  103. {
  104. static const std::array conditionNames =
  105. {
  106. "haveArtifact", "haveCreatures", "haveResources", "haveBuilding",
  107. "control", "destroy", "transport", "daysPassed",
  108. "isHuman", "daysWithoutTown", "standardWin", "constValue"
  109. };
  110. static const std::array typeNames = { "victory", "defeat" };
  111. static EventCondition JsonToCondition(const JsonNode & node)
  112. {
  113. EventCondition event;
  114. const auto & conditionName = node.Vector()[0].String();
  115. auto pos = vstd::find_pos(conditionNames, conditionName);
  116. event.condition = static_cast<EventCondition::EWinLoseType>(pos);
  117. if (node.Vector().size() > 1)
  118. {
  119. const JsonNode & data = node.Vector()[1];
  120. event.objectInstanceName = data["object"].String();
  121. event.value = data["value"].Integer();
  122. switch (event.condition)
  123. {
  124. case EventCondition::HAVE_ARTIFACT:
  125. case EventCondition::TRANSPORT:
  126. if (data["type"].isNumber()) // compatibility
  127. event.objectType = ArtifactID(data["type"].Integer());
  128. else
  129. event.objectType = ArtifactID(ArtifactID::decode(data["type"].String()));
  130. break;
  131. case EventCondition::HAVE_CREATURES:
  132. if (data["type"].isNumber()) // compatibility
  133. event.objectType = CreatureID(data["type"].Integer());
  134. else
  135. event.objectType = CreatureID(CreatureID::decode(data["type"].String()));
  136. break;
  137. case EventCondition::HAVE_RESOURCES:
  138. if (data["type"].isNumber()) // compatibility
  139. event.objectType = GameResID(data["type"].Integer());
  140. else
  141. event.objectType = GameResID(GameResID::decode(data["type"].String()));
  142. break;
  143. case EventCondition::HAVE_BUILDING:
  144. if (data["type"].isNumber()) // compatibility
  145. event.objectType = BuildingID(data["type"].Integer());
  146. else
  147. event.objectType = BuildingID(BuildingID::decode(data["type"].String()));
  148. break;
  149. case EventCondition::CONTROL:
  150. case EventCondition::DESTROY:
  151. if (data["type"].isNumber()) // compatibility
  152. event.objectType = MapObjectID(data["type"].Integer());
  153. else
  154. event.objectType = MapObjectID(MapObjectID::decode(data["type"].String()));
  155. break;
  156. }
  157. if (!data["position"].isNull())
  158. {
  159. const auto & position = data["position"].Vector();
  160. event.position.x = static_cast<si32>(position.at(0).Float());
  161. event.position.y = static_cast<si32>(position.at(1).Float());
  162. event.position.z = static_cast<si32>(position.at(2).Float());
  163. }
  164. }
  165. return event;
  166. }
  167. static JsonNode ConditionToJson(const EventCondition & event)
  168. {
  169. JsonNode json;
  170. JsonVector & asVector = json.Vector();
  171. JsonNode condition;
  172. condition.String() = conditionNames.at(event.condition);
  173. asVector.push_back(condition);
  174. JsonNode data;
  175. if(!event.objectInstanceName.empty())
  176. data["object"].String() = event.objectInstanceName;
  177. data["type"].String() = event.objectType.toString();
  178. data["value"].Integer() = event.value;
  179. if(event.position != int3(-1, -1, -1))
  180. {
  181. auto & position = data["position"].Vector();
  182. position.resize(3);
  183. position[0].Float() = event.position.x;
  184. position[1].Float() = event.position.y;
  185. position[2].Float() = event.position.z;
  186. }
  187. if(!data.isNull())
  188. asVector.push_back(data);
  189. return json;
  190. }
  191. }//namespace TriggeredEventsDetail
  192. namespace TerrainDetail
  193. {
  194. static const std::array<char, 4> flipCodes =
  195. {
  196. '_', '-', '|', '+'
  197. };
  198. }
  199. ///CMapFormatJson
  200. const int CMapFormatJson::VERSION_MAJOR = 2;
  201. const int CMapFormatJson::VERSION_MINOR = 0;
  202. const std::string CMapFormatJson::HEADER_FILE_NAME = "header.json";
  203. const std::string CMapFormatJson::OBJECTS_FILE_NAME = "objects.json";
  204. const std::string CMapFormatJson::TERRAIN_FILE_NAMES[2] = {"surface_terrain.json", "underground_terrain.json"};
  205. CMapFormatJson::CMapFormatJson():
  206. fileVersionMajor(0), fileVersionMinor(0),
  207. mapObjectResolver(std::make_unique<MapObjectResolver>(this)),
  208. map(nullptr), mapHeader(nullptr)
  209. {
  210. }
  211. TerrainId CMapFormatJson::getTerrainByCode(const std::string & code)
  212. {
  213. for(const auto & object : LIBRARY->terrainTypeHandler->objects)
  214. {
  215. if(object->shortIdentifier == code)
  216. return object->getId();
  217. }
  218. return TerrainId::NONE;
  219. }
  220. RiverId CMapFormatJson::getRiverByCode(const std::string & code)
  221. {
  222. for(const auto & object : LIBRARY->riverTypeHandler->objects)
  223. {
  224. if (object->shortIdentifier == code)
  225. return object->getId();
  226. }
  227. return RiverId::NO_RIVER;
  228. }
  229. RoadId CMapFormatJson::getRoadByCode(const std::string & code)
  230. {
  231. for(const auto & object : LIBRARY->roadTypeHandler->objects)
  232. {
  233. if (object->shortIdentifier == code)
  234. return object->getId();
  235. }
  236. return RoadId::NO_ROAD;
  237. }
  238. void CMapFormatJson::serializeAllowedFactions(JsonSerializeFormat & handler, std::set<FactionID> & value) const
  239. {
  240. std::set<FactionID> temp;
  241. if(handler.saving)
  242. {
  243. for(auto const factionID : LIBRARY->townh->getDefaultAllowed())
  244. if(vstd::contains(value, factionID))
  245. temp.insert(factionID);
  246. }
  247. handler.serializeLIC("allowedFactions", &FactionID::decode, &FactionID::encode, LIBRARY->townh->getDefaultAllowed(), temp);
  248. if(!handler.saving)
  249. value = temp;
  250. }
  251. void CMapFormatJson::serializeHeader(JsonSerializeFormat & handler)
  252. {
  253. handler.serializeStruct("name", mapHeader->name);
  254. handler.serializeStruct("description", mapHeader->description);
  255. handler.serializeStruct("author", mapHeader->author);
  256. handler.serializeStruct("authorContact", mapHeader->authorContact);
  257. handler.serializeStruct("mapVersion", mapHeader->mapVersion);
  258. handler.serializeInt("creationDateTime", mapHeader->creationDateTime, 0);
  259. handler.serializeInt("heroLevelLimit", mapHeader->levelLimit, 0);
  260. //todo: support arbitrary percentage
  261. handler.serializeEnum("difficulty", mapHeader->difficulty, HeaderDetail::difficultyMap);
  262. serializePlayerInfo(handler);
  263. handler.serializeLIC("allowedHeroes", &HeroTypeID::decode, &HeroTypeID::encode, LIBRARY->heroh->getDefaultAllowed(), mapHeader->allowedHeroes);
  264. handler.serializeStruct("victoryMessage", mapHeader->victoryMessage);
  265. handler.serializeInt("victoryIconIndex", mapHeader->victoryIconIndex);
  266. handler.serializeStruct("defeatMessage", mapHeader->defeatMessage);
  267. handler.serializeInt("defeatIconIndex", mapHeader->defeatIconIndex);
  268. handler.serializeIdArray("reservedCampaignHeroes", mapHeader->reservedCampaignHeroes);
  269. }
  270. void CMapFormatJson::serializePlayerInfo(JsonSerializeFormat & handler)
  271. {
  272. auto playersData = handler.enterStruct("players");
  273. for(int player = 0; player < PlayerColor::PLAYER_LIMIT_I; player++)
  274. {
  275. PlayerInfo & info = mapHeader->players[player];
  276. if(handler.saving)
  277. {
  278. if(!info.canAnyonePlay())
  279. continue;
  280. }
  281. auto playerData = handler.enterStruct(GameConstants::PLAYER_COLOR_NAMES[player]);
  282. if(!handler.saving)
  283. {
  284. if(handler.getCurrent().isNull())
  285. {
  286. info.canComputerPlay = false;
  287. info.canHumanPlay = false;
  288. continue;
  289. }
  290. }
  291. serializeAllowedFactions(handler, info.allowedFactions);
  292. HeaderDetail::ECanPlay canPlay = HeaderDetail::ECanPlay::NONE;
  293. if(handler.saving)
  294. {
  295. if(info.canComputerPlay)
  296. {
  297. canPlay = info.canHumanPlay ? HeaderDetail::ECanPlay::PLAYER_OR_AI : HeaderDetail::ECanPlay::AI_ONLY;
  298. }
  299. else
  300. {
  301. canPlay = info.canHumanPlay ? HeaderDetail::ECanPlay::PLAYER_ONLY : HeaderDetail::ECanPlay::NONE;
  302. }
  303. }
  304. handler.serializeEnum("canPlay", canPlay, HeaderDetail::canPlayMap);
  305. if(!handler.saving)
  306. {
  307. switch(canPlay)
  308. {
  309. case HeaderDetail::ECanPlay::PLAYER_OR_AI:
  310. info.canComputerPlay = true;
  311. info.canHumanPlay = true;
  312. break;
  313. case HeaderDetail::ECanPlay::PLAYER_ONLY:
  314. info.canComputerPlay = false;
  315. info.canHumanPlay = true;
  316. break;
  317. case HeaderDetail::ECanPlay::AI_ONLY:
  318. info.canComputerPlay = true;
  319. info.canHumanPlay = false;
  320. break;
  321. default:
  322. info.canComputerPlay = false;
  323. info.canHumanPlay = false;
  324. break;
  325. }
  326. }
  327. //saving whole structure only if position is valid
  328. if(!handler.saving || info.posOfMainTown.isValid())
  329. {
  330. auto mainTown = handler.enterStruct("mainTown");
  331. handler.serializeBool("generateHero", info.generateHeroAtMainTown);
  332. handler.serializeInt("x", info.posOfMainTown.x, -1);
  333. handler.serializeInt("y", info.posOfMainTown.y, -1);
  334. handler.serializeInt("l", info.posOfMainTown.z, -1);
  335. }
  336. if(!handler.saving)
  337. {
  338. info.hasMainTown = info.posOfMainTown.isValid();
  339. }
  340. handler.serializeString("mainHero", info.mainHeroInstance);//must be before "heroes"
  341. //heroes
  342. if(handler.saving)
  343. {
  344. //ignoring heroesNames and saving from actual map objects
  345. //TODO: optimize
  346. for(auto & hero : map->getObjects<CGHeroInstance>())
  347. {
  348. if((hero->getOwner()) == PlayerColor(player))
  349. {
  350. auto heroes = handler.enterStruct("heroes");
  351. if(hero)
  352. {
  353. auto heroData = handler.enterStruct(hero->instanceName);
  354. heroData->serializeString("name", hero->nameCustomTextId);
  355. if(hero->ID == Obj::HERO)
  356. {
  357. std::string temp;
  358. if(hero->getHeroTypeID().hasValue())
  359. temp = hero->getHeroType()->getJsonKey();
  360. handler.serializeString("type", temp);
  361. }
  362. }
  363. }
  364. }
  365. }
  366. else
  367. {
  368. info.heroesNames.clear();
  369. auto heroes = handler.enterStruct("heroes");
  370. for(const auto & hero : handler.getCurrent().Struct())
  371. {
  372. const JsonNode & data = hero.second;
  373. const std::string instanceName = hero.first;
  374. SHeroName hname;
  375. hname.heroId = HeroTypeID::NONE;
  376. std::string rawId = data["type"].String();
  377. if(!rawId.empty())
  378. hname.heroId = HeroTypeID(HeroTypeID::decode(rawId));
  379. hname.heroName = data["name"].String();
  380. if(instanceName == info.mainHeroInstance)
  381. {
  382. //this is main hero
  383. info.mainCustomHeroNameTextId = hname.heroName;
  384. info.hasRandomHero = (hname.heroId == HeroTypeID::NONE);
  385. info.mainCustomHeroId = hname.heroId;
  386. info.mainCustomHeroPortrait = HeroTypeID::NONE;
  387. //todo:mainHeroPortrait
  388. }
  389. info.heroesNames.push_back(hname);
  390. }
  391. }
  392. handler.serializeBool("randomFaction", info.isFactionRandom);
  393. }
  394. }
  395. void CMapFormatJson::readTeams(JsonDeserializer & handler)
  396. {
  397. auto teams = handler.enterArray("teams");
  398. const JsonNode & src = teams->getCurrent();
  399. if(src.getType() != JsonNode::JsonType::DATA_VECTOR)
  400. {
  401. // No alliances
  402. if(src.getType() != JsonNode::JsonType::DATA_NULL)
  403. logGlobal->error("Invalid teams field type");
  404. mapHeader->howManyTeams = 0;
  405. for(auto & player : mapHeader->players)
  406. if(player.canAnyonePlay())
  407. player.team = TeamID(mapHeader->howManyTeams++);
  408. }
  409. else
  410. {
  411. const JsonVector & srcVector = src.Vector();
  412. mapHeader->howManyTeams = static_cast<ui8>(srcVector.size());
  413. for(int team = 0; team < mapHeader->howManyTeams; team++)
  414. for(const JsonNode & playerData : srcVector[team].Vector())
  415. {
  416. PlayerColor player = PlayerColor(vstd::find_pos(GameConstants::PLAYER_COLOR_NAMES, playerData.String()));
  417. if(player.isValidPlayer())
  418. if(mapHeader->players[player.getNum()].canAnyonePlay())
  419. mapHeader->players[player.getNum()].team = TeamID(team);
  420. }
  421. for(PlayerInfo & player : mapHeader->players)
  422. if(player.canAnyonePlay() && player.team == TeamID::NO_TEAM)
  423. player.team = TeamID(mapHeader->howManyTeams++);
  424. }
  425. }
  426. void CMapFormatJson::writeTeams(JsonSerializer & handler)
  427. {
  428. std::vector<std::set<PlayerColor>> teamsData;
  429. teamsData.resize(mapHeader->howManyTeams);
  430. //get raw data
  431. for(int idx = 0; idx < mapHeader->players.size(); idx++)
  432. {
  433. const PlayerInfo & player = mapHeader->players.at(idx);
  434. int team = player.team.getNum();
  435. if(vstd::iswithin(team, 0, mapHeader->howManyTeams-1) && player.canAnyonePlay())
  436. teamsData.at(team).insert(PlayerColor(idx));
  437. }
  438. //remove single-member teams
  439. vstd::erase_if(teamsData, [](std::set<PlayerColor> & elem) -> bool
  440. {
  441. return elem.size() <= 1;
  442. });
  443. if(!teamsData.empty())
  444. {
  445. JsonNode dest;
  446. //construct output
  447. dest.setType(JsonNode::JsonType::DATA_VECTOR);
  448. for(const std::set<PlayerColor> & teamData : teamsData)
  449. {
  450. JsonNode team;
  451. for(const PlayerColor & player : teamData)
  452. team.Vector().emplace_back(GameConstants::PLAYER_COLOR_NAMES[player.getNum()]);
  453. dest.Vector().push_back(std::move(team));
  454. }
  455. handler.serializeRaw("teams", dest, std::nullopt);
  456. }
  457. }
  458. void CMapFormatJson::readTriggeredEvents(JsonDeserializer & handler)
  459. {
  460. const JsonNode & input = handler.getCurrent();
  461. mapHeader->triggeredEvents.clear();
  462. for(const auto & entry : input["triggeredEvents"].Struct())
  463. {
  464. TriggeredEvent event;
  465. event.identifier = entry.first;
  466. readTriggeredEvent(event, entry.second);
  467. mapHeader->triggeredEvents.push_back(event);
  468. }
  469. }
  470. void CMapFormatJson::readTriggeredEvent(TriggeredEvent & event, const JsonNode & source) const
  471. {
  472. using namespace TriggeredEventsDetail;
  473. event.onFulfill.jsonDeserialize(source["message"]);
  474. event.description.jsonDeserialize(source["description"]);
  475. event.effect.type = vstd::find_pos(typeNames, source["effect"]["type"].String());
  476. event.effect.toOtherMessage.jsonDeserialize(source["effect"]["messageToSend"]);
  477. event.trigger = EventExpression(source["condition"], JsonToCondition); // logical expression
  478. }
  479. void CMapFormatJson::writeTriggeredEvents(JsonSerializer & handler)
  480. {
  481. JsonNode triggeredEvents;
  482. for(const auto & event : mapHeader->triggeredEvents)
  483. writeTriggeredEvent(event, triggeredEvents[event.identifier]);
  484. handler.serializeRaw("triggeredEvents", triggeredEvents, std::nullopt);
  485. }
  486. void CMapFormatJson::writeTriggeredEvent(const TriggeredEvent & event, JsonNode & dest) const
  487. {
  488. using namespace TriggeredEventsDetail;
  489. if(!event.onFulfill.empty())
  490. event.onFulfill.jsonSerialize(dest["message"]);
  491. if(!event.description.empty())
  492. event.description.jsonSerialize(dest["description"]);
  493. dest["effect"]["type"].String() = typeNames.at(static_cast<size_t>(event.effect.type));
  494. if(!event.effect.toOtherMessage.empty())
  495. event.description.jsonSerialize(dest["effect"]["messageToSend"]);
  496. dest["condition"] = event.trigger.toJson(ConditionToJson);
  497. }
  498. void CMapFormatJson::readDisposedHeroes(JsonSerializeFormat & handler)
  499. {
  500. auto definitions = handler.enterStruct("predefinedHeroes");//DisposedHeroes are part of predefinedHeroes in VCMI map format
  501. const JsonNode & data = handler.getCurrent();
  502. for(const auto & entry : data.Struct())
  503. {
  504. HeroTypeID type(HeroTypeID::decode(entry.first));
  505. std::set<PlayerColor> mask;
  506. for(const JsonNode & playerData : entry.second["availableFor"].Vector())
  507. {
  508. PlayerColor player = PlayerColor(vstd::find_pos(GameConstants::PLAYER_COLOR_NAMES, playerData.String()));
  509. if(player.isValidPlayer())
  510. mask.insert(player);
  511. }
  512. if(!mask.empty() && mask.size() != PlayerColor::PLAYER_LIMIT_I && type.getNum() >= 0)
  513. {
  514. DisposedHero hero;
  515. hero.heroId = type;
  516. hero.players = mask;
  517. //name and portrait are not used
  518. mapHeader->disposedHeroes.push_back(hero);
  519. }
  520. }
  521. }
  522. void CMapFormatJson::writeDisposedHeroes(JsonSerializeFormat & handler)
  523. {
  524. if(mapHeader->disposedHeroes.empty())
  525. return;
  526. auto definitions = handler.enterStruct("predefinedHeroes");//DisposedHeroes are part of predefinedHeroes in VCMI map format
  527. for(DisposedHero & hero : mapHeader->disposedHeroes)
  528. {
  529. std::string type = HeroTypeID::encode(hero.heroId.getNum());
  530. auto definition = definitions->enterStruct(type);
  531. JsonNode players;
  532. definition->serializeIdArray("availableFor", hero.players);
  533. }
  534. }
  535. void CMapFormatJson::serializeRumors(JsonSerializeFormat & handler)
  536. {
  537. auto rumors = handler.enterArray("rumors");
  538. rumors.serializeStruct(map->rumors);
  539. }
  540. void CMapFormatJson::serializeTimedEvents(JsonSerializeFormat & handler)
  541. {
  542. auto events = handler.enterArray("events");
  543. std::vector<CMapEvent> temp(map->events.begin(), map->events.end());
  544. events.serializeStruct(temp);
  545. map->events.assign(temp.begin(), temp.end());
  546. }
  547. void CMapFormatJson::serializePredefinedHeroes(JsonSerializeFormat & handler)
  548. {
  549. if(handler.saving)
  550. {
  551. auto heroPool = map->getHeroesInPool();
  552. if(!heroPool.empty())
  553. {
  554. auto predefinedHeroes = handler.enterStruct("predefinedHeroes");
  555. for(auto & heroID : heroPool)
  556. {
  557. auto heroPtr = map->tryGetFromHeroPool(heroID);
  558. auto predefinedHero = handler.enterStruct(heroPtr->getHeroTypeName());
  559. heroPtr->serializeJsonDefinition(handler);
  560. }
  561. }
  562. }
  563. else
  564. {
  565. auto predefinedHeroes = handler.enterStruct("predefinedHeroes");
  566. const JsonNode & data = handler.getCurrent();
  567. for(const auto & p : data.Struct())
  568. {
  569. auto predefinedHero = handler.enterStruct(p.first);
  570. auto hero = std::make_shared<CGHeroInstance>(map->cb);
  571. hero->ID = Obj::HERO;
  572. hero->setHeroTypeName(p.first);
  573. hero->serializeJsonDefinition(handler);
  574. map->addToHeroPool(hero);
  575. }
  576. }
  577. }
  578. void CMapFormatJson::serializeOptions(JsonSerializeFormat & handler)
  579. {
  580. serializeRumors(handler);
  581. serializeTimedEvents(handler);
  582. serializePredefinedHeroes(handler);
  583. handler.serializeLIC("allowedAbilities", &SecondarySkill::decode, &SecondarySkill::encode, LIBRARY->skillh->getDefaultAllowed(), map->allowedAbilities);
  584. handler.serializeLIC("allowedArtifacts", &ArtifactID::decode, &ArtifactID::encode, LIBRARY->arth->getDefaultAllowed(), map->allowedArtifact);
  585. handler.serializeLIC("allowedSpells", &SpellID::decode, &SpellID::encode, LIBRARY->spellh->getDefaultAllowed(), map->allowedSpells);
  586. //todo:events
  587. }
  588. void CMapFormatJson::readOptions(JsonDeserializer & handler)
  589. {
  590. readDisposedHeroes(handler);
  591. serializeOptions(handler);
  592. }
  593. void CMapFormatJson::writeOptions(JsonSerializer & handler)
  594. {
  595. writeDisposedHeroes(handler);
  596. serializeOptions(handler);
  597. }
  598. ///CMapPatcher
  599. CMapPatcher::CMapPatcher(const JsonNode & stream): input(stream)
  600. {
  601. //todo: update map patches and change this
  602. fileVersionMajor = 0;
  603. fileVersionMinor = 0;
  604. }
  605. void CMapPatcher::patchMapHeader(std::unique_ptr<CMapHeader> & header)
  606. {
  607. map = nullptr;
  608. mapHeader = header.get();
  609. if (!input.isNull())
  610. readPatchData();
  611. }
  612. void CMapPatcher::readPatchData()
  613. {
  614. JsonDeserializer handler(mapObjectResolver.get(), input);
  615. readTriggeredEvents(handler);
  616. handler.serializeInt("defeatIconIndex", mapHeader->defeatIconIndex);
  617. handler.serializeInt("victoryIconIndex", mapHeader->victoryIconIndex);
  618. handler.serializeStruct("victoryString", mapHeader->victoryMessage);
  619. handler.serializeStruct("defeatString", mapHeader->defeatMessage);
  620. }
  621. ///CMapLoaderJson
  622. CMapLoaderJson::CMapLoaderJson(CInputStream * stream)
  623. : buffer(stream)
  624. , ioApi(new CProxyROIOApi(buffer))
  625. , loader("", "_", ioApi)
  626. {
  627. }
  628. std::unique_ptr<CMap> CMapLoaderJson::loadMap(IGameCallback * cb)
  629. {
  630. LOG_TRACE(logGlobal);
  631. auto result = std::make_unique<CMap>(cb);
  632. map = result.get();
  633. mapHeader = map;
  634. readMap();
  635. return result;
  636. }
  637. std::unique_ptr<CMapHeader> CMapLoaderJson::loadMapHeader()
  638. {
  639. LOG_TRACE(logGlobal);
  640. map = nullptr;
  641. auto result = std::make_unique<CMapHeader>();
  642. mapHeader = result.get();
  643. readHeader(false);
  644. return result;
  645. }
  646. bool CMapLoaderJson::isExistArchive(const std::string & archiveFilename)
  647. {
  648. return loader.existsResource(JsonPath::builtin(archiveFilename));
  649. }
  650. JsonNode CMapLoaderJson::getFromArchive(const std::string & archiveFilename)
  651. {
  652. JsonPath resource = JsonPath::builtin(archiveFilename);
  653. if(!loader.existsResource(resource))
  654. throw std::runtime_error(archiveFilename+" not found");
  655. auto data = loader.load(resource)->readAll();
  656. JsonNode res(reinterpret_cast<const std::byte*>(data.first.get()), data.second, archiveFilename);
  657. return res;
  658. }
  659. void CMapLoaderJson::readMap()
  660. {
  661. LOG_TRACE(logGlobal);
  662. readHeader(true);
  663. map->initTerrain();
  664. readTerrain();
  665. readObjects();
  666. map->calculateGuardingGreaturePositions();
  667. }
  668. void CMapLoaderJson::readHeader(const bool complete)
  669. {
  670. //do not use map field here, use only mapHeader
  671. JsonNode header = getFromArchive(HEADER_FILE_NAME);
  672. fileVersionMajor = static_cast<int>(header["versionMajor"].Integer());
  673. if(fileVersionMajor > VERSION_MAJOR)
  674. {
  675. logGlobal->error("Unsupported map format version: %d", fileVersionMajor);
  676. throw std::runtime_error("Unsupported map format version");
  677. }
  678. fileVersionMinor = static_cast<int>(header["versionMinor"].Integer());
  679. if(fileVersionMinor > VERSION_MINOR)
  680. {
  681. logGlobal->warn("Too new map format revision: %d. This map should work but some of map features may be ignored.", fileVersionMinor);
  682. }
  683. JsonDeserializer handler(mapObjectResolver.get(), header);
  684. mapHeader->version = EMapFormat::VCMI;//todo: new version field
  685. //loading mods
  686. mapHeader->mods = ModVerificationInfo::jsonDeserializeList(header["mods"]);
  687. //todo: multilevel map load support
  688. {
  689. auto levels = handler.enterStruct("mapLevels");
  690. {
  691. auto surface = handler.enterStruct("surface");
  692. handler.serializeInt("height", mapHeader->height);
  693. handler.serializeInt("width", mapHeader->width);
  694. }
  695. {
  696. auto underground = handler.enterStruct("underground");
  697. mapHeader->twoLevel = !underground->getCurrent().isNull();
  698. }
  699. }
  700. serializeHeader(handler);
  701. readTriggeredEvents(handler);
  702. readTeams(handler);
  703. //TODO: check mods
  704. if(complete)
  705. readOptions(handler);
  706. readTranslations();
  707. }
  708. void CMapLoaderJson::readTerrainTile(const std::string & src, TerrainTile & tile)
  709. {
  710. try
  711. {
  712. using namespace TerrainDetail;
  713. {//terrain type
  714. const std::string typeCode = src.substr(0, 2);
  715. tile.terrainType = getTerrainByCode(typeCode);
  716. }
  717. int startPos = 2; //0+typeCode fixed length
  718. {//terrain view
  719. int pos = startPos;
  720. while (isdigit(src.at(pos)))
  721. pos++;
  722. int len = pos - startPos;
  723. if (len <= 0)
  724. throw std::runtime_error("Invalid terrain view in " + src);
  725. const std::string rawCode = src.substr(startPos, len);
  726. tile.terView = atoi(rawCode.c_str());
  727. startPos += len;
  728. }
  729. {//terrain flip
  730. int terrainFlip = vstd::find_pos(flipCodes, src.at(startPos++));
  731. if (terrainFlip < 0)
  732. throw std::runtime_error("Invalid terrain flip in " + src);
  733. else
  734. tile.extTileFlags = terrainFlip;
  735. }
  736. if (startPos >= src.size())
  737. return;
  738. bool hasRoad = true;
  739. {//road type
  740. const std::string typeCode = src.substr(startPos, 2);
  741. startPos += 2;
  742. tile.roadType = getRoadByCode(typeCode);
  743. if(!tile.roadType) //it's not a road, it's a river
  744. {
  745. tile.roadType = Road::NO_ROAD;
  746. tile.riverType = getRiverByCode(typeCode);
  747. hasRoad = false;
  748. if(!tile.riverType)
  749. {
  750. throw std::runtime_error("Invalid river type in " + src);
  751. }
  752. }
  753. }
  754. if (hasRoad)
  755. {//road dir
  756. int pos = startPos;
  757. while (isdigit(src.at(pos)))
  758. pos++;
  759. int len = pos - startPos;
  760. if (len <= 0)
  761. throw std::runtime_error("Invalid road dir in " + src);
  762. const std::string rawCode = src.substr(startPos, len);
  763. tile.roadDir = atoi(rawCode.c_str());
  764. startPos += len;
  765. }
  766. if (hasRoad)
  767. {//road flip
  768. int flip = vstd::find_pos(flipCodes, src.at(startPos++));
  769. if (flip < 0)
  770. throw std::runtime_error("Invalid road flip in " + src);
  771. else
  772. tile.extTileFlags |= (flip << 4);
  773. }
  774. if (startPos >= src.size())
  775. return;
  776. if (hasRoad)
  777. {//river type
  778. const std::string typeCode = src.substr(startPos, 2);
  779. startPos += 2;
  780. tile.riverType = getRiverByCode(typeCode);
  781. }
  782. {//river dir
  783. int pos = startPos;
  784. while (isdigit(src.at(pos)))
  785. pos++;
  786. int len = pos - startPos;
  787. if (len <= 0)
  788. throw std::runtime_error("Invalid river dir in " + src);
  789. const std::string rawCode = src.substr(startPos, len);
  790. tile.riverDir = atoi(rawCode.c_str());
  791. startPos += len;
  792. }
  793. {//river flip
  794. int flip = vstd::find_pos(flipCodes, src.at(startPos++));
  795. if (flip < 0)
  796. throw std::runtime_error("Invalid road flip in " + src);
  797. else
  798. tile.extTileFlags |= (flip << 2);
  799. }
  800. }
  801. catch (const std::exception &)
  802. {
  803. logGlobal->error("Failed to read terrain tile: %s");
  804. }
  805. }
  806. void CMapLoaderJson::readTerrainLevel(const JsonNode & src, const int index)
  807. {
  808. int3 pos(0, 0, index);
  809. const JsonVector & rows = src.Vector();
  810. if(rows.size() != map->height)
  811. throw std::runtime_error("Invalid terrain data");
  812. for(pos.y = 0; pos.y < map->height; pos.y++)
  813. {
  814. const JsonVector & tiles = rows[pos.y].Vector();
  815. if(tiles.size() != map->width)
  816. throw std::runtime_error("Invalid terrain data");
  817. for(pos.x = 0; pos.x < map->width; pos.x++)
  818. readTerrainTile(tiles[pos.x].String(), map->getTile(pos));
  819. }
  820. }
  821. void CMapLoaderJson::readTerrain()
  822. {
  823. {
  824. const JsonNode surface = getFromArchive(TERRAIN_FILE_NAMES[0]);
  825. readTerrainLevel(surface, 0);
  826. }
  827. if(map->twoLevel)
  828. {
  829. const JsonNode underground = getFromArchive(TERRAIN_FILE_NAMES[1]);
  830. readTerrainLevel(underground, 1);
  831. }
  832. }
  833. CMapLoaderJson::MapObjectLoader::MapObjectLoader(CMapLoaderJson * _owner, JsonMap::value_type & json):
  834. owner(_owner), instance(nullptr), id(-1), jsonKey(json.first), configuration(json.second)
  835. {
  836. }
  837. void CMapLoaderJson::MapObjectLoader::construct()
  838. {
  839. //TODO:consider move to ObjectTypeHandler
  840. //find type handler
  841. std::string typeName = configuration["type"].String();
  842. std::string subtypeName = configuration["subtype"].String();
  843. if(typeName.empty())
  844. {
  845. logGlobal->error("Object type missing");
  846. logGlobal->debug(configuration.toString());
  847. return;
  848. }
  849. int3 pos;
  850. pos.x = static_cast<si32>(configuration["x"].Float());
  851. pos.y = static_cast<si32>(configuration["y"].Float());
  852. pos.z = static_cast<si32>(configuration["l"].Float());
  853. //special case for grail
  854. if(typeName == "grail")
  855. {
  856. owner->map->grailPos = pos;
  857. owner->map->grailRadius = static_cast<int>(configuration["options"]["grailRadius"].Float());
  858. return;
  859. }
  860. else if(subtypeName.empty())
  861. {
  862. logGlobal->error("Object subtype missing");
  863. logGlobal->debug(configuration.toString());
  864. return;
  865. }
  866. auto handler = LIBRARY->objtypeh->getHandlerFor( ModScope::scopeMap(), typeName, subtypeName);
  867. auto appearance = std::make_shared<ObjectTemplate>();
  868. appearance->id = Obj(handler->getIndex());
  869. appearance->subid = handler->getSubIndex();
  870. appearance->readJson(configuration["template"], false);
  871. // Will be destroyed soon and replaced with shared template
  872. instance = handler->create(owner->map->cb, appearance);
  873. instance->instanceName = jsonKey;
  874. instance->setAnchorPos(pos);
  875. owner->map->addNewObject(instance);
  876. }
  877. void CMapLoaderJson::MapObjectLoader::configure()
  878. {
  879. if(nullptr == instance)
  880. return;
  881. JsonDeserializer handler(owner->mapObjectResolver.get(), configuration);
  882. instance->serializeJson(handler);
  883. //artifact instance serialization requires access to Map object, handle it here for now
  884. //todo: find better solution for artifact instance serialization
  885. if(auto art = std::dynamic_pointer_cast<CGArtifact>(instance))
  886. {
  887. ArtifactID artID = ArtifactID::NONE;
  888. SpellID spellID = SpellID::NONE;
  889. if(art->ID == Obj::SPELL_SCROLL)
  890. {
  891. auto spellIdentifier = configuration["options"]["spell"].String();
  892. auto rawId = LIBRARY->identifiers()->getIdentifier(ModScope::scopeBuiltin(), "spell", spellIdentifier);
  893. if(rawId)
  894. spellID = rawId.value();
  895. else
  896. spellID = 0;
  897. artID = ArtifactID::SPELL_SCROLL;
  898. }
  899. else if(art->ID == Obj::ARTIFACT)
  900. {
  901. //specific artifact
  902. artID = art->getArtifact();
  903. }
  904. art->storedArtifact = owner->map->createArtifact(artID, spellID.getNum());
  905. }
  906. if(auto hero = std::dynamic_pointer_cast<CGHeroInstance>(instance))
  907. {
  908. auto o = handler.enterStruct("options");
  909. hero->serializeJsonArtifacts(handler, "artifacts", owner->map);
  910. }
  911. }
  912. void CMapLoaderJson::readObjects()
  913. {
  914. LOG_TRACE(logGlobal);
  915. std::vector<std::unique_ptr<MapObjectLoader>> loaders;//todo: optimize MapObjectLoader memory layout
  916. JsonNode data = getFromArchive(OBJECTS_FILE_NAME);
  917. //get raw data
  918. for(auto & p : data.Struct())
  919. loaders.push_back(std::make_unique<MapObjectLoader>(this, p));
  920. for(auto & ptr : loaders)
  921. ptr->construct();
  922. //configure objects after all objects are constructed so we may resolve internal IDs even to actual pointers OTF
  923. for(auto & ptr : loaders)
  924. ptr->configure();
  925. map->postInitialize();
  926. std::set<HeroTypeID> debugHeroesOnMap;
  927. for (auto const & hero : map->getObjects<CGHeroInstance>())
  928. {
  929. if(hero->ID != Obj::HERO && hero->ID != Obj::PRISON)
  930. continue;
  931. if (debugHeroesOnMap.count(hero->getHeroTypeID()))
  932. logGlobal->error("Hero is already on the map at %s", hero->visitablePos().toString());
  933. debugHeroesOnMap.insert(hero->getHeroTypeID());
  934. }
  935. }
  936. void CMapLoaderJson::readTranslations()
  937. {
  938. std::list<Languages::Options> languages{Languages::getLanguageList().begin(), Languages::getLanguageList().end()};
  939. for(auto & language : Languages::getLanguageList())
  940. {
  941. if(isExistArchive(language.identifier + ".json"))
  942. mapHeader->translations.Struct()[language.identifier] = getFromArchive(language.identifier + ".json");
  943. }
  944. mapHeader->registerMapStrings();
  945. }
  946. ///CMapSaverJson
  947. CMapSaverJson::CMapSaverJson(CInputOutputStream * stream)
  948. : buffer(stream)
  949. , ioApi(new CProxyIOApi(buffer))
  950. , saver(ioApi, "_")
  951. {
  952. fileVersionMajor = VERSION_MAJOR;
  953. fileVersionMinor = VERSION_MINOR;
  954. }
  955. //must be instantiated in .cpp file for access to complete types of all member fields
  956. CMapSaverJson::~CMapSaverJson() = default;
  957. void CMapSaverJson::addToArchive(const JsonNode & data, const std::string & filename)
  958. {
  959. std::ostringstream out;
  960. JsonWriter writer(out, false);
  961. writer.writeNode(data);
  962. out.flush();
  963. {
  964. auto s = out.str();
  965. std::unique_ptr<COutputStream> stream = saver.addFile(filename);
  966. if(stream->write(reinterpret_cast<const ui8 *>(s.c_str()), s.size()) != s.size())
  967. throw std::runtime_error("CMapSaverJson::saveHeader() zip compression failed.");
  968. }
  969. }
  970. void CMapSaverJson::saveMap(const std::unique_ptr<CMap>& map)
  971. {
  972. this->map = map.get();
  973. this->mapHeader = this->map;
  974. writeHeader();
  975. writeTerrain();
  976. writeObjects();
  977. }
  978. void CMapSaverJson::writeHeader()
  979. {
  980. logGlobal->trace("Saving header");
  981. JsonNode header;
  982. JsonSerializer handler(mapObjectResolver.get(), header);
  983. header["versionMajor"].Float() = VERSION_MAJOR;
  984. header["versionMinor"].Float() = VERSION_MINOR;
  985. //write mods
  986. header["mods"] = ModVerificationInfo::jsonSerializeList(mapHeader->mods);
  987. //todo: multilevel map save support
  988. JsonNode & levels = header["mapLevels"];
  989. levels["surface"]["height"].Float() = mapHeader->height;
  990. levels["surface"]["width"].Float() = mapHeader->width;
  991. levels["surface"]["index"].Float() = 0;
  992. if(mapHeader->twoLevel)
  993. {
  994. levels["underground"]["height"].Float() = mapHeader->height;
  995. levels["underground"]["width"].Float() = mapHeader->width;
  996. levels["underground"]["index"].Float() = 1;
  997. }
  998. serializeHeader(handler);
  999. writeTriggeredEvents(handler);
  1000. writeTeams(handler);
  1001. writeOptions(handler);
  1002. writeTranslations();
  1003. addToArchive(header, HEADER_FILE_NAME);
  1004. }
  1005. std::string CMapSaverJson::writeTerrainTile(const TerrainTile & tile)
  1006. {
  1007. using namespace TerrainDetail;
  1008. std::ostringstream out;
  1009. out.setf(std::ios::dec, std::ios::basefield);
  1010. out.unsetf(std::ios::showbase);
  1011. out << tile.getTerrain()->shortIdentifier << static_cast<int>(tile.terView) << flipCodes[tile.extTileFlags % 4];
  1012. if(tile.hasRoad())
  1013. out << tile.getRoad()->shortIdentifier << static_cast<int>(tile.roadDir) << flipCodes[(tile.extTileFlags >> 4) % 4];
  1014. if(tile.hasRiver())
  1015. out << tile.getRiver()->shortIdentifier << static_cast<int>(tile.riverDir) << flipCodes[(tile.extTileFlags >> 2) % 4];
  1016. return out.str();
  1017. }
  1018. JsonNode CMapSaverJson::writeTerrainLevel(const int index)
  1019. {
  1020. JsonNode data;
  1021. int3 pos(0,0,index);
  1022. data.Vector().resize(map->height);
  1023. for(pos.y = 0; pos.y < map->height; pos.y++)
  1024. {
  1025. JsonNode & row = data.Vector()[pos.y];
  1026. row.Vector().resize(map->width);
  1027. for(pos.x = 0; pos.x < map->width; pos.x++)
  1028. row.Vector()[pos.x].String() = writeTerrainTile(map->getTile(pos));
  1029. }
  1030. return data;
  1031. }
  1032. void CMapSaverJson::writeTerrain()
  1033. {
  1034. logGlobal->trace("Saving terrain");
  1035. //todo: multilevel map save support
  1036. JsonNode surface = writeTerrainLevel(0);
  1037. addToArchive(surface, TERRAIN_FILE_NAMES[0]);
  1038. if(map->twoLevel)
  1039. {
  1040. JsonNode underground = writeTerrainLevel(1);
  1041. addToArchive(underground, TERRAIN_FILE_NAMES[1]);
  1042. }
  1043. }
  1044. void CMapSaverJson::writeObjects()
  1045. {
  1046. logGlobal->trace("Saving objects");
  1047. JsonNode data;
  1048. JsonSerializer handler(mapObjectResolver.get(), data);
  1049. for(const auto & obj : map->getObjects())
  1050. {
  1051. //logGlobal->trace("\t%s", obj->instanceName);
  1052. auto temp = handler.enterStruct(obj->instanceName);
  1053. obj->serializeJson(handler);
  1054. }
  1055. if(map->grailPos.isValid())
  1056. {
  1057. JsonNode grail;
  1058. grail["type"].String() = "grail";
  1059. grail["x"].Float() = map->grailPos.x;
  1060. grail["y"].Float() = map->grailPos.y;
  1061. grail["l"].Float() = map->grailPos.z;
  1062. grail["options"]["radius"].Float() = map->grailRadius;
  1063. data["grail"] = grail;
  1064. }
  1065. //cleanup empty options
  1066. for(auto & p : data.Struct())
  1067. {
  1068. JsonNode & obj = p.second;
  1069. if(obj["options"].Struct().empty())
  1070. obj.Struct().erase("options");
  1071. }
  1072. addToArchive(data, OBJECTS_FILE_NAME);
  1073. }
  1074. void CMapSaverJson::writeTranslations()
  1075. {
  1076. for(auto & s : mapHeader->translations.Struct())
  1077. {
  1078. auto & language = s.first;
  1079. if(Languages::getLanguageOptions(language).identifier.empty())
  1080. {
  1081. logGlobal->error("Serializing of unsupported language %s is not permitted", language);
  1082. continue;
  1083. }
  1084. logGlobal->trace("Saving translations, language: %s", language);
  1085. addToArchive(s.second, language + ".json");
  1086. }
  1087. }
  1088. VCMI_LIB_NAMESPACE_END