Skip to content

Commit

Permalink
feat: added discord rpc plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
akorzunin committed Aug 26, 2024
1 parent a80ec4b commit 3c5f609
Show file tree
Hide file tree
Showing 30 changed files with 613 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ temp
build
android
assets/*
env.*

.godot/*
!/.godot/uid_cache.bin
Expand Down
10 changes: 10 additions & 0 deletions addons/discord-rpc-gd/Debug.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added addons/discord-rpc-gd/Logo_V2_No_Bg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions addons/discord-rpc-gd/READ_ME_PLEASE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
MINIMUM GODOT VERSION: 4.2

PLEASE ACTIVATE THE PLUGIN UNDER Project -> Project Settings... -> Plugins -> DiscordRPC -> Status
IGNORE THE RED ERRORS ON THE FIRST 2 RESTARTS
READ THE TUTORIAL LINKED IN THE WINDOW THAT WILL OPEN ON PLUGIN ENABLE

If nothing works, enable the plugin and delete /addons/discord-rpc-gd/bin/.gdignore
29 changes: 29 additions & 0 deletions addons/discord-rpc-gd/bin/discord-rpc-gd.gdextension
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[configuration]

entry_symbol = "discordrpcgd_library_init"
compatibility_minimum = 4.1

[libraries]

macos.debug = "macos/libdiscord_game_sdk_binding_debug.dylib"
macos.release = "macos/libdiscord_game_sdk_binding.dylib"
windows.debug.x86_64 = "windows/discord_game_sdk_binding_debug.dll"
windows.release.x86_64 = "windows/discord_game_sdk_binding.dll"
linux.debug.x86_64 = "linux/libdiscord_game_sdk_binding_debug.so"
linux.release.x86_64 = "linux/libdiscord_game_sdk_binding.so"
linux.debug.arm64 = "linux/libdiscord_game_sdk_binding_debug.so"
linux.release.arm64 = "linux/libdiscord_game_sdk_binding.so"
linux.debug.rv64 = "linux/libdiscord_game_sdk_binding_debug.so"
linux.release.rv64 = "linux/libdiscord_game_sdk_binding.so"

[dependencies]

macos = { "macos/libdiscord_game_sdk.dylib": "" }
windows.debug.x86_64 = { "windows/discord_game_sdk.dll": "" }
windows.release.x86_64 = { "windows/discord_game_sdk.dll": "" }
linux.debug.x86_64 = { "linux/libdiscord_game_sdk.so": "" }
linux.release.x86_64 = { "linux/libdiscord_game_sdk.so": "" }
linux.debug.arm64 = { "linux/libdiscord_game_sdk.so": "" }
linux.release.arm64 = { "linux/libdiscord_game_sdk.so": "" }
linux.debug.rv64 = { "linux/libdiscord_game_sdk.so": "" }
linux.release.rv64 = { "linux/libdiscord_game_sdk.so": "" }
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
38 changes: 38 additions & 0 deletions addons/discord-rpc-gd/example.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
class_name DiscordRPCTutorial
extends Node

## 1. Put the addons/ folder in your Godot project[br]
## 2. Enable the addon in your Project Settings under "Plugins" and "DiscordRPC". [br](if it doesn't show up restart your project and try again)[br]
## 3. Restart your project[br]
## 4. Create an Application under https://discord.com/developers/applications and get the Application ID br]
## 5. (optional) Set images under "Rich Presence" and "Art Assets" and remember the keys[br]
##
## This is your [code]_ready()[/code] function wich could be anywhere
## [codeblock]
## func _ready():
## # Application ID
## DiscordRPC.app_id = 1099618430065324082
## # this is boolean if everything worked
## print("Discord working: " + str(DiscordRPC.get_is_discord_working()))
## # Set the first custom text row of the activity here
## DiscordRPC.details = "A demo activity by vaporvee#1231"
## # Set the second custom text row of the activity here
## DiscordRPC.state = "Checkpoint 23/23"
## # Image key for small image from "Art Assets" from the Discord Developer website
## DiscordRPC.large_image = "game"
## # Tooltip text for the large image
## DiscordRPC.large_image_text = "Try it now!"
## # Image key for large image from "Art Assets" from the Discord Developer website
## DiscordRPC.small_image = "boss"
## # Tooltip text for the small image
## DiscordRPC.small_image_text = "Fighting the end boss! D:"
## # "02:41 elapsed" timestamp for the activity
## DiscordRPC.start_timestamp = int(Time.get_unix_time_from_system())
## # "59:59 remaining" timestamp for the activity
## DiscordRPC.end_timestamp = int(Time.get_unix_time_from_system()) + 3600
## # Always refresh after changing the values!
## DiscordRPC.refresh()
## [/codeblock]
##
## @tutorial(More information here): https://github.com/vaporvee/discord-rpc-godot/wiki/Quick-start
## @tutorial(Make your Application ID and else here): https://discord.com/developers/applications
Binary file added addons/discord-rpc-gd/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
267 changes: 267 additions & 0 deletions addons/discord-rpc-gd/nodes/Debug.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,267 @@
[gd_scene load_steps=9 format=3 uid="uid://c1slhdnlsv2qt"]

[ext_resource type="Texture2D" uid="uid://dnfq6kug4x6o2" path="res://addons/discord-rpc-gd/nodes/assets/Checked.svg" id="2_q6tao"]
[ext_resource type="Texture2D" uid="uid://compmm3kviqqe" path="res://addons/discord-rpc-gd/nodes/assets/Unchecked.svg" id="3_5cyem"]
[ext_resource type="Texture2D" uid="uid://dtc6ckladq0td" path="res://addons/discord-rpc-gd/nodes/assets/circle.svg" id="3_goflf"]

[sub_resource type="GDScript" id="GDScript_ak1tp"]
resource_name = "Debug"
script/source = "extends Node

func _ready():
DiscordRPC.connect(\"activity_join_request\",_on_activity_join_request)

func _process(_delta):
if(DiscordRPC.get_is_discord_working()):
$Panel/TextureRect.self_modulate = Color(\"#3eff8d\")
$Panel/TextureRect/AnimationPlayer.play(\"pulsate\")
debug_text_update()
else:
$Panel/TextureRect.self_modulate = Color(\"#797979\")
$Panel/TextureRect/AnimationPlayer.stop()
debug_text_update()


func debug_text_update():
$Panel/Info.text = \"Application ID : {id}
Details: {details}
State: {state}

Large image key: {lkey}
Large image text: {ltext}
Small image key: {skey}
Small image text: {stext}

Start timestamp: {stimestamp}
End timestamp: {etimestamp}

Party ID: {partyid}
Current party size: {cpartysize}
Max party size: {mpartysize}
Match secret: {msecret}
Join secret: {jsecret}
Spectate secret: {ssecret}
Is party public: {ppublic} (needs to be activated in Discord client settings)

Is instanced: {instanced}
\"
$Panel/Info.text = $Panel/Info.text.replace(\"{ppublic}\",str(DiscordRPC.is_public_party)).replace(\"{instanced}\",str(DiscordRPC.instanced)).replace(\"{ssecret}\",DiscordRPC.spectate_secret).replace(\"{jsecret}\",DiscordRPC.join_secret).replace(\"{msecret}\",DiscordRPC.match_secret).replace(\"{mpartysize}\",str(DiscordRPC.max_party_size)).replace(\"{cpartysize}\",str(DiscordRPC.current_party_size)).replace(\"{partyid}\",DiscordRPC.party_id).replace(\"{id}\",str(DiscordRPC.app_id)).replace(\"{details}\",DiscordRPC.details).replace(\"{state}\",DiscordRPC.state).replace(\"{lkey}\",DiscordRPC.large_image).replace(\"{ltext}\",DiscordRPC.large_image_text).replace(\"{skey}\",DiscordRPC.small_image).replace(\"{stext}\",DiscordRPC.small_image_text).replace(\"{stimestamp}\",str(DiscordRPC.start_timestamp)).replace(\"{etimestamp}\",str(DiscordRPC.end_timestamp))

var user_request = {};

func _on_activity_join_request(user_requesting):
print(user_requesting)
user_request = user_requesting

func _on_accept_join_request_pressed():
if(!user_request.is_empty()):
DiscordRPC.accept_join_request(user_request.id)

func _on_invite_with_user_id_text_submitted(new_text):
DiscordRPC.send_invite(int(new_text),true,\"this is a test invite sent from godot\")

func _on_accept_with_user_id_text_submitted(new_text):
DiscordRPC.accept_invite(int(new_text))

func _on_print_current_user_on_console_pressed():
print(DiscordRPC.get_current_user())

func _on_toggle_sdk_toggled(button_pressed):
if(button_pressed):
DiscordRPC.unclear()
else:
DiscordRPC.clear(false)

func _on_print_friends_pressed():
print(DiscordRPC.get_all_relationships())
"
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_8abo6"]
[sub_resource type="Animation" id="Animation_mmtmn"]
length = 0.001
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath(".:scale")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0.4),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [Vector2(0.5, 0.5)]
}
[sub_resource type="Animation" id="Animation_5u02v"]
resource_name = "pulsate"
loop_mode = 1
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath(".:scale")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 0.5, 1),
"transitions": PackedFloat32Array(1, 1, 1),
"update": 0,
"values": [Vector2(0.5, 0.5), Vector2(0.8, 0.8), Vector2(0.5, 0.5)]
}
[sub_resource type="AnimationLibrary" id="AnimationLibrary_a7ofc"]
_data = {
"RESET": SubResource("Animation_mmtmn"),
"pulsate": SubResource("Animation_5u02v")
}
[node name="DebugNodeGroup" type="Node"]
editor_description = "This is a Debug Node wich will show (only if the project runs) some usefull info and buttons/input"
script = SubResource("GDScript_ak1tp")
[node name="Panel" type="Panel" parent="."]
anchors_preset = -1
anchor_right = 0.373
anchor_bottom = 1.0
offset_left = -5.0
offset_right = 0.303955
grow_horizontal = 2
grow_vertical = 2
[node name="Info" type="RichTextLabel" parent="Panel"]
layout_mode = 0
offset_left = 12.0
offset_top = 21.0
offset_right = 429.0
offset_bottom = 461.0
theme_override_font_sizes/normal_font_size = 14
text = "Application ID : {id}
Details: {details}
State: {state}

Large image key: {lkey}
Large image text: {ltext}
Small image key: {skey}
Small image text: {stext}

Start timestamp: {stimestamp}
End timestamp: {etimestamp}

Party ID: {partyid}
Current party size: {cpartysize}
Max party size: {mpartysize}
Match secret: {msecret}
Join secret: {jsecret}
Spectate secret: {ssecret}
Is party public: {ppublic} (needs to be activated in Discord client settings)

Is instanced: {instanced}
"
fit_content = true
[node name="PrintCurrentUserOnConsole" type="Button" parent="Panel"]
layout_mode = 1
anchors_preset = 4
anchor_top = 0.5
anchor_bottom = 0.5
offset_left = 12.0
offset_top = 138.375
offset_right = 245.0
offset_bottom = 171.375
grow_vertical = 2
text = "Print current user on console"
[node name="PrintFriends" type="Button" parent="Panel"]
layout_mode = 1
anchors_preset = 4
anchor_top = 0.5
anchor_bottom = 0.5
offset_left = 12.0
offset_top = 176.5
offset_right = 204.0
offset_bottom = 207.5
grow_vertical = 2
text = "Print friends on console"
[node name="AcceptJoinRequest" type="Button" parent="Panel"]
layout_mode = 1
anchors_preset = 4
anchor_top = 0.5
anchor_bottom = 0.5
offset_left = 12.0
offset_top = 212.875
offset_right = 154.0
offset_bottom = 243.875
grow_vertical = 2
text = "ACCEPT REQUEST"
[node name="InviteWithUserID" type="LineEdit" parent="Panel"]
layout_mode = 1
anchors_preset = 4
anchor_top = 0.5
anchor_bottom = 0.5
offset_left = 11.0
offset_top = 250.375
offset_right = 210.0
offset_bottom = 281.375
grow_vertical = 2
size_flags_horizontal = 0
placeholder_text = "Invite with user_id here"
[node name="AcceptWithUserID" type="LineEdit" parent="Panel"]
layout_mode = 1
anchors_preset = 4
anchor_top = 0.5
anchor_bottom = 0.5
offset_left = 11.0
offset_top = 286.875
offset_right = 260.0
offset_bottom = 317.875
grow_vertical = 2
placeholder_text = "Accept Invite with user_id here"
[node name="ToggleSDK" type="CheckButton" parent="Panel"]
layout_mode = 1
anchors_preset = 4
anchor_top = 0.5
anchor_bottom = 0.5
offset_left = 298.0
offset_top = 157.375
offset_right = 1144.0
offset_bottom = 665.375
grow_vertical = 2
scale = Vector2(0.05, 0.05)
theme_override_icons/checked = ExtResource("2_q6tao")
theme_override_icons/unchecked = ExtResource("3_5cyem")
theme_override_styles/focus = SubResource("StyleBoxEmpty_8abo6")
button_pressed = true
[node name="TextureRect" type="TextureRect" parent="Panel"]
self_modulate = Color(0.47451, 0.47451, 0.47451, 1)
layout_mode = 1
anchors_preset = -1
anchor_left = 0.88
anchor_top = 0.762
anchor_right = 0.88
anchor_bottom = 0.762
offset_left = -28.8
offset_top = -28.776
offset_right = 28.0841
offset_bottom = 28.1082
grow_horizontal = 2
grow_vertical = 2
scale = Vector2(0.5, 0.5)
pivot_offset = Vector2(29.0693, 29.0693)
texture = ExtResource("3_goflf")
[node name="AnimationPlayer" type="AnimationPlayer" parent="Panel/TextureRect"]
libraries = {
"": SubResource("AnimationLibrary_a7ofc")
}
[connection signal="pressed" from="Panel/PrintCurrentUserOnConsole" to="." method="_on_print_current_user_on_console_pressed"]
[connection signal="pressed" from="Panel/PrintFriends" to="." method="_on_print_friends_pressed"]
[connection signal="pressed" from="Panel/AcceptJoinRequest" to="." method="_on_accept_join_request_pressed"]
[connection signal="text_submitted" from="Panel/InviteWithUserID" to="." method="_on_invite_with_user_id_text_submitted"]
[connection signal="text_submitted" from="Panel/AcceptWithUserID" to="." method="_on_accept_with_user_id_text_submitted"]
[connection signal="toggled" from="Panel/ToggleSDK" to="." method="_on_toggle_sdk_toggled"]
18 changes: 18 additions & 0 deletions addons/discord-rpc-gd/nodes/assets/Checked.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 3c5f609

Please sign in to comment.