2009-04-15 17:03:31 +03:00
|
|
|
/*
|
|
|
|
* CGeneralTextHandler.h, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
2017-07-13 10:26:03 +02:00
|
|
|
#pragma once
|
2009-04-15 17:03:31 +03:00
|
|
|
|
2013-10-27 16:05:01 +03:00
|
|
|
#include "JsonNode.h"
|
|
|
|
|
2022-07-26 15:07:42 +02:00
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
2013-10-26 00:45:14 +03:00
|
|
|
/// Namespace that provides utilites for unicode support (UTF-8)
|
|
|
|
namespace Unicode
|
|
|
|
{
|
|
|
|
/// evaluates size of UTF-8 character
|
2014-05-23 19:46:54 +03:00
|
|
|
size_t DLL_LINKAGE getCharacterSize(char firstByte);
|
2013-10-26 00:45:14 +03:00
|
|
|
|
|
|
|
/// test if character is a valid UTF-8 symbol
|
|
|
|
/// maxSize - maximum number of bytes this symbol may consist from ( = remainer of string)
|
2014-05-23 19:46:54 +03:00
|
|
|
bool DLL_LINKAGE isValidCharacter(const char * character, size_t maxSize);
|
2013-10-26 00:45:14 +03:00
|
|
|
|
|
|
|
/// test if text contains ASCII-string (no need for unicode conversion)
|
2013-11-09 16:49:36 +03:00
|
|
|
bool DLL_LINKAGE isValidASCII(const std::string & text);
|
|
|
|
bool DLL_LINKAGE isValidASCII(const char * data, size_t size);
|
2013-10-26 00:45:14 +03:00
|
|
|
|
|
|
|
/// test if text contains valid UTF-8 sequence
|
2013-11-09 16:49:36 +03:00
|
|
|
bool DLL_LINKAGE isValidString(const std::string & text);
|
|
|
|
bool DLL_LINKAGE isValidString(const char * data, size_t size);
|
2013-10-26 00:45:14 +03:00
|
|
|
|
|
|
|
/// converts text to unicode from specified encoding or from one specified in settings
|
2013-11-09 16:49:36 +03:00
|
|
|
std::string DLL_LINKAGE toUnicode(const std::string & text);
|
|
|
|
std::string DLL_LINKAGE toUnicode(const std::string & text, const std::string & encoding);
|
2013-10-26 00:45:14 +03:00
|
|
|
|
|
|
|
/// converts text from unicode to specified encoding or to one specified in settings
|
|
|
|
/// NOTE: usage of these functions should be avoided if possible
|
2013-11-09 16:49:36 +03:00
|
|
|
std::string DLL_LINKAGE fromUnicode(const std::string & text);
|
|
|
|
std::string DLL_LINKAGE fromUnicode(const std::string & text, const std::string & encoding);
|
2017-07-04 13:24:46 +02:00
|
|
|
|
2014-07-02 18:16:05 +03:00
|
|
|
///delete (amount) UTF characters from right
|
|
|
|
DLL_LINKAGE void trimRight(std::string & text, const size_t amount = 1);
|
2013-10-26 00:45:14 +03:00
|
|
|
};
|
|
|
|
|
2012-08-25 11:44:51 +03:00
|
|
|
class CInputStream;
|
|
|
|
|
|
|
|
/// Parser for any text files from H3
|
2013-11-09 16:49:36 +03:00
|
|
|
class DLL_LINKAGE CLegacyConfigParser
|
2012-08-25 11:44:51 +03:00
|
|
|
{
|
|
|
|
std::unique_ptr<char[]> data;
|
|
|
|
char * curr;
|
|
|
|
char * end;
|
|
|
|
|
|
|
|
void init(const std::unique_ptr<CInputStream> & input);
|
|
|
|
|
|
|
|
/// extracts part of quoted string.
|
|
|
|
std::string extractQuotedPart();
|
|
|
|
|
|
|
|
/// extracts quoted string. Any end of lines are ignored, double-quote is considered as "escaping"
|
|
|
|
std::string extractQuotedString();
|
|
|
|
|
|
|
|
/// extracts non-quoted string
|
|
|
|
std::string extractNormalString();
|
|
|
|
|
2013-10-26 00:45:14 +03:00
|
|
|
/// reads "raw" string without encoding conversion
|
|
|
|
std::string readRawString();
|
2012-08-25 11:44:51 +03:00
|
|
|
public:
|
|
|
|
/// read one entry from current line. Return ""/0 if end of line reached
|
|
|
|
std::string readString();
|
|
|
|
float readNumber();
|
|
|
|
|
2012-12-14 18:32:53 +03:00
|
|
|
template <typename numeric>
|
|
|
|
std::vector<numeric> readNumArray(size_t size)
|
|
|
|
{
|
|
|
|
std::vector<numeric> ret;
|
|
|
|
ret.reserve(size);
|
|
|
|
while (size--)
|
2020-10-01 10:38:06 +02:00
|
|
|
ret.push_back((numeric)readNumber());
|
2012-12-14 18:32:53 +03:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-08-25 11:44:51 +03:00
|
|
|
/// returns true if next entry is empty
|
2013-06-23 22:35:54 +03:00
|
|
|
bool isNextEntryEmpty() const;
|
2012-08-25 11:44:51 +03:00
|
|
|
|
|
|
|
/// end current line
|
|
|
|
bool endLine();
|
|
|
|
|
|
|
|
CLegacyConfigParser(std::string URI);
|
|
|
|
CLegacyConfigParser(const std::unique_ptr<CInputStream> & input);
|
|
|
|
};
|
|
|
|
|
2022-12-27 22:19:05 +02:00
|
|
|
class CGeneralTextHandler;
|
|
|
|
|
2022-12-27 23:17:41 +02:00
|
|
|
/// Small wrapper that provides text access API compatible with old code
|
2022-12-27 22:19:05 +02:00
|
|
|
class DLL_LINKAGE LegacyTextContainer
|
|
|
|
{
|
|
|
|
CGeneralTextHandler & owner;
|
|
|
|
std::string basePath;
|
|
|
|
|
|
|
|
public:
|
|
|
|
LegacyTextContainer(CGeneralTextHandler & owner, std::string const & basePath);
|
|
|
|
const std::string & operator[](size_t index) const;
|
|
|
|
};
|
|
|
|
|
2022-12-27 23:17:41 +02:00
|
|
|
/// Small wrapper that provides help text access API compatible with old code
|
2022-12-27 22:19:05 +02:00
|
|
|
class DLL_LINKAGE LegacyHelpContainer
|
|
|
|
{
|
|
|
|
CGeneralTextHandler & owner;
|
|
|
|
std::string basePath;
|
|
|
|
|
|
|
|
public:
|
|
|
|
LegacyHelpContainer(CGeneralTextHandler & owner, std::string const & basePath);
|
|
|
|
std::pair<std::string, std::string> operator[](size_t index) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Handles all text-related data in game
|
|
|
|
class DLL_LINKAGE CGeneralTextHandler
|
2009-01-11 00:08:18 +02:00
|
|
|
{
|
2022-12-27 22:19:05 +02:00
|
|
|
/// map identifier -> localization
|
|
|
|
std::unordered_map<std::string, std::string> stringsLocalizations;
|
|
|
|
|
|
|
|
/// map localization -> identifier
|
|
|
|
std::unordered_map<std::string, std::string> stringsIdentifiers;
|
|
|
|
|
|
|
|
/// add selected string to internal storage
|
|
|
|
void registerString(const std::string & UID, const std::string & localized);
|
|
|
|
void registerH3String(const std::string & file, size_t index, const std::string & localized);
|
|
|
|
|
|
|
|
void readToVector(std::string sourceID, std::string sourceName);
|
|
|
|
|
2009-01-11 00:08:18 +02:00
|
|
|
public:
|
2022-12-27 22:19:05 +02:00
|
|
|
/// returns translated version of a string that can be displayed to user
|
|
|
|
const std::string & translate(const std::string & identifier) const;
|
|
|
|
|
|
|
|
/// returns translated version of a string that can be displayed to user, H3-array compatibility version
|
|
|
|
const std::string & translate(const std::string & identifier, size_t index) const;
|
|
|
|
|
|
|
|
/// converts translated string into locale-independent text that can be sent to another client
|
|
|
|
const std::string & serialize(const std::string & identifier) const;
|
|
|
|
|
|
|
|
/// converts identifier into user-readable string, may be identical to 'translate' but reserved for serialization calls
|
|
|
|
const std::string & deserialize(const std::string & identifier) const;
|
2013-10-27 16:05:01 +03:00
|
|
|
|
2022-12-27 23:17:41 +02:00
|
|
|
/// Debug methods, dumps all currently known texts into console using Json-like format
|
|
|
|
void dumpAllTexts();
|
|
|
|
|
|
|
|
LegacyTextContainer allTexts;
|
2009-01-11 00:08:18 +02:00
|
|
|
|
2022-12-27 22:19:05 +02:00
|
|
|
LegacyTextContainer arraytxt;
|
|
|
|
LegacyTextContainer primarySkillNames;
|
|
|
|
LegacyTextContainer jktexts;
|
|
|
|
LegacyTextContainer heroscrn;
|
|
|
|
LegacyTextContainer overview;//text for Kingdom Overview window
|
|
|
|
LegacyTextContainer colors; //names of player colors ("red",...)
|
|
|
|
LegacyTextContainer capColors; //names of player colors with first letter capitalized ("Red",...)
|
|
|
|
LegacyTextContainer turnDurations; //turn durations for pregame (1 Minute ... Unlimited)
|
2009-01-11 00:08:18 +02:00
|
|
|
|
|
|
|
//towns
|
2022-12-27 22:19:05 +02:00
|
|
|
LegacyTextContainer tcommands, hcommands, fcommands; //texts for town screen, town hall screen and fort screen
|
|
|
|
LegacyTextContainer tavernInfo;
|
|
|
|
LegacyTextContainer tavernRumors;
|
2009-01-11 00:08:18 +02:00
|
|
|
|
2022-12-27 22:19:05 +02:00
|
|
|
LegacyTextContainer qeModCommands;
|
2020-04-01 00:01:57 +02:00
|
|
|
|
2022-12-27 22:19:05 +02:00
|
|
|
LegacyHelpContainer zelp;
|
|
|
|
LegacyTextContainer lossCondtions;
|
|
|
|
LegacyTextContainer victoryConditions;
|
2009-01-06 20:42:20 +02:00
|
|
|
|
|
|
|
//objects
|
2022-12-27 22:19:05 +02:00
|
|
|
LegacyTextContainer creGens; //names of creatures' generators
|
|
|
|
LegacyTextContainer creGens4; //names of multiple creatures' generators
|
|
|
|
LegacyTextContainer advobtxt;
|
|
|
|
LegacyTextContainer xtrainfo;
|
|
|
|
LegacyTextContainer restypes; //names of resources
|
|
|
|
LegacyTextContainer terrainNames;
|
|
|
|
LegacyTextContainer randsign;
|
2022-12-27 23:17:41 +02:00
|
|
|
LegacyTextContainer seerEmpty;
|
|
|
|
LegacyTextContainer seerNames;
|
2022-12-27 22:19:05 +02:00
|
|
|
LegacyTextContainer tentColors;
|
2009-01-11 00:08:18 +02:00
|
|
|
|
2009-01-25 18:40:50 +02:00
|
|
|
//sec skills
|
2022-12-27 22:19:05 +02:00
|
|
|
LegacyTextContainer levels;
|
2011-03-21 10:14:23 +02:00
|
|
|
std::vector<std::string> zcrexp; //more or less useful content of that file
|
2017-05-26 21:58:33 +02:00
|
|
|
//commanders
|
|
|
|
std::vector<std::string> znpc00; //more or less useful content of that file
|
2009-01-11 00:08:18 +02:00
|
|
|
|
2010-02-12 17:04:01 +02:00
|
|
|
//campaigns
|
2016-10-29 17:00:12 +02:00
|
|
|
std::vector<std::string> campaignMapNames;
|
|
|
|
std::vector<std::vector<std::string>> campaignRegionNames;
|
|
|
|
|
2022-12-27 22:19:05 +02:00
|
|
|
std::vector<std::string> findStringsWithPrefix(std::string const & prefix);
|
2010-02-12 17:04:01 +02:00
|
|
|
|
2017-07-04 13:24:46 +02:00
|
|
|
int32_t pluralText(const int32_t textIndex, const int32_t count) const;
|
|
|
|
|
2009-01-11 00:08:18 +02:00
|
|
|
CGeneralTextHandler();
|
2016-10-29 17:00:12 +02:00
|
|
|
CGeneralTextHandler(const CGeneralTextHandler&) = delete;
|
|
|
|
CGeneralTextHandler operator=(const CGeneralTextHandler&) = delete;
|
2009-01-11 00:08:18 +02:00
|
|
|
};
|
2022-07-26 15:07:42 +02:00
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_END
|