mirror of
https://github.com/TwilitRealm/dusklight
synced 2026-09-03 08:57:00 -04:00
use dusk config path for settings file
This commit is contained in:
@@ -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<std::string> 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<randomizer::logic::world::
|
||||
}
|
||||
|
||||
static void DeleteFailedGenerationFiles(randomizer::Randomizer& rando) {
|
||||
// If the output path with "//" that means we never got far enough to create any files
|
||||
if (!rando.GetSeedOutputPath().ends_with("//")) {
|
||||
// If the hash is empty, then we never generated any files
|
||||
if (!rando.GetConfig().GetHash().empty()) {
|
||||
std::filesystem::remove_all(rando.GetSeedOutputPath());
|
||||
}
|
||||
}
|
||||
@@ -1234,7 +1233,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 = g_RandomizerGenerator;
|
||||
auto r = randomizer::Randomizer{dusk::data::configured_data_path()};
|
||||
|
||||
auto generationResult = r.Generate();
|
||||
if (generationResult.has_value()) {
|
||||
@@ -1264,21 +1263,4 @@ void GenerateAndWriteSeed(std::string& generationStatusMsg) {
|
||||
}
|
||||
|
||||
generationStatusMsg = fmt::format("Seed generated! Hash: {}", randoData.mHash);
|
||||
}
|
||||
|
||||
void LoadRandomizerConfig() {
|
||||
const auto result = SDL_GetPrefPath(dusk::OrgName, dusk::AppName);
|
||||
if (!result)
|
||||
DuskLog.fatal("Unable to get PrefPath: {}", SDL_GetError());
|
||||
g_RandomizerGenerator.SetBaseOutputPath(result);
|
||||
|
||||
g_RandomizerGenerator.LoadConfig();
|
||||
}
|
||||
|
||||
randomizer::seedgen::config::Config& GetRandomizerConfig() {
|
||||
return g_RandomizerGenerator.GetConfig();
|
||||
}
|
||||
|
||||
std::string GetRandomizerConfigPath() {
|
||||
return g_RandomizerGenerator.GetConfigPath();
|
||||
}
|
||||
@@ -62,7 +62,7 @@ public:
|
||||
|
||||
std::optional<std::string> WriteToFile();
|
||||
std::optional<std::string> 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<u8> 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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<std::list<logic::location::Location*>> _playthroughSpheres{};
|
||||
std::list<std::list<logic::entrance::Entrance*>> _entranceSpheres{};
|
||||
|
||||
std::string _baseOutputPath{RANDO_SAVE_PATH};
|
||||
std::filesystem::path _baseOutputPath{RANDO_SAVE_PATH};
|
||||
};
|
||||
} // namespace randomizer
|
||||
|
||||
@@ -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<std::string>();
|
||||
this->_gameBasePath = gameBasePath;
|
||||
}
|
||||
else if (preferenceName == "Output Path")
|
||||
{
|
||||
const auto& outputPath = preferenceNode.second.as<std::string>();
|
||||
this->_outputPath = outputPath;
|
||||
}
|
||||
else if (preferenceName == "Plandomizer Path")
|
||||
{
|
||||
const auto& plandomizerPath = preferenceNode.second.as<std::string>();
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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<Component*(const std::string&, Pane&)> 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user