Fixes error noise when seed generation fails (#3527)

This commit is contained in:
Christopher Leggett 2023-12-18 17:31:29 -05:00 committed by GitHub
parent 4978c3b34f
commit bb4fb22188
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 26 deletions

View File

@ -21,28 +21,28 @@ std::vector<std::string> presetEntries;
Rando::Option* currentSetting; Rando::Option* currentSetting;
} // namespace } // namespace
std::string GenerateRandomizer(std::set<RandomizerCheck> excludedLocations, std::set<RandomizerTrick> enabledTricks, bool GenerateRandomizer(std::set<RandomizerCheck> excludedLocations, std::set<RandomizerTrick> enabledTricks,
std::string seedString) { std::string seedInput) {
auto ctx = Rando::Context::GetInstance(); const auto ctx = Rando::Context::GetInstance();
srand(time(NULL)); srand(time(NULL));
// if a blank seed was entered, make a random one // if a blank seed was entered, make a random one
if (seedString.empty()) { if (seedInput.empty()) {
seedString = std::to_string(rand() % 0xFFFFFFFF); seedInput = std::to_string(rand() % 0xFFFFFFFF);
} else if (seedString.rfind("seed_testing_count", 0) == 0 && seedString.length() > 18) { } else if (seedInput.rfind("seed_testing_count", 0) == 0 && seedInput.length() > 18) {
int count; int count;
try { try {
count = std::stoi(seedString.substr(18), nullptr); count = std::stoi(seedInput.substr(18), nullptr);
} catch (std::invalid_argument &e) { } catch (std::invalid_argument &e) {
count = 1; count = 1;
} catch (std::out_of_range &e) { } catch (std::out_of_range &e) {
count = 1; count = 1;
} }
Playthrough::Playthrough_Repeat(excludedLocations, enabledTricks, count); Playthrough::Playthrough_Repeat(excludedLocations, enabledTricks, count);
return ""; return false; // TODO: Not sure if this is correct but I don't think we support this functionality yet anyway.
} }
ctx->GetSettings()->SetSeedString(seedString); ctx->GetSettings()->SetSeedString(seedInput);
uint32_t seedHash = boost::hash_32<std::string>{}(ctx->GetSettings()->GetSeedString()); uint32_t seedHash = boost::hash_32<std::string>{}(ctx->GetSettings()->GetSeedString());
ctx->GetSettings()->SetSeed(seedHash & 0xFFFFFFFF); ctx->GetSettings()->SetSeed(seedHash & 0xFFFFFFFF);
@ -52,10 +52,10 @@ std::string GenerateRandomizer(std::set<RandomizerCheck> excludedLocations, std:
printf("\n\nFailed to generate after 5 tries.\nPress B to go back to the menu.\nA different seed might be " printf("\n\nFailed to generate after 5 tries.\nPress B to go back to the menu.\nA different seed might be "
"successful."); "successful.");
SPDLOG_DEBUG("\nRANDOMIZATION FAILED COMPLETELY. PLZ FIX\n");//RANDOTODO print seed for reproduction purposes SPDLOG_DEBUG("\nRANDOMIZATION FAILED COMPLETELY. PLZ FIX\n");//RANDOTODO print seed for reproduction purposes
return ""; return false;
} else { } else {
printf("\n\nError %d with fill.\nPress Select to exit or B to go back to the menu.\n", ret); printf("\n\nError %d with fill.\nPress Select to exit or B to go back to the menu.\n", ret);
return ""; return false;
} }
} }
@ -66,16 +66,5 @@ std::string GenerateRandomizer(std::set<RandomizerCheck> excludedLocations, std:
} }
ctx->GetOption(RSK_KEYSANITY).RestoreDelayedOption(); ctx->GetOption(RSK_KEYSANITY).RestoreDelayedOption();
} }
std::ostringstream fileNameStream; return true;
for (int i = 0; i < ctx->hashIconIndexes.size(); i++) {
if (i) {
fileNameStream << '-';
}
if (ctx->hashIconIndexes[i] < 10) {
fileNameStream << '0';
}
fileNameStream << std::to_string(ctx->hashIconIndexes[i]);
}
std::string fileName = fileNameStream.str();
return "./Randomizer/" + fileName + ".json";
} }

View File

@ -25,4 +25,4 @@
// #define CYAN "\x1b[36m" // #define CYAN "\x1b[36m"
// #define WHITE "\x1b[37m" // #define WHITE "\x1b[37m"
std::string GenerateRandomizer(std::set<RandomizerCheck> excludedLocations, std::set<RandomizerTrick> enabledTricks, std::string seedInput); bool GenerateRandomizer(std::set<RandomizerCheck> excludedLocations, std::set<RandomizerTrick> enabledTricks, std::string seedInput);

View File

@ -17,11 +17,10 @@ void RandoMain::GenerateRando(std::set<RandomizerCheck> excludedLocations, std::
// std::string settingsFileName = "./randomizer/latest_settings.json"; // std::string settingsFileName = "./randomizer/latest_settings.json";
// CVarSetString("gLoadedPreset", settingsFileName.c_str()); // CVarSetString("gLoadedPreset", settingsFileName.c_str());
std::string fileName = LUS::Context::GetPathRelativeToAppDirectory(GenerateRandomizer(excludedLocations, enabledTricks, seedString).c_str()); Rando::Context::GetInstance()->SetSeedGenerated(GenerateRandomizer(excludedLocations, enabledTricks, seedString));
CVarSave(); CVarSave();
CVarLoad(); CVarLoad();
Rando::Context::GetInstance()->SetSeedGenerated();
Rando::Context::GetInstance()->SetSpoilerLoaded(false); Rando::Context::GetInstance()->SetSpoilerLoaded(false);
Rando::Context::GetInstance()->SetPlandoLoaded(false); Rando::Context::GetInstance()->SetPlandoLoaded(false);
} }