LasTres/lib/LasTres/PJAction.pm

70 lines
1.8 KiB
Perl

package LasTres::PJAction;
use v5.36.0;
use strict;
use warnings;
use feature 'signatures';
use JSON qw/to_json from_json/;
use Moo::Role;
requires( 'identifier', 'callback', 'name' );
## IMPLEMENTORS MUST IMPLEMENT
#
# sub callback($self, $pj);
# What to do when this action is invoked by the PJ.
#
# sub identifier;
# The unique identifier of this action in the game.
#
# sub name($self, $pj);
# The name of the action, possibly variable for diferent PJs.
## OVERRIDE
# This should be a square icon, ideally of 400x400px
# If not set the frontend should attempt to show the
# action with as much dignity as possible.
#
# Should return undef or a string that is a absolute url
# to the resource.
sub icon ( $self, $pj ) {
return undef;
}
## OVERRIDE
# This function is called when a user is supposed
# to see that something is possible to be done, but they cannot because
# some prerequisite is missing.
# If you do not want the possible action to be showed do not list it,
# do not use this function in this case.
#
# Should return a true or falsy value that is not undef.
sub is_disabled ( $self, $pj ) {
return 0;
}
## OVERRIDE
# This function should return a text explanation about why
# the pj cannot use this action but they still see it as
# something possible to be done.
#
# Should return undef if the pj can do the action and a string
# with the reason otherwise.
sub disabled_reason ( $self, $pj ) {
return undef;
}
## DO NOT EXTEND NOT SUPPORTED.
sub hash ( $self, $pj ) {
return {
identifier => $self->identifier,
icon => $self->icon($pj),
name => $self->name($pj),
is_disabled => $self->is_disabled($pj) ? $JSON::true : $JSON::false,
disabled_reason => $self->disabled_reason($pj),
};
}
1;