From 32ca25cdf7882605df861859bfa2c5fc80a1f687 Mon Sep 17 00:00:00 2001 From: Alex Karle Date: Tue, 14 Apr 2020 21:02:20 -0400 Subject: [PATCH] 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. --- lib/Euchre/Dealer.pm | 6 ++++++ public/debug.html | 1 + 2 files changed, 7 insertions(+) diff --git a/lib/Euchre/Dealer.pm b/lib/Euchre/Dealer.pm index c72a7cf..52822d2 100644 --- 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 index 1d956b8..3592ae8 100644 --- a/public/debug.html +++ b/public/debug.html @@ -26,6 +26,7 @@ 'Dealer: ' + msg.game.dealer + '
' + 'Trump: ' + msg.game.trump + '
' + 'Tricks: ' + msg.game.tricks + '
' + + 'Hand Lengths: ' + msg.game.hand_lengths + '
' + 'Score: ' + msg.game.score + '
' if (typeof msg.game.trump_nominee !== 'undefined') { -- libgit2 1.1.1