Game-TextMapper
view release on metacpan or search on metacpan
lib/Game/TextMapper/Mapper.pm view on Meta::CPAN
package Game::TextMapper::Mapper;
use Game::TextMapper::Log;
use Modern::Perl '2018';
use Mojo::UserAgent;
use Mojo::Base -base;
use File::Slurper qw(read_text);
use Encode qw(encode_utf8 decode_utf8);
use Mojo::Util qw(url_escape);
use File::ShareDir 'dist_dir';
use Scalar::Util 'weaken';
=head1 ATTRIBUTES
=head2 dist_dir
You need to pass this during instantiation so that the mapper knows where to
find files it needs to include.
=cut
lib/Game/TextMapper/Mapper.pm view on Meta::CPAN
$self->map($map);
$self->process(split(/\r?\n/, $map));
}
sub process {
my $self = shift;
my $line_id = 0;
foreach (@_) {
if (/^(-?\d\d)(-?\d\d)(\d\d)?\s+(.*)/ or /^(-?\d\d+)\.(-?\d\d+)(?:\.(\d\d+))?\s+(.*)/) {
my $region = $self->make_region(x => $1, y => $2, z => $3||'00', map => $self);
weaken($region->{map});
my $rest = $4;
while (my ($tag, $label, $size) = $rest =~ /\b([a-z]+)=["â]([^"â]+)["â]\s*(\d+)?/) {
if ($tag eq 'name') {
$region->label($label);
$region->size($size) if $size;
} else {
# delay the calling of $self->other_info because the URL or the $self->glow_attributes might not be set
push(@{$self->other()}, sub () { $self->other_info($region, $label, $size, "translate(0,45)", 'opacity="0.2"') });
}
$rest =~ s/\b([a-z]+)=["â]([^"â]+)["â]\s*(\d+)?//;
lib/Game/TextMapper/Mapper.pm view on Meta::CPAN
}
$rest =~ s/["â]([^"â]+)["â]\s*(\d+)?((?:\s*[a-z]+\([^\)]+\))*)//;
}
my @types = split(/\s+/, $rest);
$region->type(\@types);
push(@{$self->regions}, $region);
push(@{$self->things}, $region);
} elsif (/^(-?\d\d-?\d\d(?:\d\d)?(?:--?\d\d-?\d\d(?:\d\d)?)+)\s+(\S+)\s*(?:["â](.+)["â])?\s*(left|right)?\s*(\d+%)?/
or /^(-?\d\d+\.-?\d\d+(?:\.\d\d+)?(?:--?\d\d+\.-?\d\d+(?:\.\d\d+)?)+)\s+(\S+)\s*(?:["â](.+)["â])?\s*(left|right)?\s*(\d+%)?/) {
my $line = $self->make_line(map => $self);
weaken($line->{map});
my $str = $1;
$line->type($2);
$line->label($3);
$line->side($4);
$line->start($5);
$line->id('line' . $line_id++);
my @points;
while ($str =~ /\G(?:(-?\d\d)(-?\d\d)(\d\d)?|(-?\d\d+)\.(-?\d\d+)\.(\d\d+)?)-?/cg) {
push(@points, Game::TextMapper::Point->new(x => $1||$4, y => $2||$5, z => $3||$6||'00'));
}
( run in 0.750 second using v1.01-cache-2.11-cpan-65fba6d93b7 )