From ece92765c90ac7185bc1942b8f06d539d57d4272 Mon Sep 17 00:00:00 2001 From: gymnast86 Date: Tue, 19 May 2026 00:51:17 -0700 Subject: [PATCH] use dusk config path for settings file --- .../randomizer/game/randomizer_context.cpp | 30 ++++--------------- .../randomizer/game/randomizer_context.hpp | 11 +------ .../generator/data/settings_list.yaml | 12 ++++---- .../generator/logic/spoiler_log.cpp | 6 ++-- src/dusk/randomizer/generator/randomizer.cpp | 22 ++------------ src/dusk/randomizer/generator/randomizer.hpp | 17 +++++------ .../randomizer/generator/seedgen/config.cpp | 24 ++++++--------- .../randomizer/generator/seedgen/config.hpp | 7 ++--- src/dusk/randomizer/generator/test/test.cpp | 2 +- src/dusk/ui/rando_config.cpp | 21 ++++++++++--- src/dusk/ui/rando_config.hpp | 10 +++++++ src/m_Do/m_Do_main.cpp | 5 +--- 12 files changed, 67 insertions(+), 100 deletions(-) diff --git a/src/dusk/randomizer/game/randomizer_context.cpp b/src/dusk/randomizer/game/randomizer_context.cpp index 017d30343d..81fcf9384b 100644 --- a/src/dusk/randomizer/game/randomizer_context.cpp +++ b/src/dusk/randomizer/game/randomizer_context.cpp @@ -3,6 +3,7 @@ #include "dusk/app_info.hpp" #include "dusk/logging.h" #include "dusk/main.h" +#include "dusk/data.hpp" #include "dusk/randomizer/game/tools.h" #include "dusk/randomizer/game/stages.h" #include "dusk/randomizer/game/verify_item_functions.h" @@ -246,8 +247,8 @@ std::optional RandomizerContext::LoadFromHash(const std::string& ha return std::nullopt; } -std::string RandomizerContext::GetSeedDataPath() const { - return std::string(SDL_GetPrefPath(dusk::OrgName, dusk::AppName)) + "randomizer/seeds/" + this->mHash + "/seed.dat"; +std::filesystem::path RandomizerContext::GetSeedDataPath() const { + return dusk::data::configured_data_path() / "randomizer" / "seeds" / this->mHash / "seed.dat"; } int RandomizerContext::SettingToEnum(const std::string& settingName) { @@ -304,8 +305,6 @@ int RandomizerContext::OptionToEnum(const std::string& optionName) { RandomizerState g_randomizerState; -randomizer::Randomizer g_RandomizerGenerator; - int RandomizerState::_create() { mInitialized = true; mEventItemStatus = QUEUE_EMPTY; @@ -1224,8 +1223,8 @@ RandomizerContext WriteSeedData(const std::unique_ptr WriteToFile(); std::optional LoadFromHash(const std::string& hash); - std::string GetSeedDataPath() const; + std::filesystem::path GetSeedDataPath() const; enum Settings { HYRULE_BARRIER_REQUIREMENTS, @@ -166,8 +166,6 @@ public: int foolishItemCount{0}; }; -extern randomizer::Randomizer g_RandomizerGenerator; - extern RandomizerState g_randomizerState; RandomizerContext& randomizer_GetContext(); @@ -217,7 +215,6 @@ std::vector HexToBytes(std::string hex); */ u32 getActorPatchesCurrentStageKey(u8 roomNo); -class stage_actor_data_class; /* * Gets the CRC32 hash of an actors name, parameters, position, and angle */ @@ -225,10 +222,4 @@ u32 getStageObjCRC32(u8* data, size_t size); void GenerateAndWriteSeed(std::string& generationStatusMsg); -void LoadRandomizerConfig(); - -randomizer::seedgen::config::Config& GetRandomizerConfig(); - -std::string GetRandomizerConfigPath(); - #endif //DUSK_RANDOMIZER_CONTEXT_HPP diff --git a/src/dusk/randomizer/generator/data/settings_list.yaml b/src/dusk/randomizer/generator/data/settings_list.yaml index dad4190507..5e120d2019 100644 --- a/src/dusk/randomizer/generator/data/settings_list.yaml +++ b/src/dusk/randomizer/generator/data/settings_list.yaml @@ -703,12 +703,12 @@ # - "Off": "Link will be dressed in his green knight's uniform." # - "On": "Link will be dressed in his Skyloft outfit seen at the start of the vanilla game." -- Name: Remove Enemy Music - Type: Preference - Default Option: "Off" - Options: - - "Off": "The background music will be interrupted by enemy drums when you get near to an enemy. Additionally, the intense music when Scaldera and Tentalus are vulnerable will play as normal." - - "On": "The background music will continue to play when you get near to enemies. Additionally, the intense music when Scaldera and Tentalus are vulnerable will not play and the background music will continue uninterrupted." +#- Name: Remove Enemy Music +# Type: Preference +# Default Option: "Off" +# Options: +# - "Off": "The background music will be interrupted by enemy drums when you get near to an enemy. Additionally, the intense music when Scaldera and Tentalus are vulnerable will play as normal." +# - "On": "The background music will continue to play when you get near to enemies. Additionally, the intense music when Scaldera and Tentalus are vulnerable will not play and the background music will continue uninterrupted." # - Name: low_health_beeping_speed # type: Preference diff --git a/src/dusk/randomizer/generator/logic/spoiler_log.cpp b/src/dusk/randomizer/generator/logic/spoiler_log.cpp index a52e2743ed..23bf5ff0ac 100644 --- a/src/dusk/randomizer/generator/logic/spoiler_log.cpp +++ b/src/dusk/randomizer/generator/logic/spoiler_log.cpp @@ -60,7 +60,7 @@ namespace randomizer::logic::spoiler_log auto& config = randomizer->GetConfig(); auto& worlds = randomizer->GetWorlds(); - std::string filepath = std::string(randomizer->GetSeedOutputPath()) + config.GetHash() + " Spoiler Log.txt"; + std::filesystem::path filepath = randomizer->GetSeedOutputPath() / (config.GetHash() + " Spoiler Log.txt"); std::ofstream spoilerLog; spoilerLog.open(filepath); @@ -230,7 +230,7 @@ namespace randomizer::logic::spoiler_log spoilerLog.close(); - utility::platform::Log("Wrote spoiler log to " + filepath); + utility::platform::Log("Wrote spoiler log to " + filepath.string()); } void GenerateAntiSpoilerLog(Randomizer* randomizer) @@ -241,7 +241,7 @@ namespace randomizer::logic::spoiler_log utility::file::create_directories(randomizer->GetSeedOutputPath()); } - std::string filepath = std::string(randomizer->GetSeedOutputPath()) + randomizer->GetConfig().GetHash() + " Anti-Spoiler Log.txt"; + std::filesystem::path filepath = randomizer->GetSeedOutputPath() / (randomizer->GetConfig().GetHash() + " Anti-Spoiler Log.txt"); std::ofstream antiSpoilerLog; antiSpoilerLog.open(filepath); diff --git a/src/dusk/randomizer/generator/randomizer.cpp b/src/dusk/randomizer/generator/randomizer.cpp index c953fc953a..ac2a1895a2 100644 --- a/src/dusk/randomizer/generator/randomizer.cpp +++ b/src/dusk/randomizer/generator/randomizer.cpp @@ -36,27 +36,11 @@ namespace randomizer return std::nullopt; } - void Randomizer::LoadConfig() { - this->_config.LoadFromFile(GetConfigPath(), GetPrefPath()); - } - void Randomizer::GenerateWorlds() { utility::time::ScopedTimer<"Seed generation took ", std::chrono::milliseconds> timer; - this->_worlds.clear(); - this->_eventIdCounter = 0; - this->_areaIdCounter = 0; - this->_locAccIdCounter = 0; - this->_playthroughSpheres.clear(); - this->_entranceSpheres.clear(); + this->_config.LoadFromFile(GetConfigPath(), GetPrefPath()); -#if RANDOMIZER_ONLY - const auto result = SDL_GetPrefPath(dusk::OrgName, dusk::AppName); - if (!result) - DuskLog.fatal("Unable to get PrefPath: {}", SDL_GetError()); - SetBaseOutputPath(result); - LoadConfig(); -#endif const std::string& configSeed = this->_config.GetSeed(); std::string hashStr = configSeed.empty() ? seedgen::seed::GenerateSeed() : configSeed; _config.SetSeed(hashStr); @@ -136,8 +120,8 @@ namespace randomizer logic::spoiler_log::GenerateAntiSpoilerLog(this); } - std::string Randomizer::GetSeedOutputPath() + std::filesystem::path Randomizer::GetSeedOutputPath() { - return this->_baseOutputPath + "seeds/" + this->_config.GetHash() + "/"; + return this->_baseOutputPath / "seeds" / this->_config.GetHash(); } } // namespace randomizer diff --git a/src/dusk/randomizer/generator/randomizer.hpp b/src/dusk/randomizer/generator/randomizer.hpp index 5e699d9590..89009e55f4 100644 --- a/src/dusk/randomizer/generator/randomizer.hpp +++ b/src/dusk/randomizer/generator/randomizer.hpp @@ -9,7 +9,8 @@ namespace randomizer class Randomizer { public: - explicit Randomizer() = default; + Randomizer() = delete; + Randomizer(const std::filesystem::path& baseOutputPath) : _baseOutputPath(baseOutputPath / "randomizer") {} /** * @brief Generates a complete randomizer seed @@ -29,14 +30,12 @@ namespace randomizer auto& GetPlaythroughSpheres() { return this->_playthroughSpheres; } auto& GetEntranceSpheres() { return this->_entranceSpheres; } - std::string GetSeedOutputPath(); - const std::string& GetBaseOutputPath() const { return this->_baseOutputPath; }; - void SetBaseOutputPath(const std::string& path) { this->_baseOutputPath = path + "randomizer/"; }; + std::filesystem::path GetSeedOutputPath(); + std::filesystem::path GetBaseOutputPath() const { return this->_baseOutputPath; }; + void SetBaseOutputPath(const std::filesystem::path& path) { this->_baseOutputPath = path / "randomizer"; }; - void LoadConfig(); - - std::string GetConfigPath() const { return this->GetBaseOutputPath() + "settings.yaml"; } - std::string GetPrefPath() const { return this->GetBaseOutputPath() + "preferences.yaml"; } + std::filesystem::path GetConfigPath() const { return this->GetBaseOutputPath() / "settings.yaml"; } + std::filesystem::path GetPrefPath() const { return this->GetBaseOutputPath() / "preferences.yaml"; } private: seedgen::config::Config _config{}; logic::world::WorldPool _worlds{}; @@ -49,6 +48,6 @@ namespace randomizer std::list> _playthroughSpheres{}; std::list> _entranceSpheres{}; - std::string _baseOutputPath{RANDO_SAVE_PATH}; + std::filesystem::path _baseOutputPath{RANDO_SAVE_PATH}; }; } // namespace randomizer diff --git a/src/dusk/randomizer/generator/seedgen/config.cpp b/src/dusk/randomizer/generator/seedgen/config.cpp index f06d3bd65c..85fb3748dc 100644 --- a/src/dusk/randomizer/generator/seedgen/config.cpp +++ b/src/dusk/randomizer/generator/seedgen/config.cpp @@ -12,6 +12,9 @@ namespace randomizer::seedgen::config { + Config::Config(const fspath& settingsPath, const fspath& preferencesPath) { + LoadFromFile(settingsPath, preferencesPath); + } void Config::LoadFromFile(const fspath& settingsPath, const fspath& preferencesPath, @@ -159,16 +162,6 @@ namespace randomizer::seedgen::config settings.InsertSetting(preferenceName, settings::Setting(preferenceInfo.get(), preferenceOption)); } - else if (preferenceName == "Game Base Path") - { - const auto& gameBasePath = preferenceNode.second.as(); - this->_gameBasePath = gameBasePath; - } - else if (preferenceName == "Output Path") - { - const auto& outputPath = preferenceNode.second.as(); - this->_outputPath = outputPath; - } else if (preferenceName == "Plandomizer Path") { const auto& plandomizerPath = preferenceNode.second.as(); @@ -205,7 +198,7 @@ namespace randomizer::seedgen::config { rewriteSettings = true; } - if (!preferencesTree["Game Base Path"] || !preferencesTree["Output Path"] || !preferencesTree["Plandomizer Path"]) + if (!preferencesTree["Plandomizer Path"]) { rewritePreferences = true; } @@ -284,8 +277,6 @@ namespace randomizer::seedgen::config YAML::Node out; for (auto& settings : this->_settingsList) { - out["Game Base Path"] = this->_gameBasePath.generic_string(); - out["Output Path"] = this->_outputPath.generic_string(); out["Plandomizer Path"] = this->_plandomizerPath.generic_string(); for (auto& [settingName, setting] : settings.GetMap()) { @@ -324,6 +315,11 @@ namespace randomizer::seedgen::config outputFile.close(); } + void Config::WriteToFile(const fspath& settingsPath, const fspath& preferencesPath) { + WriteSettingsToFile(settingsPath); + WritePreferencesToFile(preferencesPath); + } + std::string Config::GetHash() { if (this->_hash.empty()) @@ -381,8 +377,6 @@ namespace randomizer::seedgen::config auto settingInfoMap = settings::GetAllSettingsInfo(); YAML::Node root; - root["Game Base Path"] = ""; - root["Output Path"] = ""; root["Plandomizer Path"] = ""; for (const auto& [name, info] : *settingInfoMap) { diff --git a/src/dusk/randomizer/generator/seedgen/config.hpp b/src/dusk/randomizer/generator/seedgen/config.hpp index 4abd6f2cf1..a0227da9d5 100644 --- a/src/dusk/randomizer/generator/seedgen/config.hpp +++ b/src/dusk/randomizer/generator/seedgen/config.hpp @@ -46,9 +46,8 @@ namespace randomizer::seedgen::config { public: Config() = default; + Config(const fspath& settingsPath, const fspath& preferencesPath); - fspath GetGameBasePath() const { return this->_gameBasePath; } - fspath GetOutputPath() const { return this->_outputPath; } fspath GetPlandomizerPath() const { return this->_plandomizerPath; } void SetSeed(const std::string& newSeed) { this->_seed = newSeed; } std::string GetSeed() const { return this->_seed; } @@ -66,7 +65,7 @@ namespace randomizer::seedgen::config YAML::Node PreferencesToYaml(); void WriteSettingsToFile(const fspath& filePath); void WritePreferencesToFile(const fspath& preferencesPath); - // void WriteToFile(const fspath& filePath, const fspath& preferencesPath) const; + void WriteToFile(const fspath& filePath, const fspath& preferencesPath); // PermalinkError loadPermalink(std::string b64permalink); // std::string getPermalink(const bool& internal = false) const; @@ -79,8 +78,6 @@ namespace randomizer::seedgen::config std::string GetHash(); private: - fspath _gameBasePath; - fspath _outputPath; fspath _plandomizerPath; std::string _seed; diff --git a/src/dusk/randomizer/generator/test/test.cpp b/src/dusk/randomizer/generator/test/test.cpp index 4b120381c9..250874ed09 100644 --- a/src/dusk/randomizer/generator/test/test.cpp +++ b/src/dusk/randomizer/generator/test/test.cpp @@ -22,7 +22,7 @@ namespace randomizer::test::test std::cout << "Testing " << testName << std::endl; try { - Randomizer r{}; + Randomizer r{RANDO_SAVE_PATH}; r.GenerateWorlds(); } catch(const std::exception& e) { diff --git a/src/dusk/ui/rando_config.cpp b/src/dusk/ui/rando_config.cpp index 52e03c570b..93a8e367bd 100644 --- a/src/dusk/ui/rando_config.cpp +++ b/src/dusk/ui/rando_config.cpp @@ -6,12 +6,13 @@ #include "SDL3/SDL_filesystem.h" #include "bool_button.hpp" +#include "dusk/app_info.hpp" +#include "dusk/config.hpp" +#include "dusk/data.hpp" +#include "dusk/logging.h" #include "number_button.hpp" #include "pane.hpp" #include "string_button.hpp" -#include "dusk/app_info.hpp" -#include "dusk/config.hpp" -#include "dusk/logging.h" namespace dusk::ui { @@ -83,7 +84,7 @@ SelectButton& config_bool_select( } void SaveConfig() { - GetRandomizerConfig().WriteSettingsToFile(GetRandomizerConfigPath()); + GetRandomizerConfig().WriteToFile(GetRandomizerSettingsPath(), GetRandomizerPreferencesPath()); } void rando_config_group(Pane& leftPane, Pane& rightPane, std::string settingKey, std::function onSelected = nullptr) { @@ -344,4 +345,16 @@ RandomizerWindow::RandomizerWindow() { }); } +std::filesystem::path GetRandomizerSettingsPath() { + return data::configured_data_path() / "randomizer" / "settings.yaml"; +} + +std::filesystem::path GetRandomizerPreferencesPath() { + return data::configured_data_path() / "randomizer" / "preferences.yaml"; +} + +randomizer::seedgen::config::Config& GetRandomizerConfig() { + static randomizer::seedgen::config::Config s_config{GetRandomizerSettingsPath(), GetRandomizerPreferencesPath()}; + return s_config; +} } diff --git a/src/dusk/ui/rando_config.hpp b/src/dusk/ui/rando_config.hpp index b620894922..d2cd353c8f 100644 --- a/src/dusk/ui/rando_config.hpp +++ b/src/dusk/ui/rando_config.hpp @@ -1,7 +1,17 @@ #pragma once #include "window.hpp" +// Forward declaration +namespace randomizer::seedgen::config { + class Config; +} + namespace dusk::ui { + + std::filesystem::path GetRandomizerSettingsPath(); + std::filesystem::path GetRandomizerPreferencesPath(); + randomizer::seedgen::config::Config& GetRandomizerConfig(); + class RandomizerWindow : public Window { public: RandomizerWindow(); diff --git a/src/m_Do/m_Do_main.cpp b/src/m_Do/m_Do_main.cpp index 7f75bf8443..541da28c19 100644 --- a/src/m_Do/m_Do_main.cpp +++ b/src/m_Do/m_Do_main.cpp @@ -503,7 +503,7 @@ int game_main(int argc, char* argv[]) { #ifdef LOGIC_TESTS randomizer::test::test::RunTests(); #else - randomizer::Randomizer rando{}; + randomizer::Randomizer rando{dusk::data::configured_data_path()}; rando.Generate(); #endif exit(0); @@ -634,9 +634,6 @@ int game_main(int argc, char* argv[]) { dusk::audio::SetEnableReverb(dusk::getSettings().audio.enableReverb); dusk::audio::EnableHrtf = dusk::getSettings().audio.enableHrtf; - // load rando generator configuration data - LoadRandomizerConfig(); - // Run ImGui UI loop if Aurora couldn't initialize a backend if (auroraInfo.backend == BACKEND_NULL) { launchUILoop();