OpenTTD Source 20250522-master-g467f832c2f
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#include "../string_type.h"
14#include "../strings_type.h"
15
17 enum ParamType : uint8_t {
18 UNUSED,
19 RAW_STRING,
20 STRING,
21 OTHER
22 };
23
24 ParamType type;
25 uint8_t consumes;
26 std::string_view cmd;
27
28 StringParam(ParamType type, uint8_t consumes, std::string_view cmd = {}) : type(type), consumes(consumes), cmd(cmd) {}
29};
30using StringParams = std::vector<StringParam>;
31using StringParamsList = std::vector<StringParams>;
32
33std::string_view GetGameStringPtr(StringIndexInTab id);
34const StringParams &GetGameStringParams(StringIndexInTab id);
35const std::string &GetGameStringName(StringIndexInTab id);
36void RegisterGameTranslation(class Squirrel &engine);
38
41 std::string language;
43
45 LanguageStrings(const std::string &lang) : language(lang) {}
46 LanguageStrings(const LanguageStrings &other) : language(other.language), lines(other.lines) {}
47 LanguageStrings(LanguageStrings &&other) : language(std::move(other.language)), lines(std::move(other.lines)) {}
48
49 bool IsValid() const { return !this->language.empty(); }
50};
51
54 uint version;
56
57 std::vector<LanguageStrings> raw_strings;
58 std::vector<LanguageStrings> compiled_strings;
61
62 void Compile();
63
64 GameStrings() = default;
65
66 GameStrings(const GameStrings &) = delete;
67 GameStrings(GameStrings &&) = delete;
68 GameStrings &operator=(const GameStrings &) = delete;
69 GameStrings &operator=(GameStrings &&) = delete;
70};
71
72#endif /* GAME_TEXT_HPP */
A sort-of mixin that adds 'at(pos)' and 'operator[](pos)' implementations for 'ConvertibleThroughBase...
const std::string & GetGameStringName(StringIndexInTab id)
Get the name of a particular game string.
const StringParams & GetGameStringParams(StringIndexInTab id)
Get the string parameters of a particular game string.
void ReconsiderGameScriptLanguage()
Reconsider the game script language, so we use the right one.
void RegisterGameTranslation(class Squirrel &engine)
Register the current translation to the Squirrel engine.
std::string_view GetGameStringPtr(StringIndexInTab id)
Get the string pointer of a particular game string.
Container for all the game strings.
Definition game_text.hpp:53
ReferenceThroughBaseContainer< StringList > string_names
The names of the compiled strings.
Definition game_text.hpp:59
std::vector< LanguageStrings > raw_strings
The raw strings per language, first must be English/the master language!.
Definition game_text.hpp:57
std::vector< LanguageStrings > compiled_strings
The compiled strings per language, first must be English/the master language!.
Definition game_text.hpp:58
uint version
The version of the language strings.
Definition game_text.hpp:54
ReferenceThroughBaseContainer< StringParamsList > string_params
The parameters for the strings.
Definition game_text.hpp:60
void Compile()
Compile the language.
LanguageStrings * cur_language
The current (compiled) language.
Definition game_text.hpp:55
Container for the raw (unencoded) language strings of a language.
Definition game_text.hpp:40
std::string language
Name of the language (base filename). Empty string if invalid.
Definition game_text.hpp:41
ReferenceThroughBaseContainer< StringList > lines
The lines of the file to pass into the parser/encoder.
Definition game_text.hpp:42
Templated helper to make a type-safe 'typedef' representing a single POD value.