diff --git a/components/web_client_tcp.gd b/components/web_client_tcp.gd index fb95c83..cb052e4 100644 --- a/components/web_client_tcp.gd +++ b/components/web_client_tcp.gd @@ -41,6 +41,9 @@ signal cards_received(cards: Dictionary) signal received_bet_request(disallowed_bet: int) +signal received_play_winner_request() +signal request_next_round() + enum ConnectionStatus { DISCONNECTED, ATTEMPTING_CONNECTION, @@ -142,6 +145,10 @@ func _handle_response(response: String) -> void: print(data) "play_card": print(data) + "determine_play_winner_request": # single card go-around + received_play_winner_request.emit.call_deferred() + "client_won_play": + print(data) func _handle_join(data) -> void: match data["status"]: @@ -219,5 +226,13 @@ func submit_bet(bet: int, current_round: int) -> void: "bet": bet, })) +func submit_round_winner(winning_client_id: String) -> void: + _send_message(JSON.stringify({ + "response": "submit_play_winner", + "lobby_id": _lobby_id, + "client_id": winning_client_id, + })) + request_next_round.emit.call_deferred() + func _send_message(message: String) -> void: _socket.send_text(message) diff --git a/game.tscn b/game.tscn index 7c59dbf..b772db2 100644 --- a/game.tscn +++ b/game.tscn @@ -255,6 +255,7 @@ transform = Transform3D(-0.5, 0, 0.866025, 0, 1, 0, -0.866025, 0, -0.5, 3.2, 0.4 [connection signal="received_chat_message" from="WebClientTCP" to="HBoxContainer/ClientInterface" method="_on_web_client_tcp_received_chat_message"] [connection signal="received_client_id" from="WebClientTCP" to="EnvironmentManager" method="_on_web_client_tcp_received_client_id"] [connection signal="received_connection_message" from="WebClientTCP" to="HBoxContainer/ClientInterface" method="_on_web_client_tcp_received_connection_message"] +[connection signal="request_next_round" from="WebClientTCP" to="HBoxContainer/GameUI" method="_on_web_client_tcp_request_next_round"] [connection signal="pressed" from="HBoxContainer/ClientInterface/MarginContainer/VBoxContainer/ServerInputs/ConnectButton" to="HBoxContainer/ClientInterface" method="_on_connect_button_pressed"] [connection signal="pressed" from="HBoxContainer/ClientInterface/MarginContainer/VBoxContainer/ServerInputs/CreateLobbyButton" to="HBoxContainer/ClientInterface" method="_on_create_lobby_button_pressed"] [connection signal="pressed" from="HBoxContainer/ClientInterface/MarginContainer/VBoxContainer/ServerInputs/CreateLobbyButton" to="HBoxContainer/GameUI" method="_on_create_lobby_button_pressed"] diff --git a/game_client.gd b/game_client.gd index f3f8916..536d99f 100644 --- a/game_client.gd +++ b/game_client.gd @@ -64,3 +64,6 @@ func _on_submit_bet_button_pressed() -> void: func _on_web_client_tcp_received_bet_request(disallowed_bet: int) -> void: bet_input.text = "" bet_container.show() + +func _on_web_client_tcp_request_next_round() -> void: + _start_next_round() diff --git a/server_tcp.py b/server_tcp.py index 6e24033..7380c0a 100644 --- a/server_tcp.py +++ b/server_tcp.py @@ -211,7 +211,7 @@ class LobbyManager: "response": "client_submitted_bet", "client_id": client_id, "bet": bet, - }) + }), ) async def spread_played_card(self, lobby_id, client_id, played_card) -> None: @@ -221,7 +221,16 @@ class LobbyManager: "response": "client_played_card", "client_id": client_id, "card": played_card, - }) + }), + ) + + async def spread_play_winner(self, lobby_id, client_id) -> None: + await self.broadcast_message( + lobby_id, + json.dumps({ + "response": "client_won_play", + "client_id": client_id, + }), ) def get_next_client(self, lobby_id, client_id) -> str: @@ -489,10 +498,20 @@ async def process_input(message: str, websocket) -> None: client_id, data_object["played_card"], ) - - client_index = lobby_manager.get_lobby(lobby_id).client_playing_order.index(client_id) - if not client_index == (len(lobby_manager.get_lobby(lobby_id).client_playing_order) - 1): - playing_client_id = lobby_manager.get_lobby(lobby_id).client_playing_order[client_index + 1] + playing_order = lobby_manager.get_lobby(lobby_id).client_playing_order + client_index = playing_order.index(client_id) + if client_index == (len(playing_order) - 1): + # end round + await lobby_manager.send_message( + lobby_id, + lobby_manager.get_lobby_host_client_id(lobby_id), + json.dumps({ + "response": "determine_round_winner_request", + }) + ) + else: + # not all clients have played a card yet; continue + playing_client_id = playing_order[client_index + 1] await lobby_manager.send_message( lobby_id, @@ -501,6 +520,12 @@ async def process_input(message: str, websocket) -> None: "response": "request_card", }), ) + + elif data_object["response"] == "submit_play_winner": + await lobby_manager.spread_play_winner( + data_object["lobby_id"], + data_object["client_id"], + ) if __name__ == '__main__': run_local = False