Adding to the Info packet known_words.

This commit is contained in:
Sergiotarxz 2023-07-12 18:54:21 +02:00
parent f43070ffee
commit 206a934d2d
2 changed files with 14 additions and 6 deletions

View File

@ -27,7 +27,8 @@ has is_battling => ( is => 'rw' );
has remaining_frames => ( is => 'rw' ); has remaining_frames => ( is => 'rw' );
has available_actions => ( is => 'rw' ); has available_actions => ( is => 'rw' );
has npcs => ( is => 'rw' ); has npcs => ( is => 'rw' );
has known_words => ( is => 'rw' );
sub identifier { sub identifier {
return 'info'; return 'info';
@ -43,12 +44,17 @@ sub data ($self) {
my $remaining_frames = $self->remaining_frames; my $remaining_frames = $self->remaining_frames;
my $is_battling = $self->is_battling; my $is_battling = $self->is_battling;
my $available_actions = $self->available_actions; my $available_actions = $self->available_actions;
my $npcs = $self->npcs; my $npcs = $self->npcs;
my $known_words = $self->known_words;
if ( defined $is_battling ) { if ( defined $is_battling ) {
$is_battling = $is_battling ? $JSON::true : $JSON::false; $is_battling = $is_battling ? $JSON::true : $JSON::false;
} }
return { return {
(
( defined $known_words ) ? ( known_words => $known_words )
: ()
),
( (
( defined $clear ) ? ( clear => $clear ) ( defined $clear ) ? ( clear => $clear )
: () : ()
@ -85,8 +91,7 @@ sub data ($self) {
: () : ()
), ),
( (
(defined $npcs) ( defined $npcs ) ? ( npcs => $npcs )
? ( npcs => $npcs)
: () : ()
) )
}; };

View File

@ -18,6 +18,8 @@ use JSON qw/to_json/;
use Moo; use Moo;
use LasTres::Words;
__PACKAGE__->table('player_pjs'); __PACKAGE__->table('player_pjs');
__PACKAGE__->add_columns( __PACKAGE__->add_columns(
@ -157,9 +159,10 @@ sub known_words_hash ($self) {
} }
sub known_words_hash_serialized ($self) { sub known_words_hash_serialized ($self) {
my %words = %{$self->known_words_hash}; my %words = %{ $self->known_words_hash };
my @identifiers = keys %words; my @identifiers = keys %words;
%words = map { ($_->identifier => $_->serialize) } @identifiers; %words =
map { ( $words{$_}->identifier => $words{$_}->serialize ) } @identifiers;
return \%words; return \%words;
} }