Skip to content

Commit

Permalink
Merge pull request #196 from OpenBrickProtocolFoundation/improve_sett…
Browse files Browse the repository at this point in the history
…ings

feat: Improve settings
  • Loading branch information
Totto16 authored Oct 31, 2024
2 parents 899cd57 + 88387f8 commit 48605f9
Show file tree
Hide file tree
Showing 57 changed files with 1,778 additions and 288 deletions.
133 changes: 133 additions & 0 deletions assets/schema/oopetris.config.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://git.uibk.ac.at/csba1761/bsc/-/blob/main/backend/assets/environments.schema.json",
"$ref": "#/$defs/Root",
"$defs": {
"Root": {
"type": "object",
"properties": {
"controls": {
"$ref": "#/$defs/Controls"
},
"volume": {
"type": "number",
"minimum": 0.0,
"maximum": 1.0
},
"discord": {
"type": "boolean"
},
"api_url": {
"type": "string"
}
},
"required": [
"volume"
],
"additionalProperties": false
},
"Controls": {
"type": "object",
"properties": {
"selected": {
"anyOf": [
{
"type": "number",
"minimum": 0,
"multipleOf": 1
},
{
"type": "null"
}
]
},
"inputs": {
"$ref": "#/$defs/Inputs"
}
},
"required": [],
"additionalProperties": false
},
"Inputs": {
"type": "array",
"items": {
"$ref": "#/$defs/Input"
},
"additionalItems": false,
"minItems": 0,
"default": []
},
"Input": {
"description": "TODO: this isn't fully specified",
"anyOf": [
{
"$ref": "#/$defs/KeyboardInput"
},
{
"type": "object",
"additionalItems": true
}
]
},
"KeyboardInput": {
"type": "object",
"properties": {
"type": {
"const": "keyboard"
},
"drop": {
"$ref": "#/$defs/KeyboardInputKey"
},
"hold": {
"$ref": "#/$defs/KeyboardInputKey"
},
"move_down": {
"$ref": "#/$defs/KeyboardInputKey"
},
"move_left": {
"$ref": "#/$defs/KeyboardInputKey"
},
"move_right": {
"$ref": "#/$defs/KeyboardInputKey"
},
"rotate_left": {
"$ref": "#/$defs/KeyboardInputKey"
},
"rotate_right": {
"$ref": "#/$defs/KeyboardInputKey"
},
"menu": {
"type": "object",
"properties": {
"pause": {
"$ref": "#/$defs/KeyboardInputKey"
},
"open_settings": {
"$ref": "#/$defs/KeyboardInputKey"
}
},
"additionalItems": false,
"required": [
"pause",
"open_settings"
]
}
},
"required": [
"menu",
"rotate_right",
"rotate_left",
"move_right",
"rotate_right",
"move_left",
"move_down",
"hold",
"drop",
"type"
]
}
},
"KeyboardInputKey": {
"type": "string"
}
}
34 changes: 20 additions & 14 deletions platforms/android/app/jni/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -15,82 +15,88 @@ include $(PREBUILT_SHARED_LIBRARY)


include $(CLEAR_VARS)
LOCAL_MODULE := libpng
LOCAL_MODULE := png16
LOCAL_SRC_FILES := $(shell find "${SUBPROJECTS_PATH}" -name libpng16.so)
include $(PREBUILT_SHARED_LIBRARY)


include $(CLEAR_VARS)
LOCAL_MODULE := SDL2_ttf
LOCAL_MODULE := sdl2_ttf
LOCAL_SRC_FILES := $(shell find "${SUBPROJECTS_PATH}" -name libsdl2_ttf.so)
include $(PREBUILT_SHARED_LIBRARY)


include $(CLEAR_VARS)
LOCAL_MODULE := SDL2_mixer
LOCAL_MODULE := sdl2_mixer
LOCAL_SRC_FILES := $(shell find "${SUBPROJECTS_PATH}" -name libsdl2mixer.so)
include $(PREBUILT_SHARED_LIBRARY)


include $(CLEAR_VARS)
LOCAL_MODULE := libvorbis
LOCAL_MODULE := vorbis
LOCAL_SRC_FILES := $(shell find "${SUBPROJECTS_PATH}" -name libvorbis.so)
include $(PREBUILT_SHARED_LIBRARY)


include $(CLEAR_VARS)
LOCAL_MODULE := libvorbisfile
LOCAL_MODULE := vorbisfile
LOCAL_SRC_FILES := $(shell find "${SUBPROJECTS_PATH}" -name libvorbisfile.so)
include $(PREBUILT_SHARED_LIBRARY)


include $(CLEAR_VARS)
LOCAL_MODULE := libogg
LOCAL_MODULE := ogg
LOCAL_SRC_FILES := $(shell find "${SUBPROJECTS_PATH}" -name libogg.so)
include $(PREBUILT_SHARED_LIBRARY)


include $(CLEAR_VARS)
LOCAL_MODULE := libflac
LOCAL_MODULE := flac
LOCAL_SRC_FILES := $(shell find "${SUBPROJECTS_PATH}" -name libFLAC.so)
include $(PREBUILT_SHARED_LIBRARY)


include $(CLEAR_VARS)
LOCAL_MODULE := SDL2_image
LOCAL_MODULE := sdl2_image
LOCAL_SRC_FILES := $(shell find "${SUBPROJECTS_PATH}" -name libsdl2image.so)
include $(PREBUILT_SHARED_LIBRARY)


include $(CLEAR_VARS)
LOCAL_MODULE := libfmt
LOCAL_MODULE := fmt
LOCAL_SRC_FILES := $(shell find "${SUBPROJECTS_PATH}" -name libfmt.so)
include $(PREBUILT_SHARED_LIBRARY)


include $(CLEAR_VARS)
LOCAL_MODULE := liboopetris_core
LOCAL_MODULE := keyutils
LOCAL_SRC_FILES := $(shell find "${SUBPROJECTS_PATH}" -name libkeyutils.so)
include $(PREBUILT_SHARED_LIBRARY)


include $(CLEAR_VARS)
LOCAL_MODULE := oopetris_core
LIB_PATH := $(BUILD_PATH)/src/libs/core
LOCAL_SRC_FILES := $(LIB_PATH)/liboopetris_core.so
include $(PREBUILT_SHARED_LIBRARY)


include $(CLEAR_VARS)
LOCAL_MODULE := liboopetris_recordings
LOCAL_MODULE := oopetris_recordings
LIB_PATH := $(BUILD_PATH)/src/libs/recordings
LOCAL_SRC_FILES := $(LIB_PATH)/liboopetris_recordings.so
include $(PREBUILT_SHARED_LIBRARY)


include $(CLEAR_VARS)
LOCAL_MODULE := liboopetris_graphics
LOCAL_MODULE := oopetris_graphics
LIB_PATH := $(BUILD_PATH)/src
LOCAL_SRC_FILES := $(LIB_PATH)/liboopetris_graphics.so
include $(PREBUILT_SHARED_LIBRARY)


include $(CLEAR_VARS)
LOCAL_MODULE := liboopetris
LOCAL_MODULE := oopetris
LIB_PATH := $(BUILD_PATH)/src/executables
LOCAL_SRC_FILES := $(LIB_PATH)/liboopetris.so
include $(PREBUILT_SHARED_LIBRARY)
Expand All @@ -99,7 +105,7 @@ include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := main
LOCAL_SHARED_LIBRARIES := SDL2 SDL2_ttf freetype libpng SDL2_mixer libvorbis libvorbisfile libogg libflac SDL2_image libfmt liboopetris_core liboopetris_recordings liboopetris_graphics liboopetris
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
LOCAL_LDLIBS := -ldl -lGLESv1_CM -lGLESv2 -lOpenSLES -llog -landroid
LOCAL_LDFLAGS := -Wl,--no-undefined
include $(BUILD_SHARED_LIBRARY)
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ protected String getMainFunction() {
*/
protected String[] getLibraries() {
return new String[] {
"sdl2",
"SDL2",
"sdl2image",
"sdl2mixer",
// "SDL2_net",
Expand Down
6 changes: 4 additions & 2 deletions settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"$schema": "https://raw.githubusercontent.com/OpenBrickProtocolFoundation/oopetris/refs/heads/main/assets/schema/oopetris.config.schema.json",
"controls": {
"selected": null,
"inputs": [
Expand Down Expand Up @@ -75,6 +76,7 @@
}
]
},
"volume": 0.2,
"discord": false
"volume": 0.0,
"discord": false,
"api_url": "https://oopetris.totto.lt/api/"
}
1 change: 1 addition & 0 deletions src/discord/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ void DiscordInstance::clear_activity(bool wait) {
DiscordActivityWrapper::DiscordActivityWrapper(const std::string& details, discord::ActivityType type) {
m_activity.SetDetails(details.c_str());
m_activity.SetType(type);
m_activity.SetSupportedPlatforms(constants::discord::supported_platforms);
}


Expand Down
15 changes: 14 additions & 1 deletion src/discord/core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace constants::discord {

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


#if defined(__ANDROID__)
constexpr const std::uint32_t supported_platforms = DiscordActivitySupportedPlatformFlags_Android;
#elif defined(__CONSOLE__)
#error "Not supported"
#elif defined(FLATPAK_BUILD) || defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__) \
|| defined(__APPLE__) || defined(__linux__)
constexpr const std::uint32_t supported_platforms = DiscordActivitySupportedPlatformFlags_Desktop;
#else
#error "Unsupported platform"
#endif


// manually synchronized to https://discord.com/developers/applications/1220147916371394650/rich-presence/assets
enum class ArtAsset : u8 { Logo };

Expand Down
30 changes: 26 additions & 4 deletions src/executables/game/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,14 +263,21 @@ void Application::initialize() {
const auto start_time = SDL_GetTicks64();

const std::future<void> load_everything = std::async(std::launch::async, [this] {
this->m_settings_manager = std::make_unique<SettingsManager>();

this->m_settings_manager->add_callback([this](const auto& settings) { this->reload_api(settings); });

const auto current_settings = this->m_settings_manager->settings();

this->m_music_manager = std::make_unique<MusicManager>(this, num_audio_channels);
this->m_music_manager->set_volume(current_settings.volume, true, true);

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

this->m_settings_manager = std::make_unique<SettingsManager>(this);

this->m_font_manager = std::make_unique<FontManager>();

this->reload_api(current_settings);

this->load_resources();

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

#if defined(_HAVE_DISCORD_SDK)
if (m_settings_manager->settings().discord) {
if (current_settings.discord) {
auto discord_instance = DiscordInstance::initialize();
if (not discord_instance.has_value()) {
spdlog::warn(
Expand Down Expand Up @@ -413,5 +420,20 @@ void Application::load_resources() {
return m_discord_instance;
}


#endif


void Application::reload_api(const settings::Settings& settings) {

if (auto api_url = settings.api_url; api_url.has_value()) {
auto maybe_api = lobby::API::get_api(api_url.value());
if (maybe_api.has_value()) {
//TODO(Totto): do this somehow asynchronous
m_api = std::make_unique<lobby::API>(std::move(maybe_api.value()));
} else {
spdlog::error("Error in connecting to lobby API: {}", maybe_api.error());
}
} else {
spdlog::info("No lobby API provided");
}
}
9 changes: 8 additions & 1 deletion src/executables/game/application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "graphics/renderer.hpp"
#include "graphics/window.hpp"
#include "input/input.hpp"
#include "lobby/api.hpp"
#include "manager/event_dispatcher.hpp"
#include "manager/event_listener.hpp"
#include "manager/music_manager.hpp"
Expand All @@ -28,10 +29,11 @@ struct Application final : public EventListener, public ServiceProvider {
std::optional<u32> m_target_framerate;

// these fields are initalized asynchronously in a separate thread
std::unique_ptr<SettingsManager> m_settings_manager;
std::unique_ptr<MusicManager> m_music_manager;
std::shared_ptr<input::InputManager> m_input_manager;
std::unique_ptr<SettingsManager> m_settings_manager;
std::unique_ptr<FontManager> m_font_manager;
std::unique_ptr<lobby::API> m_api;


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

[[nodiscard]] const std::unique_ptr<lobby::API>& api() const override {
return m_api;
}


#if defined(_HAVE_DISCORD_SDK)

Expand All @@ -140,4 +146,5 @@ struct Application final : public EventListener, public ServiceProvider {
private:
void initialize();
void load_resources();
void reload_api(const settings::Settings& settings);
};
Loading

0 comments on commit 48605f9

Please sign in to comment.