OpenTTD Source: src/game/game_text.hpp Source File

OpenTTD Source 14.0-RC3

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);
34 void ReconsiderGameScriptLanguage();
35
37 struct LanguageStrings {
38 std::string language;
39 StringList lines;
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;
52 LanguageStrings *cur_language;
53
54 std::vector<LanguageStrings> raw_strings;
55 std::vector<LanguageStrings> compiled_strings;
56 StringList string_names;
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 */
GameStrings::version
uint version
The version of the language strings.
Definition: game_text.hpp:51
GetGameStringParams
const StringParams & GetGameStringParams(uint id)
Get the string parameters of a particular game string.
Definition: game_text.cpp:331
GetGameStringName
const std::string & GetGameStringName(uint id)
Get the name of a particular game string.
Definition: game_text.cpp:345
GameStrings::string_names
StringList string_names
The names of the compiled strings.
Definition: game_text.hpp:56
Squirrel
Definition: squirrel.hpp:23
ReconsiderGameScriptLanguage
void ReconsiderGameScriptLanguage()
Reconsider the game script language, so we use the right one.
Definition: game_text.cpp:385
StringParam
Definition: game_text.hpp:13
GameStrings::string_params
StringParamsList string_params
The parameters for the strings.
Definition: game_text.hpp:57
StringList
std::vector< std::string > StringList
Type for a list of strings.
Definition: string_type.h:60
GameStrings::raw_strings
std::vector< LanguageStrings > raw_strings
The raw strings per language, first must be English/the master language!.
Definition: game_text.hpp:54
LanguageStrings
Container for the raw (unencoded) language strings of a language.
Definition: game_text.hpp:37
RegisterGameTranslation
void RegisterGameTranslation(class Squirrel *engine)
Register the current translation to the Squirrel engine.
Definition: game_text.cpp:358
LanguageStrings::language
std::string language
Name of the language (base filename). Empty string if invalid.
Definition: game_text.hpp:38
GetGameStringPtr
const char * GetGameStringPtr(uint id)
Get the string pointer of a particular game string.
Definition: game_text.cpp:320
GameStrings::cur_language
LanguageStrings * cur_language
The current (compiled) language.
Definition: game_text.hpp:52
GameStrings::compiled_strings
std::vector< LanguageStrings > compiled_strings
The compiled strings per language, first must be English/the master language!.
Definition: game_text.hpp:55
LanguageStrings::lines
StringList lines
The lines of the file to pass into the parser/encoder.
Definition: game_text.hpp:39
GameStrings::Compile
void Compile()
Compile the language.
Definition: game_text.cpp:286
GameStrings
Container for all the game strings.
Definition: game_text.hpp:50