2011-12-14 00:23:17 +03:00
|
|
|
#pragma once
|
|
|
|
|
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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2013-10-27 16:05:01 +03:00
|
|
|
#include "JsonNode.h"
|
|
|
|
|
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
|
2013-11-09 16:49:36 +03:00
|
|
|
size_t DLL_LINKAGE getCharacterSize(ui8 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)
|
2013-11-09 16:49:36 +03:00
|
|
|
bool DLL_LINKAGE isValidCharacter(const ui8 *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);
|
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--)
|
|
|
|
ret.push_back(readNumber());
|
|
|
|
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);
|
|
|
|
};
|
|
|
|
|
2011-12-14 00:23:17 +03:00
|
|
|
class DLL_LINKAGE CGeneralTextHandler //Handles general texts
|
2009-01-11 00:08:18 +02:00
|
|
|
{
|
|
|
|
public:
|
2013-10-27 16:05:01 +03:00
|
|
|
JsonNode localizedTexts;
|
|
|
|
|
2009-01-11 00:08:18 +02:00
|
|
|
std::vector<std::string> allTexts;
|
|
|
|
|
|
|
|
std::vector<std::string> arraytxt;
|
|
|
|
std::vector<std::string> primarySkillNames;
|
|
|
|
std::vector<std::string> jktexts;
|
|
|
|
std::vector<std::string> heroscrn;
|
2010-01-25 23:25:14 +02:00
|
|
|
std::vector<std::string> overview;//text for Kingdom Overview window
|
2010-02-01 19:07:46 +02:00
|
|
|
std::vector<std::string> colors; //names of player colors ("red",...)
|
|
|
|
std::vector<std::string> capColors; //names of player colors with first letter capitalized ("Red",...)
|
2011-01-28 04:33:26 +02:00
|
|
|
std::vector<std::string> turnDurations; //turn durations for pregame (1 Minute ... Unlimited)
|
2009-01-11 00:08:18 +02:00
|
|
|
|
|
|
|
//towns
|
2009-12-23 03:46:15 +02:00
|
|
|
std::vector<std::string> tcommands, hcommands, fcommands; //texts for town screen, town hall screen and fort screen
|
2009-02-09 18:18:48 +02:00
|
|
|
std::vector<std::string> tavernInfo;
|
2009-01-11 00:08:18 +02:00
|
|
|
|
|
|
|
std::vector<std::pair<std::string,std::string> > zelp;
|
2012-08-25 11:44:51 +03:00
|
|
|
std::vector<std::string> lossCondtions;
|
|
|
|
std::vector<std::string> victoryConditions;
|
2009-01-06 20:42:20 +02:00
|
|
|
|
|
|
|
//objects
|
|
|
|
std::vector<std::string> names; //vector of objects; i-th object in vector has subnumber i
|
|
|
|
std::vector<std::string> creGens; //names of creatures' generators
|
2009-07-09 22:15:22 +03:00
|
|
|
std::vector<std::string> creGens4; //names of multiple creatures' generators
|
2009-01-06 20:42:20 +02:00
|
|
|
std::vector<std::string> advobtxt;
|
|
|
|
std::vector<std::string> xtrainfo;
|
2010-07-30 14:29:42 +03:00
|
|
|
std::vector<std::string> restypes; //names of resources
|
2009-10-22 05:09:14 +03:00
|
|
|
std::vector<std::string> terrainNames;
|
2009-03-19 16:17:19 +02:00
|
|
|
std::vector<std::string> randsign;
|
2009-01-11 00:08:18 +02:00
|
|
|
std::vector<std::pair<std::string,std::string> > mines; //first - name; second - event description
|
2010-01-26 21:43:15 +02:00
|
|
|
std::vector<std::string> seerEmpty;
|
2009-12-31 13:43:37 +02:00
|
|
|
std::vector <std::vector <std::vector <std::string> > > quests; //[quest][type][index]
|
|
|
|
//type: quest, progress, complete, rollover, log OR time limit //index: 0-2 seer hut, 3-5 border guard
|
|
|
|
std::vector<std::string> seerNames;
|
2012-07-08 19:36:20 +03:00
|
|
|
std::vector<std::string> tentColors;
|
2009-01-11 00:08:18 +02:00
|
|
|
|
2009-01-25 18:40:50 +02:00
|
|
|
//sec skills
|
|
|
|
std::vector <std::string> skillName;
|
|
|
|
std::vector <std::vector <std::string> > skillInfoTexts; //[id][level] : level 0 - basic; 2 - advanced
|
2009-01-11 00:08:18 +02:00
|
|
|
std::vector<std::string> levels;
|
2011-03-21 10:14:23 +02:00
|
|
|
std::vector<std::string> zcrexp; //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
|
|
|
|
std::vector <std::string> campaignMapNames;
|
|
|
|
std::vector < std::vector <std::string> > campaignRegionNames;
|
|
|
|
|
2013-02-16 19:37:43 +03:00
|
|
|
void readToVector(std::string sourceName, std::vector<std::string> & dest);
|
2009-01-11 00:08:18 +02:00
|
|
|
CGeneralTextHandler();
|
|
|
|
};
|