summaryrefslogtreecommitdiff
path: root/src/saveload
diff options
context:
space:
mode:
authorPatric Stout <truebrain@openttd.org>2021-06-14 13:32:12 +0200
committerPatric Stout <github@truebrain.nl>2021-06-14 21:58:05 +0200
commitaf3aba7a8830ad19fbb32819cd74ff4d5d7f51c5 (patch)
tree80796cd9f68f9e1ca8cc88de9f51cf5d858c27e2 /src/saveload
parentaa02bf27f6217f6ba9006ae95856ecdd837245c9 (diff)
downloadopenttd-af3aba7a8830ad19fbb32819cd74ff4d5d7f51c5.tar.xz
Codechange: use SLE_STRUCT(LIST) for GameScript chunks
Diffstat (limited to 'src/saveload')
-rw-r--r--src/saveload/game_sl.cpp59
1 files changed, 31 insertions, 28 deletions
diff --git a/src/saveload/game_sl.cpp b/src/saveload/game_sl.cpp
index a1093eaf4..af01d5bd0 100644
--- a/src/saveload/game_sl.cpp
+++ b/src/saveload/game_sl.cpp
@@ -111,44 +111,45 @@ static void Save_GSDT()
extern GameStrings *_current_data;
static std::string _game_saveload_string;
-static uint _game_saveload_strings;
+static uint32 _game_saveload_strings;
+
+class SlGameLanguageString : public DefaultSaveLoadHandler<SlGameLanguageString, LanguageStrings> {
+public:
+ inline static const SaveLoad description[] = {
+ SLEG_SSTR(_game_saveload_string, SLE_STR | SLF_ALLOW_CONTROL),
+ };
+
+ void Save(LanguageStrings *ls) const override
+ {
+ for (const auto &string : ls->lines) {
+ _game_saveload_string = string;
+ SlObject(nullptr, this->GetDescription());
+ }
+ }
-static const SaveLoad _game_language_header[] = {
- SLEG_SSTR(_game_saveload_string, SLE_STR),
- SLEG_VAR(_game_saveload_strings, SLE_UINT32),
+ void Load(LanguageStrings *ls) const override
+ {
+ for (uint32 i = 0; i < _game_saveload_strings; i++) {
+ SlObject(nullptr, this->GetDescription());
+ ls->lines.emplace_back(_game_saveload_string);
+ }
+ }
};
-static const SaveLoad _game_language_string[] = {
- SLEG_SSTR(_game_saveload_string, SLE_STR | SLF_ALLOW_CONTROL),
+static const SaveLoad _game_language_desc[] = {
+ SLE_SSTR(LanguageStrings, language, SLE_STR),
+ SLEG_VAR(_game_saveload_strings, SLE_UINT32),
+ SLEG_STRUCTLIST(SlGameLanguageString),
};
-static void SaveReal_GSTR(const LanguageStrings *ls)
-{
- _game_saveload_string = ls->language.c_str();
- _game_saveload_strings = (uint)ls->lines.size();
-
- SlObject(nullptr, _game_language_header);
- for (const auto &i : ls->lines) {
- _game_saveload_string = i.c_str();
- SlObject(nullptr, _game_language_string);
- }
-}
-
static void Load_GSTR()
{
delete _current_data;
_current_data = new GameStrings();
while (SlIterateArray() != -1) {
- _game_saveload_string.clear();
- SlObject(nullptr, _game_language_header);
-
- LanguageStrings ls(_game_saveload_string);
- for (uint i = 0; i < _game_saveload_strings; i++) {
- SlObject(nullptr, _game_language_string);
- ls.lines.emplace_back(_game_saveload_string);
- }
-
+ LanguageStrings ls;
+ SlObject(&ls, _game_language_desc);
_current_data->raw_strings.push_back(std::move(ls));
}
@@ -169,7 +170,9 @@ static void Save_GSTR()
for (uint i = 0; i < _current_data->raw_strings.size(); i++) {
SlSetArrayIndex(i);
- SlAutolength((AutolengthProc *)SaveReal_GSTR, &_current_data->raw_strings[i]);
+ LanguageStrings *ls = &_current_data->raw_strings[i];
+ _game_saveload_strings = (uint32)ls->lines.size();
+ SlObject(ls, _game_language_desc);
}
}