Skip to content

Commit d8b0149

Browse files
committed
settings: add additoonal setting to enable / disable discord integrations, it is disabled by default and by the by the default settings file
1 parent 871ce23 commit d8b0149

File tree

3 files changed

+36
-27
lines changed

3 files changed

+36
-27
lines changed

settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@
1010
"rotate_left": "Left",
1111
"rotate_right": "Right"
1212
},
13-
"volume": 0.2
13+
"volume": 0.2,
14+
"discord": false
1415
}

src/application.cpp

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -246,17 +246,6 @@ void Application::render() const {
246246

247247
void Application::initialize() {
248248

249-
#if defined(_HAVE_DISCORD_SDK)
250-
auto discord_instance = DiscordInstance::initialize();
251-
if (not discord_instance.has_value()) {
252-
spdlog::warn("Error initializing the discord instance, it might not be running: {}", discord_instance.error());
253-
} else {
254-
m_discord_instance = std::move(discord_instance.value());
255-
m_discord_instance->after_setup();
256-
}
257-
258-
#endif
259-
260249
try_load_settings();
261250
load_resources();
262251
push_scene(scenes::create_scene(*this, SceneId::MainMenu, ui::FullScreenLayout{ *m_window }));
@@ -268,6 +257,21 @@ void Application::initialize() {
268257
ui::RelativeLayout{ window(), 0.0, 0.0, 0.1, 0.05 }, false
269258
);
270259
#endif
260+
261+
#if defined(_HAVE_DISCORD_SDK)
262+
if (m_settings.discord) {
263+
auto discord_instance = DiscordInstance::initialize();
264+
if (not discord_instance.has_value()) {
265+
spdlog::warn(
266+
"Error initializing the discord instance, it might not be running: {}", discord_instance.error()
267+
);
268+
} else {
269+
m_discord_instance = std::move(discord_instance.value());
270+
m_discord_instance->after_setup();
271+
}
272+
}
273+
274+
#endif
271275
}
272276

273277
void Application::try_load_settings() {
@@ -281,20 +285,23 @@ void Application::try_load_settings() {
281285
spdlog::error("unable to load settings from \"{}\": {}", settings_filename, result.error());
282286
spdlog::warn("applying default settings");
283287
}
288+
289+
// apply settings
290+
m_music_manager.set_volume(m_settings.volume);
284291
}
285292

286293
void Application::load_resources() {
287294
constexpr auto fonts_size = 128;
288-
const std::vector<std::tuple<FontId, std::string>> fonts {
295+
const std::vector<std::tuple<FontId, std::string>> fonts{
289296
#if defined(__3DS__)
290297
//TODO: debug why the other font crashed, not on loading, but on trying to render text!
291-
{ FontId::Default, "LeroyLetteringLightBeta01.ttf" },
298+
{ FontId::Default, "LeroyLetteringLightBeta01.ttf" },
292299
#else
293300
{ FontId::Default, "PressStart2P.ttf" },
294301
#endif
295-
{ FontId::Arial, "arial.ttf" }, { FontId::NotoColorEmoji, "NotoColorEmoji.ttf" }, {
296-
FontId::Symbola, "Symbola.ttf"
297-
}
302+
{ FontId::Arial, "arial.ttf" },
303+
{ FontId::NotoColorEmoji, "NotoColorEmoji.ttf" },
304+
{ FontId::Symbola, "Symbola.ttf" }
298305
};
299306
for (const auto& [font_id, path] : fonts) {
300307
const auto font_path = utils::get_assets_folder() / "fonts" / path;

src/manager/settings.hpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212

1313
inline void to_json(nlohmann::json& j, const KeyboardControls& controls) {
1414
j = nlohmann::json{
15-
{ "rotate_left", magic_enum::enum_name(controls.rotate_left)},
16-
{"rotate_right", magic_enum::enum_name(controls.rotate_right)},
17-
{ "move_left", magic_enum::enum_name(controls.move_left)},
18-
{ "move_right", magic_enum::enum_name(controls.move_right)},
19-
{ "move_down", magic_enum::enum_name(controls.move_down)},
20-
{ "drop", magic_enum::enum_name(controls.drop)},
21-
{ "hold", magic_enum::enum_name(controls.hold)},
15+
{ "rotate_left", magic_enum::enum_name(controls.rotate_left) },
16+
{ "rotate_right", magic_enum::enum_name(controls.rotate_right) },
17+
{ "move_left", magic_enum::enum_name(controls.move_left) },
18+
{ "move_right", magic_enum::enum_name(controls.move_right) },
19+
{ "move_down", magic_enum::enum_name(controls.move_down) },
20+
{ "drop", magic_enum::enum_name(controls.drop) },
21+
{ "hold", magic_enum::enum_name(controls.hold) },
2222
};
2323
}
2424

@@ -82,9 +82,10 @@ inline void from_json(const nlohmann::json& j, Controls& controls) {
8282
}
8383

8484
struct Settings {
85-
Platform platform;
85+
Platform platform{};
8686
Controls controls;
87-
float volume;
87+
float volume{ 0.2f };
88+
bool discord{ false }; //changing this requires a restart
8889
};
8990

90-
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Settings, platform, controls, volume)
91+
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Settings, platform, controls, volume, discord)

0 commit comments

Comments
 (0)