summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMalkierian <malkierian@gmail.com>2024-02-15 19:44:40 -0700
committerGitHub <noreply@github.com>2024-02-15 20:44:40 -0600
commit30a063b75d504aaecec4b44a6f7d81f15fe778ff (patch)
tree05ecee9e78168a7f552309859be1767207399325
parentcf6101f4daeb8591c65b8a3d0262b4888e000d06 (diff)
[Tweak] Move Personal Notes to Save File (#3909)
* Moves personal notes to the save file under a new itemTracker save section. * Update soh/soh/Enhancements/randomizer/randomizer_item_tracker.cpp --------- Co-authored-by: Archez <Archez@users.noreply.github.com>
-rw-r--r--soh/soh/Enhancements/randomizer/randomizer_item_tracker.cpp42
1 files changed, 27 insertions, 15 deletions
diff --git a/soh/soh/Enhancements/randomizer/randomizer_item_tracker.cpp b/soh/soh/Enhancements/randomizer/randomizer_item_tracker.cpp
index f24ab818b..f63b37b62 100644
--- a/soh/soh/Enhancements/randomizer/randomizer_item_tracker.cpp
+++ b/soh/soh/Enhancements/randomizer/randomizer_item_tracker.cpp
@@ -30,6 +30,8 @@ void DrawBottle(ItemTrackerItem item);
void DrawQuest(ItemTrackerItem item);
void DrawSong(ItemTrackerItem item);
+int itemTrackerSectionId;
+
bool shouldUpdateVectors = true;
std::vector<ItemTrackerItem> mainWindowItems = {};
@@ -282,11 +284,6 @@ void ItemTrackerOnFrame() {
}
}
-void SaveNotes(uint32_t fileNum) {
- CVarSetString(("gItemTrackerNotes" + std::to_string(fileNum)).c_str(), std::string(std::begin(itemTrackerNotes), std::end(itemTrackerNotes)).c_str());
- LUS::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesOnNextTick();
-}
-
bool IsValidSaveFile() {
bool validSave = gSaveContext.fileNum >= 0 && gSaveContext.fileNum <= 2;
return validSave;
@@ -734,7 +731,7 @@ void DrawNotes(bool resizeable = false) {
}
if ((ImGui::IsItemDeactivatedAfterEdit() || (notesNeedSave && notesIdleFrames > notesMaxIdleFrames)) && IsValidSaveFile()) {
notesNeedSave = false;
- SaveNotes(gSaveContext.fileNum);
+ SaveManager::Instance->SaveSection(gSaveContext.fileNum, itemTrackerSectionId, true);
}
ImGui::EndGroup();
}
@@ -959,6 +956,26 @@ void UpdateVectors() {
shouldUpdateVectors = false;
}
+void ItemTrackerInitFile(bool isDebug) {
+ itemTrackerNotes.clear();
+ itemTrackerNotes.push_back(0);
+}
+
+void ItemTrackerSaveFile(SaveContext* saveContext, int sectionID, bool fullSave) {
+ SaveManager::Instance->SaveData("personalNotes", std::string(std::begin(itemTrackerNotes), std::end(itemTrackerNotes)).c_str());
+}
+
+void ItemTrackerLoadFile() {
+ std::string initialTrackerNotes = "";
+ SaveManager::Instance->LoadData("personalNotes", initialTrackerNotes);
+ itemTrackerNotes.resize(initialTrackerNotes.length() + 1);
+ if (initialTrackerNotes != "") {
+ SohUtils::CopyStringToCharArray(itemTrackerNotes.Data, initialTrackerNotes.c_str(), itemTrackerNotes.size());
+ } else {
+ itemTrackerNotes.push_back(0);
+ }
+}
+
void ItemTrackerWindow::DrawElement() {
UpdateVectors();
@@ -1223,14 +1240,9 @@ void ItemTrackerWindow::InitElement() {
itemTrackerNotes.push_back(0);
}
- GameInteractor::Instance->RegisterGameHook<GameInteractor::OnLoadFile>([](uint32_t fileNum) {
- const char* initialTrackerNotes = CVarGetString(("gItemTrackerNotes" + std::to_string(fileNum)).c_str(), "");
- itemTrackerNotes.resize(strlen(initialTrackerNotes) + 1);
- strcpy(itemTrackerNotes.Data, initialTrackerNotes);
- });
- GameInteractor::Instance->RegisterGameHook<GameInteractor::OnDeleteFile>([](uint32_t fileNum) {
- CVarSetString(("gItemTrackerNotes" + std::to_string(fileNum)).c_str(), "");
- LUS::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesOnNextTick();
- });
+ SaveManager::Instance->AddInitFunction(ItemTrackerInitFile);
+ itemTrackerSectionId = SaveManager::Instance->AddSaveFunction("itemTrackerData", 1, ItemTrackerSaveFile, true, -1);
+ SaveManager::Instance->AddLoadFunction("itemTrackerData", 1, ItemTrackerLoadFile);
+
GameInteractor::Instance->RegisterGameHook<GameInteractor::OnGameFrameUpdate>(ItemTrackerOnFrame);
}