Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discord RPC Integration #1530

Merged
merged 11 commits into from Sep 14, 2020
3 changes: 3 additions & 0 deletions .gitmodules
Expand Up @@ -16,3 +16,6 @@
[submodule "external/SDL_ttf"]
path = external/SDL_ttf
url = https://github.com/SuperTux/SDL_ttf
[submodule "discord-sdk"]
path = external/discord-sdk
url = https://github.com/discord/discord-rpc
21 changes: 21 additions & 0 deletions CMakeLists.txt
Expand Up @@ -169,12 +169,21 @@ else(WIN32)
endif(WIN32)
set(HAVE_SDL TRUE)

option(DISABLE_DISCORD "Do not compile the Discord integration" OFF)
Mathnerd314 marked this conversation as resolved.
Show resolved Hide resolved
option(IS_SUPERTUX_RELEASE "Build as official SuperTux release" OFF)
option(BUILD_TESTS "Build test cases" OFF)
option(ENABLE_OPENGL "Enable OpenGL support" ON)
option(ENABLE_OPENGLES2 "Enable OpenGLES2 support" OFF)
option(GLBINDING_ENABLED "Use glbinding instead of GLEW" OFF)
option(GLBINDING_DEBUG_OUTPUT "Enable glbinding debug output for each called OpenGL function" OFF)

if(DISABLE_DISCORD)
message(STATUS "WARNING : Discord is NOT to be compiled. To enable Discord, pass -DDISABLE_DISCORD=Off")
else(DISABLE_DISCORD)
set(ENABLE_DISCORD TRUE)
message(STATUS "Discord WILL be compiled. To disable Discord, pass -DDISABLE_DISCORD=On")
endif(DISABLE_DISCORD)

if(ENABLE_OPENGL)
if(ENABLE_OPENGLES2)
pkg_check_modules(GLESV2 REQUIRED glesv2)
Expand Down Expand Up @@ -505,6 +514,9 @@ include_directories(SYSTEM ${CMAKE_CURRENT_SOURCE_DIR}/external/findlocale/)
include_directories(SYSTEM ${CMAKE_CURRENT_SOURCE_DIR}/external/obstack/)
include_directories(SYSTEM ${CMAKE_CURRENT_SOURCE_DIR}/external/sexp-cpp/include/)
include_directories(SYSTEM ${CMAKE_CURRENT_SOURCE_DIR}/external/SDL_SavePNG/)
if(NOT DISABLE_DISCORD)
include_directories(SYSTEM ${CMAKE_CURRENT_SOURCE_DIR}/external/discord-sdk/include)
endif(NOT DISABLE_DISCORD)

if(WIN32)
add_definitions(-D_USE_MATH_DEFINES -DNOMINMAX)
Expand Down Expand Up @@ -563,6 +575,12 @@ if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/src/scripting/wrapper.cpp)
set(SUPERTUX_SOURCES_CXX ${SUPERTUX_SOURCES_CXX} ${CMAKE_CURRENT_SOURCE_DIR}/src/scripting/wrapper.cpp)
endif(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/src/scripting/wrapper.cpp)

## Add discord RPC

if(NOT DISABLE_DISCORD)
add_subdirectory(external/discord-sdk)
endif(NOT DISABLE_DISCORD)

## Compile everything at once (roughly equivalent to cat *.cpp | gcc)

option(COMPILE_AMALGATION "Compile all the files together at once (experimental)" OFF)
Expand Down Expand Up @@ -824,6 +842,9 @@ target_link_libraries(supertux2_lib PUBLIC sqstdlib_lib)
target_link_libraries(supertux2_lib PUBLIC tinygettext_lib)
target_link_libraries(supertux2_lib PUBLIC sexp)
target_link_libraries(supertux2_lib PUBLIC savepng)
if(NOT DISABLE_DISCORD)
target_link_libraries(supertux2_lib PUBLIC discord-rpc)
endif(NOT DISABLE_DISCORD)
if(VCPKG_BUILD)
target_link_libraries(supertux2_lib PUBLIC OpenAL::OpenAL)
else()
Expand Down
2 changes: 2 additions & 0 deletions config.h.cmake
Expand Up @@ -31,4 +31,6 @@

#define BUILD_CONFIG_DATA_DIR "${BUILD_CONFIG_DATA_DIR}"

#cmakedefine ENABLE_DISCORD

#endif /*CONFIG_H*/
1 change: 1 addition & 0 deletions external/discord-sdk
Submodule discord-sdk added at e4c0c5
30 changes: 30 additions & 0 deletions src/editor/editor.cpp
Expand Up @@ -39,6 +39,7 @@
#include "object/spawnpoint.hpp"
#include "object/tilemap.hpp"
#include "physfs/util.hpp"
#include "sdk/integration.hpp"
#include "sprite/sprite_manager.hpp"
#include "supertux/game_manager.hpp"
#include "supertux/level.hpp"
Expand Down Expand Up @@ -238,6 +239,7 @@ Editor::get_level_directory() const
void
Editor::test_level(const boost::optional<std::pair<std::string, Vector>>& test_pos)
{

Tile::draw_editor_images = false;
Compositor::s_render_lighting = true;
std::string backup_filename = m_levelfile + "~";
Expand All @@ -256,10 +258,14 @@ Editor::test_level(const boost::optional<std::pair<std::string, Vector>>& test_p
m_level->save(m_test_levelfile);
if (!m_level->is_worldmap())
{
Integration::set_level(m_level->get_name().c_str());
Integration::set_status(TESTING_LEVEL);
GameManager::current()->start_level(*current_world, backup_filename, test_pos);
}
else
{
Integration::set_worldmap(m_level->get_name().c_str());
Integration::set_status(TESTING_WORLDMAP);
GameManager::current()->start_worldmap(*current_world, "", m_test_levelfile);
}

Expand All @@ -277,6 +283,7 @@ Editor::open_level_directory()
void
Editor::set_world(std::unique_ptr<World> w)
{
Integration::set_worldmap(w->get_title().c_str());
m_world = std::move(w);
}

Expand Down Expand Up @@ -396,6 +403,17 @@ Editor::delete_current_sector()
void
Editor::set_level(std::unique_ptr<Level> level, bool reset)
{
if (level->is_worldmap())
{
Integration::set_worldmap(level->get_name().c_str());
Integration::set_status(EDITING_WORLDMAP);
}
else
{
Integration::set_level(level->get_name().c_str());
Integration::set_status(EDITING_LEVEL);
}

std::string sector_name = "main";
Vector translation;

Expand Down Expand Up @@ -470,6 +488,8 @@ Editor::quit_editor()
m_enabled = false;
Tile::draw_editor_images = false;
ScreenManager::current()->pop_screen();

Integration::set_status(MAIN_MENU);
};

check_unsaved_changes([quit] {
Expand Down Expand Up @@ -573,7 +593,17 @@ Editor::setup()
m_deactivate_request = false;
m_enabled = true;
m_toolbox_widget->update_mouse_icon();

if (m_level->is_worldmap())
{
Integration::set_status(EDITING_WORLDMAP);
}
else
{
Integration::set_status(EDITING_LEVEL);
}
}

}

void
Expand Down