commit 32ca25cdf7882605df861859bfa2c5fc80a1f687 (patch)
parent adbd90abeb0d586260e6df5a80bbe77782bfacba
Author: Alex Karle <alex@karle.co>
Date: Tue, 14 Apr 2020 21:02:20 -0400
Euchre::Game: Add hand_lengths to broadcasted gamestate
As requested per ~ckarle, this will be useful for rendering opponent
hands.
It COULD be calculated by a motivated client library, but it's easist
for the server to calculate it itself.
Diffstat:
2 files changed, 7 insertions(+), 0 deletions(-)
diff --git a/lib/Euchre/Dealer.pm b/lib/Euchre/Dealer.pm
@@ -434,10 +434,16 @@ sub broadcast_gamestate {
# Translate to human readable names for clients
my @pnames = map { defined($_) ? $_->{name} : 'Empty' } @{$game->{players}};
my @snames = map { $_->{name} } @{$game->{spectators}};
+
+ # Hand lengths are nice for rendering in the clients
+ my @hand_lengths =
+ map { defined($_) ? scalar @{$_->{hand}} : 0 } @{$game->{players}};
+
my $msg = {
%$game,
players => \@pnames,
spectators => \@snames,
+ hand_lengths => \@hand_lengths,
};
for my $p (@{$game->{players}}, @{$game->{spectators}}) {
diff --git a/public/debug.html b/public/debug.html
@@ -26,6 +26,7 @@
'Dealer: ' + msg.game.dealer + '<br>' +
'Trump: ' + msg.game.trump + '<br>' +
'Tricks: ' + msg.game.tricks + '<br>' +
+ 'Hand Lengths: ' + msg.game.hand_lengths + '<br>' +
'Score: ' + msg.game.score + '<br>'
if (typeof msg.game.trump_nominee !== 'undefined') {