mirror of
https://github.com/HarbourMasters/Shipwright.git
synced 2025-02-16 07:10:34 -05:00
[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>
This commit is contained in:
parent
cf6101f4da
commit
30a063b75d
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user