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 index 366b47d..3c9f159 100644 Binary files a/project/addons/discord-sdk-gd/bin/windows/discord_game_sdk_binding.dll 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 42aff01..b0a53a2 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~RF2021ab2d.TMP similarity index 100% rename from project/addons/discord-sdk-gd/bin/windows/~discord_game_sdk_binding_debug.dll rename to project/addons/discord-sdk-gd/bin/windows/~discord_game_sdk_binding_debug.dll~RF2021ab2d.TMP diff --git a/project/addons/discord-sdk-gd/example.gd b/project/addons/discord-sdk-gd/example.gd index 00aa61a..04f4c91 100644 --- a/project/addons/discord-sdk-gd/example.gd +++ b/project/addons/discord-sdk-gd/example.gd @@ -11,27 +11,27 @@ extends Node ## [codeblock] ## func _ready(): ## # Application ID -## discord_sdk.app_id = 1099618430065324082 +## DiscordSDK.app_id = 1099618430065324082 ## # this is boolean if everything worked -## print("Discord working: " + str(discord_sdk.get_is_discord_working())) +## print("Discord working: " + str(DiscordSDK.get_is_discord_working())) ## # Set the first custom text row of the activity here -## discord_sdk.details = "A demo activity by vaporvee#1231" +## DiscordSDK.details = "A demo activity by vaporvee#1231" ## # Set the second custom text row of the activity here -## discord_sdk.state = "Checkpoint 23/23" +## DiscordSDK.state = "Checkpoint 23/23" ## # Image key for small image from "Art Assets" from the Discord Developer website -## discord_sdk.large_image = "game" +## DiscordSDK.large_image = "game" ## # Tooltip text for the large image -## discord_sdk.large_image_text = "Try it now!" +## DiscordSDK.large_image_text = "Try it now!" ## # Image key for large image from "Art Assets" from the Discord Developer website -## discord_sdk.small_image = "boss" +## DiscordSDK.small_image = "boss" ## # Tooltip text for the small image -## discord_sdk.small_image_text = "Fighting the end boss! D:" +## DiscordSDK.small_image_text = "Fighting the end boss! D:" ## # "02:41 elapsed" timestamp for the activity -## discord_sdk.start_timestamp = int(Time.get_unix_time_from_system()) +## DiscordSDK.start_timestamp = int(Time.get_unix_time_from_system()) ## # "59:59 remaining" timestamp for the activity -## discord_sdk.end_timestamp = int(Time.get_unix_time_from_system()) + 3600 +## DiscordSDK.end_timestamp = int(Time.get_unix_time_from_system()) + 3600 ## # Always refresh after changing the values! -## discord_sdk.refresh() +## DiscordSDK.refresh() ## [/codeblock] ## ## @tutorial(More information here): https://github.com/vaporvee/discord-sdk-godot/wiki/Quick-start diff --git a/project/addons/discord-sdk-gd/nodes/Debug.tscn b/project/addons/discord-sdk-gd/nodes/Debug.tscn index f4474f2..adf08fc 100644 --- a/project/addons/discord-sdk-gd/nodes/Debug.tscn +++ b/project/addons/discord-sdk-gd/nodes/Debug.tscn @@ -9,10 +9,10 @@ resource_name = "Debug" script/source = "extends Node func _ready(): - discord_sdk.connect(\"activity_join_request\",_on_activity_join_request) + DiscordSDK.connect(\"activity_join_request\",_on_activity_join_request) func _process(_delta): - if(discord_sdk.get_is_discord_working()): + if(DiscordSDK.get_is_discord_working()): $Panel/TextureRect.self_modulate = Color(\"#3eff8d\") $Panel/TextureRect/AnimationPlayer.play(\"pulsate\") debug_text_update() @@ -45,7 +45,7 @@ Is party public: {ppublic} (needs to be activated in Discord client settings) Is instanced: {instanced} \" - $Panel/Info.text = $Panel/Info.text.replace(\"{ppublic}\",str(discord_sdk.is_public_party)).replace(\"{instanced}\",str(discord_sdk.instanced)).replace(\"{ssecret}\",discord_sdk.spectate_secret).replace(\"{jsecret}\",discord_sdk.join_secret).replace(\"{msecret}\",discord_sdk.match_secret).replace(\"{mpartysize}\",str(discord_sdk.max_party_size)).replace(\"{cpartysize}\",str(discord_sdk.current_party_size)).replace(\"{partyid}\",discord_sdk.party_id).replace(\"{id}\",str(discord_sdk.app_id)).replace(\"{details}\",discord_sdk.details).replace(\"{state}\",discord_sdk.state).replace(\"{lkey}\",discord_sdk.large_image).replace(\"{ltext}\",discord_sdk.large_image_text).replace(\"{skey}\",discord_sdk.small_image).replace(\"{stext}\",discord_sdk.small_image_text).replace(\"{stimestamp}\",str(discord_sdk.start_timestamp)).replace(\"{etimestamp}\",str(discord_sdk.end_timestamp)) + $Panel/Info.text = $Panel/Info.text.replace(\"{ppublic}\",str(DiscordSDK.is_public_party)).replace(\"{instanced}\",str(DiscordSDK.instanced)).replace(\"{ssecret}\",DiscordSDK.spectate_secret).replace(\"{jsecret}\",DiscordSDK.join_secret).replace(\"{msecret}\",DiscordSDK.match_secret).replace(\"{mpartysize}\",str(DiscordSDK.max_party_size)).replace(\"{cpartysize}\",str(DiscordSDK.current_party_size)).replace(\"{partyid}\",DiscordSDK.party_id).replace(\"{id}\",str(DiscordSDK.app_id)).replace(\"{details}\",DiscordSDK.details).replace(\"{state}\",DiscordSDK.state).replace(\"{lkey}\",DiscordSDK.large_image).replace(\"{ltext}\",DiscordSDK.large_image_text).replace(\"{skey}\",DiscordSDK.small_image).replace(\"{stext}\",DiscordSDK.small_image_text).replace(\"{stimestamp}\",str(DiscordSDK.start_timestamp)).replace(\"{etimestamp}\",str(DiscordSDK.end_timestamp)) var user_request = {}; @@ -55,25 +55,25 @@ func _on_activity_join_request(user_requesting): func _on_accept_join_request_pressed(): if(!user_request.is_empty()): - discord_sdk.accept_join_request(user_request.id) + DiscordSDK.accept_join_request(user_request.id) func _on_invite_with_user_id_text_submitted(new_text): - discord_sdk.send_invite(int(new_text),true,\"this is a test invite sent from godot\") + DiscordSDK.send_invite(int(new_text),true,\"this is a test invite sent from godot\") func _on_accept_with_user_id_text_submitted(new_text): - discord_sdk.accept_invite(int(new_text)) + DiscordSDK.accept_invite(int(new_text)) func _on_print_current_user_on_console_pressed(): - print(discord_sdk.get_current_user()) + print(DiscordSDK.get_current_user()) func _on_toggle_sdk_toggled(button_pressed): if(button_pressed): - discord_sdk.unclear() + DiscordSDK.unclear() else: - discord_sdk.clear(false) + DiscordSDK.clear(false) func _on_print_friends_pressed(): - print(discord_sdk.get_all_relationships()) + print(DiscordSDK.get_all_relationships()) " [sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_8abo6"] diff --git a/project/addons/discord-sdk-gd/nodes/discord_autoload.gd b/project/addons/discord-sdk-gd/nodes/discord_autoload.gd index 8571302..81a5048 100644 --- a/project/addons/discord-sdk-gd/nodes/discord_autoload.gd +++ b/project/addons/discord-sdk-gd/nodes/discord_autoload.gd @@ -1,7 +1,7 @@ ## This is a GDscript Node wich gets automatically added as Autoload while installing the addon. ## ## 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. +## You don't need to use it unless you are using EditorPresence. If you remove it make sure to run [code]DiscordSDK.run_callbacks()[/code] in a [code]_process[/code] function. ## ## @tutorial: https://github.com/vaporvee/discord-sdk-godot/wiki @tool @@ -11,13 +11,13 @@ class_name DiscordSDKLoaderAutoload func _process(_delta) -> void: if GDExtensionManager.get_loaded_extensions().has("res://addons/discord-sdk-gd/bin/discord-rpc-gd.gdextension"): if ProjectSettings.get_setting("DiscordSDK/EditorPresence/enabled",false) && Engine.is_editor_hint(): - if discord_sdk.app_id != 1108142249990176808: - discord_sdk.app_id = 1108142249990176808 - discord_sdk.details = ProjectSettings.get_setting("application/config/name") - discord_sdk.state = "Editing: \""+ str(get_tree().edited_scene_root.scene_file_path).replace("res://","") +"\"" - discord_sdk.large_image = "godot" - discord_sdk.large_image_text = str(Engine.get_version_info().string) - 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.run_callbacks() + if DiscordSDK.app_id != 1108142249990176808: + DiscordSDK.app_id = 1108142249990176808 + DiscordSDK.details = ProjectSettings.get_setting("application/config/name") + DiscordSDK.state = "Editing: \""+ str(get_tree().edited_scene_root.scene_file_path).replace("res://","") +"\"" + DiscordSDK.large_image = "godot" + DiscordSDK.large_image_text = str(Engine.get_version_info().string) + DiscordSDK.start_timestamp = int(Time.get_unix_time_from_system()) + DiscordSDK.refresh() + if DiscordSDK.app_id == 1108142249990176808 || !Engine.is_editor_hint(): + DiscordSDK.run_callbacks() diff --git a/project/addons/discord-sdk-gd/restart_window.tscn b/project/addons/discord-sdk-gd/restart_window.tscn index f65591c..575ccc1 100644 --- a/project/addons/discord-sdk-gd/restart_window.tscn +++ b/project/addons/discord-sdk-gd/restart_window.tscn @@ -25,7 +25,7 @@ func _on_confirmed(): [sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_5vqdt"] -[sub_resource type="Image" id="Image_3lxeh"] +[sub_resource type="Image" id="Image_3se7o"] data = { "data": PackedByteArray(255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 227, 227, 227, 36, 224, 224, 224, 168, 224, 224, 224, 233, 224, 224, 224, 236, 224, 224, 224, 170, 231, 231, 231, 31, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 227, 227, 227, 36, 224, 224, 224, 234, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 239, 230, 230, 230, 30, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 224, 224, 224, 168, 224, 224, 224, 255, 224, 224, 224, 186, 224, 224, 224, 32, 224, 224, 224, 33, 224, 224, 224, 187, 224, 224, 224, 255, 225, 225, 225, 167, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 224, 224, 224, 237, 224, 224, 224, 255, 224, 224, 224, 33, 255, 255, 255, 0, 255, 255, 255, 0, 227, 227, 227, 36, 224, 224, 224, 255, 224, 224, 224, 234, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 224, 224, 224, 237, 224, 224, 224, 255, 224, 224, 224, 33, 255, 255, 255, 0, 255, 255, 255, 0, 229, 229, 229, 38, 224, 224, 224, 255, 224, 224, 224, 229, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 224, 224, 224, 164, 224, 224, 224, 255, 224, 224, 224, 187, 225, 225, 225, 34, 227, 227, 227, 36, 224, 224, 224, 192, 224, 224, 224, 255, 224, 224, 224, 162, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 224, 224, 224, 24, 225, 225, 225, 215, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 229, 224, 224, 224, 32, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 224, 224, 224, 24, 224, 224, 224, 216, 224, 224, 224, 255, 224, 224, 224, 210, 224, 224, 224, 161, 224, 224, 224, 232, 224, 224, 224, 231, 225, 225, 225, 159, 230, 230, 230, 30, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 224, 224, 224, 107, 224, 224, 224, 255, 224, 224, 224, 210, 230, 230, 230, 20, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 224, 224, 224, 105, 230, 230, 230, 20, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 221, 224, 224, 224, 130, 255, 255, 255, 1, 255, 255, 255, 1, 225, 225, 225, 134, 224, 224, 224, 224, 225, 225, 225, 223, 224, 224, 224, 132, 255, 255, 255, 1, 255, 255, 255, 6, 224, 224, 224, 137, 224, 224, 224, 231, 224, 224, 224, 255, 255, 255, 255, 0, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 130, 225, 225, 225, 133, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 129, 224, 224, 224, 137, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 255, 255, 255, 0, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 65, 224, 224, 224, 255, 224, 224, 224, 220, 225, 225, 225, 223, 224, 224, 224, 255, 226, 226, 226, 61, 224, 224, 224, 65, 224, 224, 224, 255, 224, 224, 224, 222, 224, 224, 224, 231, 224, 224, 224, 255, 227, 227, 227, 62, 255, 255, 255, 0, 255, 255, 255, 0, 224, 224, 224, 255, 224, 224, 224, 255, 225, 225, 225, 67, 224, 224, 224, 255, 224, 224, 224, 219, 224, 224, 224, 222, 224, 224, 224, 255, 227, 227, 227, 63, 225, 225, 225, 67, 224, 224, 224, 255, 224, 224, 224, 219, 224, 224, 224, 230, 224, 224, 224, 255, 227, 227, 227, 63, 255, 255, 255, 0, 255, 255, 255, 0, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 225, 225, 225, 127, 224, 224, 224, 129, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 225, 225, 225, 126, 225, 225, 225, 135, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 255, 255, 255, 0, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 221, 225, 225, 225, 127, 255, 255, 255, 0, 255, 255, 255, 1, 224, 224, 224, 128, 224, 224, 224, 220, 224, 224, 224, 219, 225, 225, 225, 127, 255, 255, 255, 0, 255, 255, 255, 5, 225, 225, 225, 134, 224, 224, 224, 229, 224, 224, 224, 255, 255, 255, 255, 0), "format": "RGBA8", @@ -35,7 +35,7 @@ data = { } [sub_resource type="ImageTexture" id="ImageTexture_gdtpn"] -image = SubResource("Image_3lxeh") +image = SubResource("Image_3se7o") [sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_7v0rg"] diff --git a/project/main.gd b/project/main.gd index 16a7cb1..2af6f66 100644 --- a/project/main.gd +++ b/project/main.gd @@ -2,40 +2,40 @@ extends Node func _ready() -> void: set_activity() - discord_sdk.connect("activity_join_request",_on_activity_join_request) - discord_sdk.connect("activity_join",_on_activity_join) - discord_sdk.connect("activity_spectate",_on_activity_spectate) - discord_sdk.connect("relationships_init",_on_relationship_init) - discord_sdk.connect("updated_relationship", _on_updated_relationship) + DiscordSDK.connect("activity_join_request",_on_activity_join_request) + DiscordSDK.connect("activity_join",_on_activity_join) + DiscordSDK.connect("activity_spectate",_on_activity_spectate) + DiscordSDK.connect("relationships_init",_on_relationship_init) + DiscordSDK.connect("updated_relationship", _on_updated_relationship) func set_activity() -> void: - discord_sdk.clear(false) - discord_sdk.app_id = 1099618430065324082 - discord_sdk.details = "A demo activity by vaporvee#1231" - discord_sdk.state = "Checkpoint 23/23" + DiscordSDK.clear(false) + DiscordSDK.app_id = 1099618430065324082 + DiscordSDK.details = "A demo activity by vaporvee#1231" + DiscordSDK.state = "Checkpoint 23/23" - discord_sdk.large_image = "example_game" - discord_sdk.large_image_text = "Try it now!" - discord_sdk.small_image = "boss" - discord_sdk.small_image_text = "Fighting the end boss! D:" - discord_sdk.end_timestamp = int(Time.get_unix_time_from_system()) + 3600 # +1 hour in unix time + DiscordSDK.large_image = "example_game" + DiscordSDK.large_image_text = "Try it now!" + DiscordSDK.small_image = "boss" + DiscordSDK.small_image_text = "Fighting the end boss! D:" + DiscordSDK.end_timestamp = int(Time.get_unix_time_from_system()) + 3600 # +1 hour in unix time # It is NOT recommended to manage secrets locally! It's meant to be a payload wich the server understands and # returns the other variables like current_party_size, party_id etc. Most of the values must differ from the others. var my_secret: String = str(randi_range(0,999999)) - discord_sdk.party_id = "mylobbycanbeeverything_" + my_secret - discord_sdk.current_party_size = 1 - discord_sdk.max_party_size = 4 - discord_sdk.match_secret = "m_" + my_secret #better use seeds with 1 to 1 range instead of just chars - discord_sdk.join_secret = "j_" + my_secret - discord_sdk.spectate_secret = "s_" + my_secret - discord_sdk.is_public_party = true - discord_sdk.instanced = true #required for spectate - #discord_sdk.start_timestamp = int(Time.get_unix_time_from_system()) - discord_sdk.register_command(r"C:\Users\yanni\Desktop\demo\discord_sdk.exe") - #discord_sdk.register_steam(1389990) - discord_sdk.refresh() + DiscordSDK.party_id = "mylobbycanbeeverything_" + my_secret + DiscordSDK.current_party_size = 1 + DiscordSDK.max_party_size = 4 + DiscordSDK.match_secret = "m_" + my_secret #better use seeds with 1 to 1 range instead of just chars + DiscordSDK.join_secret = "j_" + my_secret + DiscordSDK.spectate_secret = "s_" + my_secret + DiscordSDK.is_public_party = true + DiscordSDK.instanced = true #required for spectate + #DiscordSDK.start_timestamp = int(Time.get_unix_time_from_system()) + DiscordSDK.register_command(r"C:\Users\yanni\Desktop\demo\DiscordSDK.exe") + #DiscordSDK.register_steam(1389990) + DiscordSDK.refresh() var user_request: Dictionary; @@ -44,13 +44,13 @@ func _on_activity_join_request(user_requesting) -> void: user_request = user_requesting func _on_activity_join(secret) -> void: - if(discord_sdk.join_secret != secret): - discord_sdk.current_party_size = clamp(int(secret) + 1, 0, discord_sdk.max_party_size) - discord_sdk.party_id = secret.replace("j_","mylobbycanbeeverything_") - discord_sdk.match_secret = secret.replace("j_","m_") - discord_sdk.join_secret = secret - discord_sdk.spectate_secret = secret.replace("j_","s_") - discord_sdk.refresh() + if(DiscordSDK.join_secret != secret): + DiscordSDK.current_party_size = clamp(int(secret) + 1, 0, DiscordSDK.max_party_size) + DiscordSDK.party_id = secret.replace("j_","mylobbycanbeeverything_") + DiscordSDK.match_secret = secret.replace("j_","m_") + DiscordSDK.join_secret = secret + DiscordSDK.spectate_secret = secret.replace("j_","s_") + DiscordSDK.refresh() func _on_activity_spectate(secret) -> void: print(secret) diff --git a/src/discordgodot.cpp b/src/discordgodot.cpp index e318cf0..31d7fd8 100644 --- a/src/discordgodot.cpp +++ b/src/discordgodot.cpp @@ -3,27 +3,27 @@ #include #include -#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); \ +#define BIND_METHOD(method, ...) godot::ClassDB::bind_method(D_METHOD(#method, ##__VA_ARGS__), &DiscordSDK::method) +#define BIND_SET_GET(property_name, variant_type) \ + godot::ClassDB::bind_method(D_METHOD("get_" #property_name), &DiscordSDK::get_##property_name); \ + godot::ClassDB::bind_method(D_METHOD("set_" #property_name, #variant_type), &DiscordSDK::set_##property_name); \ godot::ClassDB::add_property(get_class_static(), PropertyInfo(variant_type, #property_name), "set_" #property_name, "get_" #property_name) #define BIND_SIGNAL(signal_name, ...) godot::ClassDB::add_signal(get_class_static(), MethodInfo(#signal_name, ##__VA_ARGS__)) -#define SET_GET(variable, setter, ...) /*getter isn't mandatory for this project*/ \ - decltype(discord_sdk::variable) discord_sdk::get_##variable() { return variable; } \ - void discord_sdk::set_##variable(decltype(discord_sdk::variable) value) \ - { \ - variable = value; \ - setter; \ +#define SET_GET(variable, setter, ...) /*getter isn't mandatory for this project*/ \ + decltype(DiscordSDK::variable) DiscordSDK::get_##variable() { return variable; } \ + void DiscordSDK::set_##variable(decltype(DiscordSDK::variable) value) \ + { \ + variable = value; \ + setter; \ } -discord_sdk *discord_sdk::singleton = nullptr; +DiscordSDK *DiscordSDK::singleton = nullptr; discord::Core *core{}; discord::Result result; discord::Activity activity{}; discord::User user{}; -void discord_sdk::_bind_methods() +void DiscordSDK::_bind_methods() { BIND_SET_GET(app_id, Variant::INT); BIND_SET_GET(state, Variant::STRING); @@ -51,7 +51,7 @@ void discord_sdk::_bind_methods() BIND_METHOD(debug); BIND_METHOD(run_callbacks); BIND_METHOD(refresh); - ClassDB::bind_method(D_METHOD("clear", "reset_values"), &discord_sdk::clear, DEFVAL(false)); + ClassDB::bind_method(D_METHOD("clear", "reset_values"), &DiscordSDK::clear, DEFVAL(false)); BIND_METHOD(unclear); BIND_METHOD(register_command, "command"); BIND_METHOD(register_steam, "steam_id"); @@ -85,29 +85,29 @@ SET_GET(spectate_secret, activity.GetSecrets().SetSpectate(value.utf8().get_data SET_GET(instanced, activity.SetInstance(value)) SET_GET(is_public_party, activity.GetParty().SetPrivacy(static_cast(value))) -discord_sdk::discord_sdk() +DiscordSDK::DiscordSDK() { singleton = this; } -discord_sdk::~discord_sdk() +DiscordSDK::~DiscordSDK() { singleton = nullptr; delete core; // couldn't use destructor because it would not compile on linux core = nullptr; } -discord_sdk *discord_sdk::get_singleton() +DiscordSDK *DiscordSDK::get_singleton() { return singleton; } -void discord_sdk::run_callbacks() +void DiscordSDK::run_callbacks() { if (result == discord::Result::Ok && app_id > 0) ::core->RunCallbacks(); } -void discord_sdk::debug() +void DiscordSDK::debug() { result = discord::Core::Create(1080224638845591692, DiscordCreateFlags_NoRequireDiscord, &core); activity.SetState("Test from Godot!"); @@ -125,7 +125,7 @@ void discord_sdk::debug() UtilityFunctions::push_warning("Discord Activity couldn't be updated. It could be that Discord isn't running!"); } -void discord_sdk::set_app_id(int64_t value) +void DiscordSDK::set_app_id(int64_t value) { app_id = value; if (app_id > 0) @@ -140,34 +140,34 @@ void discord_sdk::set_app_id(int64_t value) core->UserManager().GetCurrentUser(&user); }); // signals core->ActivityManager().OnActivityJoin.Connect([](const char *secret) - { discord_sdk::get_singleton() + { DiscordSDK::get_singleton() ->emit_signal("activity_join", secret); }); core->ActivityManager().OnActivitySpectate.Connect([](const char *secret) - { discord_sdk::get_singleton() + { DiscordSDK::get_singleton() ->emit_signal("activity_spectate", secret); }); core->ActivityManager().OnActivityJoinRequest.Connect([this](discord::User const &user) - { discord_sdk::get_singleton() + { DiscordSDK::get_singleton() ->emit_signal("activity_join_request", user2dict(user)); }); core->OverlayManager().OnToggle.Connect([](bool is_locked) - { discord_sdk::get_singleton() + { DiscordSDK::get_singleton() ->emit_signal("overlay_toggle", is_locked); }); core->RelationshipManager().OnRefresh.Connect([&]() - { discord_sdk::get_singleton() + { DiscordSDK::get_singleton() ->emit_signal("relationships_init"); }); core->RelationshipManager().OnRelationshipUpdate.Connect([&](discord::Relationship const &relationship) - { discord_sdk::get_singleton() + { DiscordSDK::get_singleton() ->emit_signal("updated_relationship", relationship2dict(relationship)); }); } } } -int64_t discord_sdk::get_app_id() +int64_t DiscordSDK::get_app_id() { if (app_id != 0) return app_id; return old_app_id; } -void discord_sdk::refresh() +void DiscordSDK::refresh() { if (get_is_discord_working()) { @@ -179,7 +179,7 @@ void discord_sdk::refresh() UtilityFunctions::push_warning("Discord Activity couldn't be updated. It could be that Discord isn't running!"); } -void discord_sdk::clear(bool reset_values = false) +void DiscordSDK::clear(bool reset_values = false) { if (get_is_discord_working()) { @@ -212,7 +212,7 @@ void discord_sdk::clear(bool reset_values = false) } } -void discord_sdk::unclear() +void DiscordSDK::unclear() { if (old_app_id > 0) { @@ -224,69 +224,69 @@ void discord_sdk::unclear() UtilityFunctions::push_warning("Discord Activity couldn't be uncleared. Maybe it didn't get cleared before?"); } -bool discord_sdk::get_is_overlay_enabled() +bool DiscordSDK::get_is_overlay_enabled() { bool ie; if (get_is_discord_working()) core->OverlayManager().IsEnabled(&ie); return ie; } -bool discord_sdk::get_is_overlay_locked() +bool DiscordSDK::get_is_overlay_locked() { bool il; if (get_is_discord_working()) core->OverlayManager().IsLocked(&il); return il; } -void discord_sdk::set_is_overlay_locked(bool value) +void DiscordSDK::set_is_overlay_locked(bool value) { is_overlay_locked = value; if (get_is_discord_working()) core->OverlayManager().SetLocked(value, {}); } -void discord_sdk::open_invite_overlay(bool is_spectate) +void DiscordSDK::open_invite_overlay(bool is_spectate) { if (get_is_discord_working()) core->OverlayManager().OpenActivityInvite(static_cast(is_spectate + 1), {}); } -void discord_sdk::open_server_invite_overlay(String invite_code) +void DiscordSDK::open_server_invite_overlay(String invite_code) { if (get_is_discord_working()) core->OverlayManager().OpenGuildInvite(invite_code.utf8().get_data(), {}); } -void discord_sdk::open_voice_settings() +void DiscordSDK::open_voice_settings() { if (get_is_discord_working()) core->OverlayManager().OpenVoiceSettings({}); } -void discord_sdk::accept_join_request(int64_t user_id) +void DiscordSDK::accept_join_request(int64_t user_id) { 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 = "") +void DiscordSDK::send_invite(int64_t user_id, bool is_spectate = false, String message_content = "") { 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) +void DiscordSDK::accept_invite(int64_t user_id) { if (get_is_discord_working()) core->ActivityManager().AcceptInvite(user_id, {}); } -void discord_sdk::register_command(String value) +void DiscordSDK::register_command(String value) { if (get_is_discord_working()) core->ActivityManager().RegisterCommand(value.utf8().get_data()); } -void discord_sdk::register_steam(int32_t value) +void DiscordSDK::register_steam(int32_t value) { if (get_is_discord_working()) core->ActivityManager().RegisterSteam(value); } -Dictionary discord_sdk::get_current_user() +Dictionary DiscordSDK::get_current_user() { Dictionary userdict; if (get_is_discord_working()) @@ -298,7 +298,7 @@ Dictionary discord_sdk::get_current_user() return userdict; } -Dictionary discord_sdk::get_relationship(int64_t user_id) +Dictionary DiscordSDK::get_relationship(int64_t user_id) { if (get_is_discord_working()) { @@ -310,7 +310,7 @@ Dictionary discord_sdk::get_relationship(int64_t user_id) return dict; } -Array discord_sdk::get_all_relationships() +Array DiscordSDK::get_all_relationships() { Array all_relationships; core->RelationshipManager().Filter( @@ -327,12 +327,12 @@ Array discord_sdk::get_all_relationships() return all_relationships; } -int discord_sdk::get_result_int() +int DiscordSDK::get_result_int() { return static_cast(result); } -Dictionary discord_sdk::user2dict(discord::User user) +Dictionary DiscordSDK::user2dict(discord::User user) { Dictionary userdict; userdict["avatar"] = user.GetAvatar(); // can be empty when user has no avatar @@ -348,7 +348,7 @@ Dictionary discord_sdk::user2dict(discord::User user) return userdict; } -Dictionary discord_sdk::relationship2dict(discord::Relationship relationship) +Dictionary DiscordSDK::relationship2dict(discord::Relationship relationship) { Dictionary dict_relationship; Dictionary presence; @@ -420,7 +420,7 @@ Dictionary discord_sdk::relationship2dict(discord::Relationship relationship) return dict_relationship; } -bool discord_sdk::get_is_discord_working() +bool DiscordSDK::get_is_discord_working() { return result == discord::Result::Ok && app_id > 0; } \ No newline at end of file diff --git a/src/discordgodot.h b/src/discordgodot.h index 424733a..738f9c3 100644 --- a/src/discordgodot.h +++ b/src/discordgodot.h @@ -13,21 +13,21 @@ using namespace godot; -class discord_sdk : public Object +class DiscordSDK : public Object { - GDCLASS(discord_sdk, Object); + GDCLASS(DiscordSDK, Object); - static discord_sdk *singleton; + static DiscordSDK *singleton; protected: static void _bind_methods(); public: - static discord_sdk * + static DiscordSDK * get_singleton(); - discord_sdk(); - ~discord_sdk(); + DiscordSDK(); + ~DiscordSDK(); // INTERBNAL int64_t old_app_id; diff --git a/src/register_types.cpp b/src/register_types.cpp index 472ccb7..0499684 100644 --- a/src/register_types.cpp +++ b/src/register_types.cpp @@ -9,15 +9,15 @@ #include "discordgodot.h" using namespace godot; -static discord_sdk *discordsdk; +static DiscordSDK *discordsdk; void initialize_discordsdk_module(ModuleInitializationLevel p_level) { if (p_level == MODULE_INITIALIZATION_LEVEL_SCENE) { - ClassDB::register_class(); - discordsdk = memnew(discord_sdk); - Engine::get_singleton()->register_singleton("discord_sdk", discord_sdk::get_singleton()); + ClassDB::register_class(); + discordsdk = memnew(DiscordSDK); + Engine::get_singleton()->register_singleton("DiscordSDK", DiscordSDK::get_singleton()); } } @@ -25,7 +25,7 @@ void uninitialize_discordsdk_module(ModuleInitializationLevel p_level) { if (p_level == MODULE_INITIALIZATION_LEVEL_SCENE) { - Engine::get_singleton()->unregister_singleton("discord_sdk"); + Engine::get_singleton()->unregister_singleton("DiscordSDK"); } }