Archive defunct code

main
parent de918c767a
commit 0ee504bf43
  1. 82
      parse-regions.pl
  2. 37
      popup.pl
  3. 127
      test.pl
  4. 109
      wiki-tile.pl

@ -1,82 +0,0 @@
use v5.30;
use HexGrid;
use Carp;
use Data::Dumper;
my $grid = HexGrid->new(defaults => { style => { 'stroke-width' => 1, 'stroke' => 'black' }, show_coords => 1 });
$grid->make_region("Viper's Gate", colour => 'red');
my $adderwall = $grid->make_region('Adderwall', colour => 'orange');
# $adderwall->make_subregion('Adderwall foothills', colour => 'moccasin');
$grid->make_region('Adderwall foothills', colour => 'moccasin');
$grid->make_region('Midhills', colour => 'moccasin');
# $grid->make_region('Minev', colour => 'green', images => ["forest-tile.png"]);
$grid->make_region('Minev', colour => 'green');
$grid->make_region('Barrowcross', colour => 'darkgreen');
$grid->make_region('Shinei Mavet', colour => 'orange');
$grid->make_region('Jagged Shinei Mavet', colour => 'orange');
$grid->make_region('Shinei Mavet waters', colour => 'lightcyan');
# $grid->make_region('Shinei Mavet', colour => 'orange', image => 'mountain.svg');
# $grid->make_region('Jagged Shinei Mavet', colour => 'orange', images => ['mountain.svg', 'jagged.svg']);
# $grid->make_region('Shinei Mavet waters', colour => 'lightcyan', image => 'foo.png');
$grid->make_region('Southern Ocean', colour => 'skyblue');
$grid->make_region('A volcano', colour => 'orange');
$grid->make_region('Buslish Scrubs', colour => 'beige');
$grid->make_region('The Blasted Metropolis', colour => 'gray');
$grid->make_region('The sprawling grasses', colour => 'beige');
$grid->make_region('Something sandy?', colour => 'navajowhite');
$grid->make_region('Necromancer', colour => 'orange');
$grid->make_region('The Narrow Sea', colour => 'skyblue');
$grid->make_region('Naurardhon', colour => 'palegoldenrod');
$grid->make_region('The Glades of Leamingbury', colour => 'lightgreen');
$grid->make_region('Cape of Lost Causes', colour => 'gray');
$grid->make_region('Deadlands', colour => 'black');
$grid->make_region('Deadlands', colour => 'black');
$grid->make_region('Glade borders', colour => 'mediumaquamarine');
$grid->make_region('Thicket', colour => 'darkgreen');
$grid->make_region('Random house', colour => 'darkgreen');
$grid->make_region('Abbey of Plendor', colour => 'beige');
$grid->make_region('Khulanu', opacity => '0', style => { 'stroke-width' => 5, 'stroke' => 'black' });
my $tiles;
open $tiles, "$ENV{HOME}/RPG-stuff/WestOfVipers/coordinate-mapping";
my $region;
my $region_file;
start_region();
while(my $coords = <$tiles>)
{
if ($coords =~ /^\s*$/)
{
start_region();
next;
}
print $region_file $coords if $coords;
}
close $region_file if $region_file;
sub start_region
{
close $region_file if $region_file;
$region = <$tiles>;
chomp($region);
my $encoded_region = $region;
$encoded_region =~ s/\W/_/g;
open $region_file, ">region_files/$encoded_region" || croak "Can't open file for $region: $!";
say $region_file "== Style ==";
foreach my $key (keys %{$grid->{regions}{$region}{defaults}})
{
next if $key eq 'style';
say $region_file "$key: $grid->{regions}{$region}{defaults}{$key}";
}
if(my $css = $grid->{regions}{$region}{defaults}{style})
{
say $region_file "\n=== CSS ===";
foreach my $key (keys %{$grid->{regions}{$region}{defaults}{style}})
{
say $region_file "$key: $grid->{regions}{$region}{defaults}{style}{$key}";
}
}
say $region_file "\n== Tiles ==";
}

@ -1,37 +0,0 @@
use v5.30;
# use Getopt::Long;
use SVG;
my $width = 400;
my $height = 300;
my $origin_x = 0;
my $origin_height = 100;
my $corner_radius = 25;
my $gap_start = 50;
my $gap_width = 50;
my $full_height = $height + $origin_height;
my $svg = SVG->new(width => $width, height => $full_height, viewBox => "0 0 $width $full_height");
my $path_string = "M $gap_start,$height";
$path_string .= L($origin_x,$full_height);
$path_string .= L($gap_start + $gap_width,$height);
$path_string .= L($width - $corner_radius, $height);
$path_string .= a($corner_radius, $corner_radius, 0, 0, 0, $corner_radius, -$corner_radius);
$path_string .= l(0, -($height - 2*$corner_radius));
$path_string .= a($corner_radius, $corner_radius, 0, 0, 0, -$corner_radius, -$corner_radius);
$path_string .= l(-($width - 2*$corner_radius),0);
$path_string .= a($corner_radius, $corner_radius, 0, 0, 0, -$corner_radius, $corner_radius);
$path_string .= l(0, ($height - 2*$corner_radius));
$path_string .= a($corner_radius, $corner_radius, 0, 0, 0, $corner_radius, $corner_radius);
$path_string .= " Z";
my $path = $svg->path(d => $path_string, stroke => 'black', fill => 'white');
say $svg->render();
sub L { " L " . join(",", @_); }
sub l { " l " . join(",", @_); }
sub a { " a $_[0],$_[1] $_[2] $_[3] $_[4] $_[5],$_[6]"; }

@ -1,127 +0,0 @@
use v5.30;
use HexGrid;
use HexGrid::Pin;
use Data::Dumper;
use Text::Lorem;
my $lorem = Text::Lorem->new;
# my $adder_pin = new HexGrid::Pin(id => 'mountain-pin', icon => 'mountain.svg', name => 'Adder', description => $lorem->sentences(1));
my $grid = HexGrid->new(defaults => { style => { 'stroke-width' => 1, 'stroke' => 'black' }, show_coords => 1 });
$grid->make_region("Viper's Gate", colour => 'red');
# $grid->make_region('Adderwall', colour => 'orange', pins => {n => $adder_pin});
my $adderwall = $grid->make_region('Adderwall', colour => 'orange');
# $adderwall->make_subregion('Adderwall foothills', colour => 'moccasin');
$grid->make_region('Adderwall foothills', colour => 'moccasin');
$grid->make_region('Midhills', colour => 'moccasin');
# $grid->make_region('Minev', colour => 'green', images => ["forest-tile.png"]);
$grid->make_region('Minev', colour => 'green');
$grid->make_region('Barrowcross', colour => 'darkgreen');
$grid->make_region('Shinei Mavet', colour => 'orange');
$grid->make_region('Jagged Shinei Mavet', colour => 'orange');
$grid->make_region('Shinei Mavet waters', colour => 'lightcyan');
# $grid->make_region('Shinei Mavet', colour => 'orange', image => 'mountain.svg');
# $grid->make_region('Jagged Shinei Mavet', colour => 'orange', images => ['mountain.svg', 'jagged.svg']);
# $grid->make_region('Shinei Mavet waters', colour => 'lightcyan', image => 'foo.png');
$grid->make_region('Southern Ocean', colour => 'skyblue');
$grid->make_region('A volcano', colour => 'orange');
$grid->make_region('Buslish Scrubs', colour => 'beige');
$grid->make_region('The Blasted Metropolis', colour => 'gray');
$grid->make_region('The sprawling grasses', colour => 'beige');
$grid->make_region('Something sandy?', colour => 'navajowhite');
$grid->make_region('Necromancer', colour => 'orange');
$grid->make_region('The Narrow Sea', colour => 'skyblue');
$grid->make_region('Naurardhon', colour => 'palegoldenrod');
$grid->make_region('The Glades of Leamingbury', colour => 'lightgreen');
$grid->make_region('Cape of Lost Causes', colour => 'gray');
$grid->make_region('Deadlands', colour => 'black');
$grid->make_region('Deadlands', colour => 'black');
$grid->make_region('Glade borders', colour => 'mediumaquamarine');
$grid->make_region('Thicket', colour => 'darkgreen');
$grid->make_region('Random house', colour => 'darkgreen');
$grid->make_region('Abbey of Plendor', colour => 'beige');
$grid->make_region('Khulanu', opacity => '0', style => { 'stroke-width' => 5, 'stroke' => 'black' });
my $tiles;
open $tiles, "$ENV{HOME}/RPG-stuff/WestOfVipers/coordinate-mapping";
my $region = <$tiles>;
chomp($region);
while(my $coords = <$tiles>)
{
if ($coords =~ /^\s*$/)
{
$region = <$tiles>;
chomp($region);
next;
}
chomp $coords;
my %settings;
if($coords =~ /:$/)
{
for(my $line = <$tiles>; $line !~ /^;/; $line = <$tiles>)
{
my($key, $val) = split /:/, $line;
$settings{$key} = $val;
}
chop($coords);
}
my ($nw,$sw) = split /,/, $coords;
my $tile = $grid->{regions}{$region}->make_tile_at($nw, $sw, %settings);
if($region eq "Necromancer")
{
$tile->pin(new HexGrid::Pin(id => "circle-pin", icon => "foo2.svg", name => "zap", description => scalar $lorem->paragraphs(4), href => 'http://www.tensor.green'));
}
}
close $tiles;
# $grid->get_tile_at(0,0)->pin(
# $grid->{regions}{"Viper's Gate"}{tiles}{0}{0}->pin(
# {
# 'n' => new HexGrid::Pin(icon => "1"),
# 'se' => new HexGrid::Pin(icon => "2"),
# 'sw' => new HexGrid::Pin(icon => "3")
# }
# );
# $grid->get_tile_at(0,0)->pin(
# new HexGrid::Pin(icon => "foo2.svg"),
# 'se'
# );
# $grid->get_tile_at(0,0)->pin(
# new HexGrid::Pin(icon => "mountain.svg")
# );
# $grid->get_tile_at(0,0)->pin(
# new HexGrid::Pin(icon => "foo2.svg")
# );
# $grid->{regions}{"Viper's Gate"}{tiles}{0}{0}->pin(
# new HexGrid::Pin(icon => "2")
# );
# $grid->{regions}{"Viper's Gate"}{tiles}{0}{0}->pin(
# new HexGrid::Pin(icon => "3"),
# 'sw'
# );
say "<!DOCTYPE html>";
say "<html>\n<body>";
say <<EOS;
<script>
function clickPin(pinId, containerId) {
let popup = document.getElementById(pinId + '-popup');
popup.style.visibility = popup.style.visibility == 'visible' ? 'hidden' : 'visible';
}
</script>
EOS
say $grid->render;
# $grid->render;
say "</body>\n</html>";
sub random_colour
{
my $str = '#';
$str .= sprintf('%02X', int(rand(256))) for 1..3;
return $str;
}

@ -1,109 +0,0 @@
use v5.30;
use HexGrid;
use HexGrid::Pin;
use MWTemplate;
use Getopt::Long;
use File::Find;
use File::Basename;
use Carp;
use Data::Dumper;
$Data::Dumper::Indent = 1;
use feature "signatures";
no warnings "experimental::signatures";
my $template_name = "MapRegion";
my $border_width = 1;
my $border_colour = 'black';
my $show_coords = 0;
my @region_files;
my @pin_files;
my @include_dirs;
GetOptions(
'border-width=f' => \$border_width,
'border-colour|border-color=s' => \$border_colour,
'show-coords|coords!' => \$show_coords,
'region-file=s' => \@region_files,
'pin-file=s' => \@pin_files,
'directory|include-directory=s' => \@include_dirs
);
my $grid = HexGrid->new(defaults => {
style => { 'stroke-width' => $border_width, stroke => $border_colour },
show_coords => $show_coords });
@region_files = split(/,/, join(',', @region_files));
@pin_files = split(/,/, join(',', @pin_files));
@include_dirs = split(/,/, join(',', @include_dirs));
find(sub
{
push @region_files, $File::Find::name if /\.region$/;
push @pin_files, $File::Find::name if /\.pin$/;
}, @include_dirs);
foreach my $file (@region_files)
{
my $name = fileparse($file, qr/\.region/);
open my $fh, $file || croak "Couldn't open region file $file: $!";
my @region_lines = <$fh>;
close $fh;
my $tiles_file = $file;
$tiles_file =~ s/region$/tiles/;
open my $tfh, $tiles_file || croak "Couldn't open tiles file $tiles_file: $!";
my @tiles = <$tfh>;
close $tfh;
process_region($grid, $name, (join "", @region_lines), (join "", @tiles));
}
foreach my $file (@pin_files)
{
my $name = fileparse($file, qr/\.pin/);
open my $fh, $file || croak "Couldn't open pin file $file: $!";
my @lines = <$fh>;
close $fh;
process_pin($grid, $name, @lines);
}
say wrap_in_html($grid);
sub process_region($grid, $name, $region_spec, $tiles)
{
my $region = $grid->make_region($name);
my $parsed_template = MWTemplate::Parse($region_spec, $template_name);
$region->{defaults}{colour} = $parsed_template->{named_params}{colour};
$region->{defaults}{image} = $parsed_template->{named_params}{background};
say STDERR Dumper($tiles);
foreach my $coords (split /;/, $tiles)
{
# The below regex is a whitespace forgiving version of /^(-?\d+),(-?\d+)/, an int pair
do { carp "Skipping bad spec: $coords"; next; }
unless $coords =~ /^\s*(-?\s*\d+)\s*,\s*(-?\s*\d+)\s*$/;
$region->make_tile_at($1,$2);
}
}
sub process_pin($file)
{
}
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
$html_builder .= "\n" . $grid->render;
$html_builder .= "\n</body>\n</html>";
return $html_builder;
}
Loading…
Cancel
Save