Skip to content

Commit 67c4fb0

Browse files
authored
Merge pull request #136 from mgerhold/discord-integration
Add Discord integration
2 parents ae4f82c + b6bf2c0 commit 67c4fb0

File tree

26 files changed

+721
-16
lines changed

26 files changed

+721
-16
lines changed

.github/workflows/meson.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ jobs:
186186
with:
187187
name: ${{ matrix.config.name }} Executable
188188
path: build/oopetris
189+
# TODO: create a proper installer: https://mesonbuild.com/Creating-OSX-packages.html
189190

190191
- name: Upload artifacts - Windows
191192
uses: actions/upload-artifact@v4

assets/icon/1024x1024.png

21.4 KB
Loading

com.github.mgerhold.OOPetris.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,18 @@ runtime-version: "23.08"
44
sdk: org.freedesktop.Sdk
55
command: oopetris
66
modules:
7+
#TODO: remove after discord sets SONAME
8+
- name: patchelf
9+
buildsystem: simple
10+
sources:
11+
- type: archive
12+
url: https://github.com/NixOS/patchelf/releases/download/0.18.0/patchelf-0.18.0.tar.gz
13+
sha256: 64de10e4c6b8b8379db7e87f58030f336ea747c0515f381132e810dbf84a86e7
14+
build-commands:
15+
- ./configure --prefix=/app
16+
- make
17+
- make install
18+
719
- name: OOPetris
820
buildsystem: meson
921
config-opts:
@@ -28,6 +40,13 @@ cleanup:
2840
- /include
2941
- /lib/pkgconfig
3042
- /share/pkgconfig
43+
## all for the patchelf executable
44+
#TODO: remove after removing patchelf build
45+
- /bin/patchelf
46+
- /lib/debug
47+
- /share/doc
48+
- /share/man
49+
- /share/zsh
3150

3251
finish-args:
3352
- --socket=x11
@@ -36,3 +55,4 @@ finish-args:
3655
- --device=dri
3756
- --socket=pulseaudio
3857
- --share=network
58+
- --filesystem=xdg-run/discord-ipc-0:rw

meson.build

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ project(
1515
)
1616

1717
compile_args = []
18-
link_args = []
1918
deps = []
2019
recording_dependencies = []
2120

@@ -47,8 +46,8 @@ elif cpp.get_id() == 'clang'
4746
endif
4847

4948
if build_with_libcpp
50-
compile_args += '-stdlib=libc++'
51-
link_args += '-stdlib=libc++'
49+
add_global_link_arguments('-stdlib=libc++', language:['cpp'])
50+
add_global_arguments('-stdlib=libc++', language:['cpp'])
5251
deps += cpp.find_library('c++')
5352
deps += cpp.find_library('c++abi')
5453
endif
@@ -264,11 +263,11 @@ argparse_dep = dependency('argparse', required: true)
264263
recording_dependencies += argparse_dep
265264
deps += argparse_dep
266265

267-
online_multiplayer_not_supported = true
266+
online_multiplayer_supported = true
268267

269268
if meson.is_cross_build() and host_machine.system() == 'switch'
270269
compile_args += ['-D_ONLINE_MULTIPLAYER_NOT_SUPPORTED']
271-
online_multiplayer_not_supported = false
270+
online_multiplayer_supported = false
272271
else
273272
deps += dependency(
274273
'cpp-httplib',
@@ -326,6 +325,8 @@ endif
326325
is_flatpak_build = get_option('flatpak_build')
327326

328327
have_file_dialogs = false
328+
have_discord_sdk = false
329+
329330

330331
nfde_dep = dependency(
331332
'nativefiledialog-extended',
@@ -338,6 +339,16 @@ if nfde_dep.found()
338339
compile_args += '-D_HAVE_FILE_DIALOGS'
339340
endif
340341

342+
discord_sdk_dep = dependency(
343+
'discord-game-sdk',
344+
required: not meson.is_cross_build(),
345+
default_options: {'clang_libcpp': 'disabled'},
346+
)
347+
if discord_sdk_dep.found()
348+
have_discord_sdk = true
349+
deps += discord_sdk_dep
350+
compile_args += '-D_HAVE_DISCORD_SDK'
351+
endif
341352

342353

343354
src_files = []
@@ -567,7 +578,6 @@ else
567578
dependencies: deps,
568579
c_args: sdl2_mixer_defines,
569580
cpp_args: compile_args + sdl2_mixer_defines,
570-
link_args: link_args,
571581
override_options: {
572582
'warning_level': '3',
573583
'werror': true,
@@ -580,8 +590,7 @@ else
580590
recording_src_files,
581591
dependencies: recording_dependencies,
582592
include_directories: recording_inc_dirs,
583-
cpp_args: [compile_args, '-D_NO_SDL', '-D_NO_SPDLOG'],
584-
link_args: link_args,
593+
cpp_args: [compile_args, '-D_NO_SDL', '-D_NO_SPDLOG', '-D_OOPETRIS_RECORDING_UTILITY'],
585594
override_options: {
586595
'warning_level': '3',
587596
'werror': true,

platforms/make-icons.sh

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
#!/usr/bin/env bash
22

3-
for RES in 24 48 64 72 96 128 144 160 192 256 512; do
3+
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
44

5-
inkscape "--export-width=$RES" "--export-height=$RES" --export-type=png "--export-filename=../assets/icon/${RES}x${RES}.png" "../assets/OOPetris.svg"
5+
SRC_DIR=$(realpath "$SCRIPT_DIR/..")
6+
7+
for RES in 24 48 64 72 96 128 144 160 192 256 512 1024; do
8+
9+
inkscape "--export-width=$RES" "--export-height=$RES" --export-type=png "--export-filename=$SRC_DIR/assets/icon/${RES}x${RES}.png" "$SRC_DIR/assets/OOPetris.svg"
610

711
done
812

913
#TODO: this doesn't work correctly!
1014
MAX_RES="4096"
11-
inkscape "--export-width=$MAX_RES" "--export-height=$MAX_RES" --export-type=svg "--export-filename=../assets/icon/scalable.svg" "../assets/OOPetris.svg"
15+
inkscape "--export-width=$MAX_RES" "--export-height=$MAX_RES" --export-type=svg "--export-filename=$SRC_DIR/assets/icon/scalable.svg" "$SRC_DIR/assets/OOPetris.svg"

src/application.cpp

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
#include "platform/capabilities.hpp"
44
#include "scenes/scene.hpp"
55

6+
#include <chrono>
67
#include <ranges>
78

89
#if defined(__SWITCH__)
910
#include "switch.h"
1011
#endif
1112

13+
1214
Application::Application(
1315
int argc,
1416
char** argv,
@@ -48,7 +50,6 @@ void Application::run() {
4850
const double count_per_s = static_cast<double>(SDL_GetPerformanceFrequency());
4951
u64 frame_counter = 0;
5052
#endif
51-
5253
using namespace std::chrono_literals;
5354

5455
const auto sleep_time = m_target_framerate.has_value() ? std::chrono::duration_cast<std::chrono::nanoseconds>(1s)
@@ -199,6 +200,14 @@ void Application::update() {
199200
break;
200201
}
201202
}
203+
204+
#if defined(_HAVE_DISCORD_SDK)
205+
206+
if (m_discord_instance.has_value()) {
207+
m_discord_instance->update();
208+
}
209+
210+
#endif
202211
}
203212

204213
void Application::render() const {
@@ -212,6 +221,18 @@ void Application::render() const {
212221
}
213222

214223
void Application::initialize() {
224+
225+
#if defined(_HAVE_DISCORD_SDK)
226+
auto discord_instance = DiscordInstance::initialize();
227+
if (not discord_instance.has_value()) {
228+
spdlog::warn("Error initializing the discord instance, it might not be running: {}", discord_instance.error());
229+
} else {
230+
m_discord_instance = std::move(discord_instance.value());
231+
m_discord_instance->after_setup();
232+
}
233+
234+
#endif
235+
215236
try_load_settings();
216237
load_resources();
217238
push_scene(scenes::create_scene(*this, SceneId::MainMenu, ui::FullScreenLayout{ m_window }));
@@ -251,3 +272,16 @@ void Application::load_resources() {
251272
m_font_manager.load(font_id, font_path, fonts_size);
252273
}
253274
}
275+
276+
#if defined(_HAVE_DISCORD_SDK)
277+
278+
[[nodiscard]] helper::optional<DiscordInstance>& Application::discord_instance() {
279+
return m_discord_instance;
280+
}
281+
282+
[[nodiscard]] const helper::optional<DiscordInstance>& Application::discord_instance() const {
283+
return m_discord_instance;
284+
}
285+
286+
287+
#endif

src/application.hpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,15 @@ struct Application final : public EventListener, public ServiceProvider {
3535
FontManager m_font_manager;
3636
helper::optional<u32> m_target_framerate;
3737

38+
3839
#ifdef DEBUG_BUILD
3940
std::unique_ptr<ui::Label> m_fps_text{ nullptr };
4041
#endif
4142

43+
#if defined(_HAVE_DISCORD_SDK)
44+
helper::optional<DiscordInstance> m_discord_instance{ helper::nullopt };
45+
#endif
46+
4247
protected:
4348
EventDispatcher m_event_dispatcher;
4449

@@ -109,6 +114,16 @@ struct Application final : public EventListener, public ServiceProvider {
109114
return m_window;
110115
}
111116

117+
118+
#if defined(_HAVE_DISCORD_SDK)
119+
120+
[[nodiscard]] helper::optional<DiscordInstance>& discord_instance() override;
121+
[[nodiscard]] const helper::optional<DiscordInstance>& discord_instance() const override;
122+
123+
124+
#endif
125+
126+
112127
private:
113128
void initialize();
114129
void try_load_settings();

0 commit comments

Comments
 (0)