From 206a934d2d7db825a9597a060e3e7e7a4d531e8d Mon Sep 17 00:00:00 2001 From: Sergiotarxz Date: Wed, 12 Jul 2023 18:54:21 +0200 Subject: [PATCH] Adding to the Info packet known_words. --- .../Controller/Websocket/OutputPacket/Info.pm | 13 +++++++++---- lib/LasTres/Schema/Result/PJ.pm | 7 +++++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/LasTres/Controller/Websocket/OutputPacket/Info.pm b/lib/LasTres/Controller/Websocket/OutputPacket/Info.pm index c2542ae..7080dc0 100644 --- a/lib/LasTres/Controller/Websocket/OutputPacket/Info.pm +++ b/lib/LasTres/Controller/Websocket/OutputPacket/Info.pm @@ -27,7 +27,8 @@ has is_battling => ( is => 'rw' ); has remaining_frames => ( is => 'rw' ); has available_actions => ( is => 'rw' ); -has npcs => ( is => 'rw' ); +has npcs => ( is => 'rw' ); +has known_words => ( is => 'rw' ); sub identifier { return 'info'; @@ -43,12 +44,17 @@ sub data ($self) { my $remaining_frames = $self->remaining_frames; my $is_battling = $self->is_battling; my $available_actions = $self->available_actions; - my $npcs = $self->npcs; + my $npcs = $self->npcs; + my $known_words = $self->known_words; if ( defined $is_battling ) { $is_battling = $is_battling ? $JSON::true : $JSON::false; } return { + ( + ( defined $known_words ) ? ( known_words => $known_words ) + : () + ), ( ( defined $clear ) ? ( clear => $clear ) : () @@ -85,8 +91,7 @@ sub data ($self) { : () ), ( - (defined $npcs) - ? ( npcs => $npcs) + ( defined $npcs ) ? ( npcs => $npcs ) : () ) }; diff --git a/lib/LasTres/Schema/Result/PJ.pm b/lib/LasTres/Schema/Result/PJ.pm index 6b8ddb1..21b181e 100644 --- a/lib/LasTres/Schema/Result/PJ.pm +++ b/lib/LasTres/Schema/Result/PJ.pm @@ -18,6 +18,8 @@ use JSON qw/to_json/; use Moo; +use LasTres::Words; + __PACKAGE__->table('player_pjs'); __PACKAGE__->add_columns( @@ -157,9 +159,10 @@ sub known_words_hash ($self) { } sub known_words_hash_serialized ($self) { - my %words = %{$self->known_words_hash}; + my %words = %{ $self->known_words_hash }; my @identifiers = keys %words; - %words = map { ($_->identifier => $_->serialize) } @identifiers; + %words = + map { ( $words{$_}->identifier => $words{$_}->serialize ) } @identifiers; return \%words; }