1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-24 03:47:18 +02:00

Implemented new debug command "convert txt"

* use it to extract essential texts in json format
This commit is contained in:
AlexVinS 2017-11-16 23:23:03 +03:00
parent e8a7078bb1
commit 9bdd2c8d3f

View File

@ -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<std::string> & 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";