blib/lib/Game/TextMapper/Mapper/Square.pm

filter: Statementstmt 100% 27 / 27 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 9 / 9 Podpod 0.0% 0 / 4 totaltotal 90.0% 36 / 40 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« blib/lib/Game/TextMapper/Log.pm ↑ Summary blib/lib/Game/TextMapper/Mapper/Hex.pm »
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 =encoding utf8
17  
18 =head1 NAME
19  
20 Game::TextMapper::Mapper::Hex - a mapper for hex maps
21  
22 =head1 DESCRIPTION
23  
24 This class knows how to parse a text containing a square map description into
25 SVG definitions, and regions. Once the map is built, this class knows how to
26 generate the SVG for the entire map.
27  
28 =head1 SEE ALSO
29  
30 This class is derived from L<Game::TextMapper::Mapper>.
31  
32 It uses L<Game::TextMapper::Point::Square> to represent points (regions) and
33 L<Game::TextMapper::Line::Square> to represent lines.
34  
35 L<Game::TextMapper::Mapper::Hex> is a similar class for hex maps.
36  
37 =cut
38  
39 package Game::TextMapper::Mapper::Square;
40  
41 11 ▶use Game::TextMapper::Constants qw($dy);
Subroutine BEGIN: called CC=1 SCAR=0.0
42 11 ▶use Game::TextMapper::Point::Square;
Subroutine BEGIN: called CC=1 SCAR=0.0
43 11 ▶use Game::TextMapper::Line::Square;
Subroutine BEGIN: called CC=1 SCAR=0.0
44  
45 11 ▶use Modern::Perl '2018';
Subroutine BEGIN: called CC=1 SCAR=0.0
46 11 ▶use Mojo::Base 'Game::TextMapper::Mapper';
Subroutine BEGIN: called CC=1 SCAR=0.0
47  
48 1216 ▶sub make_region {
Subroutine make_region: called CC=1 SCAR=0.0
Pod undocumented
49 1216 my $self = shift;
50 1216 return Game::TextMapper::Point::Square->new(@_);
51 }
52  
53 98 ▶sub make_line {
Subroutine make_line: called CC=1 SCAR=0.0
Pod undocumented
54 98 my $self = shift;
55 98 return Game::TextMapper::Line::Square->new(@_);
56 }
57  
58 14 ▶sub shape {
Subroutine shape: called CC=1 SCAR=0.0
Pod undocumented
59 14 my $self = shift;
60 14 my $attributes = shift;
61 14 return sprintf('<rect %s x="%.1f" y="%.1f" width="%.1f" height="%.1f" />',
62 $attributes, -$dy/2, -$dy/2, $dy, $dy);
63 }
64  
65 3 ▶sub viewbox {
Subroutine viewbox: called CC=1 SCAR=0.0
Pod undocumented
66 3 my $self = shift;
67 3 my ($minx, $miny, $maxx, $maxy) = @_;
68 3 map { int($_) } (($minx - 1) * $dy, ($miny - 1) * $dy,
69 ($maxx + 1) * $dy, ($maxy + 1) * $dy);
70 }
71  
72 11 1;
« blib/lib/Game/TextMapper/Log.pm ↑ Summary blib/lib/Game/TextMapper/Mapper/Hex.pm »