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