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="Button" type="Button" parent="."]
|
||||
offset_right = 79.0
|
||||
offset_bottom = 29.0
|
||||
text = "Click me!"
|
||||
|
||||
[node name="DiscordRPC" type="DiscordRPC" parent="."]
|
||||
script = ExtResource("1_kl8ri")
|
||||
|
27
src/main.cpp
27
src/main.cpp
@@ -1,27 +1,36 @@
|
||||
#include "main.h"
|
||||
#include "./discord-game-sdk-cpp/discord.h"
|
||||
#include <godot_cpp/core/class_db.hpp>
|
||||
#include <godot_cpp/variant/utility_functions.hpp>
|
||||
#include "discord-game-sdk-cpp/discord.h"
|
||||
|
||||
using namespace godot;
|
||||
|
||||
DiscordSDK *DiscordSDK::singleton = nullptr;
|
||||
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);
|
||||
discord::Activity activity{};
|
||||
@@ -31,9 +40,5 @@ void DiscordRPC::_ready()
|
||||
assets.SetLargeImage("test1");
|
||||
assets.SetSmallImage("godot");
|
||||
core->ActivityManager().UpdateActivity(activity, [](discord::Result result) {});
|
||||
}
|
||||
|
||||
void DiscordRPC::_process(float delta)
|
||||
{
|
||||
::core->RunCallbacks();
|
||||
}
|
36
src/main.h
36
src/main.h
@@ -1,27 +1,27 @@
|
||||
#ifndef DISCORDRPC_H
|
||||
#define DISCORDRPC_H
|
||||
#ifndef MAIN_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(DiscordRPC, Node)
|
||||
GDCLASS(DiscordSDK, Object);
|
||||
|
||||
private:
|
||||
float time_passed;
|
||||
static DiscordSDK *singleton;
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
DiscordRPC();
|
||||
~DiscordRPC();
|
||||
public:
|
||||
static DiscordSDK *get_singleton();
|
||||
|
||||
void _ready();
|
||||
void _process(float delta);
|
||||
};
|
||||
}
|
||||
DiscordSDK();
|
||||
~DiscordSDK();
|
||||
|
||||
void debug();
|
||||
};
|
||||
|
||||
#endif
|
@@ -1,37 +1,46 @@
|
||||
#include "register_types.h"
|
||||
|
||||
#include "main.h"
|
||||
|
||||
#include <gdextension_interface.h>
|
||||
#include <godot_cpp/core/defs.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 "main.h"
|
||||
using namespace godot;
|
||||
|
||||
void initialize_discordrpc_module(ModuleInitializationLevel p_level) {
|
||||
if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) {
|
||||
return;
|
||||
}
|
||||
static DiscordSDK *discordsdk;
|
||||
|
||||
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) {
|
||||
if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) {
|
||||
return;
|
||||
discordsdk = memnew(DiscordSDK);
|
||||
Engine::get_singleton()->register_singleton("DiscordSDK", DiscordSDK::get_singleton());
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
// Initialization.
|
||||
GDExtensionBool GDE_EXPORT discordrpcgd_library_init(const GDExtensionInterface *p_interface, const GDExtensionClassLibraryPtr p_library, GDExtensionInitialization *r_initialization) {
|
||||
godot::GDExtensionBinding::InitObject init_obj(p_interface, p_library, r_initialization);
|
||||
|
||||
init_obj.register_initializer(initialize_discordrpc_module);
|
||||
init_obj.register_terminator(uninitialize_discordrpc_module);
|
||||
init_obj.set_minimum_library_initialization_level(MODULE_INITIALIZATION_LEVEL_SCENE);
|
||||
|
||||
return init_obj.init();
|
||||
void gdextension_terminate(ModuleInitializationLevel p_level)
|
||||
{
|
||||
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);
|
||||
|
||||
init_obj.register_initializer(gdextension_initialize);
|
||||
init_obj.register_terminator(gdextension_terminate);
|
||||
init_obj.set_minimum_library_initialization_level(MODULE_INITIALIZATION_LEVEL_SCENE);
|
||||
|
||||
return init_obj.init();
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,7 +1,7 @@
|
||||
#ifndef DISCORDRPC_REGISTER_TYPES_H
|
||||
#define DISCORDRPC_REGISTER_TYPES_H
|
||||
#ifndef REGISTER_TYPES_H
|
||||
#define REGISTER_TYPES_H
|
||||
|
||||
void initialize_discordrpc_module();
|
||||
void uninitialize_discordrpc_module();
|
||||
|
||||
#endif // DISCORDRPC_REGISTER_TYPES_H
|
||||
#endif // REGISTER_TYPES_H
|
Reference in New Issue
Block a user