started making editor presence with gdextension instead of gdscript
This commit is contained in:
Binary file not shown.
@@ -1,22 +1,21 @@
|
|||||||
## This is a GDscript Node wich gets automatically added as Autoload while installing the addon.
|
## 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.
|
## 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]DiscordSDK.run_callbacks()[/code] in a [code]_process[/code] function.
|
## You don't need to use it. 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
|
## @tutorial: https://github.com/vaporvee/discord-sdk-godot/wiki
|
||||||
@tool
|
|
||||||
extends Node
|
extends Node
|
||||||
|
|
||||||
func _process(_delta) -> void:
|
func _process(_delta) -> void:
|
||||||
if GDExtensionManager.get_loaded_extensions().has("res://addons/discord-sdk-gd/bin/discord-rpc-gd.gdextension"):
|
#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 EditorInterface.get_editor_settings().get_setting("DiscordSDK/EditorPresence/enabled") && Engine.is_editor_hint():
|
||||||
if DiscordSDK.app_id != 1108142249990176808:
|
#if DiscordSDK.app_id != 1108142249990176808:
|
||||||
DiscordSDK.app_id = 1108142249990176808
|
#DiscordSDK.app_id = 1108142249990176808
|
||||||
DiscordSDK.details = ProjectSettings.get_setting("application/config/name")
|
#DiscordSDK.details = ProjectSettings.get_setting("application/config/name")
|
||||||
DiscordSDK.state = "Editing: \""+ str(get_tree().edited_scene_root.scene_file_path).replace("res://","") +"\""
|
#DiscordSDK.state = "Editing: \""+ str(get_tree().edited_scene_root.scene_file_path).replace("res://","") +"\""
|
||||||
DiscordSDK.large_image = "godot"
|
#DiscordSDK.large_image = "godot"
|
||||||
DiscordSDK.large_image_text = str(Engine.get_version_info().string)
|
#DiscordSDK.large_image_text = str(Engine.get_version_info().string)
|
||||||
DiscordSDK.start_timestamp = int(Time.get_unix_time_from_system())
|
#DiscordSDK.start_timestamp = int(Time.get_unix_time_from_system())
|
||||||
DiscordSDK.refresh()
|
#DiscordSDK.refresh()
|
||||||
if DiscordSDK.app_id == 1108142249990176808 || !Engine.is_editor_hint():
|
#if DiscordSDK.app_id == 1108142249990176808 || !Engine.is_editor_hint():
|
||||||
DiscordSDK.run_callbacks()
|
DiscordSDK.run_callbacks()
|
||||||
|
@@ -8,9 +8,7 @@ var restart_window: ConfirmationDialog = preload("res://addons/discord-sdk-gd/re
|
|||||||
|
|
||||||
func _enter_tree() -> void:
|
func _enter_tree() -> void:
|
||||||
add_custom_type("DiscordSDKDebug","Node",DiscordSDKDebug,DiscordSDKDebug_icon)
|
add_custom_type("DiscordSDKDebug","Node",DiscordSDKDebug,DiscordSDKDebug_icon)
|
||||||
ProjectSettings.set_setting("DiscordSDK/EditorPresence/enabled",false)
|
EditorInterface.get_editor_settings().set_setting("DiscordSDK/EditorPresence/enabled",false)
|
||||||
ProjectSettings.set_as_basic("DiscordSDK/EditorPresence/enabled",true)
|
|
||||||
ProjectSettings.set_initial_value("DiscordSDK/EditorPresence/enabled",false)
|
|
||||||
|
|
||||||
func _enable_plugin() -> void:
|
func _enable_plugin() -> void:
|
||||||
if FileAccess.file_exists(ProjectSettings.globalize_path("res://") + "addons/discord-sdk-gd/bin/.gdignore"):
|
if FileAccess.file_exists(ProjectSettings.globalize_path("res://") + "addons/discord-sdk-gd/bin/.gdignore"):
|
||||||
@@ -25,7 +23,7 @@ func _disable_plugin() -> void:
|
|||||||
remove_autoload_singleton("DiscordSDKLoader")
|
remove_autoload_singleton("DiscordSDKLoader")
|
||||||
FileAccess.open("res://addons/discord-sdk-gd/bin/.gdignore",FileAccess.WRITE)
|
FileAccess.open("res://addons/discord-sdk-gd/bin/.gdignore",FileAccess.WRITE)
|
||||||
remove_custom_type("DiscordSDKDebug")
|
remove_custom_type("DiscordSDKDebug")
|
||||||
ProjectSettings.clear("DiscordSDK/EditorPresence/enabled")
|
EditorInterface.get_editor_settings().erase("DiscordSDK/EditorPresence/enabled")
|
||||||
push_warning("Please restart the editor to fully disable the DiscordSDK plugin")
|
push_warning("Please restart the editor to fully disable the DiscordSDK plugin")
|
||||||
|
|
||||||
func save_and_restart() -> void:
|
func save_and_restart() -> void:
|
||||||
|
60
src/editor_presence.cpp
Normal file
60
src/editor_presence.cpp
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
#include "editor_presence.h"
|
||||||
|
#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()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
EditorPresence::EditorPresence()
|
||||||
|
{
|
||||||
|
singleton = this;
|
||||||
|
}
|
||||||
|
EditorPresence::~EditorPresence()
|
||||||
|
{
|
||||||
|
singleton = nullptr;
|
||||||
|
}
|
||||||
|
EditorPresence *EditorPresence::get_singleton()
|
||||||
|
{
|
||||||
|
return singleton;
|
||||||
|
}
|
||||||
|
|
||||||
|
void EditorPresence::_ready()
|
||||||
|
{
|
||||||
|
result = discord::Core::Create(1108142249990176808, DiscordCreateFlags_NoRequireDiscord, &core);
|
||||||
|
activity.SetState("Test from Godot!");
|
||||||
|
activity.SetDetails("I worked months on this");
|
||||||
|
if (project_settings->has_setting("application/config/name"))
|
||||||
|
{
|
||||||
|
activity.GetAssets().SetLargeImage(String(project_settings->get_setting("application/config/name")).utf8());
|
||||||
|
}
|
||||||
|
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 (result == discord::Result::Ok)
|
||||||
|
::core->RunCallbacks();
|
||||||
|
}
|
30
src/editor_presence.h
Normal file
30
src/editor_presence.h
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
#ifndef DISCORDGODOT_H
|
||||||
|
#define DISCORDGODOT_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>
|
||||||
|
|
||||||
|
using namespace godot;
|
||||||
|
|
||||||
|
class EditorPresence : public Node
|
||||||
|
{
|
||||||
|
GDCLASS(EditorPresence, Node);
|
||||||
|
|
||||||
|
static EditorPresence *singleton;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
static void _bind_methods();
|
||||||
|
|
||||||
|
public:
|
||||||
|
static EditorPresence *
|
||||||
|
get_singleton();
|
||||||
|
|
||||||
|
EditorPresence();
|
||||||
|
~EditorPresence();
|
||||||
|
void _ready() override;
|
||||||
|
void _process(double delta) override;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
Reference in New Issue
Block a user