Skip to content

Commit

Permalink
make seal and ready be 2 signals and 2 functions instead of 4
Browse files Browse the repository at this point in the history
Update lobby_client.cpp

make the functions be lobby response again.

Update LobbyClient.xml

make data be a dictionary

make data be a variant instead

Update lobby_client.cpp

Update LobbyClient.xml
  • Loading branch information
Ughuuu committed Nov 30, 2024
1 parent bd5215b commit 39ca373
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 95 deletions.
51 changes: 19 additions & 32 deletions modules/blazium_sdk/doc_classes/LobbyClient.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
Generates [signal lobby_created] signal.
</description>
</method>
<method name="is_host">
<return type="bool" />
<description>
Returns true if you are the host.
</description>
</method>
<method name="join_lobby">
<return type="ViewLobbyResponse" />
<param index="0" name="lobby_id" type="String" />
Expand Down Expand Up @@ -60,15 +66,15 @@
</method>
<method name="lobby_data">
<return type="LobbyResponse" />
<param index="0" name="data" type="String" />
<param index="0" name="data" type="Variant" />
<description>
Send data either to the host, or if you are host send data to all peers.
Generates [signal received_data] signal.
</description>
</method>
<method name="lobby_data_to">
<return type="LobbyResponse" />
<param index="0" name="data" type="String" />
<param index="0" name="data" type="Variant" />
<param index="1" name="target_peer" type="String" />
<description>
Send data either to a peer, works only if you are host.
Expand All @@ -77,20 +83,15 @@
</method>
<method name="lobby_ready">
<return type="LobbyResponse" />
<param index="0" name="ready" type="bool" />
<description>
Ready up in the lobby. You need to be in a lobby and unready to run this.
Generates [signal peer_ready].
</description>
</method>
<method name="lobby_unready">
<return type="LobbyResponse" />
<description>
Ready up in the lobby. You need to be in a lobby and ready to run this.
Generates [signal peer_unready].
</description>
</method>
<method name="seal_lobby">
<return type="LobbyResponse" />
<param index="0" name="seal" type="bool" />
<description>
Seals the lobby. You need to be the host to do this and the lobby needs to be unsealed.
Generates [signal lobby_sealed].
Expand All @@ -104,13 +105,6 @@
Generates [signal peer_named] signal if you are in lobby.
</description>
</method>
<method name="unseal_lobby">
<return type="LobbyResponse" />
<description>
Unseals the lobby. You need to be the host to do this and the lobby needs to be sealed.
Generates [signal lobby_unsealed].
</description>
</method>
<method name="view_lobby">
<return type="ViewLobbyResponse" />
<param index="0" name="lobby_id" type="String" default="&quot;&quot;" />
Expand All @@ -125,13 +119,13 @@
True if the client is connected, else false.
</member>
<member name="lobby" type="LobbyInfo" setter="" getter="get_lobby">
The current lobby.
The current lobby. Reflects changes to the lobby.
</member>
<member name="peer" type="LobbyPeer" setter="" getter="get_peer">
The current peer.
The current peer. Reflects changes to the self peer.
</member>
<member name="peers" type="LobbyPeer[]" setter="" getter="get_peers" default="[]">
The lobby peers.
The lobby peers. Reflects changes to all peers.
</member>
<member name="server_url" type="String" setter="set_server_url" getter="get_server_url" default="&quot;wss://lobby.blazium.app/connect&quot;">
Set to what url this lobby should connect to.
Expand Down Expand Up @@ -171,15 +165,11 @@
</description>
</signal>
<signal name="lobby_sealed">
<param index="0" name="sealed" type="bool" />
<description>
Signal generated after the host seals the lobby.
</description>
</signal>
<signal name="lobby_unsealed">
<description>
Signal generated after the host unseals the lobby.
</description>
</signal>
<signal name="peer_joined">
<param index="0" name="peer" type="LobbyPeer" />
<description>
Expand All @@ -201,24 +191,21 @@
</signal>
<signal name="peer_ready">
<param index="0" name="peer" type="LobbyPeer" />
<param index="1" name="ready" type="bool" />
<description>
Signal generated after a peer is ready.
</description>
</signal>
<signal name="peer_unready">
<param index="0" name="peer" type="LobbyPeer" />
<description>
Signal generated after a peer is unready.
</description>
</signal>
<signal name="received_data">
<param index="0" name="data" type="String" />
+ <param index="0" name="data" type="Object" />
+ <param index="1" name="from_peer" type="String" />
<description>
Signal generated after a lobby_data call.
</description>
</signal>
<signal name="received_data_to">
<param index="0" name="data" type="String" />
+ <param index="0" name="data" type="Object" />
+ <param index="1" name="from_peer" type="String" />
<description>
Signal generated after a data_to call.
</description>
Expand Down
86 changes: 29 additions & 57 deletions modules/blazium_sdk/lobby/lobby_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ LobbyClient::~LobbyClient() {
void LobbyClient::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_server_url", "server_url"), &LobbyClient::set_server_url);
ClassDB::bind_method(D_METHOD("get_server_url"), &LobbyClient::get_server_url);
ClassDB::bind_method(D_METHOD("is_host"), &LobbyClient::is_host);
ClassDB::bind_method(D_METHOD("get_connected"), &LobbyClient::get_connected);
ClassDB::bind_method(D_METHOD("get_lobby"), &LobbyClient::get_lobby);
ClassDB::bind_method(D_METHOD("get_peer"), &LobbyClient::get_peer);
Expand All @@ -67,27 +68,23 @@ void LobbyClient::_bind_methods() {
ClassDB::bind_method(D_METHOD("list_lobby", "start", "count"), &LobbyClient::list_lobby, DEFVAL(0), DEFVAL(10));
ClassDB::bind_method(D_METHOD("view_lobby", "lobby_id", "password"), &LobbyClient::view_lobby, DEFVAL(""), DEFVAL(""));
ClassDB::bind_method(D_METHOD("kick_peer", "peer_id"), &LobbyClient::kick_peer);
ClassDB::bind_method(D_METHOD("lobby_ready"), &LobbyClient::lobby_ready);
ClassDB::bind_method(D_METHOD("lobby_unready"), &LobbyClient::lobby_unready);
ClassDB::bind_method(D_METHOD("seal_lobby"), &LobbyClient::seal_lobby);
ClassDB::bind_method(D_METHOD("unseal_lobby"), &LobbyClient::unseal_lobby);
ClassDB::bind_method(D_METHOD("lobby_ready", "ready"), &LobbyClient::lobby_ready);
ClassDB::bind_method(D_METHOD("seal_lobby", "seal"), &LobbyClient::seal_lobby);
ClassDB::bind_method(D_METHOD("lobby_data", "data"), &LobbyClient::lobby_data);
ClassDB::bind_method(D_METHOD("lobby_data_to", "data", "target_peer"), &LobbyClient::lobby_data_to);

// Register signals
ADD_SIGNAL(MethodInfo("disconnected_from_lobby"));
ADD_SIGNAL(MethodInfo("peer_named", PropertyInfo(Variant::OBJECT, "peer", PROPERTY_HINT_RESOURCE_TYPE, "LobbyPeer")));
ADD_SIGNAL(MethodInfo("received_data", PropertyInfo(Variant::STRING, "data")));
ADD_SIGNAL(MethodInfo("received_data_to", PropertyInfo(Variant::STRING, "data")));
ADD_SIGNAL(MethodInfo("received_data", PropertyInfo(Variant::OBJECT, "data"), PropertyInfo(Variant::STRING, "from_peer")));
ADD_SIGNAL(MethodInfo("received_data_to", PropertyInfo(Variant::OBJECT, "data"), PropertyInfo(Variant::STRING, "from_peer")));
ADD_SIGNAL(MethodInfo("lobby_created", PropertyInfo(Variant::OBJECT, "lobby", PROPERTY_HINT_RESOURCE_TYPE, "LobbyInfo"), PropertyInfo(Variant::ARRAY, "peers", PROPERTY_HINT_ARRAY_TYPE, "LobbyPeer")));
ADD_SIGNAL(MethodInfo("lobby_joined", PropertyInfo(Variant::OBJECT, "lobby", PROPERTY_HINT_RESOURCE_TYPE, "LobbyInfo"), PropertyInfo(Variant::ARRAY, "peers", PROPERTY_HINT_ARRAY_TYPE, "LobbyPeer")));
ADD_SIGNAL(MethodInfo("lobby_left"));
ADD_SIGNAL(MethodInfo("lobby_sealed"));
ADD_SIGNAL(MethodInfo("lobby_unsealed"));
ADD_SIGNAL(MethodInfo("lobby_sealed", PropertyInfo(Variant::BOOL, "sealed")));
ADD_SIGNAL(MethodInfo("peer_joined", PropertyInfo(Variant::OBJECT, "peer", PROPERTY_HINT_RESOURCE_TYPE, "LobbyPeer")));
ADD_SIGNAL(MethodInfo("peer_left", PropertyInfo(Variant::OBJECT, "peer", PROPERTY_HINT_RESOURCE_TYPE, "LobbyPeer"), PropertyInfo(Variant::BOOL, "kicked")));
ADD_SIGNAL(MethodInfo("peer_ready", PropertyInfo(Variant::OBJECT, "peer", PROPERTY_HINT_RESOURCE_TYPE, "LobbyPeer")));
ADD_SIGNAL(MethodInfo("peer_unready", PropertyInfo(Variant::OBJECT, "peer", PROPERTY_HINT_RESOURCE_TYPE, "LobbyPeer")));
ADD_SIGNAL(MethodInfo("peer_ready", PropertyInfo(Variant::OBJECT, "peer", PROPERTY_HINT_RESOURCE_TYPE, "LobbyPeer"), PropertyInfo(Variant::BOOL, "ready")));
ADD_SIGNAL(MethodInfo("append_log", PropertyInfo(Variant::STRING, "command"), PropertyInfo(Variant::STRING, "info"), PropertyInfo(Variant::STRING, "logs")));
}

Expand Down Expand Up @@ -230,27 +227,14 @@ Ref<LobbyClient::LobbyResponse> LobbyClient::kick_peer(const String &p_peer_id)
return response;
}

Ref<LobbyClient::LobbyResponse> LobbyClient::lobby_ready() {
Ref<LobbyClient::LobbyResponse> LobbyClient::lobby_ready(bool p_ready) {
String id = _increment_counter();
Dictionary command;
command["command"] = "lobby_ready";
Dictionary data_dict;
command["data"] = data_dict;
data_dict["id"] = id;
Array command_array;
Ref<LobbyResponse> response;
response.instantiate();
command_array.push_back(LOBBY_REQUEST);
command_array.push_back(response);
_commands[id] = command_array;
_send_data(command);
return response;
}

Ref<LobbyClient::LobbyResponse> LobbyClient::lobby_unready() {
String id = _increment_counter();
Dictionary command;
command["command"] = "lobby_unready";
if (p_ready) {
command["command"] = "lobby_ready";
} else {
command["command"] = "lobby_unready";
}
Dictionary data_dict;
command["data"] = data_dict;
data_dict["id"] = id;
Expand Down Expand Up @@ -282,27 +266,14 @@ Ref<LobbyClient::LobbyResponse> LobbyClient::set_peer_name(const String &p_peer_
return response;
}

Ref<LobbyClient::LobbyResponse> LobbyClient::seal_lobby() {
Ref<LobbyClient::LobbyResponse> LobbyClient::seal_lobby(bool seal) {
String id = _increment_counter();
Dictionary command;
command["command"] = "seal_lobby";
Dictionary data_dict;
command["data"] = data_dict;
data_dict["id"] = id;
Array command_array;
Ref<LobbyResponse> response;
response.instantiate();
command_array.push_back(LOBBY_REQUEST);
command_array.push_back(response);
_commands[id] = command_array;
_send_data(command);
return response;
}

Ref<LobbyClient::LobbyResponse> LobbyClient::unseal_lobby() {
String id = _increment_counter();
Dictionary command;
command["command"] = "unseal_lobby";
if (seal) {
command["command"] = "seal_lobby";
} else {
command["command"] = "unseal_lobby";
}
Dictionary data_dict;
command["data"] = data_dict;
data_dict["id"] = id;
Expand All @@ -316,7 +287,7 @@ Ref<LobbyClient::LobbyResponse> LobbyClient::unseal_lobby() {
return response;
}

Ref<LobbyClient::LobbyResponse> LobbyClient::lobby_data(const String &p_peer_data) {
Ref<LobbyClient::LobbyResponse> LobbyClient::lobby_data(const Variant &p_peer_data) {
String id = _increment_counter();
Dictionary command;
command["command"] = "lobby_data";
Expand All @@ -334,7 +305,7 @@ Ref<LobbyClient::LobbyResponse> LobbyClient::lobby_data(const String &p_peer_dat
return response;
}

Ref<LobbyClient::LobbyResponse> LobbyClient::lobby_data_to(const String &p_peer_data, const String &p_target_peer) {
Ref<LobbyClient::LobbyResponse> LobbyClient::lobby_data_to(const Variant &p_peer_data, const String &p_target_peer) {
String id = _increment_counter();
Dictionary command;
command["command"] = "data_to";
Expand Down Expand Up @@ -460,7 +431,8 @@ void LobbyClient::_receive_data(const Dictionary &p_dict) {
}
}
if (command == "peer_state") {
peer->set_id(data_dict.get("peer_id", ""));
Dictionary peer_dict = data_dict.get("peer", Dictionary());
peer->set_id(peer_dict.get("id", ""));
} else if (command == "lobby_created") {
lobby->set_dict(data_dict.get("lobby", Dictionary()));
update_peers(data_dict, peers);
Expand All @@ -478,10 +450,10 @@ void LobbyClient::_receive_data(const Dictionary &p_dict) {
} else if (command == "lobby_sealed") {
Dictionary lobby_dict = data_dict.get("lobby", Dictionary());
lobby->set_sealed(true);
emit_signal("lobby_sealed");
emit_signal("lobby_sealed", true);
} else if (command == "lobby_unsealed") {
lobby->set_sealed(false);
emit_signal("lobby_unsealed");
emit_signal("lobby_sealed", false);
} else if (command == "lobby_list") {
Array arr = data_dict.get("lobbies", Array());
TypedArray<Dictionary> lobbies_input = arr;
Expand Down Expand Up @@ -532,7 +504,7 @@ void LobbyClient::_receive_data(const Dictionary &p_dict) {
Ref<LobbyPeer> updated_peer = peers[i];
if (updated_peer->get_id() == String(peer_id)) {
updated_peer->set_ready(true);
emit_signal("peer_ready", updated_peer);
emit_signal("peer_ready", updated_peer, true);
break;
}
}
Expand All @@ -545,7 +517,7 @@ void LobbyClient::_receive_data(const Dictionary &p_dict) {
Ref<LobbyPeer> updated_peer = peers[i];
if (updated_peer->get_id() == String(data_dict.get("peer_id", ""))) {
updated_peer->set_ready(false);
emit_signal("peer_unready", updated_peer);
emit_signal("peer_ready", updated_peer, false);
break;
}
}
Expand All @@ -570,9 +542,9 @@ void LobbyClient::_receive_data(const Dictionary &p_dict) {
}
sort_peers_by_id(peers);
} else if (command == "lobby_data") {
emit_signal("received_data", data_dict.get("peer_data", ""));
emit_signal("received_data", data_dict.get("peer_data", Variant()), data_dict.get("from_peer", ""));
} else if (command == "data_to") {
emit_signal("received_data_to", data_dict.get("peer_data", ""));
emit_signal("received_data_to", data_dict.get("peer_data", Variant()), data_dict.get("from_peer", ""));
} else if (command == "lobby_data_sent") {
// nothing for now
} else if (command == "data_to_sent") {
Expand Down
11 changes: 5 additions & 6 deletions modules/blazium_sdk/lobby/lobby_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ class LobbyClient : public BlaziumClient {
public:
void set_server_url(const String &p_server_url) { this->server_url = p_server_url; }
String get_server_url() { return server_url; }
bool is_host() { return lobby->get_host() == peer->get_id(); }
bool get_connected() { return connected; }
void set_lobby(const Ref<LobbyInfo> &p_lobby) { this->lobby = p_lobby; }
Ref<LobbyInfo> get_lobby() { return lobby; }
Expand All @@ -308,13 +309,11 @@ class LobbyClient : public BlaziumClient {
Ref<ListLobbyResponse> list_lobby(int p_start, int p_count);
Ref<ViewLobbyResponse> view_lobby(const String &p_lobby_id, const String &p_password);
Ref<LobbyResponse> kick_peer(const String &p_peer_id);
Ref<LobbyResponse> lobby_ready();
Ref<LobbyResponse> lobby_unready();
Ref<LobbyResponse> lobby_ready(bool p_ready);
Ref<LobbyResponse> set_peer_name(const String &p_peer_name);
Ref<LobbyResponse> seal_lobby();
Ref<LobbyResponse> unseal_lobby();
Ref<LobbyResponse> lobby_data(const String &p_peer_data);
Ref<LobbyResponse> lobby_data_to(const String &p_peer_data, const String &p_target_peer);
Ref<LobbyResponse> seal_lobby(bool seal);
Ref<LobbyResponse> lobby_data(const Variant &p_peer_data);
Ref<LobbyResponse> lobby_data_to(const Variant &p_peer_data, const String &p_target_peer);

LobbyClient();
~LobbyClient();
Expand Down

0 comments on commit 39ca373

Please sign in to comment.