File Coverage

blib/lib/Game/TextMapper/Mapper/Square.pm
Criterion Covered Total %
statement 26 26 100.0
branch n/a
condition n/a
subroutine 9 9 100.0
pod 0 4 0.0
total 35 39 89.7


line stmt bran cond sub pod time code
1             # Copyright (C) 2009-2021 Alex Schroeder
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 .
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.
31              
32             It uses L to represent points (regions) and
33             L to represent lines.
34              
35             L is a similar class for hex maps.
36              
37             =cut
38              
39             package Game::TextMapper::Mapper::Square;
40              
41 11     11   88 use Game::TextMapper::Constants qw($dy);
  11         31  
  11         1724  
42 11     11   6476 use Game::TextMapper::Point::Square;
  11         37  
  11         130  
43 11     11   7115 use Game::TextMapper::Line::Square;
  11         45  
  11         152  
44              
45 11     11   662 use Modern::Perl '2018';
  11         30  
  11         64  
46 11     11   3981 use Mojo::Base 'Game::TextMapper::Mapper';
  11         44  
  11         98  
47              
48             sub make_region {
49 1259     1259 0 1999 my $self = shift;
50 1259         3398 return Game::TextMapper::Point::Square->new(@_);
51             }
52              
53             sub make_line {
54 86     86 0 174 my $self = shift;
55 86         411 return Game::TextMapper::Line::Square->new(@_);
56             }
57              
58             sub shape {
59 14     14 0 26 my $self = shift;
60 14         23 my $attributes = shift;
61 14         190 return sprintf('',
62             $attributes, -$dy/2, -$dy/2, $dy, $dy);
63             }
64              
65             sub viewbox {
66 3     3 0 9 my $self = shift;
67 3         15 my ($minx, $miny, $maxx, $maxy) = @_;
68 3         22 map { int($_) } (($minx - 1) * $dy, ($miny - 1) * $dy,
  12         38  
69             ($maxx + 1) * $dy, ($maxy + 1) * $dy);
70             }
71              
72             1;