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

OpenTTD Source 15.0-RC2

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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
10#ifndef GAME_TEXT_HPP
11#define GAME_TEXT_HPP
12
13#include "../string_type.h"
14#include "../strings_type.h"
15
16 struct StringParam {
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);
37void ReconsiderGameScriptLanguage();
38
40 struct LanguageStrings {
41 std::string language;
42 TypedIndexContainer<StringList, StringIndexInTab> lines;
43
44 LanguageStrings() {}
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
53 struct GameStrings {
54 uint version;
55 LanguageStrings *cur_language;
56
57 std::vector<LanguageStrings> raw_strings;
58 std::vector<LanguageStrings> compiled_strings;
59 TypedIndexContainer<StringList, StringIndexInTab> string_names;
60 TypedIndexContainer<StringParamsList, StringIndexInTab> string_params;
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 */
Squirrel
Definition squirrel.hpp:24
TypedIndexContainer
A sort-of mixin that implements 'at(pos)' and 'operator[](pos)' only for a specific type.
Definition convertible_through_base.hpp:38
GetGameStringName
const std::string & GetGameStringName(StringIndexInTab id)
Get the name of a particular game string.
Definition game_text.cpp:340
GetGameStringParams
const StringParams & GetGameStringParams(StringIndexInTab id)
Get the string parameters of a particular game string.
Definition game_text.cpp:326
ReconsiderGameScriptLanguage
void ReconsiderGameScriptLanguage()
Reconsider the game script language, so we use the right one.
Definition game_text.cpp:381
RegisterGameTranslation
void RegisterGameTranslation(class Squirrel &engine)
Register the current translation to the Squirrel engine.
Definition game_text.cpp:353
GetGameStringPtr
std::string_view GetGameStringPtr(StringIndexInTab id)
Get the string pointer of a particular game string.
Definition game_text.cpp:315
GameStrings
Container for all the game strings.
Definition game_text.hpp:53
GameStrings::raw_strings
std::vector< LanguageStrings > raw_strings
The raw strings per language, first must be English/the master language!.
Definition game_text.hpp:57
GameStrings::string_names
TypedIndexContainer< StringList, StringIndexInTab > string_names
The names of the compiled strings.
Definition game_text.hpp:59
GameStrings::compiled_strings
std::vector< LanguageStrings > compiled_strings
The compiled strings per language, first must be English/the master language!.
Definition game_text.hpp:58
GameStrings::version
uint version
The version of the language strings.
Definition game_text.hpp:54
GameStrings::Compile
void Compile()
Compile the language.
Definition game_text.cpp:281
GameStrings::cur_language
LanguageStrings * cur_language
The current (compiled) language.
Definition game_text.hpp:55
GameStrings::string_params
TypedIndexContainer< StringParamsList, StringIndexInTab > string_params
The parameters for the strings.
Definition game_text.hpp:60
LanguageStrings
Container for the raw (unencoded) language strings of a language.
Definition game_text.hpp:40
LanguageStrings::language
std::string language
Name of the language (base filename). Empty string if invalid.
Definition game_text.hpp:41
LanguageStrings::lines
TypedIndexContainer< StringList, StringIndexInTab > lines
The lines of the file to pass into the parser/encoder.
Definition game_text.hpp:42
StringParam
Definition game_text.hpp:16
StrongType::Typedef
Templated helper to make a type-safe 'typedef' representing a single POD value.
Definition strong_typedef_type.hpp:130