Game-CharacterSheetGenerator
view release on metacpan or search on metacpan
lib/Game/CharacterSheetGenerator.pm view on Meta::CPAN
=head1 DESCRIPTION
Character Sheet Generator is a web application that generates characters for the
Halberts & Helmets game. It does two things: it generates the stats for random
characters, and it populates a SVG file with those values.
Here's an example of the stats generated:
name: Diara
str: 11
dex: 10
con: 13
int: 10
wis: 9
cha: 7
level: 1
xp: 0
thac0: 19
class: halfling
hp: 4
ac: 6
property: backpack
property: rope
property: leather armour
property: silver dagger
property: sling
property: pouch with 30 stones
abilities: 1/6 for normal tasks
abilities: 2/6 to hide and sneak
abilities: 5/6 to hide and sneak outside
abilities: +1 for ranged weapons
abilities: AC -2 against giants
charsheet: Charaktersheet.svg
breath: 13
poison: 8
petrify: 10
wands: 9
spells: 12
Think of it as key value pairs. Some keys have multiple values, resulting in
multiline values.
The SVG file acts as a template. For every key in the character, a C<text>
element with a matching id is searched and if found, C<tspan> elements matching
the value are inserted.
The C<charsheet> key is special because it tells the app which file to load.
On a technical level, Character Sheet Generator is a web app based on the
Mojolicious framework. This class in particular uses L<Mojolicious::Lite>.
See L<Mojolicious::Guides> for more information.
=cut
package Game::CharacterSheetGenerator;
our $VERSION = 1.03;
use Modern::Perl;
use Game::CharacterSheetGenerator::ElfNames qw(elf_name);
use Game::CharacterSheetGenerator::DwarfNames qw(dwarf_name);
use Game::CharacterSheetGenerator::HalflingNames qw(halfling_name);
use Game::CharacterSheetGenerator::HumanNames qw(human_name);
use Mojolicious::Lite;
use Mojo::UserAgent;
use Mojo::Log;
use File::ShareDir "dist_dir";
use I18N::AcceptLanguage;
use XML::LibXML;
use List::Util qw(shuffle max);
use POSIX qw(floor ceil);
use Cwd;
no warnings qw(uninitialized numeric);
# Commands for the command line!
push @{app->commands->namespaces}, "Game::CharacterSheetGenerator::Command";
# Change scheme if "X-Forwarded-Proto" header is set (presumably to HTTPS)
app->hook(before_dispatch => sub {
my $c = shift;
$c->req->url->base->scheme("https")
if $c->req->headers->header("X-Forwarded-Proto") } );
=head2 Configuration
As a Mojolicious application, it will read a config file called
F<character-sheet-generator.conf> in the same directory, if it exists. As the
default log level is "debug", one use of the config file is to change the log
level using the C<loglevel> key, and if you're not running the server in a
terminal, using the C<logfile> key to set a file.
The default map and table are stored in the F<contrib> directory. You can change
this directory using the C<contrib> key. By default, the directory included with
the distribution is used. Thus, if you're a developer, you probably want to use
something like the following to use the files from the source directory.
The code also needs to know where the Face Generator can be found, if at all.
You can set the URL using the C<face_generator_url> key. If you're a developer
and have it running locally on port 3020, this is what you'd use:
{
loglevel => "debug",
logfile => undef,
contrib => "share",
face_generator_url => "http://localhost:3020",
}
=cut
plugin Config => {
default => {
loglevel => "warn",
logfile => undef,
contrib => undef,
},
file => getcwd() . "/character-sheet-generator.conf",
};
my $log = Mojo::Log->new;
( run in 1.337 second using v1.01-cache-2.11-cpan-75ffa21a3d4 )