You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
wiki-map/tests/paths.pl

78 lines
2.6 KiB

11 months ago
use v5.36;
use rlib '..';
use HexGrid;
use HexGrid::Path;
use Carp;
use Data::Dumper;
my $MAP_SIZE = 5;
11 months ago
my $grid = HexGrid->new(defaults => {
style => { 'stroke-width' => 1, stroke => 'white' },
show_coords => 1});
11 months ago
my $region = $grid->make_region("TEST");
for (my $nw=-$MAP_SIZE; $nw <= $MAP_SIZE; $nw++)
{
for (my $sw=-$MAP_SIZE; $sw <= $MAP_SIZE; $sw++)
{
$region->make_tile_at($nw, $sw);
}
}
# generic "standard" path
11 months ago
$grid->make_path_from('test-id',
[[0,0], [1,0], [1,1], [2,0], [2,-1], [2,-2], [1,-2], [1,-1], [2,-1], [3,-1]],
colour => 'lime', css_class => 'path', style => { 'stroke-width' => 5 }
);
# Single tile paths
11 months ago
$grid->make_path_from('point-id', [[-1,1]],
colour => 'cyan', css_class => 'path', style => { 'stroke-width' => 5 }
);
$grid->add_path(HexGrid::Path->new(id => 'point-starts', tiles => [$grid->get_tile_at(-2,2)],
starts_from => $HexGrid::DIR{n},
colour => 'yellow', css_class => 'path', style => { 'stroke-width' => 5 }));
$grid->add_path(HexGrid::Path->new(id => 'point-ends', tiles => [$grid->get_tile_at(-3,3)],
ends_to => $HexGrid::DIR{nw},
colour => 'blue', css_class => 'path', style => { 'stroke-width' => 5 }));
$grid->add_path(HexGrid::Path->new(id => 'point-starts-ends-1', tiles => [$grid->get_tile_at(-2,3)],
starts_from => $HexGrid::DIR{sw}, ends_to => $HexGrid::DIR{ne},
colour => 'magenta', css_class => 'path', style => { 'stroke-width' => 5 }));
$grid->add_path(HexGrid::Path->new(id => 'point-starts-ends-2', tiles => [$grid->get_tile_at(-1,2)],
starts_from => $HexGrid::DIR{sw}, ends_to => $HexGrid::DIR{n},
colour => 'orange', css_class => 'path', style => { 'stroke-width' => 5 }));
# starts_from/ends_to paths
$grid->add_path(HexGrid::Path->new(id => 'starts', starts_from => $HexGrid::DIR{ne},
tiles => [$grid->get_tile_at(4,-1), $grid->get_tile_at(5,-1), $grid->get_tile_at(5,0)],
colour => 'yellow', css_class => 'path', style => { 'stroke-width' => 5 }));
$grid->add_path(HexGrid::Path->new(id => 'ends', ends_to => $HexGrid::DIR{nw},
tiles => [$grid->get_tile_at(4,1), $grid->get_tile_at(4,0), $grid->get_tile_at(3,1)],
colour => 'blue', css_class => 'path', style => { 'stroke-width' => 5 }));
$grid->add_path(HexGrid::Path->new(id => 'starts-ends',
starts_from => $HexGrid::DIR{sw}, ends_to => $HexGrid::DIR{s},
tiles => [$grid->get_tile_at(2,3), $grid->get_tile_at(3,3), $grid->get_tile_at(4,3)],
colour => 'magenta', css_class => 'path', style => { 'stroke-width' => 5 }));
#loop
11 months ago
$grid->make_path_from('loop-id',
[[-2,0], [-1,0], [-1,-1], [-2,-1], [-2,0]],
colour => 'red', css_class => 'path', style => { 'stroke-width' => 5 }
);
say $grid->render;