CGeneralTextHandler.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. #pragma once
  2. /*
  3. * CGeneralTextHandler.h, part of VCMI engine
  4. *
  5. * Authors: listed in file AUTHORS in main folder
  6. *
  7. * License: GNU General Public License v2.0 or later
  8. * Full text of license available in license.txt file, in main folder
  9. *
  10. */
  11. #include "JsonNode.h"
  12. /// Namespace that provides utilites for unicode support (UTF-8)
  13. namespace Unicode
  14. {
  15. /// evaluates size of UTF-8 character
  16. size_t DLL_LINKAGE getCharacterSize(ui8 firstByte);
  17. /// test if character is a valid UTF-8 symbol
  18. /// maxSize - maximum number of bytes this symbol may consist from ( = remainer of string)
  19. bool DLL_LINKAGE isValidCharacter(const ui8 *character, size_t maxSize);
  20. /// test if text contains ASCII-string (no need for unicode conversion)
  21. bool DLL_LINKAGE isValidASCII(const std::string & text);
  22. bool DLL_LINKAGE isValidASCII(const char * data, size_t size);
  23. /// test if text contains valid UTF-8 sequence
  24. bool DLL_LINKAGE isValidString(const std::string & text);
  25. bool DLL_LINKAGE isValidString(const char * data, size_t size);
  26. /// converts text to unicode from specified encoding or from one specified in settings
  27. std::string DLL_LINKAGE toUnicode(const std::string & text);
  28. std::string DLL_LINKAGE toUnicode(const std::string & text, const std::string & encoding);
  29. /// converts text from unicode to specified encoding or to one specified in settings
  30. /// NOTE: usage of these functions should be avoided if possible
  31. std::string DLL_LINKAGE fromUnicode(const std::string & text);
  32. std::string DLL_LINKAGE fromUnicode(const std::string & text, const std::string & encoding);
  33. };
  34. class CInputStream;
  35. /// Parser for any text files from H3
  36. class DLL_LINKAGE CLegacyConfigParser
  37. {
  38. std::unique_ptr<char[]> data;
  39. char * curr;
  40. char * end;
  41. void init(const std::unique_ptr<CInputStream> & input);
  42. /// extracts part of quoted string.
  43. std::string extractQuotedPart();
  44. /// extracts quoted string. Any end of lines are ignored, double-quote is considered as "escaping"
  45. std::string extractQuotedString();
  46. /// extracts non-quoted string
  47. std::string extractNormalString();
  48. /// reads "raw" string without encoding conversion
  49. std::string readRawString();
  50. public:
  51. /// read one entry from current line. Return ""/0 if end of line reached
  52. std::string readString();
  53. float readNumber();
  54. template <typename numeric>
  55. std::vector<numeric> readNumArray(size_t size)
  56. {
  57. std::vector<numeric> ret;
  58. ret.reserve(size);
  59. while (size--)
  60. ret.push_back(readNumber());
  61. return ret;
  62. }
  63. /// returns true if next entry is empty
  64. bool isNextEntryEmpty() const;
  65. /// end current line
  66. bool endLine();
  67. CLegacyConfigParser(std::string URI);
  68. CLegacyConfigParser(const std::unique_ptr<CInputStream> & input);
  69. };
  70. class DLL_LINKAGE CGeneralTextHandler //Handles general texts
  71. {
  72. public:
  73. JsonNode localizedTexts;
  74. std::vector<std::string> allTexts;
  75. std::vector<std::string> arraytxt;
  76. std::vector<std::string> primarySkillNames;
  77. std::vector<std::string> jktexts;
  78. std::vector<std::string> heroscrn;
  79. std::vector<std::string> overview;//text for Kingdom Overview window
  80. std::vector<std::string> colors; //names of player colors ("red",...)
  81. std::vector<std::string> capColors; //names of player colors with first letter capitalized ("Red",...)
  82. std::vector<std::string> turnDurations; //turn durations for pregame (1 Minute ... Unlimited)
  83. //towns
  84. std::vector<std::string> tcommands, hcommands, fcommands; //texts for town screen, town hall screen and fort screen
  85. std::vector<std::string> tavernInfo;
  86. std::vector<std::pair<std::string,std::string> > zelp;
  87. std::vector<std::string> lossCondtions;
  88. std::vector<std::string> victoryConditions;
  89. //objects
  90. std::vector<std::string> names; //vector of objects; i-th object in vector has subnumber i
  91. std::vector<std::string> creGens; //names of creatures' generators
  92. std::vector<std::string> creGens4; //names of multiple creatures' generators
  93. std::vector<std::string> advobtxt;
  94. std::vector<std::string> xtrainfo;
  95. std::vector<std::string> restypes; //names of resources
  96. std::vector<std::string> terrainNames;
  97. std::vector<std::string> randsign;
  98. std::vector<std::pair<std::string,std::string> > mines; //first - name; second - event description
  99. std::vector<std::string> seerEmpty;
  100. std::vector <std::vector <std::vector <std::string> > > quests; //[quest][type][index]
  101. //type: quest, progress, complete, rollover, log OR time limit //index: 0-2 seer hut, 3-5 border guard
  102. std::vector<std::string> seerNames;
  103. std::vector<std::string> tentColors;
  104. //sec skills
  105. std::vector <std::string> skillName;
  106. std::vector <std::vector <std::string> > skillInfoTexts; //[id][level] : level 0 - basic; 2 - advanced
  107. std::vector<std::string> levels;
  108. std::vector<std::string> zcrexp; //more or less useful content of that file
  109. //campaigns
  110. std::vector <std::string> campaignMapNames;
  111. std::vector < std::vector <std::string> > campaignRegionNames;
  112. void readToVector(std::string sourceName, std::vector<std::string> & dest);
  113. CGeneralTextHandler();
  114. };