should work but it doesn't whatever
This commit is contained in:
Binary file not shown.
6
project/main.gd
Normal file
6
project/main.gd
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
extends Node
|
||||||
|
|
||||||
|
|
||||||
|
# Called when the node enters the scene tree for the first time.
|
||||||
|
func _ready():
|
||||||
|
DiscordSDK.debug()
|
@@ -1,10 +1,6 @@
|
|||||||
[gd_scene format=3 uid="uid://dmx2xuigcpvt4"]
|
[gd_scene load_steps=2 format=3 uid="uid://dmx2xuigcpvt4"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" path="res://main.gd" id="1_kl8ri"]
|
||||||
|
|
||||||
[node name="Node" type="Node"]
|
[node name="Node" type="Node"]
|
||||||
|
script = ExtResource("1_kl8ri")
|
||||||
[node name="Button" type="Button" parent="."]
|
|
||||||
offset_right = 79.0
|
|
||||||
offset_bottom = 29.0
|
|
||||||
text = "Click me!"
|
|
||||||
|
|
||||||
[node name="DiscordRPC" type="DiscordRPC" parent="."]
|
|
||||||
|
27
src/main.cpp
27
src/main.cpp
@@ -1,27 +1,36 @@
|
|||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
#include "./discord-game-sdk-cpp/discord.h"
|
||||||
#include <godot_cpp/core/class_db.hpp>
|
#include <godot_cpp/core/class_db.hpp>
|
||||||
#include <godot_cpp/variant/utility_functions.hpp>
|
#include <godot_cpp/variant/utility_functions.hpp>
|
||||||
#include "discord-game-sdk-cpp/discord.h"
|
|
||||||
|
|
||||||
using namespace godot;
|
using namespace godot;
|
||||||
|
|
||||||
|
DiscordSDK *DiscordSDK::singleton = nullptr;
|
||||||
discord::Core *core{};
|
discord::Core *core{};
|
||||||
|
|
||||||
void DiscordRPC::_bind_methods()
|
void DiscordSDK::_bind_methods()
|
||||||
{
|
{
|
||||||
|
ClassDB::bind_method(D_METHOD("debug"), &DiscordSDK::debug);
|
||||||
}
|
}
|
||||||
|
|
||||||
DiscordRPC::DiscordRPC()
|
DiscordSDK *DiscordSDK::get_singleton()
|
||||||
{
|
{
|
||||||
// initialize any variables here
|
return singleton;
|
||||||
}
|
}
|
||||||
|
|
||||||
DiscordRPC::~DiscordRPC()
|
DiscordSDK::DiscordSDK()
|
||||||
{
|
{
|
||||||
// add your cleanup here
|
ERR_FAIL_COND(singleton != nullptr);
|
||||||
|
singleton = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiscordRPC::_ready()
|
DiscordSDK::~DiscordSDK()
|
||||||
|
{
|
||||||
|
ERR_FAIL_COND(singleton != this);
|
||||||
|
singleton = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiscordSDK::debug()
|
||||||
{
|
{
|
||||||
auto result = discord::Core::Create(1080224638845591692, DiscordCreateFlags_Default, &core);
|
auto result = discord::Core::Create(1080224638845591692, DiscordCreateFlags_Default, &core);
|
||||||
discord::Activity activity{};
|
discord::Activity activity{};
|
||||||
@@ -31,9 +40,5 @@ void DiscordRPC::_ready()
|
|||||||
assets.SetLargeImage("test1");
|
assets.SetLargeImage("test1");
|
||||||
assets.SetSmallImage("godot");
|
assets.SetSmallImage("godot");
|
||||||
core->ActivityManager().UpdateActivity(activity, [](discord::Result result) {});
|
core->ActivityManager().UpdateActivity(activity, [](discord::Result result) {});
|
||||||
}
|
|
||||||
|
|
||||||
void DiscordRPC::_process(float delta)
|
|
||||||
{
|
|
||||||
::core->RunCallbacks();
|
::core->RunCallbacks();
|
||||||
}
|
}
|
28
src/main.h
28
src/main.h
@@ -1,27 +1,27 @@
|
|||||||
#ifndef DISCORDRPC_H
|
#ifndef MAIN_H
|
||||||
#define DISCORDRPC_H
|
#define MAIN_H
|
||||||
|
|
||||||
#include <godot_cpp/classes/node.hpp>
|
#include <godot_cpp/classes/object.hpp>
|
||||||
|
#include <godot_cpp/core/class_db.hpp>
|
||||||
|
|
||||||
namespace godot
|
using namespace godot;
|
||||||
|
|
||||||
|
class DiscordSDK : public Object
|
||||||
{
|
{
|
||||||
class DiscordRPC : public Node
|
GDCLASS(DiscordSDK, Object);
|
||||||
{
|
|
||||||
GDCLASS(DiscordRPC, Node)
|
|
||||||
|
|
||||||
private:
|
static DiscordSDK *singleton;
|
||||||
float time_passed;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DiscordRPC();
|
static DiscordSDK *get_singleton();
|
||||||
~DiscordRPC();
|
|
||||||
|
|
||||||
void _ready();
|
DiscordSDK();
|
||||||
void _process(float delta);
|
~DiscordSDK();
|
||||||
|
|
||||||
|
void debug();
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
@@ -1,35 +1,44 @@
|
|||||||
#include "register_types.h"
|
#include "register_types.h"
|
||||||
|
|
||||||
#include "main.h"
|
|
||||||
|
|
||||||
#include <gdextension_interface.h>
|
#include <gdextension_interface.h>
|
||||||
#include <godot_cpp/core/defs.hpp>
|
|
||||||
#include <godot_cpp/core/class_db.hpp>
|
#include <godot_cpp/core/class_db.hpp>
|
||||||
|
#include <godot_cpp/core/defs.hpp>
|
||||||
|
#include <godot_cpp/classes/engine.hpp>
|
||||||
#include <godot_cpp/godot.hpp>
|
#include <godot_cpp/godot.hpp>
|
||||||
|
|
||||||
|
#include "main.h"
|
||||||
using namespace godot;
|
using namespace godot;
|
||||||
|
|
||||||
void initialize_discordrpc_module(ModuleInitializationLevel p_level) {
|
static DiscordSDK *discordsdk;
|
||||||
if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ClassDB::register_class<DiscordRPC>();
|
void gdextension_initialize(ModuleInitializationLevel p_level)
|
||||||
}
|
{
|
||||||
|
if (p_level == MODULE_INITIALIZATION_LEVEL_SCENE)
|
||||||
|
{
|
||||||
|
ClassDB::register_class<DiscordSDK>();
|
||||||
|
|
||||||
void uninitialize_discordrpc_module(ModuleInitializationLevel p_level) {
|
discordsdk = memnew(DiscordSDK);
|
||||||
if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) {
|
Engine::get_singleton()->register_singleton("DiscordSDK", DiscordSDK::get_singleton());
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" {
|
void gdextension_terminate(ModuleInitializationLevel p_level)
|
||||||
// Initialization.
|
{
|
||||||
GDExtensionBool GDE_EXPORT discordrpcgd_library_init(const GDExtensionInterface *p_interface, const GDExtensionClassLibraryPtr p_library, GDExtensionInitialization *r_initialization) {
|
if (p_level == MODULE_INITIALIZATION_LEVEL_SCENE)
|
||||||
|
{
|
||||||
|
Engine::get_singleton()->unregister_singleton("DiscordSDK");
|
||||||
|
memdelete(discordsdk);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
GDExtensionBool GDE_EXPORT discordrpcgd_library_init(const GDExtensionInterface *p_interface, GDExtensionClassLibraryPtr p_library, GDExtensionInitialization *r_initialization)
|
||||||
|
{
|
||||||
godot::GDExtensionBinding::InitObject init_obj(p_interface, p_library, r_initialization);
|
godot::GDExtensionBinding::InitObject init_obj(p_interface, p_library, r_initialization);
|
||||||
|
|
||||||
init_obj.register_initializer(initialize_discordrpc_module);
|
init_obj.register_initializer(gdextension_initialize);
|
||||||
init_obj.register_terminator(uninitialize_discordrpc_module);
|
init_obj.register_terminator(gdextension_terminate);
|
||||||
init_obj.set_minimum_library_initialization_level(MODULE_INITIALIZATION_LEVEL_SCENE);
|
init_obj.set_minimum_library_initialization_level(MODULE_INITIALIZATION_LEVEL_SCENE);
|
||||||
|
|
||||||
return init_obj.init();
|
return init_obj.init();
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
#ifndef DISCORDRPC_REGISTER_TYPES_H
|
#ifndef REGISTER_TYPES_H
|
||||||
#define DISCORDRPC_REGISTER_TYPES_H
|
#define REGISTER_TYPES_H
|
||||||
|
|
||||||
void initialize_discordrpc_module();
|
void initialize_discordrpc_module();
|
||||||
void uninitialize_discordrpc_module();
|
void uninitialize_discordrpc_module();
|
||||||
|
|
||||||
#endif // DISCORDRPC_REGISTER_TYPES_H
|
#endif // REGISTER_TYPES_H
|
Reference in New Issue
Block a user