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

Restored text export command

This commit is contained in:
Ivan Savenko
2022-12-28 01:13:48 +02:00
parent 1979b3e97f
commit a499390b9c
2 changed files with 29 additions and 60 deletions

View File

@@ -664,36 +664,7 @@ void processCommand(const std::string &message)
// } // }
else if(message=="convert txt") else if(message=="convert txt")
{ {
std::cout << "Command accepted.\t"; VLC->generaltexth->dumpAllTexts();
const bfs::path outPath =
VCMIDirs::get().userExtractedPath();
bfs::create_directories(outPath);
auto extractVector = [=](const std::vector<std::string> & source, const std::string & name)
{
JsonNode data(JsonNode::JsonType::DATA_VECTOR);
size_t index = 0;
for(auto & line : source)
{
JsonNode lineNode(JsonNode::JsonType::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 config") else if(message=="get config")
{ {

View File

@@ -543,14 +543,12 @@ CGeneralTextHandler::CGeneralTextHandler():
} }
if (VLC->modh->modules.COMMANDERS) if (VLC->modh->modules.COMMANDERS)
{ {
if (CResourceHandler::get()->existsResource(ResourceID("DATA/ZNPC00.TXT", EResType::TEXT))) if (CResourceHandler::get()->existsResource(ResourceID("DATA/ZNPC00.TXT", EResType::TEXT)))
readToVector("vcmi.znpc00", "DATA/ZNPC00.TXT" ); readToVector("vcmi.znpc00", "DATA/ZNPC00.TXT" );
} }
}
dumpAllTexts();
} int32_t CGeneralTextHandler::pluralText(const int32_t textIndex, const int32_t count) const
int32_t CGeneralTextHandler::pluralText(const int32_t textIndex, const int32_t count) const
{ {
if(textIndex == 0) if(textIndex == 0)
return 0; return 0;
@@ -558,28 +556,28 @@ int32_t CGeneralTextHandler::pluralText(const int32_t textIndex, const int32_t c
return -textIndex; return -textIndex;
else if(count == 1) else if(count == 1)
return textIndex; return textIndex;
else else
return textIndex + 1; return textIndex + 1;
} }
void CGeneralTextHandler::dumpAllTexts() void CGeneralTextHandler::dumpAllTexts()
{ {
logGlobal->trace("BEGIN TEXT EXPORT"); logGlobal->info("BEGIN TEXT EXPORT");
for ( auto const & entry : stringsLocalizations) for ( auto const & entry : stringsLocalizations)
{ {
auto cleanString = entry.second; auto cleanString = entry.second;
boost::replace_all(cleanString, "\\", "\\\\"); boost::replace_all(cleanString, "\\", "\\\\");
boost::replace_all(cleanString, "\n", "\\n"); boost::replace_all(cleanString, "\n", "\\n");
boost::replace_all(cleanString, "\r", "\\r"); boost::replace_all(cleanString, "\r", "\\r");
boost::replace_all(cleanString, "\t", "\\t"); boost::replace_all(cleanString, "\t", "\\t");
boost::replace_all(cleanString, "\"", "\\\""); boost::replace_all(cleanString, "\"", "\\\"");
logGlobal->trace("\"%s\" : \"%s\",", entry.first, cleanString); logGlobal->info("\"%s\" : \"%s\",", entry.first, cleanString);
} }
logGlobal->trace("END TEXT EXPORT"); logGlobal->info("END TEXT EXPORT");
} }
size_t CGeneralTextHandler::getCampaignLength(size_t campaignID) const size_t CGeneralTextHandler::getCampaignLength(size_t campaignID) const
{ {
assert(campaignID < scenariosCountPerCampaign.size()); assert(campaignID < scenariosCountPerCampaign.size());