From 9bdd2c8d3fba608a651e60503c1f67c72166c10b Mon Sep 17 00:00:00 2001 From: AlexVinS Date: Thu, 16 Nov 2017 23:23:03 +0300 Subject: [PATCH] Implemented new debug command "convert txt" * use it to extract essential texts in json format --- client/CMT.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/client/CMT.cpp b/client/CMT.cpp index 1283a9f31..461f08038 100644 --- a/client/CMT.cpp +++ b/client/CMT.cpp @@ -681,6 +681,39 @@ void processCommand(const std::string &message) // readed >> fname; // client->loadGame(fname); // } + else if(message=="convert txt") + { + std::cout << "Command accepted.\t"; + + const bfs::path outPath = + VCMIDirs::get().userCachePath() / "extracted"; + + bfs::create_directories(outPath); + + auto extractVector = [=](const std::vector & source, const std::string & name) + { + JsonNode data(JsonNode::DATA_VECTOR); + size_t index = 0; + for(auto & line : source) + { + JsonNode lineNode(JsonNode::DATA_STRUCT); + lineNode["text"].String() = line; + lineNode["index"].Integer() = index++; + data.Vector().push_back(lineNode); + } + + const bfs::path filePath = outPath / (name + ".json"); + bfs::ofstream file(filePath); + file << data.toJson(); + }; + + extractVector(VLC->generaltexth->allTexts, "generalTexts"); + extractVector(VLC->generaltexth->jktexts, "jkTexts"); + extractVector(VLC->generaltexth->arraytxt, "arrayTexts"); + + std::cout << "\rExtracting done :)\n"; + std::cout << " Extracted files can be found in " << outPath << " directory\n"; + } else if(message=="get txt") { std::cout << "Command accepted.\t";