Changeset - r25679:73234761fb15
[Not reviewed]
master
0 1 0
Patric Stout - 3 years ago 2021-06-14 11:32:12
truebrain@openttd.org
Codechange: use SLE_STRUCT(LIST) for GameScript chunks
1 file changed with 28 insertions and 25 deletions:
0 comments (0 inline, 0 general)
src/saveload/game_sl.cpp
Show inline comments
 
@@ -102,80 +102,83 @@ static void Load_GSDT()
 
	if ((CompanyID)SlIterateArray() != (CompanyID)-1) SlErrorCorrupt("Too many GameScript configs");
 
}
 

	
 
static void Save_GSDT()
 
{
 
	SlSetArrayIndex(0);
 
	SlAutolength((AutolengthProc *)SaveReal_GSDT, nullptr);
 
}
 

	
 
extern GameStrings *_current_data;
 

	
 
static std::string _game_saveload_string;
 
static uint _game_saveload_strings;
 
static uint32 _game_saveload_strings;
 

	
 
static const SaveLoad _game_language_header[] = {
 
	SLEG_SSTR(_game_saveload_string, SLE_STR),
 
	 SLEG_VAR(_game_saveload_strings, SLE_UINT32),
 
};
 

	
 
static const SaveLoad _game_language_string[] = {
 
class SlGameLanguageString : public DefaultSaveLoadHandler<SlGameLanguageString, LanguageStrings> {
 
public:
 
	inline static const SaveLoad description[] = {
 
	SLEG_SSTR(_game_saveload_string, SLE_STR | SLF_ALLOW_CONTROL),
 
};
 

	
 
static void SaveReal_GSTR(const LanguageStrings *ls)
 
	void Save(LanguageStrings *ls) const override
 
{
 
	_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);
 
		for (const auto &string : ls->lines) {
 
			_game_saveload_string = string;
 
			SlObject(nullptr, this->GetDescription());
 
	}
 
}
 

	
 
	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_desc[] = {
 
	SLE_SSTR(LanguageStrings, language, SLE_STR),
 
	SLEG_VAR(_game_saveload_strings, SLE_UINT32),
 
	SLEG_STRUCTLIST(SlGameLanguageString),
 
};
 

	
 
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));
 
	}
 

	
 
	/* If there were no strings in the savegame, set GameStrings to nullptr */
 
	if (_current_data->raw_strings.size() == 0) {
 
		delete _current_data;
 
		_current_data = nullptr;
 
		return;
 
	}
 

	
 
	_current_data->Compile();
 
	ReconsiderGameScriptLanguage();
 
}
 

	
 
static void Save_GSTR()
 
{
 
	if (_current_data == nullptr) return;
 

	
 
	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);
 
	}
 
}
 

	
 
static const ChunkHandler game_chunk_handlers[] = {
 
	{ 'GSTR', Save_GSTR, Load_GSTR, nullptr, nullptr, CH_ARRAY },
 
	{ 'GSDT', Save_GSDT, Load_GSDT, nullptr, nullptr, CH_ARRAY },
 
};
 

	
 
extern const ChunkHandlerTable _game_chunk_handlers(game_chunk_handlers);
0 comments (0 inline, 0 general)