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 hex map description into SVG |
25
|
|
|
|
|
|
|
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 square maps. |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=cut |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
package Game::TextMapper::Mapper::Hex; |
40
|
|
|
|
|
|
|
|
41
|
1
|
|
|
1
|
|
459
|
use Game::TextMapper::Constants qw($dx $dy); |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
102
|
|
42
|
1
|
|
|
1
|
|
442
|
use Game::TextMapper::Point::Hex; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
8
|
|
43
|
1
|
|
|
1
|
|
435
|
use Game::TextMapper::Line::Hex; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
8
|
|
44
|
|
|
|
|
|
|
|
45
|
1
|
|
|
1
|
|
29
|
use Modern::Perl '2018'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
3
|
|
46
|
1
|
|
|
1
|
|
100
|
use Mojo::Base 'Game::TextMapper::Mapper'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
4
|
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub make_region { |
49
|
1381
|
|
|
1381
|
0
|
1770
|
my $self = shift; |
50
|
1381
|
|
|
|
|
2538
|
return Game::TextMapper::Point::Hex->new(@_); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub make_line { |
54
|
253
|
|
|
253
|
0
|
332
|
my $self = shift; |
55
|
253
|
|
|
|
|
592
|
return Game::TextMapper::Line::Hex->new(@_); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub shape { |
59
|
31
|
|
|
31
|
0
|
41
|
my $self = shift; |
60
|
31
|
|
|
|
|
72
|
my $attributes = shift; |
61
|
|
|
|
|
|
|
my $points = join(" ", map { |
62
|
31
|
|
|
|
|
61
|
sprintf("%.1f,%.1f", $_->[0], $_->[1]) } Game::TextMapper::Point::Hex::corners()); |
|
186
|
|
|
|
|
753
|
|
63
|
31
|
|
|
|
|
143
|
return qq{}; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub viewbox { |
67
|
6
|
|
|
6
|
0
|
14
|
my $self = shift; |
68
|
6
|
|
|
|
|
19
|
my ($minx, $miny, $maxx, $maxy) = @_; |
69
|
6
|
|
|
|
|
57
|
map { int($_) } ($minx * $dx * 3/2 - $dx - 60, ($miny - 1.5) * $dy, |
|
24
|
|
|
|
|
54
|
|
70
|
|
|
|
|
|
|
$maxx * $dx * 3/2 + $dx + 60, ($maxy + 1) * $dy); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
1; |