line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Game::TileMap::Legend; |
2
|
|
|
|
|
|
|
$Game::TileMap::Legend::VERSION = '1.000'; |
3
|
3
|
|
|
3
|
|
38
|
use v5.10; |
|
3
|
|
|
|
|
10
|
|
4
|
3
|
|
|
3
|
|
15
|
use strict; |
|
3
|
|
|
|
|
10
|
|
|
3
|
|
|
|
|
88
|
|
5
|
3
|
|
|
3
|
|
16
|
use warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
107
|
|
6
|
|
|
|
|
|
|
|
7
|
3
|
|
|
3
|
|
17
|
use Moo; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
17
|
|
8
|
3
|
|
|
3
|
|
969
|
use Mooish::AttributeBuilder -standard; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
17
|
|
9
|
3
|
|
|
3
|
|
366
|
use Carp qw(croak); |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
170
|
|
10
|
|
|
|
|
|
|
|
11
|
3
|
|
|
3
|
|
20
|
use constant TERRAIN_CLASS => 'terrain'; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
326
|
|
12
|
3
|
|
|
3
|
|
22
|
use constant WALL_OBJECT => 'wall'; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
183
|
|
13
|
3
|
|
|
3
|
|
21
|
use constant VOID_OBJECT => 'void'; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
2056
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has field 'classes' => ( |
16
|
|
|
|
|
|
|
default => sub { {} }, |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# isa => HashRef [ ArrayRef [Str]], |
19
|
|
|
|
|
|
|
); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
has param 'characters_per_tile' => ( |
22
|
|
|
|
|
|
|
default => sub { 1 }, |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# isa => PositiveInt, |
25
|
|
|
|
|
|
|
); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
has field '_object_map' => ( |
28
|
|
|
|
|
|
|
lazy => 1, |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# isa => HashRef [Str], |
31
|
|
|
|
|
|
|
); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
has field 'objects' => ( |
34
|
|
|
|
|
|
|
default => sub { {} }, |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# isa => HashRef [Any], |
37
|
|
|
|
|
|
|
); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
has field 'walls' => ( |
40
|
|
|
|
|
|
|
default => sub { {} }, |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# isa => HashRef [Bool], |
43
|
|
|
|
|
|
|
); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
has field 'voids' => ( |
46
|
|
|
|
|
|
|
default => sub { {} }, |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# isa => HashRef [Bool], |
49
|
|
|
|
|
|
|
); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub _build_object_map |
52
|
|
|
|
|
|
|
{ |
53
|
3
|
|
|
3
|
|
37
|
my $self = shift; |
54
|
3
|
|
|
|
|
5
|
my %classes = %{$self->classes}; |
|
3
|
|
|
|
|
18
|
|
55
|
3
|
|
|
|
|
9
|
my %objects = %{$self->objects}; |
|
3
|
|
|
|
|
36
|
|
56
|
3
|
|
|
|
|
10
|
my %map_reverse; |
57
|
|
|
|
|
|
|
|
58
|
3
|
|
|
|
|
12
|
foreach my $class (keys %classes) { |
59
|
8
|
|
|
|
|
13
|
my @objects = map { $objects{$_} } @{$classes{$class}}; |
|
21
|
|
|
|
|
42
|
|
|
8
|
|
|
|
|
15
|
|
60
|
8
|
|
|
|
|
15
|
foreach my $obj (@objects) { |
61
|
21
|
|
|
|
|
49
|
$map_reverse{$obj} = $class; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
3
|
|
|
|
|
31
|
return \%map_reverse; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub get_class_of_object |
69
|
|
|
|
|
|
|
{ |
70
|
191
|
|
|
191
|
1
|
327
|
my ($self, $obj) = @_; |
71
|
|
|
|
|
|
|
|
72
|
191
|
|
33
|
|
|
3270
|
return $self->_object_map->{$obj} |
73
|
|
|
|
|
|
|
// croak "no such object '$obj' in map legend"; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub add_wall |
77
|
|
|
|
|
|
|
{ |
78
|
4
|
|
|
4
|
1
|
28
|
my ($self, $marker, $object) = @_; |
79
|
4
|
|
100
|
|
|
26
|
$object //= WALL_OBJECT; |
80
|
|
|
|
|
|
|
|
81
|
4
|
|
|
|
|
15
|
$self->add_terrain($marker, $object); |
82
|
4
|
|
|
|
|
14
|
$self->walls->{$object} = !!1; |
83
|
4
|
|
|
|
|
15
|
return $self; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub add_void |
87
|
|
|
|
|
|
|
{ |
88
|
4
|
|
|
4
|
1
|
11
|
my ($self, $marker, $object) = @_; |
89
|
4
|
|
100
|
|
|
20
|
$object //= VOID_OBJECT; |
90
|
|
|
|
|
|
|
|
91
|
4
|
|
|
|
|
12
|
$self->add_terrain($marker, $object); |
92
|
4
|
|
|
|
|
17
|
$self->voids->{$object} = !!1; |
93
|
4
|
|
|
|
|
14
|
return $self; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub add_terrain |
97
|
|
|
|
|
|
|
{ |
98
|
10
|
|
|
10
|
1
|
22
|
my ($self, $marker, $object) = @_; |
99
|
|
|
|
|
|
|
|
100
|
10
|
|
|
|
|
25
|
return $self->add_object(TERRAIN_CLASS, $marker, $object); |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub add_object |
104
|
|
|
|
|
|
|
{ |
105
|
21
|
|
|
21
|
1
|
43
|
my ($self, $class, $marker, $object) = @_; |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
croak "marker '$marker' is already used" |
108
|
21
|
50
|
|
|
|
55
|
if exists $self->objects->{$marker}; |
109
|
|
|
|
|
|
|
|
110
|
21
|
50
|
|
|
|
50
|
croak "marker '$marker' has wrong length" |
111
|
|
|
|
|
|
|
unless length $marker == $self->characters_per_tile; |
112
|
|
|
|
|
|
|
|
113
|
21
|
|
|
|
|
45
|
push @{$self->classes->{$class}}, $marker; |
|
21
|
|
|
|
|
50
|
|
114
|
21
|
|
|
|
|
50
|
$self->objects->{$marker} = $object; |
115
|
|
|
|
|
|
|
|
116
|
21
|
|
|
|
|
50
|
return $self; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
1; |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
__END__ |