diff --git a/coord_tripler.pl b/coord_tripler.pl new file mode 100644 index 0000000..4344f43 --- /dev/null +++ b/coord_tripler.pl @@ -0,0 +1,47 @@ +use v5.36; +use rlib '.'; + +use Carp; +use Data::Dumper; + +use feature "signatures"; +no warnings "experimental::signatures"; + +my $coords_regex = qr/^\s*(-?\d+)\s*,\s*(-?\d+)\s*$/; + +my %regions_to_tiles; +my %tiles_to_regions; + +my $input_file = shift; +open (my $input_fh, $input_file); + +my $output_file = shift // "$input_file.out"; +open (my $output_fh, ">$output_file"); + +while (my $line = <$input_fh>) +{ + my @fields = split '; ', $line; + print $output_fh (shift @fields) . "; "; #region name + print $output_fh (shift @fields) . "; "; #background colour + my @expanded_tile_specs = (); + foreach my $coords (@fields) + { + do { carp "Skipping bad spec: $coords"; next; } unless $coords =~ $coords_regex; + my $nw_base = $1 * 3; + my $sw_base = $2 * 3; + + my @new = ("$nw_base,$sw_base"); + push @new, ($nw_base+1) . "," . ($sw_base); + push @new, ($nw_base-1) . "," . ($sw_base); + push @new, ($nw_base) . "," . ($sw_base+1); + push @new, ($nw_base) . "," . ($sw_base-1); + push @new, ($nw_base+1) . "," . ($sw_base-1); + push @new, ($nw_base-1) . "," . ($sw_base+1); + + push @expanded_tile_specs, (join "; ", @new); + } + say $output_fh (join "; ", @expanded_tile_specs); +} + +close $input_fh; +close $output_fh; diff --git a/grid-tester.pl b/grid-tester.pl new file mode 100644 index 0000000..dd34c91 --- /dev/null +++ b/grid-tester.pl @@ -0,0 +1,68 @@ +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 = ""; + $html_builder .= "\n\n"; + $html_builder .= "\n" . < + function clickPin(pinId, containerId) { + let popup = document.getElementById(pinId + '-popup'); + popup.style.visibility = popup.style.visibility == 'visible' ? 'hidden' : 'visible'; + } + +EOS + if(1) + { + $html_builder .= < + function toggleCoords(show) { + for (var elem of document.getElementsByClassName('coords')) { + elem.style.visibility = show ? 'visible' : 'hidden'; + } + } + + + +EOS + } + $html_builder .= "\n" . $grid->render; + $html_builder .= "\n\n"; + return $html_builder; +} + diff --git a/test-regions b/test-regions new file mode 100644 index 0000000..f6039f8 --- /dev/null +++ b/test-regions @@ -0,0 +1,3 @@ +Minev; #2F7621; 0,1; 0,2; 1,1; 2,0; 0,3; 1,2; 2,1; 1,3; 2,2; 3,1; 1,4; 2,3; 3,2; 2,4; 3,3; 4,2; 3,4; 4,3; 5,2; 4,4; 5,3; 5,4; 6,3; 5,5; 6,5 +Buslish; #E7F79C; 0,5; 1,5; 0,6; 2,5; 1,6; 0,7; -1,8; 2,5; 3,5; 2,6; 1,7; 0,8; 4,5; 3,6; 1,8; 0,9; 4,6; 3,7; 2,8; 1,9; 4,7; 3,8; 2,9; 3,9 +Midhills; #E7CE5A; 5,6; 4,8; 5,7; 6,6