Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions soh/soh/Enhancements/randomizer/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
#include "soh/Enhancements/randomizer/randomizerTypes.h"
#include "trial.h"
#include "dungeon.h"
#include "3drando/random.hpp"

#include "soh/OTRGlobals.h"

#include <spdlog/spdlog.h>

#include <libultraship/bridge/consolevariablebridge.h>
#include <libultraship/libultraship.h>

namespace Rando {
std::shared_ptr<Settings> Settings::mInstance;
Expand Down Expand Up @@ -3471,6 +3473,48 @@ void Settings::SetAllToContext() {
}
}

void Settings::RandomizeAllSettings() {
// Randomize all settings except tricks
for (int i = 0; i < RSK_MAX; i++) {
switch (static_cast<RandomizerSettingKey>(i)) {
case RSK_STARTING_SKULLTULA_TOKEN:
case RSK_STARTING_HEARTS:
case RSK_STARTING_ZELDAS_LULLABY:
case RSK_STARTING_EPONAS_SONG:
case RSK_STARTING_SARIAS_SONG:
case RSK_STARTING_SUNS_SONG:
case RSK_STARTING_SONG_OF_TIME:
case RSK_STARTING_SONG_OF_STORMS:
case RSK_STARTING_MINUET_OF_FOREST:
case RSK_STARTING_BOLERO_OF_FIRE:
case RSK_STARTING_SERENADE_OF_WATER:
case RSK_STARTING_REQUIEM_OF_SPIRIT:
case RSK_STARTING_NOCTURNE_OF_SHADOW:
case RSK_STARTING_PRELUDE_OF_LIGHT:
continue;
default:
break;
}

auto key = static_cast<RandomizerSettingKey>(i);
Option& option = mOptions[key];

if (option.GetOptionCount() == 0) {
continue;
}

uint8_t randomIndex = Random(0, static_cast<uint32_t>(option.GetOptionCount()));

option.SetContextIndex(randomIndex);
if (!option.GetCVarName().empty()) {
CVarSetInteger(option.GetCVarName().c_str(), randomIndex);
}
option.RunCallback();
Comment thread
serprex marked this conversation as resolved.
}

Ship::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesNextFrame();
}

std::shared_ptr<Settings> Settings::GetInstance() {
if (mInstance == nullptr) {
mInstance = std::make_shared<Settings>();
Expand Down
7 changes: 7 additions & 0 deletions soh/soh/Enhancements/randomizer/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,13 @@ class Settings {
*/
void SetAllToContext();

/**
* @brief Randomizes all randomizer settings (excluding tricks) to random valid values.
* This function iterates through all options and sets them to a random index within
* their valid range.
*/
void RandomizeAllSettings();

static std::shared_ptr<Settings> GetInstance();

private:
Expand Down
22 changes: 15 additions & 7 deletions soh/soh/SohGui/SohMenuRandomizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -585,15 +585,23 @@ void SohMenu::AddMenuRandomizer() {
.Options(ButtonOptions()
.Size(ImVec2(250.f, 0.f))
.DisabledTooltip("Must be on File Select to generate a randomizer seed."));
AddWidget(path, "Spoiler File", WIDGET_CUSTOM)
.CustomFunction([](WidgetInfo& info) {
JoinRandoGenerationThread();
if (!CVarGetInteger(CVAR_RANDOMIZER_SETTING("DontGenerateSpoiler"), 0)) {
std::string spoilerfilepath = CVarGetString(CVAR_GENERAL("SpoilerLog"), "");
ImGui::Text("Spoiler File: %s", spoilerfilepath.c_str());
}
AddWidget(path, "Randomize All Settings", WIDGET_BUTTON)
.Callback([](WidgetInfo& info) { Rando::Settings::GetInstance()->RandomizeAllSettings(); })
.PreFunc([](WidgetInfo& info) {
info.options->disabled = CVarGetInteger(CVAR_GENERAL("RandoGenerating"), 0) ||
CVarGetInteger(CVAR_GENERAL("OnFileSelectNameEntry"), 0);
})
.Options(ButtonOptions()
.Size(ImVec2(250.f, 0.f))
.Tooltip("Randomizes all randomizer settings to random valid values (excludes tricks)."))
.SameLine(true);
AddWidget(path, "Spoiler File", WIDGET_CUSTOM).CustomFunction([](WidgetInfo& info) {
JoinRandoGenerationThread();
if (!CVarGetInteger(CVAR_RANDOMIZER_SETTING("DontGenerateSpoiler"), 0)) {
std::string spoilerfilepath = CVarGetString(CVAR_GENERAL("SpoilerLog"), "");
ImGui::Text("Spoiler File: %s", spoilerfilepath.c_str());
}
});

// Enhancements
AddWidget(path, "Enhancements", WIDGET_SEPARATOR_TEXT);
Expand Down
Loading