added the user singleton
This commit is contained in:
@@ -7,17 +7,22 @@
|
||||
#include <godot_cpp/godot.hpp>
|
||||
|
||||
#include "activity.h"
|
||||
#include "user.h"
|
||||
using namespace godot;
|
||||
|
||||
static Discord_Activity *discordactivity;
|
||||
static Discord_User *discorduser;
|
||||
|
||||
void gdextension_initialize(ModuleInitializationLevel p_level)
|
||||
{
|
||||
if (p_level == MODULE_INITIALIZATION_LEVEL_SCENE)
|
||||
{
|
||||
ClassDB::register_class<Discord_Activity>();
|
||||
ClassDB::register_class<Discord_User>();
|
||||
discordactivity = memnew(Discord_Activity);
|
||||
discorduser = memnew(Discord_User);
|
||||
Engine::get_singleton()->register_singleton("Discord_Activity", Discord_Activity::get_singleton());
|
||||
Engine::get_singleton()->register_singleton("Discord_User", Discord_User::get_singleton());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +31,9 @@ void gdextension_terminate(ModuleInitializationLevel p_level)
|
||||
if (p_level == MODULE_INITIALIZATION_LEVEL_SCENE)
|
||||
{
|
||||
Engine::get_singleton()->unregister_singleton("Discord_Activity");
|
||||
Engine::get_singleton()->unregister_singleton("Discord_User");
|
||||
memdelete(discordactivity);
|
||||
memdelete(discorduser);
|
||||
}
|
||||
}
|
||||
|
||||
|
39
src/user.cpp
Normal file
39
src/user.cpp
Normal file
@@ -0,0 +1,39 @@
|
||||
#include "user.h"
|
||||
#include <string>
|
||||
#include "./discord-game-sdk-cpp/discord.h"
|
||||
#include <godot_cpp/core/class_db.hpp>
|
||||
#include <godot_cpp/classes/editor_plugin.hpp>
|
||||
#include <godot_cpp/variant/utility_functions.hpp>
|
||||
#include <godot_cpp/classes/time.hpp>
|
||||
|
||||
using namespace godot;
|
||||
|
||||
Discord_User *Discord_User::singleton = nullptr;
|
||||
|
||||
void Discord_User::_bind_methods()
|
||||
{
|
||||
ClassDB::bind_method(D_METHOD("get_name"), &Discord_User::get_name);
|
||||
}
|
||||
|
||||
Discord_User *Discord_User::get_singleton()
|
||||
{
|
||||
return singleton;
|
||||
}
|
||||
|
||||
Discord_User::Discord_User()
|
||||
{
|
||||
ERR_FAIL_COND(singleton != nullptr);
|
||||
singleton = this;
|
||||
}
|
||||
|
||||
Discord_User::~Discord_User()
|
||||
{
|
||||
ERR_FAIL_COND(singleton != this);
|
||||
singleton = nullptr;
|
||||
}
|
||||
|
||||
String Discord_User::get_name() const
|
||||
{
|
||||
discord::User user;
|
||||
return user.GetUsername();
|
||||
}
|
28
src/user.h
Normal file
28
src/user.h
Normal file
@@ -0,0 +1,28 @@
|
||||
#ifndef USER_H
|
||||
#define USER_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <godot_cpp/classes/object.hpp>
|
||||
#include <godot_cpp/core/class_db.hpp>
|
||||
|
||||
using namespace godot;
|
||||
|
||||
class Discord_User : public Object
|
||||
{
|
||||
GDCLASS(Discord_User, Object);
|
||||
|
||||
static Discord_User *singleton;
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
static Discord_User *get_singleton();
|
||||
|
||||
Discord_User();
|
||||
~Discord_User();
|
||||
|
||||
String get_name() const;
|
||||
};
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user