clients now keep track of expected and actual bets for every client
This commit is contained in:
@@ -0,0 +1,24 @@
|
|||||||
|
class_name BetResult
|
||||||
|
extends Resource
|
||||||
|
|
||||||
|
@export var expected: int = 0
|
||||||
|
@export var actual: int = 0
|
||||||
|
|
||||||
|
func _init(
|
||||||
|
expected: int = 0,
|
||||||
|
actual: int = 0,
|
||||||
|
) -> void:
|
||||||
|
self.expected = expected
|
||||||
|
self.actual = actual
|
||||||
|
|
||||||
|
func set_expected(value: int) -> void:
|
||||||
|
self.expected = value
|
||||||
|
|
||||||
|
func add_win() -> void:
|
||||||
|
self.actual += 1
|
||||||
|
|
||||||
|
func _to_string() -> String:
|
||||||
|
return "BetResult(expected: {e}, actual: {a})".format({
|
||||||
|
"e": expected,
|
||||||
|
"a": actual,
|
||||||
|
})
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
uid://c82xeik4pxj57
|
||||||
@@ -38,10 +38,14 @@ signal connection_status_changed(new_status: ConnectionStatus)
|
|||||||
|
|
||||||
# This signal is messy as fuck
|
# This signal is messy as fuck
|
||||||
signal client_order_received(client_ids: Array[String], client_ids_playing_order: Array[String], client_names: Array[String])
|
signal client_order_received(client_ids: Array[String], client_ids_playing_order: Array[String], client_names: Array[String])
|
||||||
|
|
||||||
|
signal received_expected_bet(client_id: String, expected_bet: int)
|
||||||
|
signal new_round_started()
|
||||||
signal cards_received(cards: Dictionary)
|
signal cards_received(cards: Dictionary)
|
||||||
signal trump_received(trump_id: int)
|
signal trump_received(trump_id: int)
|
||||||
signal received_bet_request(disallowed_bet: int)
|
signal received_bet_request(disallowed_bet: int)
|
||||||
signal received_win()
|
signal received_win()
|
||||||
|
signal received_winning_client(client_id: String)
|
||||||
signal notify_play_card_request()
|
signal notify_play_card_request()
|
||||||
signal received_played_card(client_id: String, card_id: int)
|
signal received_played_card(client_id: String, card_id: int)
|
||||||
signal received_play_winner_request()
|
signal received_play_winner_request()
|
||||||
@@ -130,18 +134,20 @@ func _handle_response(response: String) -> void:
|
|||||||
received_chat_message.emit.call_deferred(data["client_name"], data["message"])
|
received_chat_message.emit.call_deferred(data["client_name"], data["message"])
|
||||||
|
|
||||||
"new_round_started":
|
"new_round_started":
|
||||||
#print(data)
|
|
||||||
if data["current_round"] == 1:
|
if data["current_round"] == 1:
|
||||||
var playing_order: Array[String] = []
|
var playing_order: Array[String] = []
|
||||||
playing_order.assign(data["playing_order"])
|
playing_order.assign(data["playing_order"])
|
||||||
client_order_received.emit.call_deferred(playing_order, _connected_client_ids, _connected_client_names)
|
client_order_received.emit.call_deferred(playing_order, _connected_client_ids, _connected_client_names)
|
||||||
|
|
||||||
var received_cards = data["cards"]
|
var received_cards = data["cards"]
|
||||||
#print(received_cards)
|
new_round_started.emit.call_deferred()
|
||||||
cards_received.emit.call_deferred(received_cards)
|
cards_received.emit.call_deferred(received_cards)
|
||||||
trump_received.emit.call_deferred(data["trump"])
|
trump_received.emit.call_deferred(data["trump"])
|
||||||
"client_submitted_bet":
|
"client_submitted_bet":
|
||||||
print(data)
|
received_expected_bet.emit.call_deferred(
|
||||||
|
data["client_id"],
|
||||||
|
data["bet"],
|
||||||
|
)
|
||||||
"request_bet":
|
"request_bet":
|
||||||
received_bet_request.emit.call_deferred(data["disallowed_bet"])
|
received_bet_request.emit.call_deferred(data["disallowed_bet"])
|
||||||
"begin_playing_cards":
|
"begin_playing_cards":
|
||||||
@@ -159,6 +165,7 @@ func _handle_response(response: String) -> void:
|
|||||||
"client_won_play":
|
"client_won_play":
|
||||||
if data["client_id"] == _client_id:
|
if data["client_id"] == _client_id:
|
||||||
received_win.emit.call_deferred()
|
received_win.emit.call_deferred()
|
||||||
|
received_winning_client.emit.call_deferred(data["client_id"])
|
||||||
|
|
||||||
func _handle_join(data) -> void:
|
func _handle_join(data) -> void:
|
||||||
match data["status"]:
|
match data["status"]:
|
||||||
|
|||||||
@@ -27,6 +27,8 @@ var _own_client_id: String
|
|||||||
@export var player_hand_scene: PackedScene
|
@export var player_hand_scene: PackedScene
|
||||||
@export var card_scene: PackedScene
|
@export var card_scene: PackedScene
|
||||||
|
|
||||||
|
var _bets: Dictionary[String, Array] # Array[BetResult]
|
||||||
|
|
||||||
## Cards played in the current play.
|
## Cards played in the current play.
|
||||||
var _plays: Array[Play]
|
var _plays: Array[Play]
|
||||||
var _trump_id: int = -1
|
var _trump_id: int = -1
|
||||||
@@ -64,6 +66,7 @@ func _on_web_client_tcp_client_order_received(client_ids: Array[String], client_
|
|||||||
new_ids.append_array(client_ids.slice(0, own_index))
|
new_ids.append_array(client_ids.slice(0, own_index))
|
||||||
|
|
||||||
for index in new_ids.size():
|
for index in new_ids.size():
|
||||||
|
_bets[new_ids[index]] = []
|
||||||
var hand: PlayerHand
|
var hand: PlayerHand
|
||||||
if client_ids[index] == _own_client_id:
|
if client_ids[index] == _own_client_id:
|
||||||
hand = own_player_hand
|
hand = own_player_hand
|
||||||
@@ -108,3 +111,15 @@ func _on_web_client_tcp_trump_received(trump_id: int) -> void:
|
|||||||
var trump_card: PlayingCard = card_scene.instantiate()
|
var trump_card: PlayingCard = card_scene.instantiate()
|
||||||
trump_card.setup_card_details(_trump_id)
|
trump_card.setup_card_details(_trump_id)
|
||||||
trump_container.add_child(trump_card)
|
trump_container.add_child(trump_card)
|
||||||
|
|
||||||
|
func _on_web_client_tcp_new_round_started() -> void:
|
||||||
|
# prepare a fresh BetResults bunch for the new round! the clients are hungry.
|
||||||
|
for client_id in _bets.keys():
|
||||||
|
_bets[client_id].append(BetResult.new())
|
||||||
|
|
||||||
|
func _on_web_client_tcp_received_expected_bet(client_id: String, expected_bet: int) -> void:
|
||||||
|
_bets[client_id][_bets[client_id].size() - 1].set_expected(expected_bet)
|
||||||
|
|
||||||
|
func _on_web_client_tcp_received_winning_client(client_id: String) -> void:
|
||||||
|
_bets[client_id][_bets[client_id].size() - 1].add_win()
|
||||||
|
print(_bets)
|
||||||
|
|||||||
@@ -287,14 +287,17 @@ transform = Transform3D(0.957037, -0.289967, -1.26749e-08, 1.48302e-15, -4.37114
|
|||||||
[connection signal="connection_status_changed" from="WebClientTCP" to="HBoxContainer/ClientInterface" method="_on_web_client_tcp_connection_status_changed"]
|
[connection signal="connection_status_changed" from="WebClientTCP" to="HBoxContainer/ClientInterface" method="_on_web_client_tcp_connection_status_changed"]
|
||||||
[connection signal="disconnected_from_lobby" from="WebClientTCP" to="HBoxContainer/ClientInterface" method="_on_web_client_tcp_disconnected_from_lobby"]
|
[connection signal="disconnected_from_lobby" from="WebClientTCP" to="HBoxContainer/ClientInterface" method="_on_web_client_tcp_disconnected_from_lobby"]
|
||||||
[connection signal="disconnected_from_server" from="WebClientTCP" to="HBoxContainer/ClientInterface" method="_on_web_client_tcp_disconnected_from_server"]
|
[connection signal="disconnected_from_server" from="WebClientTCP" to="HBoxContainer/ClientInterface" method="_on_web_client_tcp_disconnected_from_server"]
|
||||||
|
[connection signal="new_round_started" from="WebClientTCP" to="EnvironmentManager" method="_on_web_client_tcp_new_round_started"]
|
||||||
[connection signal="notify_play_card_request" from="WebClientTCP" to="HBoxContainer/GameUI" method="_on_web_client_tcp_notify_play_card_request"]
|
[connection signal="notify_play_card_request" from="WebClientTCP" to="HBoxContainer/GameUI" method="_on_web_client_tcp_notify_play_card_request"]
|
||||||
[connection signal="received_bet_request" from="WebClientTCP" to="HBoxContainer/GameUI" method="_on_web_client_tcp_received_bet_request"]
|
[connection signal="received_bet_request" from="WebClientTCP" to="HBoxContainer/GameUI" method="_on_web_client_tcp_received_bet_request"]
|
||||||
[connection signal="received_chat_message" from="WebClientTCP" to="HBoxContainer/ClientInterface" method="_on_web_client_tcp_received_chat_message"]
|
[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_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="received_connection_message" from="WebClientTCP" to="HBoxContainer/ClientInterface" method="_on_web_client_tcp_received_connection_message"]
|
||||||
|
[connection signal="received_expected_bet" from="WebClientTCP" to="EnvironmentManager" method="_on_web_client_tcp_received_expected_bet"]
|
||||||
[connection signal="received_play_winner_request" from="WebClientTCP" to="EnvironmentManager" method="_on_web_client_tcp_received_play_winner_request"]
|
[connection signal="received_play_winner_request" from="WebClientTCP" to="EnvironmentManager" method="_on_web_client_tcp_received_play_winner_request"]
|
||||||
[connection signal="received_played_card" from="WebClientTCP" to="EnvironmentManager" method="_on_web_client_tcp_received_played_card"]
|
[connection signal="received_played_card" from="WebClientTCP" to="EnvironmentManager" method="_on_web_client_tcp_received_played_card"]
|
||||||
[connection signal="received_win" from="WebClientTCP" to="HBoxContainer/GameUI" method="_on_web_client_tcp_received_win"]
|
[connection signal="received_win" from="WebClientTCP" to="HBoxContainer/GameUI" method="_on_web_client_tcp_received_win"]
|
||||||
|
[connection signal="received_winning_client" from="WebClientTCP" to="EnvironmentManager" method="_on_web_client_tcp_received_winning_client"]
|
||||||
[connection signal="request_next_play" from="WebClientTCP" to="HBoxContainer/GameUI" method="_on_web_client_tcp_request_next_play"]
|
[connection signal="request_next_play" from="WebClientTCP" to="HBoxContainer/GameUI" method="_on_web_client_tcp_request_next_play"]
|
||||||
[connection signal="request_next_round" from="WebClientTCP" to="HBoxContainer/GameUI" method="_on_web_client_tcp_request_next_round"]
|
[connection signal="request_next_round" from="WebClientTCP" to="HBoxContainer/GameUI" method="_on_web_client_tcp_request_next_round"]
|
||||||
[connection signal="trump_received" from="WebClientTCP" to="EnvironmentManager" method="_on_web_client_tcp_trump_received"]
|
[connection signal="trump_received" from="WebClientTCP" to="EnvironmentManager" method="_on_web_client_tcp_trump_received"]
|
||||||
|
|||||||
Reference in New Issue
Block a user