line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyright (C) 2009-2022 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::Point::Square - a square on a map |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 SYNOPSIS |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
use Modern::Perl; |
25
|
|
|
|
|
|
|
use Game::TextMapper::Point::Square; |
26
|
|
|
|
|
|
|
my $square = Game::TextMapper::Point::Square->new(x => 1, y => 1, z => 0); |
27
|
|
|
|
|
|
|
say $square->svg_region('', [0]); |
28
|
|
|
|
|
|
|
# |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head1 DESCRIPTION |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
This class holds information about a square region: coordinates, a label, and |
33
|
|
|
|
|
|
|
types. Types are the kinds of symbols that can be found in the region: a keep, a |
34
|
|
|
|
|
|
|
tree, a mountain. They correspond to SVG definitions. The class knows how to |
35
|
|
|
|
|
|
|
draw a SVG rectangle at the correct coordinates using these definitions. |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 SEE ALSO |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
This is a specialisation of L. |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
The SVG size is determined by C<$dy> from L. |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=cut |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
package Game::TextMapper::Point::Square; |
46
|
|
|
|
|
|
|
|
47
|
1
|
|
|
1
|
|
6
|
use Game::TextMapper::Constants qw($dy); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
110
|
|
48
|
|
|
|
|
|
|
|
49
|
1
|
|
|
1
|
|
8
|
use Game::TextMapper::Point; |
|
1
|
|
|
|
|
10
|
|
|
1
|
|
|
|
|
6
|
|
50
|
1
|
|
|
1
|
|
26
|
use Modern::Perl '2018'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
51
|
1
|
|
|
1
|
|
181
|
use Mojo::Util qw(url_escape); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
50
|
|
52
|
1
|
|
|
1
|
|
6
|
use Mojo::Base 'Game::TextMapper::Point'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
53
|
1
|
|
|
1
|
|
141
|
use Encode; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
878
|
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub svg_region { |
56
|
1121
|
|
|
1121
|
1
|
3880
|
my ($self, $attributes, $offset) = @_; |
57
|
1121
|
50
|
|
|
|
1668
|
return sprintf(qq{ \n}, |
58
|
|
|
|
|
|
|
$self->x, $self->y, $self->z != 0 ? $self->z : '', # z 0 is not printed at all for the $id |
59
|
|
|
|
|
|
|
($self->x - 0.5) * $dy, |
60
|
|
|
|
|
|
|
($self->y + $offset->[$self->z] - 0.5) * $dy, |
61
|
|
|
|
|
|
|
$dy, $dy, $attributes); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub svg { |
65
|
2242
|
|
|
2242
|
1
|
7273
|
my ($self, $offset) = @_; |
66
|
2242
|
|
|
|
|
3274
|
my $x = $self->x; |
67
|
2242
|
|
|
|
|
7253
|
my $y = $self->y; |
68
|
2242
|
|
|
|
|
6949
|
my $z = $self->z; |
69
|
2242
|
|
|
|
|
6890
|
$y += $offset->[$z]; |
70
|
2242
|
|
|
|
|
2553
|
my $data = ''; |
71
|
2242
|
|
|
|
|
2421
|
for my $type (@{$self->type}) { |
|
2242
|
|
|
|
|
3278
|
|
72
|
1471
|
|
|
|
|
10132
|
$data .= sprintf(qq{ \n}, |
73
|
|
|
|
|
|
|
$x * $dy, |
74
|
|
|
|
|
|
|
$y * $dy, # square |
75
|
|
|
|
|
|
|
$type); |
76
|
|
|
|
|
|
|
} |
77
|
2242
|
|
|
|
|
6660
|
return $data; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub svg_coordinates { |
81
|
1121
|
|
|
1121
|
1
|
3761
|
my ($self, $offset) = @_; |
82
|
1121
|
|
|
|
|
1656
|
my $x = $self->x; |
83
|
1121
|
|
|
|
|
3663
|
my $y = $self->y; |
84
|
1121
|
|
|
|
|
3471
|
my $z = $self->z; |
85
|
1121
|
|
|
|
|
3445
|
$y += $offset->[$z]; |
86
|
1121
|
|
|
|
|
1335
|
my $data = ''; |
87
|
1121
|
|
|
|
|
1566
|
$data .= qq{
|
88
|
1121
|
|
|
|
|
5194
|
$data .= sprintf(qq{ x="%.1f" y="%.1f"}, |
89
|
|
|
|
|
|
|
$x * $dy, |
90
|
|
|
|
|
|
|
($y - 0.4) * $dy); # square |
91
|
1121
|
|
|
|
|
1387
|
$data .= ' '; |
92
|
1121
|
|
50
|
|
|
1765
|
$data .= $self->map->text_attributes || ''; |
93
|
1121
|
|
|
|
|
6490
|
$data .= '>'; |
94
|
1121
|
|
|
|
|
1727
|
$data .= Game::TextMapper::Point::coord($self->x, $self->y, "."); # original |
95
|
1121
|
|
|
|
|
2001
|
$data .= qq{\n}; |
96
|
1121
|
|
|
|
|
2874
|
return $data; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub svg_label { |
100
|
1121
|
|
|
1121
|
1
|
5147
|
my ($self, $url, $offset) = @_; |
101
|
1121
|
100
|
|
|
|
1555
|
return '' unless defined $self->label; |
102
|
5
|
|
|
|
|
22
|
my $attributes = $self->map->label_attributes; |
103
|
5
|
50
|
|
|
|
29
|
if ($self->size) { |
104
|
0
|
0
|
|
|
|
0
|
if (not $attributes =~ s/\bfont-size="\d+pt"/'font-size="' . $self->size . 'pt"'/e) { |
|
0
|
|
|
|
|
0
|
|
105
|
0
|
|
|
|
|
0
|
$attributes .= ' font-size="' . $self->size . '"'; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
} |
108
|
5
|
50
|
0
|
|
|
22
|
$url =~ s/\%s/url_escape(encode_utf8($self->label))/e or $url .= url_escape(encode_utf8($self->label)) if $url; |
|
0
|
|
|
|
|
0
|
|
109
|
5
|
|
|
|
|
9
|
my $x = $self->x; |
110
|
5
|
|
|
|
|
82
|
my $y = $self->y; |
111
|
5
|
|
|
|
|
20
|
my $z = $self->z; |
112
|
5
|
|
|
|
|
17
|
$y += $offset->[$z]; |
113
|
5
|
|
50
|
|
|
11
|
my $data = sprintf(qq{ } |
|
|
|
50
|
|
|
|
|
114
|
|
|
|
|
|
|
. $self->label |
115
|
|
|
|
|
|
|
. qq{}, |
116
|
|
|
|
|
|
|
$x * $dy, |
117
|
|
|
|
|
|
|
($y + 0.4) * $dy, # square |
118
|
|
|
|
|
|
|
$attributes ||'', |
119
|
|
|
|
|
|
|
$self->map->glow_attributes ||''); |
120
|
5
|
50
|
|
|
|
81
|
$data .= qq{} if $url; |
121
|
5
|
|
50
|
|
|
9
|
$data .= sprintf(qq{} |
122
|
|
|
|
|
|
|
. $self->label |
123
|
|
|
|
|
|
|
. qq{}, |
124
|
|
|
|
|
|
|
$x * $dy, |
125
|
|
|
|
|
|
|
($y + 0.4) * $dy, # square |
126
|
|
|
|
|
|
|
$attributes ||''); |
127
|
5
|
50
|
|
|
|
45
|
$data .= qq{} if $url; |
128
|
5
|
|
|
|
|
9
|
$data .= qq{\n}; |
129
|
5
|
|
|
|
|
19
|
return $data; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
1; |