mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-11-11 13:10:45 +00:00
Saveload: Add mechanism for custom handling of missing table fields
This commit is contained in:
parent
07afb0e00b
commit
10c136f039
@ -2208,7 +2208,7 @@ static uint8_t GetSavegameTableFileType(const SaveLoad &sld)
|
||||
* @param slt The NamedSaveLoad table with objects to save/load.
|
||||
* @return The ordered SaveLoad array to use.
|
||||
*/
|
||||
std::vector<SaveLoad> SlTableHeader(const NamedSaveLoadTable &slt)
|
||||
std::vector<SaveLoad> SlTableHeader(const NamedSaveLoadTable &slt, TableHeaderSpecialHandler *special_handler)
|
||||
{
|
||||
/* You can only use SlTableHeader if you are a CH_TABLE. */
|
||||
assert(_sl.block_mode == CH_TABLE || _sl.block_mode == CH_SPARSE_TABLE);
|
||||
@ -2255,6 +2255,8 @@ std::vector<SaveLoad> SlTableHeader(const NamedSaveLoadTable &slt)
|
||||
|
||||
auto sld_it = std::lower_bound(key_lookup.begin(), key_lookup.end(), key);
|
||||
if (sld_it == key_lookup.end() || sld_it->name != key) {
|
||||
if (special_handler != nullptr && special_handler->MissingField(key, type, saveloads)) continue; // Special handler took responsibility for missing field
|
||||
|
||||
/* SLA_LOADCHECK triggers this debug statement a lot and is perfectly normal. */
|
||||
DEBUG(sl, _sl.action == SLA_LOAD ? 2 : 6, "Field '%s' of type 0x%02X not found, skipping", key.c_str(), type);
|
||||
|
||||
|
@ -1071,9 +1071,15 @@ void SlObjectSaveFiltered(void *object, const SaveLoadTable &slt);
|
||||
void SlObjectLoadFiltered(void *object, const SaveLoadTable &slt);
|
||||
void SlObjectPtrOrNullFiltered(void *object, const SaveLoadTable &slt);
|
||||
|
||||
struct TableHeaderSpecialHandler {
|
||||
virtual ~TableHeaderSpecialHandler() {}
|
||||
|
||||
virtual bool MissingField(const std::string &key, uint8_t type, std::vector<SaveLoad> &saveloads) { return false; } // By default, do not handle
|
||||
};
|
||||
|
||||
bool SlIsTableChunk();
|
||||
void SlSkipTableHeader();
|
||||
std::vector<SaveLoad> SlTableHeader(const NamedSaveLoadTable &slt);
|
||||
std::vector<SaveLoad> SlTableHeader(const NamedSaveLoadTable &slt, TableHeaderSpecialHandler *special_handler = nullptr);
|
||||
std::vector<SaveLoad> SlTableHeaderOrRiff(const NamedSaveLoadTable &slt);
|
||||
void SlSaveTableObjectChunk(const SaveLoadTable &slt);
|
||||
void SlLoadTableOrRiffFiltered(const SaveLoadTable &slt);
|
||||
|
Loading…
Reference in New Issue
Block a user