mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Rename _current_data to _current_gamestrings_data.
parent
ae51308615
commit
35cd05b27d
|
@ -311,7 +311,7 @@ void GameStrings::Compile()
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The currently loaded game strings. */
|
/** The currently loaded game strings. */
|
||||||
std::shared_ptr<GameStrings> _current_data = nullptr;
|
std::shared_ptr<GameStrings> _current_gamestrings_data = nullptr;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the string pointer of a particular game string.
|
* Get the string pointer of a particular game string.
|
||||||
|
@ -320,8 +320,8 @@ std::shared_ptr<GameStrings> _current_data = nullptr;
|
||||||
*/
|
*/
|
||||||
std::string_view GetGameStringPtr(StringIndexInTab id)
|
std::string_view GetGameStringPtr(StringIndexInTab id)
|
||||||
{
|
{
|
||||||
if (_current_data == nullptr || _current_data->cur_language == nullptr || id.base() >= _current_data->cur_language->lines.size()) return GetStringPtr(STR_UNDEFINED);
|
if (_current_gamestrings_data == nullptr || _current_gamestrings_data->cur_language == nullptr || id.base() >= _current_gamestrings_data->cur_language->lines.size()) return GetStringPtr(STR_UNDEFINED);
|
||||||
return _current_data->cur_language->lines[id];
|
return _current_gamestrings_data->cur_language->lines[id];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -334,8 +334,8 @@ const StringParams &GetGameStringParams(StringIndexInTab id)
|
||||||
/* An empty result for STR_UNDEFINED. */
|
/* An empty result for STR_UNDEFINED. */
|
||||||
static StringParams empty;
|
static StringParams empty;
|
||||||
|
|
||||||
if (id.base() >= _current_data->string_params.size()) return empty;
|
if (id.base() >= _current_gamestrings_data->string_params.size()) return empty;
|
||||||
return _current_data->string_params[id];
|
return _current_gamestrings_data->string_params[id];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -348,8 +348,8 @@ const std::string &GetGameStringName(StringIndexInTab id)
|
||||||
/* The name for STR_UNDEFINED. */
|
/* The name for STR_UNDEFINED. */
|
||||||
static const std::string undefined = "STR_UNDEFINED";
|
static const std::string undefined = "STR_UNDEFINED";
|
||||||
|
|
||||||
if (id.base() >= _current_data->string_names.size()) return undefined;
|
if (id.base() >= _current_gamestrings_data->string_names.size()) return undefined;
|
||||||
return _current_data->string_names[id];
|
return _current_gamestrings_data->string_names[id];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -358,8 +358,8 @@ const std::string &GetGameStringName(StringIndexInTab id)
|
||||||
*/
|
*/
|
||||||
void RegisterGameTranslation(Squirrel *engine)
|
void RegisterGameTranslation(Squirrel *engine)
|
||||||
{
|
{
|
||||||
_current_data = LoadTranslations();
|
_current_gamestrings_data = LoadTranslations();
|
||||||
if (_current_data == nullptr) return;
|
if (_current_gamestrings_data == nullptr) return;
|
||||||
|
|
||||||
HSQUIRRELVM vm = engine->GetVM();
|
HSQUIRRELVM vm = engine->GetVM();
|
||||||
sq_pushroottable(vm);
|
sq_pushroottable(vm);
|
||||||
|
@ -367,7 +367,7 @@ void RegisterGameTranslation(Squirrel *engine)
|
||||||
if (SQ_FAILED(sq_get(vm, -2))) return;
|
if (SQ_FAILED(sq_get(vm, -2))) return;
|
||||||
|
|
||||||
int idx = 0;
|
int idx = 0;
|
||||||
for (const auto &p : _current_data->string_names) {
|
for (const auto &p : _current_gamestrings_data->string_names) {
|
||||||
sq_pushstring(vm, p, -1);
|
sq_pushstring(vm, p, -1);
|
||||||
sq_pushinteger(vm, idx);
|
sq_pushinteger(vm, idx);
|
||||||
sq_rawset(vm, -3);
|
sq_rawset(vm, -3);
|
||||||
|
@ -384,15 +384,15 @@ void RegisterGameTranslation(Squirrel *engine)
|
||||||
*/
|
*/
|
||||||
void ReconsiderGameScriptLanguage()
|
void ReconsiderGameScriptLanguage()
|
||||||
{
|
{
|
||||||
if (_current_data == nullptr) return;
|
if (_current_gamestrings_data == nullptr) return;
|
||||||
|
|
||||||
std::string language = FS2OTTD(_current_language->file.stem());
|
std::string language = FS2OTTD(_current_language->file.stem());
|
||||||
for (auto &p : _current_data->compiled_strings) {
|
for (auto &p : _current_gamestrings_data->compiled_strings) {
|
||||||
if (p.language == language) {
|
if (p.language == language) {
|
||||||
_current_data->cur_language = &p;
|
_current_gamestrings_data->cur_language = &p;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_current_data->cur_language = &_current_data->compiled_strings[0];
|
_current_gamestrings_data->cur_language = &_current_gamestrings_data->compiled_strings[0];
|
||||||
}
|
}
|
||||||
|
|
|
@ -113,7 +113,7 @@ struct GSDTChunkHandler : ChunkHandler {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
extern std::shared_ptr<GameStrings> _current_data;
|
extern std::shared_ptr<GameStrings> _current_gamestrings_data;
|
||||||
|
|
||||||
static std::string _game_saveload_string;
|
static std::string _game_saveload_string;
|
||||||
static uint32_t _game_saveload_strings;
|
static uint32_t _game_saveload_strings;
|
||||||
|
@ -159,21 +159,21 @@ struct GSTRChunkHandler : ChunkHandler {
|
||||||
{
|
{
|
||||||
const std::vector<SaveLoad> slt = SlCompatTableHeader(_game_language_desc, _game_language_sl_compat);
|
const std::vector<SaveLoad> slt = SlCompatTableHeader(_game_language_desc, _game_language_sl_compat);
|
||||||
|
|
||||||
_current_data = std::make_shared<GameStrings>();
|
_current_gamestrings_data = std::make_shared<GameStrings>();
|
||||||
|
|
||||||
while (SlIterateArray() != -1) {
|
while (SlIterateArray() != -1) {
|
||||||
LanguageStrings ls;
|
LanguageStrings ls;
|
||||||
SlObject(&ls, slt);
|
SlObject(&ls, slt);
|
||||||
_current_data->raw_strings.push_back(std::move(ls));
|
_current_gamestrings_data->raw_strings.push_back(std::move(ls));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If there were no strings in the savegame, set GameStrings to nullptr */
|
/* If there were no strings in the savegame, set GameStrings to nullptr */
|
||||||
if (_current_data->raw_strings.empty()) {
|
if (_current_gamestrings_data->raw_strings.empty()) {
|
||||||
_current_data.reset();
|
_current_gamestrings_data.reset();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_current_data->Compile();
|
_current_gamestrings_data->Compile();
|
||||||
ReconsiderGameScriptLanguage();
|
ReconsiderGameScriptLanguage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -181,11 +181,11 @@ struct GSTRChunkHandler : ChunkHandler {
|
||||||
{
|
{
|
||||||
SlTableHeader(_game_language_desc);
|
SlTableHeader(_game_language_desc);
|
||||||
|
|
||||||
if (_current_data == nullptr) return;
|
if (_current_gamestrings_data == nullptr) return;
|
||||||
|
|
||||||
for (uint i = 0; i < _current_data->raw_strings.size(); i++) {
|
for (uint i = 0; i < _current_gamestrings_data->raw_strings.size(); i++) {
|
||||||
SlSetArrayIndex(i);
|
SlSetArrayIndex(i);
|
||||||
SlObject(&_current_data->raw_strings[i], _game_language_desc);
|
SlObject(&_current_gamestrings_data->raw_strings[i], _game_language_desc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue