| 1 | # Copyright (C) 2009-2021 Alex Schroeder <alex@gnu.org> | ||||||||||||||||||||||||||||
| 2 | # | ||||||||||||||||||||||||||||
| 3 | # This program is free software: you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 4 | # the terms of the GNU Affero General Public License as published by the Free | ||||||||||||||||||||||||||||
| 5 | # Software Foundation, either version 3 of the License, or (at your option) any | ||||||||||||||||||||||||||||
| 6 | # later version. | ||||||||||||||||||||||||||||
| 7 | # | ||||||||||||||||||||||||||||
| 8 | # This program is distributed in the hope that it will be useful, but WITHOUT | ||||||||||||||||||||||||||||
| 9 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||||||||||||||||||||||||||||
| 10 | # FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more | ||||||||||||||||||||||||||||
| 11 | # details. | ||||||||||||||||||||||||||||
| 12 | # | ||||||||||||||||||||||||||||
| 13 | # You should have received a copy of the GNU Affero General Public License along | ||||||||||||||||||||||||||||
| 14 | # with this program. If not, see <http://www.gnu.org/licenses/>. | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | =head1 NAME | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | Game::TextMapper::Command::render | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | text-mapper random [--hex|--square|help] | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | This takes a map description on STDIN and prints the SVG on STDOUT. | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | text-mapper random | text-mapper render > map.svg | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | =head1 OPTIONS | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | C<help> prints the man page. | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | C<--hex> is the default: this uses L<Game::TextMapper::Mapper::Hex> to render a | ||||||||||||||||||||||||||||
| 35 | hex map. | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | C<--square> uses L<Game::TextMapper::Mapper::Square> to render a square map. | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | This is important if the algorithm can produce both kinds of map, like | ||||||||||||||||||||||||||||
| 40 | L<Game::TextMapper::Schroeder::Alpine>. | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | =head1 EXAMPLES | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | Hex map: | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | text-mapper random Game::TextMapper::Schroeder::Alpine \ | ||||||||||||||||||||||||||||
| 47 | --role Game::TextMapper::Schroeder::Hex \ | ||||||||||||||||||||||||||||
| 48 | | text-mapper render > map.svg | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | Square map: | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | text-mapper random Game::TextMapper::Schroeder::Alpine \ | ||||||||||||||||||||||||||||
| 53 | --role Game::TextMapper::Schroeder::Square \ | ||||||||||||||||||||||||||||
| 54 | | text-mapper render --square > map.svg | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | =cut | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | package Game::TextMapper::Command::render; | ||||||||||||||||||||||||||||
| 59 | 1 | ▶ | use Modern::Perl '2018'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 60 | 1 | ▶ | use Mojo::Base 'Mojolicious::Command'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 61 | 1 | ▶ | use File::ShareDir 'dist_dir'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 62 | 1 | ▶ | use Pod::Simple::Text; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 63 | 1 | ▶ | use Getopt::Long qw(GetOptionsFromArray); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 64 | 1 | ▶ | use Encode; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 1 | has description => 'Render map from STDIN to STDOUT, as SVG (all UTF-8)'; | |||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 0 | ▶ | has usage => sub { my $self = shift; $self->extract_usage }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=2.6
| |||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 1 | ▶ | sub run { | ||||||||||||||||||||||||||
|
Subroutine
run: called CC=6 SCAR=21.9
Pod
documented
| |||||||||||||||||||||||||||||
| 71 | 1 | my ($self, @args) = @_; | |||||||||||||||||||||||||||
| 72 | 1 | ▶ | my $dist_dir = $self->app->config('contrib') // dist_dir('Game-TextMapper'); | ||||||||||||||||||||||||||
|
Condition33%1/3
$self->app->config("contrib") // dist_dir("Game-TextMapper")
MC/DC0%0/2
$self->app->config("contrib") // dist_dir("Game-TextMapper")
$self->app->config("contrib")
dist_dir("Game-TextMapper")
Truth table33%1/3
A // B
A= $self->app->config("contrib")B= dist_dir("Game-TextMapper")
| |||||||||||||||||||||||||||||
| 73 | 1 | my $hex; | |||||||||||||||||||||||||||
| 74 | my $square; | ||||||||||||||||||||||||||||
| 75 | 1 | ▶ | if (@args and $args[0] eq 'help') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@args and $args[0] eq "help"
MC/DC0%0/2
@args and $args[0] eq "help"
@args
$args[0] eq "help"
Truth table33%1/3
A and B
A= @argsB= $args[0] eq "help"
| |||||||||||||||||||||||||||||
| 76 | 0 | seek(DATA, 0, 0); # read from this file | |||||||||||||||||||||||||||
| 77 | 0 | my $parser = Pod::Simple::Text->new(); | |||||||||||||||||||||||||||
| 78 | 0 | $parser->output_fh(*STDOUT); | |||||||||||||||||||||||||||
| 79 | 0 | $parser->parse_lines(<DATA>); | |||||||||||||||||||||||||||
| 80 | 0 | return 1; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | 1 | GetOptionsFromArray (\@args, "hex" => \$hex, "square" => \$square); | |||||||||||||||||||||||||||
| 83 | 1 | ▶ | warn "Unhandled arguments: @args\n" if @args; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | 1 | my $mapper; | |||||||||||||||||||||||||||
| 85 | 1 | ▶ | if ($square) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | 0 | $mapper = Game::TextMapper::Mapper::Square->new(dist_dir => $dist_dir, local_files => 1); | |||||||||||||||||||||||||||
| 87 | } else { | ||||||||||||||||||||||||||||
| 88 | 1 | $mapper = Game::TextMapper::Mapper::Hex->new(dist_dir => $dist_dir, local_files => 1); | |||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | 1 | local $/ = undef; | |||||||||||||||||||||||||||
| 91 | 1 | $mapper->initialize(decode_utf8 <STDIN>); | |||||||||||||||||||||||||||
| 92 | 1 | print encode_utf8 $mapper->svg; | |||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 1 | 1; | |||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | __DATA__ | ||||||||||||||||||||||||||||