added getter and setter
This commit is contained in:
Binary file not shown.
@@ -1,7 +1,10 @@
|
||||
extends Node
|
||||
|
||||
func _ready():
|
||||
DiscordSDK.set_app_id(918857075105349632)
|
||||
DiscordSDK.set_details("Made with GDExtension")
|
||||
DiscordSDK.set_state("This is a test from GDScript in Godot 4") #TODO:Change functions to variables if possible
|
||||
DiscordSDK.app_id = 918857075105349632
|
||||
print(DiscordSDK.app_id)
|
||||
DiscordSDK.details = "Made with GDExtension"
|
||||
print(DiscordSDK.details)
|
||||
DiscordSDK.state = "This is a test from GDScript in Godot 4" #TODO:Change functions to variables if possible
|
||||
print(DiscordSDK.state)
|
||||
DiscordSDK.refresh()
|
||||
|
32
src/main.cpp
32
src/main.cpp
@@ -17,14 +17,14 @@ void DiscordSDK::_bind_methods()
|
||||
ClassDB::bind_method(D_METHOD("debug"), &DiscordSDK::debug);
|
||||
ClassDB::bind_method(D_METHOD("coreupdate"), &DiscordSDK::coreupdate);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_app_id"), &DiscordSDK::get_app_id);
|
||||
ClassDB::bind_method(D_METHOD("set_app_id", "app_id"), &DiscordSDK::set_app_id);
|
||||
ClassDB::bind_method(D_METHOD("get_app_id", "app_id"), &DiscordSDK::get_app_id);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "app_id"), "set_app_id", "get_app_id");
|
||||
ClassDB::bind_method(D_METHOD("get_state"), &DiscordSDK::get_state);
|
||||
ClassDB::bind_method(D_METHOD("set_state", "state"), &DiscordSDK::set_state);
|
||||
ClassDB::bind_method(D_METHOD("get_state", "state"), &DiscordSDK::get_state);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::STRING, "state"), "set_state", "get_state");
|
||||
ClassDB::bind_method(D_METHOD("get_details"), &DiscordSDK::get_details);
|
||||
ClassDB::bind_method(D_METHOD("set_details", "details"), &DiscordSDK::set_details);
|
||||
ClassDB::bind_method(D_METHOD("get_details", "details"), &DiscordSDK::get_details);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::STRING, "details"), "set_details", "get_details");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("refresh"), &DiscordSDK::refresh);
|
||||
@@ -64,33 +64,33 @@ void DiscordSDK::coreupdate()
|
||||
::core->RunCallbacks();
|
||||
}
|
||||
|
||||
void DiscordSDK::set_app_id(int appid)
|
||||
void DiscordSDK::set_app_id(const int64_t &appid)
|
||||
{
|
||||
p_appid = appid;
|
||||
result = discord::Core::Create(appid, DiscordCreateFlags_NoRequireDiscord, &core);
|
||||
app_id = appid;
|
||||
result = discord::Core::Create(app_id, DiscordCreateFlags_NoRequireDiscord, &core);
|
||||
}
|
||||
int DiscordSDK::get_app_id()
|
||||
int64_t DiscordSDK::get_app_id() const
|
||||
{
|
||||
return p_appid;
|
||||
return app_id;
|
||||
}
|
||||
|
||||
void DiscordSDK::set_state(String state)
|
||||
void DiscordSDK::set_state(const String &pstate)
|
||||
{
|
||||
p_state = state;
|
||||
state = pstate;
|
||||
activity.SetState(state.utf8().get_data());
|
||||
}
|
||||
String DiscordSDK::get_state()
|
||||
String DiscordSDK::get_state() const
|
||||
{
|
||||
return p_state;
|
||||
return state;
|
||||
}
|
||||
void DiscordSDK::set_details(String details)
|
||||
void DiscordSDK::set_details(const String &detail)
|
||||
{
|
||||
p_details = details;
|
||||
details = detail;
|
||||
activity.SetDetails(details.utf8().get_data());
|
||||
}
|
||||
String DiscordSDK::get_details()
|
||||
String DiscordSDK::get_details() const
|
||||
{
|
||||
return p_details;
|
||||
return details;
|
||||
}
|
||||
|
||||
void DiscordSDK::refresh()
|
||||
|
19
src/main.h
19
src/main.h
@@ -17,7 +17,7 @@ protected:
|
||||
static void _bind_methods();
|
||||
|
||||
private:
|
||||
int app_id;
|
||||
int64_t app_id;
|
||||
String state;
|
||||
String details;
|
||||
|
||||
@@ -27,19 +27,16 @@ public:
|
||||
DiscordSDK();
|
||||
~DiscordSDK();
|
||||
|
||||
int p_appid;
|
||||
String p_state;
|
||||
String p_details;
|
||||
|
||||
void debug();
|
||||
void coreupdate();
|
||||
void refresh();
|
||||
int get_app_id();
|
||||
void set_app_id(int appid);
|
||||
String get_state();
|
||||
void set_state(String state);
|
||||
String get_details();
|
||||
void set_details(String details);
|
||||
|
||||
int64_t get_app_id() const;
|
||||
void set_app_id(const int64_t &p_app_id);
|
||||
String get_state() const;
|
||||
void set_state(const String &p_state);
|
||||
String get_details() const;
|
||||
void set_details(const String &p_details);
|
||||
};
|
||||
|
||||
#endif
|
@@ -26,7 +26,7 @@ void gdextension_terminate(ModuleInitializationLevel p_level)
|
||||
{
|
||||
if (p_level == MODULE_INITIALIZATION_LEVEL_SCENE)
|
||||
{
|
||||
Engine::get_singleton()->unregister_singleton("DiscordActivity");
|
||||
Engine::get_singleton()->unregister_singleton("DiscordSDK");
|
||||
memdelete(discordsdk);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user