added the user singleton
This commit is contained in:
5
.vscode/settings.json
vendored
5
.vscode/settings.json
vendored
@@ -3,5 +3,8 @@
|
||||
"godot-cpp/include",
|
||||
"godot-cpp/gen/include",
|
||||
"godot-cpp/gdextension",
|
||||
]
|
||||
],
|
||||
"files.associations": {
|
||||
"xlocbuf": "cpp"
|
||||
}
|
||||
}
|
Binary file not shown.
Binary file not shown.
@@ -15,4 +15,6 @@ func _ready():
|
||||
|
||||
Discord_Activity.refresh()
|
||||
|
||||
print(Discord_User.get_name())
|
||||
|
||||
$Info.text = $Info.text.replace("{isdiscordworking}",str(Discord_Activity.get_is_discord_working())).replace("{id}",str(Discord_Activity.app_id)).replace("{details}",Discord_Activity.details).replace("{state}",Discord_Activity.state).replace("{lkey}",Discord_Activity.large_image).replace("{ltext}",Discord_Activity.large_image_text).replace("{skey}",Discord_Activity.small_image).replace("{stext}",Discord_Activity.small_image_text).replace("{stimestamp}",str(Discord_Activity.start_timestamp)).replace("{etimestamp}",str(Discord_Activity.end_timestamp))
|
||||
|
@@ -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