feat: improved ServerNode scriptability
This commit is contained in:
parent
cfb901ec46
commit
6add0813d1
4 changed files with 42 additions and 18 deletions
|
|
@ -13,6 +13,9 @@ void ServerNode::_bind_methods() {
|
|||
ADD_SIGNAL(MethodInfo(sig_connection_lost));
|
||||
|
||||
ClassDB::bind_method(D_METHOD("open"), &self_type::open);
|
||||
ClassDB::bind_method(D_METHOD("close"), &self_type::close);
|
||||
ClassDB::bind_method(D_METHOD("is_open"), &self_type::is_open);
|
||||
ClassDB::bind_static_method(self_type::get_class_static(), "get_singleton", &self_type::get_singleton);
|
||||
}
|
||||
|
||||
void ServerNode::enter_tree() {
|
||||
|
|
@ -25,17 +28,20 @@ void ServerNode::enter_tree() {
|
|||
}
|
||||
|
||||
void ServerNode::process(double delta) {
|
||||
bool new_is_connected{ ydi::server::has_client() };
|
||||
if (this->is_connected != new_is_connected) {
|
||||
this->is_connected = new_is_connected;
|
||||
emit_signal(this->is_connected ? sig_connection_established : sig_connection_lost);
|
||||
}
|
||||
if (!ydi::server::has_client()) {
|
||||
return;
|
||||
}
|
||||
Vector<NetworkData::ClueID> new_clues{};
|
||||
if (ydi::server::receive::new_clues(new_clues)) {
|
||||
for (NetworkData::ClueID clue : new_clues) {
|
||||
emit_signal(sig_clue_revealed, clue);
|
||||
}
|
||||
}
|
||||
bool new_is_connected{ ydi::server::has_client() };
|
||||
if (this->is_connected != new_is_connected) {
|
||||
this->is_connected = new_is_connected;
|
||||
emit_signal(this->is_connected ? sig_connection_established : sig_connection_lost);
|
||||
}
|
||||
}
|
||||
|
||||
void ServerNode::exit_tree() {
|
||||
|
|
@ -69,6 +75,14 @@ ServerNode *ServerNode::get_singleton() {
|
|||
return singleton_instance;
|
||||
}
|
||||
|
||||
void ServerNode::open() {
|
||||
ydi::server::open();
|
||||
bool ServerNode::open() {
|
||||
return ydi::server::open();
|
||||
}
|
||||
|
||||
void ServerNode::close() {
|
||||
ydi::server::close();
|
||||
}
|
||||
|
||||
bool ServerNode::is_open() const {
|
||||
return ydi::server::is_running();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue