Skip to content

Commit

Permalink
feat: settings_manager add api url, so that you can change it
Browse files Browse the repository at this point in the history
  • Loading branch information
Totto16 committed Oct 28, 2024
1 parent 90fac21 commit 10ea649
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
14 changes: 10 additions & 4 deletions src/manager/settings_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include <spdlog/spdlog.h>

SettingsManager::SettingsManager(ServiceProvider* service_provider) : m_service_provider{ service_provider } {
SettingsManager::SettingsManager() {
const std::filesystem::path settings_file = utils::get_root_folder() / detail::settings_filename;

const auto result = json::try_parse_json_file<detail::Settings>(settings_file);
Expand All @@ -18,7 +18,11 @@ SettingsManager::SettingsManager(ServiceProvider* service_provider) : m_service_
spdlog::warn("applying default settings");

m_settings = {
detail::Settings{ {}, std::nullopt, 1.0, false }
detail::Settings{ .controls = {},
.selected = std::nullopt,
.volume = 1.0,
.discord = false,
.api_url = std::nullopt }
};
}
}
Expand All @@ -34,15 +38,17 @@ void detail::to_json(nlohmann::json& obj, const detail::Settings& settings) {
{ "controls",
nlohmann::json{ { "inputs", settings.controls }, { "selected", settings.selected } },
{ "volume", settings.volume },
{ "discord", settings.discord } }
{ "discord", settings.discord },
{ "api_url", settings.api_url } }
};
}

void detail::from_json(const nlohmann::json& obj, detail::Settings& settings) {

::json::check_for_no_additional_keys(obj, { "controls", "volume", "discord" });
::json::check_for_no_additional_keys(obj, { "controls", "volume", "discord", "api_url" });

obj.at("volume").get_to(settings.volume);
obj.at("api_url").get_to(settings.api_url);
obj.at("discord").get_to(settings.discord);

const auto& controls = obj.at("controls");
Expand Down
6 changes: 3 additions & 3 deletions src/manager/settings_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ namespace detail {
std::vector<Controls> controls;
std::optional<u32> selected;
float volume{ 0.2F };
bool discord{ false }; //changing this requires a restart
std::optional<bool> discord; //changing this requires a restart
std::optional<std::string> api_url;
};


Expand All @@ -87,11 +88,10 @@ namespace detail {

struct SettingsManager {
private:
ServiceProvider* m_service_provider;
detail::Settings m_settings;

public:
OOPETRIS_GRAPHICS_EXPORTED explicit SettingsManager(ServiceProvider* service_provider);
OOPETRIS_GRAPHICS_EXPORTED explicit SettingsManager();

OOPETRIS_GRAPHICS_EXPORTED [[nodiscard]] const detail::Settings& settings() const;
};

0 comments on commit 10ea649

Please sign in to comment.