Преглед изворни кода

Implemented new debug command "convert txt"
* use it to extract essential texts in json format

AlexVinS пре 8 година
родитељ
комит
9bdd2c8d3f
1 измењених фајлова са 33 додато и 0 уклоњено
  1. 33 0
      client/CMT.cpp

+ 33 - 0
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<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";