Skip to content

Commit 10ea649

Browse files
committed
feat: settings_manager add api url, so that you can change it
1 parent 90fac21 commit 10ea649

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

src/manager/settings_manager.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#include <spdlog/spdlog.h>
88

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

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

2020
m_settings = {
21-
detail::Settings{ {}, std::nullopt, 1.0, false }
21+
detail::Settings{ .controls = {},
22+
.selected = std::nullopt,
23+
.volume = 1.0,
24+
.discord = false,
25+
.api_url = std::nullopt }
2226
};
2327
}
2428
}
@@ -34,15 +38,17 @@ void detail::to_json(nlohmann::json& obj, const detail::Settings& settings) {
3438
{ "controls",
3539
nlohmann::json{ { "inputs", settings.controls }, { "selected", settings.selected } },
3640
{ "volume", settings.volume },
37-
{ "discord", settings.discord } }
41+
{ "discord", settings.discord },
42+
{ "api_url", settings.api_url } }
3843
};
3944
}
4045

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

43-
::json::check_for_no_additional_keys(obj, { "controls", "volume", "discord" });
48+
::json::check_for_no_additional_keys(obj, { "controls", "volume", "discord", "api_url" });
4449

4550
obj.at("volume").get_to(settings.volume);
51+
obj.at("api_url").get_to(settings.api_url);
4652
obj.at("discord").get_to(settings.discord);
4753

4854
const auto& controls = obj.at("controls");

src/manager/settings_manager.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ namespace detail {
7474
std::vector<Controls> controls;
7575
std::optional<u32> selected;
7676
float volume{ 0.2F };
77-
bool discord{ false }; //changing this requires a restart
77+
std::optional<bool> discord; //changing this requires a restart
78+
std::optional<std::string> api_url;
7879
};
7980

8081

@@ -87,11 +88,10 @@ namespace detail {
8788

8889
struct SettingsManager {
8990
private:
90-
ServiceProvider* m_service_provider;
9191
detail::Settings m_settings;
9292

9393
public:
94-
OOPETRIS_GRAPHICS_EXPORTED explicit SettingsManager(ServiceProvider* service_provider);
94+
OOPETRIS_GRAPHICS_EXPORTED explicit SettingsManager();
9595

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

0 commit comments

Comments
 (0)