change to a UObject
This commit is contained in:
parent
63b467f81d
commit
bd995f047d
3 changed files with 37 additions and 18 deletions
Binary file not shown.
|
@ -4,27 +4,41 @@
|
||||||
|
|
||||||
#include "discord-rpc.h"
|
#include "discord-rpc.h"
|
||||||
|
|
||||||
DEFINE_LOG_CATEGORY(DiscordLogCategory)
|
DEFINE_LOG_CATEGORY(Discord)
|
||||||
|
|
||||||
/*static*/ void UDiscordRpcBlueprint::Initialize(const FString& applicationId, bool autoRegister)
|
static UDiscordRpc* self = nullptr;
|
||||||
|
static void ReadyHandler() {
|
||||||
|
UE_LOG(Discord, Log, TEXT("Discord connected"));
|
||||||
|
if (self) {
|
||||||
|
self->IsConnected = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void DisconnectHandler(int errorCode, const char* message) {
|
||||||
|
UE_LOG(Discord, Log, TEXT("Discord disconnected (%d): %s"), errorCode, message);
|
||||||
|
if (self) {
|
||||||
|
self->IsConnected = false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
void UDiscordRpc::Initialize(const FString& applicationId, bool autoRegister)
|
||||||
{
|
{
|
||||||
|
self = this;
|
||||||
|
IsConnected = false;
|
||||||
DiscordEventHandlers handlers{};
|
DiscordEventHandlers handlers{};
|
||||||
handlers.ready = []() {
|
handlers.ready = ReadyHandler;
|
||||||
UE_LOG(DiscordLogCategory, Log, TEXT("Discord connected"));
|
handlers.disconnected = DisconnectHandler;
|
||||||
};
|
|
||||||
handlers.disconnected = [](int errorCode, const char* message) {
|
|
||||||
UE_LOG(DiscordLogCategory, Log, TEXT("Discord disconnected (%d): %s"), errorCode, message);
|
|
||||||
};
|
|
||||||
auto appId = StringCast<ANSICHAR>(*applicationId);
|
auto appId = StringCast<ANSICHAR>(*applicationId);
|
||||||
Discord_Initialize((const char*)appId.Get(), &handlers, autoRegister);
|
Discord_Initialize((const char*)appId.Get(), &handlers, autoRegister);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*static*/ void UDiscordRpcBlueprint::Shutdown()
|
void UDiscordRpc::Shutdown()
|
||||||
{
|
{
|
||||||
Discord_Shutdown();
|
Discord_Shutdown();
|
||||||
|
self = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*static*/ void UDiscordRpcBlueprint::RunCallbacks()
|
void UDiscordRpc::RunCallbacks()
|
||||||
{
|
{
|
||||||
Discord_RunCallbacks();
|
Discord_RunCallbacks();
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,22 +6,27 @@
|
||||||
#include "CoreMinimal.h"
|
#include "CoreMinimal.h"
|
||||||
#include "DiscordRpcBlueprint.generated.h"
|
#include "DiscordRpcBlueprint.generated.h"
|
||||||
|
|
||||||
DECLARE_LOG_CATEGORY_EXTERN(DiscordLogCategory, Log, All);
|
DECLARE_LOG_CATEGORY_EXTERN(Discord, Log, All);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
UCLASS()
|
UCLASS(BlueprintType, meta = (DisplayName = "Discord RPC"), Category = "Discord")
|
||||||
class DISCORDRPC_API UDiscordRpcBlueprint : public UBlueprintFunctionLibrary
|
class DISCORDRPC_API UDiscordRpc : public UObject
|
||||||
{
|
{
|
||||||
GENERATED_BODY()
|
GENERATED_BODY()
|
||||||
|
|
||||||
UFUNCTION(BlueprintCallable, meta = (DisplayName = "Discord Initialize connection", Keywords = "Discord rpc"), Category = "Discord")
|
public:
|
||||||
static void Initialize(const FString& applicationId, bool autoRegister);
|
|
||||||
|
UFUNCTION(BlueprintCallable, meta = (DisplayName = "Discord initialize connection", Keywords = "Discord rpc"), Category = "Discord")
|
||||||
|
void Initialize(const FString& applicationId, bool autoRegister);
|
||||||
|
|
||||||
UFUNCTION(BlueprintCallable, meta = (DisplayName = "Discord shut down connection", Keywords = "Discord rpc"), Category = "Discord")
|
UFUNCTION(BlueprintCallable, meta = (DisplayName = "Discord shut down connection", Keywords = "Discord rpc"), Category = "Discord")
|
||||||
static void Shutdown();
|
void Shutdown();
|
||||||
|
|
||||||
UFUNCTION(BlueprintCallable, meta = (DisplayName = "Discord check for callbacks", Keywords = "Discord rpc"), Category = "Discord")
|
UFUNCTION(BlueprintCallable, meta = (DisplayName = "Discord check for callbacks", Keywords = "Discord rpc"), Category = "Discord")
|
||||||
static void RunCallbacks();
|
void RunCallbacks();
|
||||||
|
|
||||||
|
UPROPERTY(BlueprintReadOnly, meta = (DisplayName = "Discord connected", Keywords = "Discord rpc"), Category = "Discord")
|
||||||
|
bool IsConnected;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue