44 lines
1.1 KiB
C++
44 lines
1.1 KiB
C++
#include "client_node.h"
|
|
#include "ydi_client.h"
|
|
|
|
String const ClientNode::sig_connection_changed{ "connection_changed" };
|
|
|
|
void ClientNode::_bind_methods() {
|
|
ClassDB::bind_method(D_METHOD("connect_to_server", "server_url"), &self_type::connect_to_server);
|
|
ADD_SIGNAL(MethodInfo(sig_connection_changed, PropertyInfo(Variant::INT, "connected", PROPERTY_HINT_ENUM, "Disconnected,Connected,Authenticated")));
|
|
}
|
|
|
|
void ClientNode::process() {
|
|
NetworkData::ConnectionStatus const new_status{ ydi::client::status() };
|
|
if (new_status != this->state) {
|
|
this->state = new_status;
|
|
emit_signal(sig_connection_changed, new_status);
|
|
}
|
|
}
|
|
|
|
void ClientNode::exit_tree() {
|
|
ydi::client::disconnect();
|
|
}
|
|
|
|
void ClientNode::_notification(int what) {
|
|
if (Engine::get_singleton()->is_editor_hint()) {
|
|
return;
|
|
}
|
|
switch (what) {
|
|
case NOTIFICATION_ENTER_TREE:
|
|
set_process(true);
|
|
return;
|
|
case NOTIFICATION_PROCESS:
|
|
process();
|
|
return;
|
|
case NOTIFICATION_EXIT_TREE:
|
|
exit_tree();
|
|
return;
|
|
default:
|
|
return;
|
|
}
|
|
}
|
|
|
|
void ClientNode::connect_to_server(String const &server) {
|
|
ydi::client::connect(server);
|
|
}
|