finished custom EditorPresence GDExtension class
This commit is contained in:
@@ -2,20 +2,9 @@
|
||||
#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()
|
||||
{
|
||||
}
|
||||
@@ -35,26 +24,29 @@ EditorPresence *EditorPresence::get_singleton()
|
||||
void EditorPresence::_ready()
|
||||
{
|
||||
result = discord::Core::Create(1108142249990176808, DiscordCreateFlags_NoRequireDiscord, &core);
|
||||
activity.SetState("Test from Godot!");
|
||||
activity.SetDetails("I worked months on this");
|
||||
activity.SetState("Editing a project...");
|
||||
activity.SetDetails(String(project_settings->get_setting("application/config/name")).utf8());
|
||||
if (project_settings->has_setting("application/config/name"))
|
||||
{
|
||||
activity.GetAssets().SetLargeImage(String(project_settings->get_setting("application/config/name")).utf8());
|
||||
activity.GetAssets().SetLargeImage("godot");
|
||||
}
|
||||
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 (state_string.utf8() != activity.GetState())
|
||||
{
|
||||
godot::Node *edited_scene_root = editor_interface->get_edited_scene_root();
|
||||
activity.SetState(String("Editing: \"" + edited_scene_root->get_scene_file_path() + "\"").replace("res://", "").utf8());
|
||||
if (result == discord::Result::Ok)
|
||||
core->ActivityManager().UpdateActivity(activity, [](discord::Result result) {});
|
||||
}
|
||||
if (result == discord::Result::Ok)
|
||||
::core->RunCallbacks();
|
||||
core->RunCallbacks();
|
||||
}
|
@@ -1,10 +1,14 @@
|
||||
#ifndef DISCORDGODOT_H
|
||||
#define DISCORDGODOT_H
|
||||
#ifndef EDITOR_PRESENCE_H
|
||||
#define EDITOR_PRESENCE_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>
|
||||
#include <godot_cpp/classes/project_settings.hpp>
|
||||
#include <godot_cpp/classes/engine.hpp>
|
||||
#include <godot_cpp/classes/time.hpp>
|
||||
#include <godot_cpp/classes/editor_interface.hpp>
|
||||
|
||||
using namespace godot;
|
||||
|
||||
@@ -21,6 +25,17 @@ public:
|
||||
static EditorPresence *
|
||||
get_singleton();
|
||||
|
||||
godot::Engine *engine = godot::Engine::get_singleton();
|
||||
godot::ProjectSettings *project_settings = godot::ProjectSettings::get_singleton();
|
||||
godot::Time *time = godot::Time::get_singleton();
|
||||
godot::EditorInterface *editor_interface = godot::EditorInterface::get_singleton();
|
||||
|
||||
discord::Core *core{};
|
||||
discord::Result result;
|
||||
discord::Activity activity{};
|
||||
|
||||
String state_string;
|
||||
|
||||
EditorPresence();
|
||||
~EditorPresence();
|
||||
void _ready() override;
|
||||
|
@@ -7,6 +7,7 @@
|
||||
#include <godot_cpp/godot.hpp>
|
||||
|
||||
#include "discordgodot.h"
|
||||
#include "editor_presence.h"
|
||||
using namespace godot;
|
||||
|
||||
static DiscordSDK *discordsdk;
|
||||
@@ -18,6 +19,7 @@ void initialize_discordsdk_module(ModuleInitializationLevel p_level)
|
||||
ClassDB::register_class<DiscordSDK>();
|
||||
discordsdk = memnew(DiscordSDK);
|
||||
Engine::get_singleton()->register_singleton("DiscordSDK", DiscordSDK::get_singleton());
|
||||
ClassDB::register_class<EditorPresence>();
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user