Update randomizer save format (#1635)

* Update randomizer save format

* Move changes to LoadRandomizerVersion2
This commit is contained in:
Garrett Cox 2022-10-02 05:11:12 -05:00 committed by GitHub
parent f3f357c874
commit 75d0402525
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 96 additions and 48 deletions

View File

@ -256,7 +256,6 @@ void Randomizer::LoadRandomizerSettings(const char* spoilerFileName) {
}
for(auto randoSetting : gSaveContext.randoSettings) {
if(randoSetting.key == RSK_NONE) break;
this->randoSettings[randoSetting.key] = randoSetting.value;
}
}
@ -493,8 +492,7 @@ void Randomizer::ParseRandomizerSettingsFile(const char* spoilerFileName) {
try {
// clear out existing settings
// RANDOTODO don't use magic number for settings array size
for(size_t i = 0; i < 300; i++) {
for(size_t i = 0; i < RSK_MAX; i++) {
gSaveContext.randoSettings[i].key = RSK_NONE;
gSaveContext.randoSettings[i].value = 0;
}
@ -503,13 +501,12 @@ void Randomizer::ParseRandomizerSettingsFile(const char* spoilerFileName) {
spoilerFileStream >> spoilerFileJson;
json settingsJson = spoilerFileJson["settings"];
int index = 0;
for (auto it = settingsJson.begin(); it != settingsJson.end(); ++it) {
// todo load into cvars for UI
std::string numericValueString;
if(SpoilerfileSettingNameToEnum.count(it.key())) {
RandomizerSettingKey index = SpoilerfileSettingNameToEnum[it.key()];
gSaveContext.randoSettings[index].key = SpoilerfileSettingNameToEnum[it.key()];
// this is annoying but the same strings are used in different orders
// and i don't want the spoilerfile to just have numbers instead of
@ -795,7 +792,6 @@ void Randomizer::ParseRandomizerSettingsFile(const char* spoilerFileName) {
}
break;
}
index++;
}
}
@ -995,25 +991,23 @@ void Randomizer::ParseItemLocationsFile(const char* spoilerFileName, bool silent
index++;
}
index = 0;
for (auto it = locationsJson.begin(); it != locationsJson.end(); ++it) {
RandomizerCheck randomizerCheck = SpoilerfileCheckNameToEnum[it.key()];
if (it->is_structured()) {
json itemJson = *it;
for (auto itemit = itemJson.begin(); itemit != itemJson.end(); ++itemit) {
// todo handle prices
if (itemit.key() == "item") {
gSaveContext.itemLocations[index].check = SpoilerfileCheckNameToEnum[it.key()];
gSaveContext.itemLocations[index].get = SpoilerfileGetNameToEnum[itemit.value()];
gSaveContext.itemLocations[randomizerCheck].check = randomizerCheck;
gSaveContext.itemLocations[randomizerCheck].get = SpoilerfileGetNameToEnum[itemit.value()];
} else if (itemit.key() == "price") {
merchantPrices[gSaveContext.itemLocations[index].check] = itemit.value();
merchantPrices[gSaveContext.itemLocations[randomizerCheck].check] = itemit.value();
}
}
} else {
gSaveContext.itemLocations[index].check = SpoilerfileCheckNameToEnum[it.key()];
gSaveContext.itemLocations[index].get = SpoilerfileGetNameToEnum[it.value()];
gSaveContext.itemLocations[randomizerCheck].check = randomizerCheck;
gSaveContext.itemLocations[randomizerCheck].get = SpoilerfileGetNameToEnum[it.value()];
}
index++;
}
if(!silent) {

View File

@ -1024,7 +1024,8 @@ typedef enum {
RSK_SUNLIGHT_ARROWS,
RSK_ENABLE_BOMBCHU_DROPS,
RSK_BOMBCHUS_IN_LOGIC,
RSK_LINKS_POCKET
RSK_LINKS_POCKET,
RSK_MAX
} RandomizerSettingKey;
typedef enum {

View File

@ -29,7 +29,8 @@ SaveManager::SaveManager() {
AddSaveFunction("base", 2, SaveBase);
AddLoadFunction("randomizer", 1, LoadRandomizerVersion1);
AddSaveFunction("randomizer", 1, SaveRandomizer);
AddLoadFunction("randomizer", 2, LoadRandomizerVersion2);
AddSaveFunction("randomizer", 2, SaveRandomizer);
AddInitFunction(InitFileImpl);
@ -118,46 +119,97 @@ void SaveManager::LoadRandomizerVersion1() {
});
}
void SaveManager::LoadRandomizerVersion2() {
if(!CVar_GetS32("gRandomizer", 0)) return;
SaveManager::Instance->LoadArray("itemLocations", RC_MAX, [&](size_t i) {
gSaveContext.itemLocations[i].check = RandomizerCheck(i);
SaveManager::Instance->LoadData("", gSaveContext.itemLocations[i].get);
});
SaveManager::Instance->LoadArray("seed", ARRAY_COUNT(gSaveContext.seedIcons), [&](size_t i) {
SaveManager::Instance->LoadData("", gSaveContext.seedIcons[i]);
});
SaveManager::Instance->LoadArray("randoSettings", RSK_MAX, [&](size_t i) {
gSaveContext.randoSettings[i].key = RandomizerSettingKey(i);
SaveManager::Instance->LoadData("", gSaveContext.randoSettings[i].value);
});
SaveManager::Instance->LoadArray("hintLocations", ARRAY_COUNT(gSaveContext.hintLocations), [&](size_t i) {
SaveManager::Instance->LoadStruct("", [&]() {
SaveManager::Instance->LoadData("check", gSaveContext.hintLocations[i].check);
std::string hintText;
SaveManager::Instance->LoadData("hintText", hintText);
memcpy(gSaveContext.hintLocations[i].hintText, hintText.c_str(), hintText.length());
});
});
std::string childAltarText;
SaveManager::Instance->LoadData("childAltarText", childAltarText);
memcpy(gSaveContext.childAltarText, childAltarText.c_str(), childAltarText.length());
std::string adultAltarText;
SaveManager::Instance->LoadData("adultAltarText", adultAltarText);
memcpy(gSaveContext.adultAltarText, adultAltarText.c_str(), adultAltarText.length());
std::string ganonHintText;
SaveManager::Instance->LoadData("ganonHintText", ganonHintText);
memcpy(gSaveContext.ganonHintText, ganonHintText.c_str(), ganonHintText.length());
std::string ganonText;
SaveManager::Instance->LoadData("ganonText", ganonText);
memcpy(gSaveContext.ganonText, ganonText.c_str(), ganonText.length());
SaveManager::Instance->LoadData("adultTradeItems", gSaveContext.adultTradeItems);
SaveManager::Instance->LoadData("pendingIceTrapCount", gSaveContext.pendingIceTrapCount);
std::shared_ptr<Randomizer> randomizer = OTRGlobals::Instance->gRandomizer;
size_t merchantPricesSize = 0;
if (randomizer->GetRandoSettingValue(RSK_SHUFFLE_SCRUBS) > 0) {
merchantPricesSize += NUM_SCRUBS;
}
if (randomizer->GetRandoSettingValue(RSK_SHOPSANITY) > 0) {
merchantPricesSize += NUM_SHOP_ITEMS;
}
SaveManager::Instance->LoadArray("merchantPrices", merchantPricesSize, [&](size_t i) {
SaveManager::Instance->LoadStruct("", [&]() {
RandomizerCheck rc;
SaveManager::Instance->LoadData("check", rc);
uint32_t price;
SaveManager::Instance->LoadData("price", price);
randomizer->merchantPrices[rc] = price;
});
});
}
void SaveManager::SaveRandomizer() {
if(!gSaveContext.n64ddFlag) return;
for (int i = 0; i < ARRAY_COUNT(gSaveContext.itemLocations); i++) {
SaveManager::Instance->SaveData("get" + std::to_string(i), gSaveContext.itemLocations[i].get);
SaveManager::Instance->SaveData("check" + std::to_string(i), gSaveContext.itemLocations[i].check);
}
SaveManager::Instance->SaveArray("itemLocations", RC_MAX, [&](size_t i) {
SaveManager::Instance->SaveData("", gSaveContext.itemLocations[i].get);
});
for (int i = 0; i < ARRAY_COUNT(gSaveContext.seedIcons); i++) {
SaveManager::Instance->SaveData("seed" + std::to_string(i), gSaveContext.seedIcons[i]);
}
SaveManager::Instance->SaveArray("seed", ARRAY_COUNT(gSaveContext.seedIcons), [&](size_t i) {
SaveManager::Instance->SaveData("", gSaveContext.seedIcons[i]);
});
for (int i = 0; i < ARRAY_COUNT(gSaveContext.randoSettings); i++) {
SaveManager::Instance->SaveData("sk" + std::to_string(i), gSaveContext.randoSettings[i].key);
SaveManager::Instance->SaveData("sv" + std::to_string(i), gSaveContext.randoSettings[i].value);
}
SaveManager::Instance->SaveArray("randoSettings", RSK_MAX, [&](size_t i) {
SaveManager::Instance->SaveData("", gSaveContext.randoSettings[i].value);
});
for (int i = 0; i < ARRAY_COUNT(gSaveContext.hintLocations); i++) {
SaveManager::Instance->SaveData("hc" + std::to_string(i), gSaveContext.hintLocations[i].check);
for (int j = 0; j < ARRAY_COUNT(gSaveContext.hintLocations[i].hintText); j++) {
SaveManager::Instance->SaveData("ht" + std::to_string(i) + "-" + std::to_string(j), gSaveContext.hintLocations[i].hintText[j]);
}
}
SaveManager::Instance->SaveArray("hintLocations", ARRAY_COUNT(gSaveContext.hintLocations), [&](size_t i) {
SaveManager::Instance->SaveStruct("", [&]() {
SaveManager::Instance->SaveData("check", gSaveContext.hintLocations[i].check);
SaveManager::Instance->SaveData("hintText", gSaveContext.hintLocations[i].hintText);
});
});
for (int i = 0; i < ARRAY_COUNT(gSaveContext.childAltarText); i++) {
SaveManager::Instance->SaveData("cat" + std::to_string(i), gSaveContext.childAltarText[i]);
}
for (int i = 0; i < ARRAY_COUNT(gSaveContext.adultAltarText); i++) {
SaveManager::Instance->SaveData("aat" + std::to_string(i), gSaveContext.adultAltarText[i]);
}
for (int i = 0; i < ARRAY_COUNT(gSaveContext.ganonHintText); i++) {
SaveManager::Instance->SaveData("ght" + std::to_string(i), gSaveContext.ganonHintText[i]);
}
for (int i = 0; i < ARRAY_COUNT(gSaveContext.ganonText); i++) {
SaveManager::Instance->SaveData("gt" + std::to_string(i), gSaveContext.ganonText[i]);
}
SaveManager::Instance->SaveData("childAltarText", gSaveContext.childAltarText);
SaveManager::Instance->SaveData("adultAltarText", gSaveContext.adultAltarText);
SaveManager::Instance->SaveData("ganonHintText", gSaveContext.ganonHintText);
SaveManager::Instance->SaveData("ganonText", gSaveContext.ganonText);
SaveManager::Instance->SaveData("adultTradeItems", gSaveContext.adultTradeItems);

View File

@ -116,6 +116,7 @@ public:
static void InitFileDebug();
static void LoadRandomizerVersion1();
static void LoadRandomizerVersion2();
static void SaveRandomizer();
static void LoadBaseVersion1();