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::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
|
|
7
|
use Game::TextMapper::Constants qw($dy); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
68
|
|
48
|
|
|
|
|
|
|
|
49
|
1
|
|
|
1
|
|
5
|
use Game::TextMapper::Point; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
6
|
|
50
|
1
|
|
|
1
|
|
24
|
use Modern::Perl '2018'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
9
|
|
51
|
1
|
|
|
1
|
|
227
|
use Mojo::Util qw(url_escape); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
46
|
|
52
|
1
|
|
|
1
|
|
5
|
use Mojo::Base 'Game::TextMapper::Point'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
24
|
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub svg_region { |
55
|
1126
|
|
|
1126
|
1
|
3848
|
my ($self, $attributes, $offset) = @_; |
56
|
1126
|
|
|
|
|
1566
|
return sprintf(qq{ \n}, |
57
|
|
|
|
|
|
|
$self->x, $self->y, $self->z, |
58
|
|
|
|
|
|
|
($self->x - 0.5) * $dy, |
59
|
|
|
|
|
|
|
($self->y + $offset->[$self->z] - 0.5) * $dy, |
60
|
|
|
|
|
|
|
$dy, $dy, $attributes); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub svg { |
64
|
2252
|
|
|
2252
|
1
|
7085
|
my ($self, $offset) = @_; |
65
|
2252
|
|
|
|
|
3151
|
my $x = $self->x; |
66
|
2252
|
|
|
|
|
7889
|
my $y = $self->y; |
67
|
2252
|
|
|
|
|
7048
|
my $z = $self->z; |
68
|
2252
|
|
|
|
|
6963
|
$y += $offset->[$z]; |
69
|
2252
|
|
|
|
|
2617
|
my $data = ''; |
70
|
2252
|
|
|
|
|
2387
|
for my $type (@{$self->type}) { |
|
2252
|
|
|
|
|
3309
|
|
71
|
1474
|
|
|
|
|
9598
|
$data .= sprintf(qq{ \n}, |
72
|
|
|
|
|
|
|
$x * $dy, |
73
|
|
|
|
|
|
|
$y * $dy, # square |
74
|
|
|
|
|
|
|
$type); |
75
|
|
|
|
|
|
|
} |
76
|
2252
|
|
|
|
|
6542
|
return $data; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub svg_coordinates { |
80
|
1126
|
|
|
1126
|
1
|
3839
|
my ($self, $offset) = @_; |
81
|
1126
|
|
|
|
|
1622
|
my $x = $self->x; |
82
|
1126
|
|
|
|
|
3965
|
my $y = $self->y; |
83
|
1126
|
|
|
|
|
3573
|
my $z = $self->z; |
84
|
1126
|
|
|
|
|
3401
|
$y += $offset->[$z]; |
85
|
1126
|
|
|
|
|
1308
|
my $data = ''; |
86
|
1126
|
|
|
|
|
1561
|
$data .= qq{
|
87
|
1126
|
|
|
|
|
5017
|
$data .= sprintf(qq{ x="%.1f" y="%.1f"}, |
88
|
|
|
|
|
|
|
$x * $dy, |
89
|
|
|
|
|
|
|
($y - 0.4) * $dy); # square |
90
|
1126
|
|
|
|
|
1357
|
$data .= ' '; |
91
|
1126
|
|
50
|
|
|
1773
|
$data .= $self->map->text_attributes || ''; |
92
|
1126
|
|
|
|
|
6774
|
$data .= '>'; |
93
|
1126
|
|
|
|
|
1882
|
$data .= Game::TextMapper::Point::coord($self->x, $self->y, "."); # original |
94
|
1126
|
|
|
|
|
2033
|
$data .= qq{\n}; |
95
|
1126
|
|
|
|
|
2832
|
return $data; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub svg_label { |
99
|
1126
|
|
|
1126
|
1
|
5318
|
my ($self, $url, $offset) = @_; |
100
|
1126
|
100
|
|
|
|
1560
|
return '' unless defined $self->label; |
101
|
5
|
|
|
|
|
23
|
my $attributes = $self->map->label_attributes; |
102
|
5
|
50
|
|
|
|
31
|
if ($self->size) { |
103
|
0
|
0
|
|
|
|
0
|
if (not $attributes =~ s/\bfont-size="\d+pt"/'font-size="' . $self->size . 'pt"'/e) { |
|
0
|
|
|
|
|
0
|
|
104
|
0
|
|
|
|
|
0
|
$attributes .= ' font-size="' . $self->size . '"'; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
} |
107
|
5
|
50
|
0
|
|
|
20
|
$url =~ s/\%s/url_escape($self->label)/e or $url .= url_escape($self->label) if $url; |
|
0
|
|
|
|
|
0
|
|
108
|
5
|
|
|
|
|
13
|
my $x = $self->x; |
109
|
5
|
|
|
|
|
22
|
my $y = $self->y; |
110
|
5
|
|
|
|
|
18
|
my $z = $self->z; |
111
|
5
|
|
|
|
|
17
|
$y += $offset->[$z]; |
112
|
5
|
|
50
|
|
|
13
|
my $data = sprintf(qq{ } |
|
|
|
50
|
|
|
|
|
113
|
|
|
|
|
|
|
. $self->label |
114
|
|
|
|
|
|
|
. qq{}, |
115
|
|
|
|
|
|
|
$x * $dy, |
116
|
|
|
|
|
|
|
($y + 0.4) * $dy, # square |
117
|
|
|
|
|
|
|
$attributes ||'', |
118
|
|
|
|
|
|
|
$self->map->glow_attributes ||''); |
119
|
5
|
50
|
|
|
|
80
|
$data .= qq{} if $url; |
120
|
5
|
|
50
|
|
|
12
|
$data .= sprintf(qq{} |
121
|
|
|
|
|
|
|
. $self->label |
122
|
|
|
|
|
|
|
. qq{}, |
123
|
|
|
|
|
|
|
$x * $dy, |
124
|
|
|
|
|
|
|
($y + 0.4) * $dy, # square |
125
|
|
|
|
|
|
|
$attributes ||''); |
126
|
5
|
50
|
|
|
|
45
|
$data .= qq{} if $url; |
127
|
5
|
|
|
|
|
11
|
$data .= qq{\n}; |
128
|
5
|
|
|
|
|
18
|
return $data; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
1; |