finished custom EditorPresence GDExtension class

This commit is contained in:
2023-12-18 19:27:08 +01:00
parent ea829e8603
commit 3f58da00ad
9 changed files with 57 additions and 41 deletions

View File

@@ -6,16 +6,8 @@
## @tutorial: https://github.com/vaporvee/discord-sdk-godot/wiki
extends Node
func _ready() -> void:
pass
func _process(_delta) -> void:
#if GDExtensionManager.get_loaded_extensions().has("res://addons/discord-sdk-gd/bin/discord-rpc-gd.gdextension"):
#if EditorInterface.get_editor_settings().get_setting("DiscordSDK/EditorPresence/enabled") && Engine.is_editor_hint():
#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()

View File

@@ -8,9 +8,14 @@ var restart_window: ConfirmationDialog = preload("res://addons/discord-sdk-gd/re
func _enter_tree() -> void:
add_custom_type("DiscordSDKDebug","Node",DiscordSDKDebug,DiscordSDKDebug_icon)
EditorInterface.get_editor_settings().set_setting("DiscordSDK/EditorPresence/enabled",false)
EditorInterface.get_editor_settings().settings_changed.connect(_on_editor_settings_changed)
func _ready() -> void:
await RenderingServer.frame_post_draw
_on_editor_settings_changed()
func _enable_plugin() -> void:
EditorInterface.get_editor_settings().set_setting("DiscordSDK/EditorPresence/enabled",false)
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")
add_autoload_singleton("DiscordSDKLoader","res://addons/discord-sdk-gd/nodes/discord_autoload.gd")
@@ -32,3 +37,12 @@ func save_and_restart() -> void:
func save_no_restart() -> void:
EditorInterface.restart_editor(false)
var editor_presence
func _on_editor_settings_changed() -> void:
if ClassDB.class_exists("EditorPresence") && editor_presence == null:
editor_presence = ClassDB.instantiate("EditorPresence")
if EditorInterface.get_editor_settings().has_setting("DiscordSDK/EditorPresence/enabled") && EditorInterface.get_editor_settings().get_setting("DiscordSDK/EditorPresence/enabled"):
add_child(editor_presence)
else:
remove_child(editor_presence)

View File

@@ -9,7 +9,7 @@ Button/styles/focus = SubResource("StyleBoxEmpty_1t7mm")
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_5vqdt"]
[sub_resource type="Image" id="Image_6icdx"]
[sub_resource type="Image" id="Image_hgiu4"]
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",
@@ -19,7 +19,7 @@ data = {
}
[sub_resource type="ImageTexture" id="ImageTexture_gdtpn"]
image = SubResource("Image_6icdx")
image = SubResource("Image_hgiu4")
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_7v0rg"]
@@ -38,9 +38,9 @@ cancel_button_text = "Save and restart"
anchors_preset = 5
anchor_left = 0.5
anchor_right = 0.5
offset_left = -207.0
offset_left = 8.0
offset_top = 8.0
offset_right = 207.0
offset_right = 422.0
offset_bottom = 451.0
grow_horizontal = 2
mouse_filter = 1
@@ -102,10 +102,11 @@ theme_override_font_sizes/normal_font_size = 16
theme_override_styles/normal = SubResource("StyleBoxEmpty_7v0rg")
bbcode_enabled = true
text = "[center]Thanks for enabling the
[rainbow][b]Discord Game SDK Plugin[/b][/rainbow]
[rainbow]Discord Game SDK Plugin[/rainbow]
made by vaporvee. ❤️
You need to [wave][b]restart[/b][/wave] the editor to fully enable this plugin!
Do you want to [wave][b]save[/b][/wave] your project before restarting?
(Error messages after the first restart are normal. Please ignore them)"
You need to [wave]restart[/wave] the editor to fully enable this plugin!
Do you want to [wave]save[/wave] your project before restarting?
Error messages after the first two restarts are normal. Please ignore them!"

View File

@@ -2,20 +2,9 @@
#include "lib/discord_game_sdk/cpp/discord.h"
#include <godot_cpp/core/class_db.hpp>
#include <godot_cpp/variant/utility_functions.hpp>
#include <godot_cpp/classes/project_settings.hpp>
#include <godot_cpp/classes/engine.hpp>
#include <godot_cpp/classes/time.hpp>
Ref<ProjectSettings> project_settings = ProjectSettings::get_singleton();
Ref<Engine> engine = Engine::get_singleton();
Ref<Time> time = Time::get_singleton();
EditorPresence *EditorPresence::singleton = nullptr;
discord::Core *core{};
discord::Result result;
discord::Activity activity{};
void EditorPresence::_bind_methods()
{
}
@@ -35,26 +24,29 @@ EditorPresence *EditorPresence::get_singleton()
void EditorPresence::_ready()
{
result = discord::Core::Create(1108142249990176808, DiscordCreateFlags_NoRequireDiscord, &core);
activity.SetState("Test from Godot!");
activity.SetDetails("I worked months on this");
activity.SetState("Editing a project...");
activity.SetDetails(String(project_settings->get_setting("application/config/name")).utf8());
if (project_settings->has_setting("application/config/name"))
{
activity.GetAssets().SetLargeImage(String(project_settings->get_setting("application/config/name")).utf8());
activity.GetAssets().SetLargeImage("godot");
}
activity.GetAssets().SetLargeText(String(engine->get_version_info()["string"]).utf8());
activity.GetTimestamps().SetStart(time->get_unix_time_from_system());
if (result == discord::Result::Ok)
{
core->ActivityManager().UpdateActivity(activity, [](discord::Result result) {});
}
else
{
UtilityFunctions::push_warning("EditorPresence couldn't be loaded! Maybe your Discord isn't running?");
}
}
void EditorPresence::_process(double delta)
{
if (state_string.utf8() != activity.GetState())
{
godot::Node *edited_scene_root = editor_interface->get_edited_scene_root();
activity.SetState(String("Editing: \"" + edited_scene_root->get_scene_file_path() + "\"").replace("res://", "").utf8());
if (result == discord::Result::Ok)
::core->RunCallbacks();
core->ActivityManager().UpdateActivity(activity, [](discord::Result result) {});
}
if (result == discord::Result::Ok)
core->RunCallbacks();
}

View File

@@ -1,10 +1,14 @@
#ifndef DISCORDGODOT_H
#define DISCORDGODOT_H
#ifndef EDITOR_PRESENCE_H
#define EDITOR_PRESENCE_H
#include <stdio.h>
#include "lib/discord_game_sdk/cpp/discord.h"
#include <godot_cpp/classes/node.hpp>
#include <godot_cpp/core/class_db.hpp>
#include <godot_cpp/classes/project_settings.hpp>
#include <godot_cpp/classes/engine.hpp>
#include <godot_cpp/classes/time.hpp>
#include <godot_cpp/classes/editor_interface.hpp>
using namespace godot;
@@ -21,6 +25,17 @@ public:
static EditorPresence *
get_singleton();
godot::Engine *engine = godot::Engine::get_singleton();
godot::ProjectSettings *project_settings = godot::ProjectSettings::get_singleton();
godot::Time *time = godot::Time::get_singleton();
godot::EditorInterface *editor_interface = godot::EditorInterface::get_singleton();
discord::Core *core{};
discord::Result result;
discord::Activity activity{};
String state_string;
EditorPresence();
~EditorPresence();
void _ready() override;

View File

@@ -7,6 +7,7 @@
#include <godot_cpp/godot.hpp>
#include "discordgodot.h"
#include "editor_presence.h"
using namespace godot;
static DiscordSDK *discordsdk;
@@ -18,6 +19,7 @@ void initialize_discordsdk_module(ModuleInitializationLevel p_level)
ClassDB::register_class<DiscordSDK>();
discordsdk = memnew(DiscordSDK);
Engine::get_singleton()->register_singleton("DiscordSDK", DiscordSDK::get_singleton());
ClassDB::register_class<EditorPresence>();
}
}