Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
3102af6
feat: refactor lobby usage
Totto16 Oct 27, 2024
8f879a6
chore: add narrow type (u8) to enum classes, where it was missing
Totto16 Oct 28, 2024
5be10d3
fix: sdl_key comparison was incorrect, fix it and add test to have c…
Totto16 Oct 28, 2024
c230a9c
chore: add json schema for the settings
Totto16 Oct 28, 2024
6585500
fix: use settings manager to initialize the volume
Totto16 Oct 28, 2024
9cdeabf
fix: reorder key detection in color row
Totto16 Oct 28, 2024
e06340c
fix: set supported platform for the discord sdk
Totto16 Oct 28, 2024
8b31729
fix: use newer sld::Key APi in textinput
Totto16 Oct 28, 2024
62606a7
feat: settings_manager add api url, so that you can change it
Totto16 Oct 28, 2024
9f0d328
WIP: make settings menu better
Totto16 Oct 28, 2024
e7e9c9d
feat: add keyutils subproject, to use on linux
Totto16 Oct 28, 2024
f4b0843
feat: add support to the http clients, for resetting the bearer token
Totto16 Oct 28, 2024
1cc90f3
feat: APi add logout and better login configuration
Totto16 Oct 28, 2024
0b62889
feat: add SecretStorage, that store values safely
Totto16 Oct 28, 2024
f9488d6
fix: make SecretStorage return the errors instead of printing them di…
Totto16 Oct 28, 2024
e2d82d0
fix: catch error in get_api and return a helper::unexpected
Totto16 Oct 28, 2024
2f64579
feat: WIP, add dummy implementations for SecretStorage on platforms, …
Totto16 Oct 28, 2024
e629feb
fix: add generic SecretStorage implementation
Totto16 Oct 28, 2024
52c24ac
fix; move function definition to the correct place outside of an unre…
Totto16 Oct 28, 2024
db5a449
fix: keyutils wrap, add patch to fix a different signed comparison
Totto16 Oct 28, 2024
4481344
fix don#t specify constexpr const values as std::string, but as const…
Totto16 Oct 28, 2024
20bed1e
fix: also use keyutils on android
Totto16 Oct 29, 2024
cb1e320
fix: android clean up shared library names + add keyutils.so + fix SD…
Totto16 Oct 29, 2024
7370bb0
fix: don't support android for discord
Totto16 Oct 29, 2024
be8c356
feat: add secret Provider to windows, WIP
Totto16 Oct 29, 2024
c88476c
fix: fix all windows related errors in secret.cpp
Totto16 Oct 29, 2024
ddcc600
fix: try to fix windows winsock2 problem
Totto16 Oct 29, 2024
c5ff067
fix: fix clang-tidy warnings
Totto16 Oct 29, 2024
6f2645e
fix: fix more complex clang-tidy warnings
Totto16 Oct 29, 2024
5228ed3
fix: assign 0 instead of nullptr in windows secret manager
Totto16 Oct 29, 2024
0716e93
feat: use distinct type for payload of SecretStorage, so that you can…
Totto16 Oct 29, 2024
0d4aec4
fix: fix small logic error in parse_json
Totto16 Oct 29, 2024
d4c0bb7
fix: windows: don't export template function
Totto16 Oct 29, 2024
2276523
fix: fix settings menu layout, make it more readable
Totto16 Oct 29, 2024
06c9299
fix: fix json serialization by using correct Initializers, iif the in…
Totto16 Oct 29, 2024
5fe9dad
fix: also take volume into account, when checking if the settings nee…
Totto16 Oct 29, 2024
dd58ba8
fix: don't install schema for config.json
Totto16 Oct 30, 2024
88387f8
fix: write default settings file, if none is present
Totto16 Oct 31, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading