diff --git a/SConstruct b/SConstruct index 0b41431..e3d1976 100644 --- a/SConstruct +++ b/SConstruct @@ -28,7 +28,9 @@ else: # make sure our binding library is properly includes env.Append(LIBPATH=["src/lib/discord_game_sdk/bin/"]) sources = Glob("src/lib/discord_game_sdk/cpp/*.cpp") -env.Append(CPPPATH=["src/lib/discord_game_sdk/cpp/"]) # this line for some reason doesn't get understanded by most linux distros +env.Append( + CPPPATH=["src/lib/discord_game_sdk/cpp/"] +) # this line for some reason doesn't get understanded by most linux distros env.Append(LIBS=["discord_game_sdk"]) # tweak this if you want to use different folders, or more folders, to store your source code in. @@ -51,11 +53,13 @@ env.Depends( Copy("$TARGET", "$SOURCE"), ), ) -if(discord_library_second != ""): +if discord_library_second != "": env.Depends( library, Command( - "project/addons/discord-sdk-gd/bin/" + libexportfolder + discord_library_second, + "project/addons/discord-sdk-gd/bin/" + + libexportfolder + + discord_library_second, "src/lib/discord_game_sdk/bin/" + discord_library_second, Copy("$TARGET", "$SOURCE"), ), diff --git a/project/addons/discord-sdk-gd/bin/linux/libdiscord_game_sdk.so b/project/addons/discord-sdk-gd/bin/linux/libdiscord_game_sdk.so new file mode 100644 index 0000000..9dacf94 Binary files /dev/null and b/project/addons/discord-sdk-gd/bin/linux/libdiscord_game_sdk.so differ diff --git a/project/addons/discord-sdk-gd/bin/windows/discord_game_sdk_binding.dll b/project/addons/discord-sdk-gd/bin/windows/discord_game_sdk_binding.dll new file mode 100644 index 0000000..bf4b3d0 Binary files /dev/null and b/project/addons/discord-sdk-gd/bin/windows/discord_game_sdk_binding.dll differ diff --git a/project/addons/discord-sdk-gd/bin/windows/discord_game_sdk_binding_debug.dll b/project/addons/discord-sdk-gd/bin/windows/discord_game_sdk_binding_debug.dll index bca7e73..0f8b52d 100644 Binary files a/project/addons/discord-sdk-gd/bin/windows/discord_game_sdk_binding_debug.dll and b/project/addons/discord-sdk-gd/bin/windows/discord_game_sdk_binding_debug.dll differ diff --git a/project/addons/discord-sdk-gd/bin/windows/~discord_game_sdk_binding_debug.dll b/project/addons/discord-sdk-gd/bin/windows/~discord_game_sdk_binding_debug.dll index bca7e73..0345fad 100644 Binary files a/project/addons/discord-sdk-gd/bin/windows/~discord_game_sdk_binding_debug.dll and b/project/addons/discord-sdk-gd/bin/windows/~discord_game_sdk_binding_debug.dll differ diff --git a/project/addons/discord-sdk-gd/nodes/core_updater.gd b/project/addons/discord-sdk-gd/nodes/discord_autoload.gd similarity index 66% rename from project/addons/discord-sdk-gd/nodes/core_updater.gd rename to project/addons/discord-sdk-gd/nodes/discord_autoload.gd index 6ecca2d..3852777 100644 --- a/project/addons/discord-sdk-gd/nodes/core_updater.gd +++ b/project/addons/discord-sdk-gd/nodes/discord_autoload.gd @@ -1,13 +1,12 @@ -## [color=yellow]PLEASE IGNORE![/color] This is a important Node wich gets automatically added as Singleton. +## This is a GDscript Node wich gets automatically added as Autoload while installing the addon. ## -## The DiscordSDKLoader Node automatically gets added as Singleton while installing the addon. -## It has to run in the background to comunicate with Discord. -## You don't need to use it. +## It can run in the background to comunicate with Discord. +## You don't need to use it unless you are using EditorPresence. If you remove it make sure to run [code]discord_sdk.run_callbacks()[/code] in a [code]_process[/code] function. ## ## @tutorial: https://github.com/vaporvee/discord-sdk-godot/wiki @tool -class_name core_updater extends Node +class_name DiscordSDKLoaderAutoload func _process(_delta): if(ProjectSettings.get_setting("DiscordSDK/EditorPresence/enabled") && Engine.is_editor_hint()): @@ -20,4 +19,4 @@ func _process(_delta): discord_sdk.start_timestamp = int(Time.get_unix_time_from_system()) discord_sdk.refresh() if(discord_sdk.app_id == 1108142249990176808 || !Engine.is_editor_hint()): - discord_sdk.coreupdate() + discord_sdk.run_callbacks() diff --git a/project/addons/discord-sdk-gd/plugin.gd b/project/addons/discord-sdk-gd/plugin.gd index ac8c140..f086bbc 100644 --- a/project/addons/discord-sdk-gd/plugin.gd +++ b/project/addons/discord-sdk-gd/plugin.gd @@ -13,15 +13,16 @@ func _enter_tree() -> void: ProjectSettings.set_setting("DiscordSDK/EditorPresence/enabled",false) ProjectSettings.set_as_basic("DiscordSDK/EditorPresence/enabled",true) ProjectSettings.set_initial_value("DiscordSDK/EditorPresence/enabled",false) - get_node("/root/").add_child(DiscordLoader.new()) func _enable_plugin() -> void: + add_autoload_singleton("DiscordSDKAutoload","res://addons/discord-sdk-gd/nodes/discord_autoload.gd") if FileAccess.file_exists(ProjectSettings.globalize_path("res://") + "addons/discord-sdk-gd/bin/.gdignore"): DirAccess.remove_absolute(ProjectSettings.globalize_path("res://") + "addons/discord-sdk-gd/bin/.gdignore") if FileAccess.file_exists(ProjectSettings.globalize_path("res://") + "addons/discord-sdk-gd/nodes/.gdignore"): DirAccess.remove_absolute(ProjectSettings.globalize_path("res://") + "addons/discord-sdk-gd/nodes/.gdignore") func _disable_plugin() -> void: + remove_autoload_singleton("DiscordSDKAutoload") FileAccess.open("res://addons/discord-sdk-gd/bin/.gdignore",FileAccess.WRITE) FileAccess.open("res://addons/discord-sdk-gd/nodes/.gdignore",FileAccess.WRITE) remove_custom_type("DiscordSDKDebug") diff --git a/src/discordgodot.cpp b/src/discordgodot.cpp index 8cfd857..2d49b76 100644 --- a/src/discordgodot.cpp +++ b/src/discordgodot.cpp @@ -3,7 +3,7 @@ #include #include -#define BIND_METHOD(method, ...) godot::ClassDB::bind_method(D_METHOD(#method, __VA_ARGS__), &discord_sdk::method) +#define BIND_METHOD(method, ...) godot::ClassDB::bind_method(D_METHOD(#method, ##__VA_ARGS__), &discord_sdk::method) #define BIND_SET_GET(property_name, variant_type) \ godot::ClassDB::bind_method(D_METHOD("get_" #property_name), &discord_sdk::get_##property_name); \ godot::ClassDB::bind_method(D_METHOD("set_" #property_name, #variant_type), &discord_sdk::set_##property_name); \ @@ -49,7 +49,7 @@ void discord_sdk::_bind_methods() BIND_SIGNAL(overlay_toggle, PropertyInfo(Variant::BOOL, "is_locked")); BIND_SIGNAL(relationships_init); BIND_METHOD(debug); - BIND_METHOD(coreupdate); + BIND_METHOD(run_callbacks); BIND_METHOD(refresh); ClassDB::bind_method(D_METHOD("clear", "reset_values"), &discord_sdk::clear, DEFVAL(false)); BIND_METHOD(unclear); @@ -93,11 +93,8 @@ discord_sdk::discord_sdk() discord_sdk::~discord_sdk() { - if (app_id != 0) - { - set_app_id(0); - core->~Core(); - } + app_id = 0; + core->~Core(); singleton = nullptr; } @@ -106,7 +103,7 @@ discord_sdk *discord_sdk::get_singleton() return singleton; } -void discord_sdk::coreupdate() +void discord_sdk::run_callbacks() { if (result == discord::Result::Ok && app_id > 0) ::core->RunCallbacks(); @@ -173,7 +170,7 @@ int64_t discord_sdk::get_app_id() void discord_sdk::refresh() { - if (result == discord::Result::Ok && app_id > 0) + if (get_is_discord_working()) { activity.GetParty().SetPrivacy(discord::ActivityPartyPrivacy::Public); activity.SetType(discord::ActivityType::Playing); @@ -185,7 +182,7 @@ void discord_sdk::refresh() void discord_sdk::clear(bool reset_values = false) { - if (result == discord::Result::Ok) + if (get_is_discord_working()) { if (reset_values) { @@ -212,8 +209,7 @@ void discord_sdk::clear(bool reset_values = false) else old_app_id = app_id; set_app_id(0); - delete core; - core = nullptr; + core->~Core(); } } @@ -232,69 +228,69 @@ void discord_sdk::unclear() bool discord_sdk::get_is_overlay_enabled() { bool ie; - if (result == discord::Result::Ok && app_id > 0) + if (get_is_discord_working()) core->OverlayManager().IsEnabled(&ie); return ie; } bool discord_sdk::get_is_overlay_locked() { bool il; - if (result == discord::Result::Ok && app_id > 0) + if (get_is_discord_working()) core->OverlayManager().IsLocked(&il); return il; } void discord_sdk::set_is_overlay_locked(bool value) { is_overlay_locked = value; - if (result == discord::Result::Ok && app_id > 0) + if (get_is_discord_working()) core->OverlayManager().SetLocked(value, {}); } void discord_sdk::open_invite_overlay(bool is_spectate) { - if (result == discord::Result::Ok && app_id > 0) + if (get_is_discord_working()) core->OverlayManager().OpenActivityInvite(static_cast(is_spectate + 1), {}); } void discord_sdk::open_server_invite_overlay(String invite_code) { - if (result == discord::Result::Ok && app_id > 0) + if (get_is_discord_working()) core->OverlayManager().OpenGuildInvite(invite_code.utf8().get_data(), {}); } void discord_sdk::open_voice_settings() { - if (result == discord::Result::Ok && app_id > 0) + if (get_is_discord_working()) core->OverlayManager().OpenVoiceSettings({}); } void discord_sdk::accept_join_request(int64_t user_id) { - if (result == discord::Result::Ok && app_id > 0) + if (get_is_discord_working()) core->ActivityManager().SendRequestReply(user_id, static_cast(1), {}); } void discord_sdk::send_invite(int64_t user_id, bool is_spectate = false, String message_content = "") { - if (result == discord::Result::Ok && app_id > 0) + if (get_is_discord_working()) core->ActivityManager().SendInvite(user_id, static_cast(is_spectate + 1), message_content.utf8().get_data(), {}); } void discord_sdk::accept_invite(int64_t user_id) { - if (result == discord::Result::Ok && app_id > 0) + if (get_is_discord_working()) core->ActivityManager().AcceptInvite(user_id, {}); } void discord_sdk::register_command(String value) { - if (result == discord::Result::Ok && app_id > 0) + if (get_is_discord_working()) core->ActivityManager().RegisterCommand(value.utf8().get_data()); } void discord_sdk::register_steam(int32_t value) { - if (result == discord::Result::Ok && app_id > 0) + if (get_is_discord_working()) core->ActivityManager().RegisterSteam(value); } Dictionary discord_sdk::get_current_user() { Dictionary userdict; - if (result == discord::Result::Ok && app_id > 0) + if (get_is_discord_working()) { discord::User user{}; core->UserManager().GetCurrentUser(&user); @@ -305,7 +301,7 @@ Dictionary discord_sdk::get_current_user() Dictionary discord_sdk::get_relationship(int64_t user_id) { - if (result == discord::Result::Ok && app_id > 0) + if (get_is_discord_working()) { discord::Relationship relationship{}; core->RelationshipManager().Get(user_id, &relationship); diff --git a/src/discordgodot.h b/src/discordgodot.h index c4a6abe..9a47b9f 100644 --- a/src/discordgodot.h +++ b/src/discordgodot.h @@ -54,7 +54,7 @@ public: H_SET_GET(bool, is_overlay_locked) void debug(); - void coreupdate(); + void run_callbacks(); void refresh(); void clear(bool reset_values); void unclear(); diff --git a/src/lib/godot-cpp b/src/lib/godot-cpp index d627942..54136ee 160000 --- a/src/lib/godot-cpp +++ b/src/lib/godot-cpp @@ -1 +1 @@ -Subproject commit d627942b647105aff600225a59dffa65de206247 +Subproject commit 54136ee8357c5140a3775c54f08db5f7deda2058 diff --git a/src/loader_node.cpp b/src/loader_node.cpp deleted file mode 100644 index 6d9d7cc..0000000 --- a/src/loader_node.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include "loader_node.h" -#include "discordgodot.h" -#include -#include - -using namespace godot; - -#define EDITOR_PRESENCE_ID 1108142249990176808 - -void DiscordLoader::_bind_methods() -{ -} - -DiscordLoader::DiscordLoader() -{ -} - -DiscordLoader::~DiscordLoader() -{ -} - -void DiscordLoader::_process(double delta) -{ - discord_sdk *singleton = discord_sdk::get_singleton(); - singleton->coreupdate(); -} \ No newline at end of file diff --git a/src/loader_node.h b/src/loader_node.h deleted file mode 100644 index a0c4bd7..0000000 --- a/src/loader_node.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef LOADER_NODE_H -#define LOADER_NODE_H - -#include - -namespace godot -{ - - class DiscordLoader : public Node - { - GDCLASS(DiscordLoader, Node) - - protected: - static void _bind_methods(); - - public: - DiscordLoader(); - ~DiscordLoader(); - - void _process(double delta) override; - }; - -} - -#endif \ No newline at end of file diff --git a/src/register_types.cpp b/src/register_types.cpp index 6b42d04..37f3fc6 100644 --- a/src/register_types.cpp +++ b/src/register_types.cpp @@ -7,7 +7,6 @@ #include #include "discordgodot.h" -#include "loader_node.h" using namespace godot; static discord_sdk *discordsdk; @@ -20,7 +19,6 @@ void initialize_discordsdk_module(ModuleInitializationLevel p_level) discordsdk = memnew(discord_sdk); Engine::get_singleton()->register_singleton("discord_sdk", discord_sdk::get_singleton()); } - ClassDB::register_class(); } void uninitialize_discordsdk_module(ModuleInitializationLevel p_level)