refactored lobby logic; streamlined commands and added PeerMessages to client for more cohesive socket messaging
This commit is contained in:
@@ -12,12 +12,6 @@ extends Control
|
|||||||
@export var name_input: LineEdit
|
@export var name_input: LineEdit
|
||||||
@export var lobby_code_input: LineEdit
|
@export var lobby_code_input: LineEdit
|
||||||
|
|
||||||
@export var output: Label
|
|
||||||
|
|
||||||
func _write_line(text: String) -> void:
|
|
||||||
#output.text += text + "\n"
|
|
||||||
pass
|
|
||||||
|
|
||||||
func _on_create_lobby_button_pressed() -> void:
|
func _on_create_lobby_button_pressed() -> void:
|
||||||
client.create_lobby(name_input.text.strip_edges())
|
client.create_lobby(name_input.text.strip_edges())
|
||||||
|
|
||||||
@@ -28,34 +22,6 @@ func _on_disconnect_lobby_button_pressed() -> void:
|
|||||||
leave_lobby_button.disabled = true
|
leave_lobby_button.disabled = true
|
||||||
client.leave_lobby()
|
client.leave_lobby()
|
||||||
|
|
||||||
func _on_web_client_tcp_connected_to_server() -> void:
|
|
||||||
_write_line("You are connected to the server")
|
|
||||||
|
|
||||||
func _on_web_client_tcp_connection_error_occurred() -> void:
|
|
||||||
#connect_button.disabled = false
|
|
||||||
pass
|
|
||||||
|
|
||||||
func _on_web_client_tcp_disconnected_from_server() -> void:
|
|
||||||
_write_line("You were disconnected from the server")
|
|
||||||
|
|
||||||
func _on_web_client_tcp_connected_to_lobby(lobby_id: String) -> void:
|
|
||||||
lobby_code_input.text = lobby_id
|
|
||||||
_write_line("You connected to lobby {lobby_id}".format({"lobby_id": lobby_id}))
|
|
||||||
|
|
||||||
func _on_web_client_tcp_disconnected_from_lobby() -> void:
|
|
||||||
_write_line("You disconnected from the lobby")
|
|
||||||
|
|
||||||
func _on_web_client_tcp_client_joined_lobby(client_name: String, connected_client_names: Array) -> void:
|
|
||||||
_write_line("{client_name} joined the lobby{you}".format({
|
|
||||||
"client_name": client_name,
|
|
||||||
"you": " (that's you!)" if client_name == name_input.text.strip_edges() else ""
|
|
||||||
}))
|
|
||||||
_update_connected_players(connected_client_names)
|
|
||||||
|
|
||||||
func _on_web_client_tcp_client_left_lobby(client_name: String, connected_client_names: Array) -> void:
|
|
||||||
_write_line("{client_name} left the lobby".format({"client_name": client_name}))
|
|
||||||
_update_connected_players(connected_client_names)
|
|
||||||
|
|
||||||
func _on_web_client_tcp_connection_status_changed(new_status: WebClient.ConnectionStatus) -> void:
|
func _on_web_client_tcp_connection_status_changed(new_status: WebClient.ConnectionStatus) -> void:
|
||||||
match new_status:
|
match new_status:
|
||||||
WebClient.ConnectionStatus.DISCONNECTED:
|
WebClient.ConnectionStatus.DISCONNECTED:
|
||||||
@@ -96,8 +62,11 @@ func _on_web_client_tcp_connection_status_changed(new_status: WebClient.Connecti
|
|||||||
name_input.editable = false
|
name_input.editable = false
|
||||||
lobby_code_input.editable = false
|
lobby_code_input.editable = false
|
||||||
|
|
||||||
func _on_web_client_tcp_received_connection_message(message: String) -> void:
|
|
||||||
_write_line(message)
|
|
||||||
|
|
||||||
func _update_connected_players(new_client_names: Array[String]) -> void:
|
func _update_connected_players(new_client_names: Array[String]) -> void:
|
||||||
connected_players_label.text = "Connected Players:\n" + "\n".join(new_client_names)
|
connected_players_label.text = "Connected Players:\n" + "\n".join(new_client_names)
|
||||||
|
|
||||||
|
func _on_web_client_connected_to_lobby(lobby_id: String, client_id: String) -> void:
|
||||||
|
lobby_code_input.text = lobby_id
|
||||||
|
|
||||||
|
func _on_web_client_connected_clients_changed(connected_client_names: Array[String]) -> void:
|
||||||
|
_update_connected_players(connected_client_names)
|
||||||
|
|||||||
+58
-59
@@ -9,7 +9,6 @@ const SENDER_SYSTEM: String = "SYSTEM"
|
|||||||
## Remote: wss://denizk0461.dev/magsrv
|
## Remote: wss://denizk0461.dev/magsrv
|
||||||
const SERVER_ADDRESS: String = "127.0.0.1:9974"
|
const SERVER_ADDRESS: String = "127.0.0.1:9974"
|
||||||
|
|
||||||
#var _tcp := StreamPeerTCP.new()
|
|
||||||
var _socket := WebSocketPeer.new()
|
var _socket := WebSocketPeer.new()
|
||||||
|
|
||||||
var _new_status: int = WebSocketPeer.STATE_CLOSED
|
var _new_status: int = WebSocketPeer.STATE_CLOSED
|
||||||
@@ -18,6 +17,7 @@ var _processed_status: int = -1
|
|||||||
var _lobby_id: String
|
var _lobby_id: String
|
||||||
var _client_id: String
|
var _client_id: String
|
||||||
var _client_name: String
|
var _client_name: String
|
||||||
|
var _is_host: bool
|
||||||
|
|
||||||
var received_data: Array
|
var received_data: Array
|
||||||
var cached_response: String
|
var cached_response: String
|
||||||
@@ -32,18 +32,10 @@ var _connected_client_names: Array[String] = []
|
|||||||
|
|
||||||
@export var chat_panel: ChatPanel
|
@export var chat_panel: ChatPanel
|
||||||
|
|
||||||
signal connected_to_server()
|
signal connected_to_lobby(lobby_id: String, client_id: String)
|
||||||
signal connection_error_occurred()
|
|
||||||
signal disconnected_from_server()
|
|
||||||
|
|
||||||
signal connected_to_lobby(lobby_id: String)
|
signal connected_clients_changed(connected_client_names: Array[String])
|
||||||
signal disconnected_from_lobby()
|
|
||||||
signal received_client_id(client_id: String)
|
|
||||||
|
|
||||||
signal client_joined_lobby(client_name: String, connected_client_names: Array[String])
|
|
||||||
signal client_left_lobby(client_name: String, connected_client_names: Array[String])
|
|
||||||
|
|
||||||
signal received_connection_message(message: String)
|
|
||||||
signal received_chat_message(client_name: String, message: String)
|
signal received_chat_message(client_name: String, message: String)
|
||||||
|
|
||||||
signal connection_status_changed(new_status: ConnectionStatus)
|
signal connection_status_changed(new_status: ConnectionStatus)
|
||||||
@@ -85,17 +77,14 @@ func _process(_delta: float) -> void:
|
|||||||
if not _processed_status == _new_status:
|
if not _processed_status == _new_status:
|
||||||
match _new_status:
|
match _new_status:
|
||||||
WebSocketPeer.STATE_OPEN:
|
WebSocketPeer.STATE_OPEN:
|
||||||
print("open")
|
chat_panel.put_chat_message(SENDER_SYSTEM, "You successfully connected to the server.")
|
||||||
connected_to_server.emit()
|
|
||||||
connection_status_changed.emit(ConnectionStatus.LOBBYLESS)
|
connection_status_changed.emit(ConnectionStatus.LOBBYLESS)
|
||||||
WebSocketPeer.STATE_CONNECTING:
|
WebSocketPeer.STATE_CONNECTING:
|
||||||
print("connecting")
|
|
||||||
connection_status_changed.emit(ConnectionStatus.ATTEMPTING_CONNECTION)
|
connection_status_changed.emit(ConnectionStatus.ATTEMPTING_CONNECTION)
|
||||||
WebSocketPeer.STATE_CLOSING:
|
WebSocketPeer.STATE_CLOSING:
|
||||||
print("closing")
|
|
||||||
pass
|
pass
|
||||||
WebSocketPeer.STATE_CLOSED:
|
WebSocketPeer.STATE_CLOSED:
|
||||||
print("closed")
|
chat_panel.put_chat_message(SENDER_SYSTEM, "You lost connection to the server.")
|
||||||
connection_status_changed.emit(ConnectionStatus.DISCONNECTED)
|
connection_status_changed.emit(ConnectionStatus.DISCONNECTED)
|
||||||
|
|
||||||
_processed_status = _new_status
|
_processed_status = _new_status
|
||||||
@@ -103,10 +92,7 @@ func _process(_delta: float) -> void:
|
|||||||
if _processed_status == WebSocketPeer.STATE_OPEN:
|
if _processed_status == WebSocketPeer.STATE_OPEN:
|
||||||
while _socket.get_available_packet_count():
|
while _socket.get_available_packet_count():
|
||||||
cached_response = _socket.get_packet().get_string_from_utf8()
|
cached_response = _socket.get_packet().get_string_from_utf8()
|
||||||
#print(cached_response)
|
|
||||||
#cached_response += (received_data[1] as PackedByteArray).get_string_from_utf8()
|
|
||||||
if cached_response.ends_with("}"):
|
if cached_response.ends_with("}"):
|
||||||
#print(cached_response)
|
|
||||||
_handle_response(cached_response)
|
_handle_response(cached_response)
|
||||||
cached_response = ""
|
cached_response = ""
|
||||||
|
|
||||||
@@ -122,29 +108,33 @@ func _listen_for_data() -> void:
|
|||||||
func _handle_response(response: String) -> void:
|
func _handle_response(response: String) -> void:
|
||||||
var data = JSON.parse_string(response)
|
var data = JSON.parse_string(response)
|
||||||
match data["response"]:
|
match data["response"]:
|
||||||
"create_lobby":
|
"created_lobby":
|
||||||
if data["status"] == "ok":
|
|
||||||
_lobby_id = data["lobby_id"]
|
_lobby_id = data["lobby_id"]
|
||||||
_client_id = data["client_id"]
|
_client_id = data["client_id"]
|
||||||
received_client_id.emit.call_deferred(_client_id)
|
chat_panel.put_chat_message(SENDER_SYSTEM, "You created and connected to lobby {lobby_id} with client ID {client_id}.".format({
|
||||||
connected_to_lobby.emit.call_deferred(_lobby_id)
|
"lobby_id": _lobby_id,
|
||||||
|
"client_id": _client_id,
|
||||||
|
}))
|
||||||
connection_status_changed.emit.call_deferred(ConnectionStatus.JOINED)
|
connection_status_changed.emit.call_deferred(ConnectionStatus.JOINED)
|
||||||
|
connected_to_lobby.emit.call_deferred(_lobby_id, _client_id)
|
||||||
"join_lobby_response":
|
"join_lobby_response":
|
||||||
_handle_join(data)
|
_handle_join(data)
|
||||||
"client_joined_lobby":
|
"joined_lobby":
|
||||||
print(data["connected_client_ids"])
|
|
||||||
_connected_client_ids.assign(data["connected_client_ids"])
|
_connected_client_ids.assign(data["connected_client_ids"])
|
||||||
_connected_client_names.assign(data["connected_client_names"])
|
_connected_client_names.assign(data["connected_client_names"])
|
||||||
client_joined_lobby.emit.call_deferred(data["new_client_name"], _connected_client_names)
|
connected_clients_changed.emit.call_deferred(_connected_client_names)
|
||||||
|
chat_panel.put_chat_message(SENDER_SYSTEM, "{client_name} joined the lobby.".format({
|
||||||
|
"client_name": data["client_name"],
|
||||||
|
}))
|
||||||
"leave_lobby_request":
|
"leave_lobby_request":
|
||||||
leave_lobby()
|
leave_lobby()
|
||||||
"leave_lobby":
|
"left_lobby":
|
||||||
if data["status"] == "ok":
|
|
||||||
client_left_lobby.emit.call_deferred(data["client_name"])
|
|
||||||
"client_left_lobby":
|
|
||||||
_connected_client_ids.assign(data["connected_client_ids"])
|
_connected_client_ids.assign(data["connected_client_ids"])
|
||||||
_connected_client_names.assign(data["connected_client_names"])
|
_connected_client_names.assign(data["connected_client_names"])
|
||||||
client_left_lobby.emit.call_deferred(data["client_name"], _connected_client_names)
|
connected_clients_changed.emit.call_deferred(_connected_client_names)
|
||||||
|
chat_panel.put_chat_message(SENDER_SYSTEM, "{client_name} left the lobby.".format({
|
||||||
|
"client_name": data["client_name"],
|
||||||
|
}))
|
||||||
|
|
||||||
## A chat message has been received
|
## A chat message has been received
|
||||||
"receive_chat_message":
|
"receive_chat_message":
|
||||||
@@ -203,16 +193,19 @@ func _handle_response(response: String) -> void:
|
|||||||
func _handle_join(data) -> void:
|
func _handle_join(data) -> void:
|
||||||
match data["status"]:
|
match data["status"]:
|
||||||
"lobby_not_found":
|
"lobby_not_found":
|
||||||
received_connection_message.emit.call_deferred("Could not join; lobby does not exist")
|
chat_panel.put_chat_message(SENDER_SYSTEM, "Could not join; lobby does not exist.")
|
||||||
connection_status_changed.emit.call_deferred(ConnectionStatus.LOBBYLESS)
|
connection_status_changed.emit.call_deferred(ConnectionStatus.LOBBYLESS)
|
||||||
"lobby_full":
|
"lobby_full":
|
||||||
received_connection_message.emit.call_deferred("Could not join; lobby is full")
|
chat_panel.put_chat_message(SENDER_SYSTEM, "Could not join; lobby is full.")
|
||||||
connection_status_changed.emit.call_deferred(ConnectionStatus.LOBBYLESS)
|
connection_status_changed.emit.call_deferred(ConnectionStatus.LOBBYLESS)
|
||||||
"ok":
|
"ok":
|
||||||
_client_id = data["client_id"]
|
_client_id = data["client_id"]
|
||||||
connected_to_lobby.emit.call_deferred(_lobby_id)
|
chat_panel.put_chat_message(SENDER_SYSTEM, "You connected to lobby {lobby_id} with client ID {client_id}.".format({
|
||||||
received_client_id.emit.call_deferred(_client_id)
|
"lobby_id": _lobby_id,
|
||||||
|
"client_id": _client_id,
|
||||||
|
}))
|
||||||
connection_status_changed.emit.call_deferred(ConnectionStatus.JOINED)
|
connection_status_changed.emit.call_deferred(ConnectionStatus.JOINED)
|
||||||
|
connected_to_lobby.emit.call_deferred(_lobby_id, _client_id)
|
||||||
|
|
||||||
func _exit_tree() -> void:
|
func _exit_tree() -> void:
|
||||||
disconnect_from_server()
|
disconnect_from_server()
|
||||||
@@ -224,31 +217,9 @@ func connect_to_server(text: String) -> void:
|
|||||||
|
|
||||||
func disconnect_from_server() -> void:
|
func disconnect_from_server() -> void:
|
||||||
_socket.close()
|
_socket.close()
|
||||||
disconnected_from_server.emit()
|
chat_panel.put_chat_message(SENDER_SYSTEM, "You were disconnected from the server.")
|
||||||
connection_status_changed.emit(ConnectionStatus.DISCONNECTED)
|
connection_status_changed.emit(ConnectionStatus.DISCONNECTED)
|
||||||
|
|
||||||
func create_lobby(client_name: String) -> void:
|
|
||||||
_client_name = client_name
|
|
||||||
|
|
||||||
_send_message(TCPMessages.create_lobby(client_name))
|
|
||||||
|
|
||||||
func join_lobby(lobby_id: String, client_name: String) -> void:
|
|
||||||
_lobby_id = lobby_id
|
|
||||||
_client_name = client_name
|
|
||||||
|
|
||||||
_send_message(TCPMessages.join_lobby(_lobby_id, client_name))
|
|
||||||
connection_status_changed.emit.call_deferred(ConnectionStatus.ATTEMPTING_JOIN)
|
|
||||||
|
|
||||||
func leave_lobby() -> void:
|
|
||||||
_send_message(TCPMessages.leave_lobby(_lobby_id, _client_id))
|
|
||||||
|
|
||||||
_lobby_id = ""
|
|
||||||
_client_id = ""
|
|
||||||
_client_name = ""
|
|
||||||
|
|
||||||
disconnected_from_lobby.emit.call_deferred()
|
|
||||||
connection_status_changed.emit.call_deferred(ConnectionStatus.LOBBYLESS)
|
|
||||||
|
|
||||||
func send_chat_message(message: String) -> void:
|
func send_chat_message(message: String) -> void:
|
||||||
#_send_message(TCPMessages.send_chat_message(_lobby_id, _client_id, message))
|
#_send_message(TCPMessages.send_chat_message(_lobby_id, _client_id, message))
|
||||||
pass
|
pass
|
||||||
@@ -309,5 +280,33 @@ func submit_play_winner(winning_client_id: String) -> void:
|
|||||||
func _send_message(message: String) -> void:
|
func _send_message(message: String) -> void:
|
||||||
_socket.send_text(message)
|
_socket.send_text(message)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
func create_lobby(client_name: String) -> void:
|
||||||
|
_client_name = client_name
|
||||||
|
_send_message(PeerMessages.create_lobby(client_name))
|
||||||
|
|
||||||
|
func join_lobby(lobby_id: String, client_name: String) -> void:
|
||||||
|
_lobby_id = lobby_id
|
||||||
|
_client_name = client_name
|
||||||
|
_send_message(PeerMessages.join_lobby(_lobby_id, client_name))
|
||||||
|
connection_status_changed.emit.call_deferred(ConnectionStatus.ATTEMPTING_JOIN)
|
||||||
|
|
||||||
|
func leave_lobby() -> void:
|
||||||
|
_send_message(PeerMessages.leave_lobby(_lobby_id, _client_id))
|
||||||
|
|
||||||
|
connection_status_changed.emit.call_deferred(ConnectionStatus.LOBBYLESS)
|
||||||
|
|
||||||
|
# Notify user about disconnect
|
||||||
|
chat_panel.put_chat_message(SENDER_SYSTEM, "You were disconnected from the lobby {lobby_id}.".format({
|
||||||
|
"lobby_id": _lobby_id,
|
||||||
|
}))
|
||||||
|
|
||||||
|
# Reset saved data about lobby and client
|
||||||
|
_lobby_id = ""
|
||||||
|
_client_id = ""
|
||||||
|
_client_name = ""
|
||||||
|
|
||||||
func _on_chat_panel_message_sent(message: String) -> void:
|
func _on_chat_panel_message_sent(message: String) -> void:
|
||||||
_send_message(TCPMessages.send_chat_message(_lobby_id, _client_id, message))
|
_send_message(PeerMessages.send_chat_message(_lobby_id, _client_id, message))
|
||||||
|
|||||||
@@ -76,9 +76,6 @@ func _on_web_client_tcp_client_order_received(client_ids: Array[String], client_
|
|||||||
|
|
||||||
hand_associations[client_ids[index]] = hand
|
hand_associations[client_ids[index]] = hand
|
||||||
|
|
||||||
func _on_web_client_tcp_received_client_id(client_id: String) -> void:
|
|
||||||
_own_client_id = client_id
|
|
||||||
|
|
||||||
func _on_web_client_tcp_cards_received(cards: Dictionary) -> void:
|
func _on_web_client_tcp_cards_received(cards: Dictionary) -> void:
|
||||||
for client_id in cards.keys():
|
for client_id in cards.keys():
|
||||||
var card_ids: Array[int]
|
var card_ids: Array[int]
|
||||||
@@ -139,3 +136,6 @@ func _on_web_client_tcp_received_end_game_request() -> void:
|
|||||||
for score_result: ScoreResult in scores:
|
for score_result: ScoreResult in scores:
|
||||||
hand_associations[score_result.client_id].display_rank(rank, score_result.score)
|
hand_associations[score_result.client_id].display_rank(rank, score_result.score)
|
||||||
rank -= 1
|
rank -= 1
|
||||||
|
|
||||||
|
func _on_web_client_connected_to_lobby(lobby_id: String, client_id: String) -> void:
|
||||||
|
_own_client_id = client_id
|
||||||
|
|||||||
@@ -369,26 +369,19 @@ script = ExtResource("8_j5wjh")
|
|||||||
playing_card_scene = ExtResource("6_eow3j")
|
playing_card_scene = ExtResource("6_eow3j")
|
||||||
|
|
||||||
[connection signal="cards_received" from="WebClient" to="EnvironmentManager" method="_on_web_client_tcp_cards_received"]
|
[connection signal="cards_received" from="WebClient" to="EnvironmentManager" method="_on_web_client_tcp_cards_received"]
|
||||||
[connection signal="client_joined_lobby" from="WebClient" to="Interface/ClientInterface" method="_on_web_client_tcp_client_joined_lobby"]
|
|
||||||
[connection signal="client_joined_lobby" from="WebClient" to="HBoxContainer/GameUI" method="_on_web_client_tcp_client_joined_lobby"]
|
|
||||||
[connection signal="client_left_lobby" from="WebClient" to="Interface/ClientInterface" method="_on_web_client_tcp_client_left_lobby"]
|
|
||||||
[connection signal="client_left_lobby" from="WebClient" to="HBoxContainer/GameUI" method="_on_web_client_tcp_client_left_lobby"]
|
|
||||||
[connection signal="client_order_received" from="WebClient" to="EnvironmentManager" method="_on_web_client_tcp_client_order_received"]
|
[connection signal="client_order_received" from="WebClient" to="EnvironmentManager" method="_on_web_client_tcp_client_order_received"]
|
||||||
[connection signal="connected_to_lobby" from="WebClient" to="Interface/ClientInterface" method="_on_web_client_tcp_connected_to_lobby"]
|
[connection signal="connected_clients_changed" from="WebClient" to="Interface/ClientInterface" method="_on_web_client_connected_clients_changed"]
|
||||||
[connection signal="connected_to_server" from="WebClient" to="Interface/ClientInterface" method="_on_web_client_tcp_connected_to_server"]
|
[connection signal="connected_clients_changed" from="WebClient" to="HBoxContainer/GameUI" method="_on_web_client_connected_clients_changed"]
|
||||||
[connection signal="connection_error_occurred" from="WebClient" to="Interface/ClientInterface" method="_on_web_client_tcp_connection_error_occurred"]
|
[connection signal="connected_to_lobby" from="WebClient" to="Interface/ClientInterface" method="_on_web_client_connected_to_lobby"]
|
||||||
|
[connection signal="connected_to_lobby" from="WebClient" to="EnvironmentManager" method="_on_web_client_connected_to_lobby"]
|
||||||
[connection signal="connection_status_changed" from="WebClient" to="Interface/ClientInterface" method="_on_web_client_tcp_connection_status_changed"]
|
[connection signal="connection_status_changed" from="WebClient" to="Interface/ClientInterface" method="_on_web_client_tcp_connection_status_changed"]
|
||||||
[connection signal="connection_status_changed" from="WebClient" to="Interface/ChatPanel" method="_on_web_client_connection_status_changed"]
|
[connection signal="connection_status_changed" from="WebClient" to="Interface/ChatPanel" method="_on_web_client_connection_status_changed"]
|
||||||
[connection signal="connection_status_changed" from="WebClient" to="Interface/ConnectionOverlay" method="_on_web_client_connection_status_changed"]
|
[connection signal="connection_status_changed" from="WebClient" to="Interface/ConnectionOverlay" method="_on_web_client_connection_status_changed"]
|
||||||
[connection signal="disconnected_from_lobby" from="WebClient" to="Interface/ClientInterface" method="_on_web_client_tcp_disconnected_from_lobby"]
|
|
||||||
[connection signal="disconnected_from_server" from="WebClient" to="Interface/ClientInterface" method="_on_web_client_tcp_disconnected_from_server"]
|
|
||||||
[connection signal="new_round_started" from="WebClient" to="EnvironmentManager" method="_on_web_client_tcp_new_round_started"]
|
[connection signal="new_round_started" from="WebClient" to="EnvironmentManager" method="_on_web_client_tcp_new_round_started"]
|
||||||
[connection signal="notify_play_card_request" from="WebClient" to="HBoxContainer/GameUI" method="_on_web_client_tcp_notify_play_card_request"]
|
[connection signal="notify_play_card_request" from="WebClient" to="HBoxContainer/GameUI" method="_on_web_client_tcp_notify_play_card_request"]
|
||||||
[connection signal="received_bet_request" from="WebClient" to="HBoxContainer/GameUI" method="_on_web_client_tcp_received_bet_request"]
|
[connection signal="received_bet_request" from="WebClient" to="HBoxContainer/GameUI" method="_on_web_client_tcp_received_bet_request"]
|
||||||
[connection signal="received_bet_request" from="WebClient" to="HBoxContainer/GameUI/BetContainer/BetInput" method="_on_web_client_tcp_received_bet_request"]
|
[connection signal="received_bet_request" from="WebClient" to="HBoxContainer/GameUI/BetContainer/BetInput" method="_on_web_client_tcp_received_bet_request"]
|
||||||
[connection signal="received_chat_message" from="WebClient" to="Interface/ClientInterface" method="_on_web_client_tcp_received_chat_message"]
|
[connection signal="received_chat_message" from="WebClient" to="Interface/ClientInterface" method="_on_web_client_tcp_received_chat_message"]
|
||||||
[connection signal="received_client_id" from="WebClient" to="EnvironmentManager" method="_on_web_client_tcp_received_client_id"]
|
|
||||||
[connection signal="received_connection_message" from="WebClient" to="Interface/ClientInterface" method="_on_web_client_tcp_received_connection_message"]
|
|
||||||
[connection signal="received_end_game_request" from="WebClient" to="EnvironmentManager" method="_on_web_client_tcp_received_end_game_request"]
|
[connection signal="received_end_game_request" from="WebClient" to="EnvironmentManager" method="_on_web_client_tcp_received_end_game_request"]
|
||||||
[connection signal="received_expected_bet" from="WebClient" to="EnvironmentManager" method="_on_web_client_tcp_received_expected_bet"]
|
[connection signal="received_expected_bet" from="WebClient" to="EnvironmentManager" method="_on_web_client_tcp_received_expected_bet"]
|
||||||
[connection signal="received_first_card" from="WebClient" to="EnvironmentManager/PlayerHand0" method="_on_web_client_tcp_received_first_card"]
|
[connection signal="received_first_card" from="WebClient" to="EnvironmentManager/PlayerHand0" method="_on_web_client_tcp_received_first_card"]
|
||||||
|
|||||||
+4
-6
@@ -69,12 +69,6 @@ func _set_current_round(round: int) -> void:
|
|||||||
_current_round = round
|
_current_round = round
|
||||||
round_label.text = str(_current_round)
|
round_label.text = str(_current_round)
|
||||||
|
|
||||||
func _on_web_client_tcp_client_joined_lobby(client_name: String, connected_client_names: Array[String]) -> void:
|
|
||||||
_update_player_count(connected_client_names.size())
|
|
||||||
|
|
||||||
func _on_web_client_tcp_client_left_lobby(client_name: String, connected_client_names: Array[String]) -> void:
|
|
||||||
_update_player_count(connected_client_names.size())
|
|
||||||
|
|
||||||
func _on_player_hand_card_selected(card_id: int) -> void:
|
func _on_player_hand_card_selected(card_id: int) -> void:
|
||||||
play_card_button.disabled = card_id == -1
|
play_card_button.disabled = card_id == -1
|
||||||
|
|
||||||
@@ -106,3 +100,7 @@ func _on_web_client_tcp_received_win() -> void:
|
|||||||
|
|
||||||
func _on_web_client_tcp_request_next_play() -> void:
|
func _on_web_client_tcp_request_next_play() -> void:
|
||||||
_start_next_play()
|
_start_next_play()
|
||||||
|
|
||||||
|
|
||||||
|
func _on_web_client_connected_clients_changed(connected_client_names: Array[String]) -> void:
|
||||||
|
_update_player_count(connected_client_names.size())
|
||||||
|
|||||||
@@ -0,0 +1,85 @@
|
|||||||
|
extends Node
|
||||||
|
|
||||||
|
func create_lobby(
|
||||||
|
client_name: String,
|
||||||
|
) -> String:
|
||||||
|
return JSON.stringify({
|
||||||
|
"response": "create_lobby",
|
||||||
|
"client_name": client_name,
|
||||||
|
})
|
||||||
|
|
||||||
|
func join_lobby(
|
||||||
|
lobby_id: String,
|
||||||
|
client_name: String,
|
||||||
|
) -> String:
|
||||||
|
return JSON.stringify({
|
||||||
|
"response": "join_lobby",
|
||||||
|
"lobby_id": lobby_id,
|
||||||
|
"client_name": client_name,
|
||||||
|
})
|
||||||
|
|
||||||
|
func leave_lobby(
|
||||||
|
lobby_id: String,
|
||||||
|
client_id: String,
|
||||||
|
) -> String:
|
||||||
|
return JSON.stringify({
|
||||||
|
"response": "leave_lobby",
|
||||||
|
"lobby_id": lobby_id,
|
||||||
|
"client_id": client_id,
|
||||||
|
})
|
||||||
|
|
||||||
|
func start_game(
|
||||||
|
lobby_id: String,
|
||||||
|
) -> String:
|
||||||
|
return JSON.stringify({
|
||||||
|
"response": "start_game",
|
||||||
|
"lobby_id": lobby_id,
|
||||||
|
})
|
||||||
|
|
||||||
|
func submit_bet(
|
||||||
|
lobby_id: String,
|
||||||
|
client_id: String,
|
||||||
|
bet: int,
|
||||||
|
) -> String:
|
||||||
|
return JSON.stringify({
|
||||||
|
"response": "submit_bet",
|
||||||
|
"lobby_id": lobby_id,
|
||||||
|
"client_id": client_id,
|
||||||
|
"bet": bet,
|
||||||
|
})
|
||||||
|
|
||||||
|
func submit_card(
|
||||||
|
lobby_id: String,
|
||||||
|
client_id: String,
|
||||||
|
card_id: int,
|
||||||
|
) -> String:
|
||||||
|
return JSON.stringify({
|
||||||
|
"response": "submit_bet",
|
||||||
|
"lobby_id": lobby_id,
|
||||||
|
"client_id": client_id,
|
||||||
|
"card_id": card_id,
|
||||||
|
})
|
||||||
|
|
||||||
|
func submit_take_winner(
|
||||||
|
lobby_id: String,
|
||||||
|
client_id: String,
|
||||||
|
winner_client_id,
|
||||||
|
) -> String:
|
||||||
|
return JSON.stringify({
|
||||||
|
"response": "submit_bet",
|
||||||
|
"lobby_id": lobby_id,
|
||||||
|
"client_id": client_id,
|
||||||
|
"winner_client_id": winner_client_id,
|
||||||
|
})
|
||||||
|
|
||||||
|
func send_chat_message(
|
||||||
|
lobby_id: String,
|
||||||
|
client_id: String,
|
||||||
|
message: String,
|
||||||
|
) -> String:
|
||||||
|
return JSON.stringify({
|
||||||
|
"response": "send_chat_message",
|
||||||
|
"lobby_id": lobby_id,
|
||||||
|
"client_id": client_id,
|
||||||
|
"message": message,
|
||||||
|
})
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
uid://do1kihnsu3gty
|
||||||
@@ -19,6 +19,7 @@ config/icon="res://icon.svg"
|
|||||||
|
|
||||||
TCPMessages="*res://globals/tcp_messages.gd"
|
TCPMessages="*res://globals/tcp_messages.gd"
|
||||||
CardManager="*res://cards/card_manager.tscn"
|
CardManager="*res://cards/card_manager.tscn"
|
||||||
|
PeerMessages="*res://globals/peer_messages.gd"
|
||||||
|
|
||||||
[display]
|
[display]
|
||||||
|
|
||||||
|
|||||||
+5
-6
@@ -69,9 +69,9 @@ class LobbyManager:
|
|||||||
await self.broadcast_message(
|
await self.broadcast_message(
|
||||||
lobby_id,
|
lobby_id,
|
||||||
json.dumps({
|
json.dumps({
|
||||||
"response": "client_joined_lobby",
|
"response": "joined_lobby",
|
||||||
"new_client_id": client_id,
|
"client_id": client_id,
|
||||||
"new_client_name": client_name,
|
"client_name": client_name,
|
||||||
"connected_client_ids": self.get_lobby_client_ids(lobby_id),
|
"connected_client_ids": self.get_lobby_client_ids(lobby_id),
|
||||||
"connected_client_names": self.get_lobby_client_names(lobby_id),
|
"connected_client_names": self.get_lobby_client_names(lobby_id),
|
||||||
})
|
})
|
||||||
@@ -92,7 +92,7 @@ class LobbyManager:
|
|||||||
await self.broadcast_message(
|
await self.broadcast_message(
|
||||||
lobby_id,
|
lobby_id,
|
||||||
json.dumps({
|
json.dumps({
|
||||||
"response": "client_left_lobby",
|
"response": "left_lobby",
|
||||||
"status": "ok",
|
"status": "ok",
|
||||||
"client_name": client_name,
|
"client_name": client_name,
|
||||||
"connected_client_ids": self.get_lobby_client_ids(lobby_id),
|
"connected_client_ids": self.get_lobby_client_ids(lobby_id),
|
||||||
@@ -302,8 +302,7 @@ async def process_input(message: str, websocket) -> None:
|
|||||||
new_lobby_id,
|
new_lobby_id,
|
||||||
new_client_id,
|
new_client_id,
|
||||||
json.dumps({
|
json.dumps({
|
||||||
"response": "create_lobby",
|
"response": "created_lobby",
|
||||||
"status": "ok",
|
|
||||||
"lobby_id": new_lobby_id,
|
"lobby_id": new_lobby_id,
|
||||||
"client_id": new_client_id,
|
"client_id": new_client_id,
|
||||||
}),
|
}),
|
||||||
|
|||||||
Reference in New Issue
Block a user