OpenTTD Source  20241121-master-g67a0fccfad
game_text.hpp
Go to the documentation of this file.
1 /*
2  * This file is part of OpenTTD.
3  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6  */
7 
10 #ifndef GAME_TEXT_HPP
11 #define GAME_TEXT_HPP
12 
13 struct StringParam {
14  enum ParamType {
15  UNUSED,
16  RAW_STRING,
17  STRING,
18  OTHER
19  };
20 
21  ParamType type;
22  uint8_t consumes;
23  const char *cmd;
24 
25  StringParam(ParamType type, uint8_t consumes, const char *cmd) : type(type), consumes(consumes), cmd(cmd) {}
26 };
27 using StringParams = std::vector<StringParam>;
28 using StringParamsList = std::vector<StringParams>;
29 
30 const char *GetGameStringPtr(uint id);
31 const StringParams &GetGameStringParams(uint id);
32 const std::string &GetGameStringName(uint id);
33 void RegisterGameTranslation(class Squirrel *engine);
35 
38  std::string language;
40 
41  LanguageStrings() {}
42  LanguageStrings(const std::string &lang) : language(lang) {}
43  LanguageStrings(const LanguageStrings &other) : language(other.language), lines(other.lines) {}
44  LanguageStrings(LanguageStrings &&other) : language(std::move(other.language)), lines(std::move(other.lines)) {}
45 
46  bool IsValid() const { return !this->language.empty(); }
47 };
48 
50 struct GameStrings {
51  uint version;
53 
54  std::vector<LanguageStrings> raw_strings;
55  std::vector<LanguageStrings> compiled_strings;
57  StringParamsList string_params;
58 
59  void Compile();
60 
61  GameStrings() = default;
62 
63  GameStrings(const GameStrings &) = delete;
64  GameStrings(GameStrings &&) = delete;
65  GameStrings &operator=(const GameStrings &) = delete;
66  GameStrings &operator=(GameStrings &&) = delete;
67 };
68 
69 #endif /* GAME_TEXT_HPP */
void RegisterGameTranslation(class Squirrel *engine)
Register the current translation to the Squirrel engine.
Definition: game_text.cpp:356
const StringParams & GetGameStringParams(uint id)
Get the string parameters of a particular game string.
Definition: game_text.cpp:329
void ReconsiderGameScriptLanguage()
Reconsider the game script language, so we use the right one.
Definition: game_text.cpp:383
const char * GetGameStringPtr(uint id)
Get the string pointer of a particular game string.
Definition: game_text.cpp:318
const std::string & GetGameStringName(uint id)
Get the name of a particular game string.
Definition: game_text.cpp:343
std::vector< std::string > StringList
Type for a list of strings.
Definition: string_type.h:60
Container for all the game strings.
Definition: game_text.hpp:50
std::vector< LanguageStrings > raw_strings
The raw strings per language, first must be English/the master language!.
Definition: game_text.hpp:54
std::vector< LanguageStrings > compiled_strings
The compiled strings per language, first must be English/the master language!.
Definition: game_text.hpp:55
uint version
The version of the language strings.
Definition: game_text.hpp:51
StringList string_names
The names of the compiled strings.
Definition: game_text.hpp:56
void Compile()
Compile the language.
Definition: game_text.cpp:284
StringParamsList string_params
The parameters for the strings.
Definition: game_text.hpp:57
LanguageStrings * cur_language
The current (compiled) language.
Definition: game_text.hpp:52
Container for the raw (unencoded) language strings of a language.
Definition: game_text.hpp:37
std::string language
Name of the language (base filename). Empty string if invalid.
Definition: game_text.hpp:38
StringList lines
The lines of the file to pass into the parser/encoder.
Definition: game_text.hpp:39