Skip to content

Commit 48605f9

Browse files
authored
Merge pull request #196 from OpenBrickProtocolFoundation/improve_settings
feat: Improve settings
2 parents 899cd57 + 88387f8 commit 48605f9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1778
-288
lines changed
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
{
2+
"$schema": "https://json-schema.org/draft/2020-12/schema",
3+
"$id": "https://git.uibk.ac.at/csba1761/bsc/-/blob/main/backend/assets/environments.schema.json",
4+
"$ref": "#/$defs/Root",
5+
"$defs": {
6+
"Root": {
7+
"type": "object",
8+
"properties": {
9+
"controls": {
10+
"$ref": "#/$defs/Controls"
11+
},
12+
"volume": {
13+
"type": "number",
14+
"minimum": 0.0,
15+
"maximum": 1.0
16+
},
17+
"discord": {
18+
"type": "boolean"
19+
},
20+
"api_url": {
21+
"type": "string"
22+
}
23+
},
24+
"required": [
25+
"volume"
26+
],
27+
"additionalProperties": false
28+
},
29+
"Controls": {
30+
"type": "object",
31+
"properties": {
32+
"selected": {
33+
"anyOf": [
34+
{
35+
"type": "number",
36+
"minimum": 0,
37+
"multipleOf": 1
38+
},
39+
{
40+
"type": "null"
41+
}
42+
]
43+
},
44+
"inputs": {
45+
"$ref": "#/$defs/Inputs"
46+
}
47+
},
48+
"required": [],
49+
"additionalProperties": false
50+
},
51+
"Inputs": {
52+
"type": "array",
53+
"items": {
54+
"$ref": "#/$defs/Input"
55+
},
56+
"additionalItems": false,
57+
"minItems": 0,
58+
"default": []
59+
},
60+
"Input": {
61+
"description": "TODO: this isn't fully specified",
62+
"anyOf": [
63+
{
64+
"$ref": "#/$defs/KeyboardInput"
65+
},
66+
{
67+
"type": "object",
68+
"additionalItems": true
69+
}
70+
]
71+
},
72+
"KeyboardInput": {
73+
"type": "object",
74+
"properties": {
75+
"type": {
76+
"const": "keyboard"
77+
},
78+
"drop": {
79+
"$ref": "#/$defs/KeyboardInputKey"
80+
},
81+
"hold": {
82+
"$ref": "#/$defs/KeyboardInputKey"
83+
},
84+
"move_down": {
85+
"$ref": "#/$defs/KeyboardInputKey"
86+
},
87+
"move_left": {
88+
"$ref": "#/$defs/KeyboardInputKey"
89+
},
90+
"move_right": {
91+
"$ref": "#/$defs/KeyboardInputKey"
92+
},
93+
"rotate_left": {
94+
"$ref": "#/$defs/KeyboardInputKey"
95+
},
96+
"rotate_right": {
97+
"$ref": "#/$defs/KeyboardInputKey"
98+
},
99+
"menu": {
100+
"type": "object",
101+
"properties": {
102+
"pause": {
103+
"$ref": "#/$defs/KeyboardInputKey"
104+
},
105+
"open_settings": {
106+
"$ref": "#/$defs/KeyboardInputKey"
107+
}
108+
},
109+
"additionalItems": false,
110+
"required": [
111+
"pause",
112+
"open_settings"
113+
]
114+
}
115+
},
116+
"required": [
117+
"menu",
118+
"rotate_right",
119+
"rotate_left",
120+
"move_right",
121+
"rotate_right",
122+
"move_left",
123+
"move_down",
124+
"hold",
125+
"drop",
126+
"type"
127+
]
128+
}
129+
},
130+
"KeyboardInputKey": {
131+
"type": "string"
132+
}
133+
}

platforms/android/app/jni/Android.mk

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,82 +15,88 @@ include $(PREBUILT_SHARED_LIBRARY)
1515

1616

1717
include $(CLEAR_VARS)
18-
LOCAL_MODULE := libpng
18+
LOCAL_MODULE := png16
1919
LOCAL_SRC_FILES := $(shell find "${SUBPROJECTS_PATH}" -name libpng16.so)
2020
include $(PREBUILT_SHARED_LIBRARY)
2121

2222

2323
include $(CLEAR_VARS)
24-
LOCAL_MODULE := SDL2_ttf
24+
LOCAL_MODULE := sdl2_ttf
2525
LOCAL_SRC_FILES := $(shell find "${SUBPROJECTS_PATH}" -name libsdl2_ttf.so)
2626
include $(PREBUILT_SHARED_LIBRARY)
2727

2828

2929
include $(CLEAR_VARS)
30-
LOCAL_MODULE := SDL2_mixer
30+
LOCAL_MODULE := sdl2_mixer
3131
LOCAL_SRC_FILES := $(shell find "${SUBPROJECTS_PATH}" -name libsdl2mixer.so)
3232
include $(PREBUILT_SHARED_LIBRARY)
3333

3434

3535
include $(CLEAR_VARS)
36-
LOCAL_MODULE := libvorbis
36+
LOCAL_MODULE := vorbis
3737
LOCAL_SRC_FILES := $(shell find "${SUBPROJECTS_PATH}" -name libvorbis.so)
3838
include $(PREBUILT_SHARED_LIBRARY)
3939

4040

4141
include $(CLEAR_VARS)
42-
LOCAL_MODULE := libvorbisfile
42+
LOCAL_MODULE := vorbisfile
4343
LOCAL_SRC_FILES := $(shell find "${SUBPROJECTS_PATH}" -name libvorbisfile.so)
4444
include $(PREBUILT_SHARED_LIBRARY)
4545

4646

4747
include $(CLEAR_VARS)
48-
LOCAL_MODULE := libogg
48+
LOCAL_MODULE := ogg
4949
LOCAL_SRC_FILES := $(shell find "${SUBPROJECTS_PATH}" -name libogg.so)
5050
include $(PREBUILT_SHARED_LIBRARY)
5151

5252

5353
include $(CLEAR_VARS)
54-
LOCAL_MODULE := libflac
54+
LOCAL_MODULE := flac
5555
LOCAL_SRC_FILES := $(shell find "${SUBPROJECTS_PATH}" -name libFLAC.so)
5656
include $(PREBUILT_SHARED_LIBRARY)
5757

5858

5959
include $(CLEAR_VARS)
60-
LOCAL_MODULE := SDL2_image
60+
LOCAL_MODULE := sdl2_image
6161
LOCAL_SRC_FILES := $(shell find "${SUBPROJECTS_PATH}" -name libsdl2image.so)
6262
include $(PREBUILT_SHARED_LIBRARY)
6363

6464

6565
include $(CLEAR_VARS)
66-
LOCAL_MODULE := libfmt
66+
LOCAL_MODULE := fmt
6767
LOCAL_SRC_FILES := $(shell find "${SUBPROJECTS_PATH}" -name libfmt.so)
6868
include $(PREBUILT_SHARED_LIBRARY)
6969

7070

7171
include $(CLEAR_VARS)
72-
LOCAL_MODULE := liboopetris_core
72+
LOCAL_MODULE := keyutils
73+
LOCAL_SRC_FILES := $(shell find "${SUBPROJECTS_PATH}" -name libkeyutils.so)
74+
include $(PREBUILT_SHARED_LIBRARY)
75+
76+
77+
include $(CLEAR_VARS)
78+
LOCAL_MODULE := oopetris_core
7379
LIB_PATH := $(BUILD_PATH)/src/libs/core
7480
LOCAL_SRC_FILES := $(LIB_PATH)/liboopetris_core.so
7581
include $(PREBUILT_SHARED_LIBRARY)
7682

7783

7884
include $(CLEAR_VARS)
79-
LOCAL_MODULE := liboopetris_recordings
85+
LOCAL_MODULE := oopetris_recordings
8086
LIB_PATH := $(BUILD_PATH)/src/libs/recordings
8187
LOCAL_SRC_FILES := $(LIB_PATH)/liboopetris_recordings.so
8288
include $(PREBUILT_SHARED_LIBRARY)
8389

8490

8591
include $(CLEAR_VARS)
86-
LOCAL_MODULE := liboopetris_graphics
92+
LOCAL_MODULE := oopetris_graphics
8793
LIB_PATH := $(BUILD_PATH)/src
8894
LOCAL_SRC_FILES := $(LIB_PATH)/liboopetris_graphics.so
8995
include $(PREBUILT_SHARED_LIBRARY)
9096

9197

9298
include $(CLEAR_VARS)
93-
LOCAL_MODULE := liboopetris
99+
LOCAL_MODULE := oopetris
94100
LIB_PATH := $(BUILD_PATH)/src/executables
95101
LOCAL_SRC_FILES := $(LIB_PATH)/liboopetris.so
96102
include $(PREBUILT_SHARED_LIBRARY)
@@ -99,7 +105,7 @@ include $(PREBUILT_SHARED_LIBRARY)
99105

100106
include $(CLEAR_VARS)
101107
LOCAL_MODULE := main
102-
LOCAL_SHARED_LIBRARIES := SDL2 SDL2_ttf freetype libpng SDL2_mixer libvorbis libvorbisfile libogg libflac SDL2_image libfmt liboopetris_core liboopetris_recordings liboopetris_graphics liboopetris
108+
LOCAL_SHARED_LIBRARIES := SDL2 sdl2_ttf freetype png16 sdl2_mixer vorbis vorbisfile ogg flac sdl2_image fmt keyutils oopetris_core oopetris_recordings oopetris_graphics oopetris
103109
LOCAL_LDLIBS := -ldl -lGLESv1_CM -lGLESv2 -lOpenSLES -llog -landroid
104110
LOCAL_LDFLAGS := -Wl,--no-undefined
105111
include $(BUILD_SHARED_LIBRARY)

platforms/android/app/src/main/java/org/libsdl/app/SDLActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ protected String getMainFunction() {
269269
*/
270270
protected String[] getLibraries() {
271271
return new String[] {
272-
"sdl2",
272+
"SDL2",
273273
"sdl2image",
274274
"sdl2mixer",
275275
// "SDL2_net",

settings.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"$schema": "https://raw.githubusercontent.com/OpenBrickProtocolFoundation/oopetris/refs/heads/main/assets/schema/oopetris.config.schema.json",
23
"controls": {
34
"selected": null,
45
"inputs": [
@@ -75,6 +76,7 @@
7576
}
7677
]
7778
},
78-
"volume": 0.2,
79-
"discord": false
79+
"volume": 0.0,
80+
"discord": false,
81+
"api_url": "https://oopetris.totto.lt/api/"
8082
}

src/discord/core.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ void DiscordInstance::clear_activity(bool wait) {
146146
DiscordActivityWrapper::DiscordActivityWrapper(const std::string& details, discord::ActivityType type) {
147147
m_activity.SetDetails(details.c_str());
148148
m_activity.SetType(type);
149+
m_activity.SetSupportedPlatforms(constants::discord::supported_platforms);
149150
}
150151

151152

src/discord/core.hpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace constants::discord {
2323

2424
//TODO(Totto): this isn't correct for all platforms and needs to be tested
2525
#if defined(__ANDROID__)
26-
constexpr const char* platform_dependent_launch_arguments = "";
26+
#error "Not supported"
2727
#elif defined(__CONSOLE__)
2828
#error "Not supported"
2929
#elif defined(FLATPAK_BUILD)
@@ -39,6 +39,19 @@ namespace constants::discord {
3939
#error "Unsupported platform"
4040
#endif
4141

42+
43+
#if defined(__ANDROID__)
44+
constexpr const std::uint32_t supported_platforms = DiscordActivitySupportedPlatformFlags_Android;
45+
#elif defined(__CONSOLE__)
46+
#error "Not supported"
47+
#elif defined(FLATPAK_BUILD) || defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__) \
48+
|| defined(__APPLE__) || defined(__linux__)
49+
constexpr const std::uint32_t supported_platforms = DiscordActivitySupportedPlatformFlags_Desktop;
50+
#else
51+
#error "Unsupported platform"
52+
#endif
53+
54+
4255
// manually synchronized to https://discord.com/developers/applications/1220147916371394650/rich-presence/assets
4356
enum class ArtAsset : u8 { Logo };
4457

src/executables/game/application.cpp

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -263,14 +263,21 @@ void Application::initialize() {
263263
const auto start_time = SDL_GetTicks64();
264264

265265
const std::future<void> load_everything = std::async(std::launch::async, [this] {
266+
this->m_settings_manager = std::make_unique<SettingsManager>();
267+
268+
this->m_settings_manager->add_callback([this](const auto& settings) { this->reload_api(settings); });
269+
270+
const auto current_settings = this->m_settings_manager->settings();
271+
266272
this->m_music_manager = std::make_unique<MusicManager>(this, num_audio_channels);
273+
this->m_music_manager->set_volume(current_settings.volume, true, true);
267274

268275
this->m_input_manager = std::make_shared<input::InputManager>(this->m_window);
269276

270-
this->m_settings_manager = std::make_unique<SettingsManager>(this);
271-
272277
this->m_font_manager = std::make_unique<FontManager>();
273278

279+
this->reload_api(current_settings);
280+
274281
this->load_resources();
275282

276283
#if !defined(NDEBUG)
@@ -283,7 +290,7 @@ void Application::initialize() {
283290
#endif
284291

285292
#if defined(_HAVE_DISCORD_SDK)
286-
if (m_settings_manager->settings().discord) {
293+
if (current_settings.discord) {
287294
auto discord_instance = DiscordInstance::initialize();
288295
if (not discord_instance.has_value()) {
289296
spdlog::warn(
@@ -413,5 +420,20 @@ void Application::load_resources() {
413420
return m_discord_instance;
414421
}
415422

416-
417423
#endif
424+
425+
426+
void Application::reload_api(const settings::Settings& settings) {
427+
428+
if (auto api_url = settings.api_url; api_url.has_value()) {
429+
auto maybe_api = lobby::API::get_api(api_url.value());
430+
if (maybe_api.has_value()) {
431+
//TODO(Totto): do this somehow asynchronous
432+
m_api = std::make_unique<lobby::API>(std::move(maybe_api.value()));
433+
} else {
434+
spdlog::error("Error in connecting to lobby API: {}", maybe_api.error());
435+
}
436+
} else {
437+
spdlog::info("No lobby API provided");
438+
}
439+
}

src/executables/game/application.hpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "graphics/renderer.hpp"
66
#include "graphics/window.hpp"
77
#include "input/input.hpp"
8+
#include "lobby/api.hpp"
89
#include "manager/event_dispatcher.hpp"
910
#include "manager/event_listener.hpp"
1011
#include "manager/music_manager.hpp"
@@ -28,10 +29,11 @@ struct Application final : public EventListener, public ServiceProvider {
2829
std::optional<u32> m_target_framerate;
2930

3031
// these fields are initalized asynchronously in a separate thread
32+
std::unique_ptr<SettingsManager> m_settings_manager;
3133
std::unique_ptr<MusicManager> m_music_manager;
3234
std::shared_ptr<input::InputManager> m_input_manager;
33-
std::unique_ptr<SettingsManager> m_settings_manager;
3435
std::unique_ptr<FontManager> m_font_manager;
36+
std::unique_ptr<lobby::API> m_api;
3537

3638

3739
#if !defined(NDEBUG)
@@ -127,6 +129,10 @@ struct Application final : public EventListener, public ServiceProvider {
127129
return *m_input_manager;
128130
}
129131

132+
[[nodiscard]] const std::unique_ptr<lobby::API>& api() const override {
133+
return m_api;
134+
}
135+
130136

131137
#if defined(_HAVE_DISCORD_SDK)
132138

@@ -140,4 +146,5 @@ struct Application final : public EventListener, public ServiceProvider {
140146
private:
141147
void initialize();
142148
void load_resources();
149+
void reload_api(const settings::Settings& settings);
143150
};

0 commit comments

Comments
 (0)