diff --git a/src/dusk/imgui/ImGuiMenuRandomizer.cpp b/src/dusk/imgui/ImGuiMenuRandomizer.cpp index fe05d4fdb8..7da3860536 100644 --- a/src/dusk/imgui/ImGuiMenuRandomizer.cpp +++ b/src/dusk/imgui/ImGuiMenuRandomizer.cpp @@ -5,6 +5,8 @@ #include "dusk/logging.h" #include "dusk/data.hpp" +#include "dusk/map_loader_definitions.h" +#include "dusk/ui/rando_config.hpp" #include "dusk/randomizer/generator/logic/search.hpp" #include "dusk/randomizer/generator/utility/string.hpp" #include "dusk/randomizer/game/randomizer_context.hpp" @@ -16,8 +18,6 @@ #include #include -#include "dusk/map_loader_definitions.h" -#include "dusk/randomizer/generator/utility/string.hpp" namespace dusk { @@ -78,8 +78,7 @@ namespace dusk { } if (ImGui::BeginMenu(loadSeedText.c_str(), playerIsOnTitleScreen())) { - std::filesystem::path seedDirectory = - dusk::data::configured_data_path() / "randomizer" / "seeds"; + std::filesystem::path seedDirectory = ui::GetRandomizerSeedsPath(); std::list hashes{}; @@ -115,9 +114,7 @@ namespace dusk { if (ImGui::BeginMenu("Delete Seed")) { - std::filesystem::path seedDirectory = - dusk::data::configured_data_path() / "randomizer" / "seeds"; - + std::filesystem::path seedDirectory = ui::GetRandomizerSeedsPath(); std::list hashes{}; for (const auto& entry : std::filesystem::directory_iterator(seedDirectory)) { @@ -251,7 +248,7 @@ namespace dusk { auto trackerHash = trackerRando->GetConfig().GetHash(false); // If no hash, or seeds switched, try to create tracker world from currently active seed if (trackerHash.empty() || (trackerHash != contextHash && !contextHash.empty())) { - *trackerRando = randomizer::Randomizer(data::configured_data_path()); + *trackerRando = randomizer::Randomizer(ui::GetRandomizerPath()); trackerRando->GenerateTrackerWorld(); } @@ -347,7 +344,7 @@ namespace dusk { } randomizer::Randomizer* ImGuiMenuRandomizer::getTrackerRando() { - static randomizer::Randomizer trackerRando{data::configured_data_path()}; + static randomizer::Randomizer trackerRando{ui::GetRandomizerPath()}; return &trackerRando; } @@ -403,7 +400,7 @@ namespace dusk { } } - auto counts = m_LocationInfo | std::views::transform([](const std::pair& location) { return location.second.accessibleCount; }); + auto counts = m_LocationInfo | std::views::transform([](const std::pair& location) { return location.second.collectedCount; }); m_numCollectedLocations = std::accumulate(counts.begin(), counts.end(), 0); } } // namespace dusk \ No newline at end of file diff --git a/src/dusk/randomizer/game/randomizer_context.cpp b/src/dusk/randomizer/game/randomizer_context.cpp index 4c683a1de4..0451e3fb84 100644 --- a/src/dusk/randomizer/game/randomizer_context.cpp +++ b/src/dusk/randomizer/game/randomizer_context.cpp @@ -1,9 +1,10 @@ #include "randomizer_context.hpp" -#include "dusk/app_info.hpp" #include "dusk/logging.h" #include "dusk/main.h" #include "dusk/data.hpp" +#include "dusk/ui/rando_config.hpp" +#include "dusk/randomizer/game/flags.h" #include "dusk/randomizer/game/tools.h" #include "dusk/randomizer/game/stages.h" #include "dusk/randomizer/game/verify_item_functions.h" @@ -12,7 +13,6 @@ #include "dusk/randomizer/generator/randomizer.hpp" #include "dusk/randomizer/generator/utility/text.hpp" -#include "SDL3/SDL_filesystem.h" #include #include @@ -23,7 +23,6 @@ #include "d/d_meter2_draw.h" #include "d/d_meter2_info.h" #include "d/d_msg_flow.h" -#include "flags.h" std::optional RandomizerContext::WriteToFile() { @@ -268,7 +267,7 @@ std::optional RandomizerContext::LoadFromHash(const std::string& ha } std::filesystem::path RandomizerContext::GetSeedDataPath() const { - return dusk::data::configured_data_path() / "randomizer" / "seeds" / this->mHash / "seed.dat"; + return dusk::ui::GetRandomizerSeedsPath() / this->mHash / "seed.dat"; } int RandomizerContext::SettingToEnum(const std::string& settingName) { @@ -1283,7 +1282,7 @@ static void DeleteFailedGenerationFiles(randomizer::Randomizer& rando) { * Generates a seed and writes the necessary seed files to the players seed directory */ void GenerateAndWriteSeed(std::string& generationStatusMsg) { - auto r = randomizer::Randomizer{dusk::data::configured_data_path()}; + auto r = randomizer::Randomizer{dusk::ui::GetRandomizerPath()}; auto generationResult = r.Generate(); if (generationResult.has_value()) { diff --git a/src/dusk/randomizer/generator/randomizer.cpp b/src/dusk/randomizer/generator/randomizer.cpp index 7e63e427d0..632ad3e95d 100644 --- a/src/dusk/randomizer/generator/randomizer.cpp +++ b/src/dusk/randomizer/generator/randomizer.cpp @@ -13,8 +13,8 @@ #include -#include "dusk/data.hpp" #include "dusk/logging.h" +#include "dusk/ui/rando_config.hpp" #include "dusk/randomizer/game/randomizer_context.hpp" namespace randomizer @@ -51,7 +51,7 @@ namespace randomizer return; } - std::filesystem::path seedSettings = dusk::data::configured_data_path() / "randomizer" / "seeds" / + std::filesystem::path seedSettings = dusk::ui::GetRandomizerSeedsPath() / contextHash / (contextHash + " Anti-Spoiler Log.txt"); this->_config.LoadFromFile(seedSettings, GetPrefPath()); diff --git a/src/dusk/randomizer/generator/randomizer.hpp b/src/dusk/randomizer/generator/randomizer.hpp index 4fef986968..ac743485f8 100644 --- a/src/dusk/randomizer/generator/randomizer.hpp +++ b/src/dusk/randomizer/generator/randomizer.hpp @@ -10,7 +10,7 @@ namespace randomizer { public: Randomizer() = delete; - Randomizer(const std::filesystem::path& baseOutputPath) : _baseOutputPath(baseOutputPath / "randomizer") {} + Randomizer(const std::filesystem::path& baseOutputPath) : _baseOutputPath(baseOutputPath) {} /** * @brief Generates a complete randomizer seed @@ -39,7 +39,7 @@ namespace 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 SetBaseOutputPath(const std::filesystem::path& path) { this->_baseOutputPath = path; }; std::filesystem::path GetConfigPath() const { return this->GetBaseOutputPath() / "settings.yaml"; } std::filesystem::path GetPrefPath() const { return this->GetBaseOutputPath() / "preferences.yaml"; } diff --git a/src/dusk/ui/rando_config.cpp b/src/dusk/ui/rando_config.cpp index 820765cbd7..3cd7e6c7a1 100644 --- a/src/dusk/ui/rando_config.cpp +++ b/src/dusk/ui/rando_config.cpp @@ -3,11 +3,8 @@ #include #include -#include "SDL3/SDL_filesystem.h" - #include "bool_button.hpp" #include "modal.hpp" -#include "dusk/app_info.hpp" #include "dusk/config.hpp" #include "dusk/data.hpp" #include "dusk/logging.h" @@ -222,6 +219,12 @@ Document* show_seed_gen_modal(std::string_view message) { } RandomizerWindow::RandomizerWindow() { + + // Create rando directories if they don't exist + if (!std::filesystem::exists(GetRandomizerSeedsPath())) { + std::filesystem::create_directories(GetRandomizerSeedsPath()); + } + add_tab("Seed Management", [this](Rml::Element* content) { auto& leftPane = add_child(content, Pane::Type::Controlled); auto& rightPane = add_child(content, Pane::Type::Controlled); @@ -237,12 +240,7 @@ RandomizerWindow::RandomizerWindow() { }, }), rightPane, [](Pane& pane) { - std::filesystem::path seedDirectory = - dusk::data::configured_data_path() / "randomizer" / "seeds"; - - if (!std::filesystem::exists(seedDirectory)) { - std::filesystem::create_directories(seedDirectory); - } + std::filesystem::path seedDirectory = GetRandomizerSeedsPath(); if (std::filesystem::is_empty(seedDirectory)) { pane.add_rml( @@ -275,12 +273,7 @@ RandomizerWindow::RandomizerWindow() { leftPane.register_control( leftPane.add_button("Delete Seeds"), rightPane, [](Pane& pane) { - std::filesystem::path seedDirectory = - dusk::data::configured_data_path() / "randomizer" / "seeds"; - - if (!std::filesystem::exists(seedDirectory)) { - std::filesystem::create_directories(seedDirectory); - } + std::filesystem::path seedDirectory = GetRandomizerSeedsPath(); if (std::filesystem::is_empty(seedDirectory)) { pane.add_rml( @@ -493,12 +486,20 @@ void RandomizerWindow::update() { } } +std::filesystem::path GetRandomizerPath() { + return data::configured_data_path() / "randomizer"; +} + std::filesystem::path GetRandomizerSettingsPath() { - return data::configured_data_path() / "randomizer" / "settings.yaml"; + return GetRandomizerPath() / "settings.yaml"; } std::filesystem::path GetRandomizerPreferencesPath() { - return data::configured_data_path() / "randomizer" / "preferences.yaml"; + return GetRandomizerPath() / "preferences.yaml"; +} + +std::filesystem::path GetRandomizerSeedsPath() { + return GetRandomizerPath() / "seeds"; } randomizer::seedgen::config::Config& GetRandomizerConfig() { diff --git a/src/dusk/ui/rando_config.hpp b/src/dusk/ui/rando_config.hpp index 111c7c756d..9bcbcb80a1 100644 --- a/src/dusk/ui/rando_config.hpp +++ b/src/dusk/ui/rando_config.hpp @@ -8,8 +8,10 @@ namespace randomizer::seedgen::config { namespace dusk::ui { + std::filesystem::path GetRandomizerPath(); std::filesystem::path GetRandomizerSettingsPath(); std::filesystem::path GetRandomizerPreferencesPath(); + std::filesystem::path GetRandomizerSeedsPath(); randomizer::seedgen::config::Config& GetRandomizerConfig(); class RandomizerWindow : public Window { diff --git a/src/m_Do/m_Do_main.cpp b/src/m_Do/m_Do_main.cpp index 541da28c19..2f7120f1d5 100644 --- a/src/m_Do/m_Do_main.cpp +++ b/src/m_Do/m_Do_main.cpp @@ -64,6 +64,7 @@ #include "dusk/ui/prelaunch.hpp" #include "dusk/ui/preset.hpp" #include "dusk/ui/ui.hpp" +#include "dusk/ui/rando_config.hpp" #include "version.h" #include @@ -503,7 +504,7 @@ int game_main(int argc, char* argv[]) { #ifdef LOGIC_TESTS randomizer::test::test::RunTests(); #else - randomizer::Randomizer rando{dusk::data::configured_data_path()}; + randomizer::Randomizer rando{dusk::ui::GetRandomizerPath()}; rando.Generate(); #endif exit(0);