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.
69 lines
1.6 KiB
69 lines
1.6 KiB
5 months ago
|
use v5.36;
|
||
|
use rlib '.';
|
||
|
|
||
|
use HexGrid;
|
||
|
use HexGrid::Pin;
|
||
|
|
||
|
use Carp;
|
||
|
use Data::Dumper;
|
||
|
|
||
|
use feature "signatures";
|
||
|
no warnings "experimental::signatures";
|
||
|
|
||
|
my $coords_regex = qr/^\s*(-?\d+)\s*,\s*(-?\d+)\s*$/;
|
||
|
|
||
|
my $grid = HexGrid->new(defaults => {
|
||
|
style => { 'stroke-width' => 1, stroke => 'black' },
|
||
|
show_coords => 1});
|
||
|
|
||
|
my $test_file = shift;
|
||
|
open (my $test_fh, $test_file);
|
||
|
|
||
|
while (my $line = <$test_fh>)
|
||
|
{
|
||
|
my @fields = split '; ', $line;
|
||
|
my $region = $grid->make_region(shift @fields);
|
||
|
$region->{defaults}{colour} = shift @fields;
|
||
|
foreach my $coords (@fields)
|
||
|
{
|
||
|
do { carp "Skipping bad spec: $coords"; next; } unless $coords =~ $coords_regex;
|
||
|
$region->make_tile_at($1,$2);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
# say $grid->render;
|
||
|
say wrap_in_html($grid);
|
||
|
close $test_fh;
|
||
|
|
||
|
sub wrap_in_html($grid)
|
||
|
{
|
||
|
my $html_builder = "<!DOCTYPE html>";
|
||
|
$html_builder .= "\n<html>\n<body>";
|
||
|
$html_builder .= "\n" . <<EOS;
|
||
|
<script>
|
||
|
function clickPin(pinId, containerId) {
|
||
|
let popup = document.getElementById(pinId + '-popup');
|
||
|
popup.style.visibility = popup.style.visibility == 'visible' ? 'hidden' : 'visible';
|
||
|
}
|
||
|
</script>
|
||
|
EOS
|
||
|
if(1)
|
||
|
{
|
||
|
$html_builder .= <<EOS;
|
||
|
<script>
|
||
|
function toggleCoords(show) {
|
||
|
for (var elem of document.getElementsByClassName('coords')) {
|
||
|
elem.style.visibility = show ? 'visible' : 'hidden';
|
||
|
}
|
||
|
}
|
||
|
</script>
|
||
|
<label for="show-coords-checkbox">Show coordinates</label>
|
||
|
<input type="checkbox" checked id="show-coords-checkbox" onclick="toggleCoords(event.srcElement.checked)" />
|
||
|
EOS
|
||
|
}
|
||
|
$html_builder .= "\n" . $grid->render;
|
||
|
$html_builder .= "\n</body>\n</html>";
|
||
|
return $html_builder;
|
||
|
}
|
||
|
|