mirror of
https://github.com/HarbourMasters/Shipwright.git
synced 2024-11-25 02:42:18 -05:00
Section Save Modification (#2947)
* Modified `SaveManager::AddSaveFunction` to return the section index assigned to the section name for ease of remembering it on the other end. Also added a clarifying comment. * Modified SaveFunc to accept a boolean for whether the section is being saved individually or as part of a game save (fullSave == true means game save, so all sections registered for game save sync).
This commit is contained in:
parent
279c40cb7d
commit
5daf5a14ac
@ -339,7 +339,7 @@ void LoadStatsVersion1() {
|
||||
});
|
||||
}
|
||||
|
||||
void SaveStats(SaveContext* saveContext, int sectionID) {
|
||||
void SaveStats(SaveContext* saveContext, int sectionID, bool fullSave) {
|
||||
SaveManager::Instance->SaveData("buildVersion", saveContext->sohStats.buildVersion);
|
||||
SaveManager::Instance->SaveData("buildVersionMajor", saveContext->sohStats.buildVersionMajor);
|
||||
SaveManager::Instance->SaveData("buildVersionMinor", saveContext->sohStats.buildVersionMinor);
|
||||
|
@ -268,7 +268,7 @@ void SaveManager::LoadRandomizerVersion2() {
|
||||
});
|
||||
}
|
||||
|
||||
void SaveManager::SaveRandomizer(SaveContext* saveContext, int sectionID) {
|
||||
void SaveManager::SaveRandomizer(SaveContext* saveContext, int sectionID, bool fullSave) {
|
||||
|
||||
if(!saveContext->n64ddFlag) return;
|
||||
|
||||
@ -716,7 +716,7 @@ void SaveManager::SaveFileThreaded(int fileNum, SaveContext* saveContext, int se
|
||||
}
|
||||
|
||||
currentJsonContext = §ionBlock["data"];
|
||||
sectionHandlerPair.second.func(saveContext, sectionID);
|
||||
sectionHandlerPair.second.func(saveContext, sectionID, true);
|
||||
}
|
||||
} else {
|
||||
SaveFuncInfo svi = sectionSaveHandlers.find(sectionID)->second;
|
||||
@ -731,7 +731,7 @@ void SaveManager::SaveFileThreaded(int fileNum, SaveContext* saveContext, int se
|
||||
nlohmann::json& sectionBlock = saveBlock["sections"][sectionName];
|
||||
sectionBlock["version"] = sectionVersion;
|
||||
currentJsonContext = §ionBlock["data"];
|
||||
svi.func(saveContext, sectionID);
|
||||
svi.func(saveContext, sectionID, false);
|
||||
}
|
||||
|
||||
#if defined(__SWITCH__) || defined(__WIIU__)
|
||||
@ -750,6 +750,7 @@ void SaveManager::SaveFileThreaded(int fileNum, SaveContext* saveContext, int se
|
||||
}
|
||||
|
||||
// SaveSection creates a copy of gSaveContext to prevent mid-save data modification, and passes its reference to SaveFileThreaded
|
||||
// This should never be called with threaded == false except during file creation
|
||||
void SaveManager::SaveSection(int fileNum, int sectionID, bool threaded) {
|
||||
// Don't save in Boss rush.
|
||||
if (fileNum == 0xFF || fileNum == 0xFE) {
|
||||
@ -871,11 +872,11 @@ void SaveManager::AddLoadFunction(const std::string& name, int version, LoadFunc
|
||||
sectionLoadHandlers[name][version] = func;
|
||||
}
|
||||
|
||||
void SaveManager::AddSaveFunction(const std::string& name, int version, SaveFunc func, bool saveWithBase, int parentSection = -1) {
|
||||
int SaveManager::AddSaveFunction(const std::string& name, int version, SaveFunc func, bool saveWithBase, int parentSection = -1) {
|
||||
if (sectionRegistry.contains(name)) {
|
||||
SPDLOG_ERROR("Adding save function for section that already has one: " + name);
|
||||
assert(false);
|
||||
return;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int index = sectionIndex;
|
||||
@ -887,6 +888,7 @@ void SaveManager::AddSaveFunction(const std::string& name, int version, SaveFunc
|
||||
SaveFuncInfo sfi = { name, version, func, saveWithBase, parentSection };
|
||||
sectionSaveHandlers.emplace(index, sfi);
|
||||
sectionRegistry.emplace(name, index);
|
||||
return index;
|
||||
}
|
||||
|
||||
void SaveManager::AddPostFunction(const std::string& name, PostFunc func) {
|
||||
@ -1656,7 +1658,7 @@ void SaveManager::LoadBaseVersion4() {
|
||||
SaveManager::Instance->LoadData("dogParams", gSaveContext.dogParams);
|
||||
}
|
||||
|
||||
void SaveManager::SaveBase(SaveContext* saveContext, int sectionID) {
|
||||
void SaveManager::SaveBase(SaveContext* saveContext, int sectionID, bool fullSave) {
|
||||
SaveManager::Instance->SaveData("entranceIndex", saveContext->entranceIndex);
|
||||
SaveManager::Instance->SaveData("linkAge", saveContext->linkAge);
|
||||
SaveManager::Instance->SaveData("cutsceneIndex", saveContext->cutsceneIndex);
|
||||
|
@ -44,7 +44,7 @@ class SaveManager {
|
||||
|
||||
using InitFunc = void (*)(bool isDebug);
|
||||
using LoadFunc = void (*)();
|
||||
using SaveFunc = void (*)(SaveContext* saveContext, int sectionID);
|
||||
using SaveFunc = void (*)(SaveContext* saveContext, int sectionID, bool fullSave);
|
||||
using PostFunc = void (*)(int version);
|
||||
|
||||
typedef struct {
|
||||
@ -75,7 +75,7 @@ class SaveManager {
|
||||
|
||||
// Adds a function that is called when saving. This should only be called once for each function, the version is
|
||||
// filled in automatically.
|
||||
void AddSaveFunction(const std::string& name, int version, SaveFunc func, bool saveWithBase, int parentSection);
|
||||
int AddSaveFunction(const std::string& name, int version, SaveFunc func, bool saveWithBase, int parentSection);
|
||||
|
||||
// Adds a function to be called after loading is complete. This is to handle any cleanup required from loading old
|
||||
// versions.
|
||||
@ -144,13 +144,13 @@ class SaveManager {
|
||||
|
||||
static void LoadRandomizerVersion1();
|
||||
static void LoadRandomizerVersion2();
|
||||
static void SaveRandomizer(SaveContext* saveContext, int sectionID);
|
||||
static void SaveRandomizer(SaveContext* saveContext, int sectionID, bool fullSave);
|
||||
|
||||
static void LoadBaseVersion1();
|
||||
static void LoadBaseVersion2();
|
||||
static void LoadBaseVersion3();
|
||||
static void LoadBaseVersion4();
|
||||
static void SaveBase(SaveContext* saveContext, int sectionID);
|
||||
static void SaveBase(SaveContext* saveContext, int sectionID, bool fullSave);
|
||||
|
||||
std::vector<InitFunc> initFuncs;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user