|
|
@ -1,4 +1,4 @@ |
|
|
|
use v5.30; |
|
|
|
use v5.36; |
|
|
|
|
|
|
|
|
|
|
|
use HexGrid; |
|
|
|
use HexGrid; |
|
|
|
use HexGrid::Pin; |
|
|
|
use HexGrid::Pin; |
|
|
@ -24,13 +24,23 @@ my $border_width = 1; |
|
|
|
my $border_colour = 'black'; |
|
|
|
my $border_colour = 'black'; |
|
|
|
my $show_coords = 0; |
|
|
|
my $show_coords = 0; |
|
|
|
|
|
|
|
|
|
|
|
GetOptions( |
|
|
|
my $interactive = 1; |
|
|
|
'border-width=f' => \$border_width, |
|
|
|
my $do_subregions = 1; |
|
|
|
'border-colour|border-color=s' => \$border_colour, |
|
|
|
|
|
|
|
'show-coords|coords!' => \$show_coords, |
|
|
|
GetOptions |
|
|
|
|
|
|
|
( |
|
|
|
'api-url=s' => \$api_url, |
|
|
|
'api-url=s' => \$api_url, |
|
|
|
'region-template-name=s' => \$region_template_name, |
|
|
|
'region-template-name=s' => \$region_template_name, |
|
|
|
'site-template-name=s' => \$site_template_name |
|
|
|
'subregion-template-name=s' => \$subregion_template_name, |
|
|
|
|
|
|
|
'location-template-name=s' => \$location_template_name, |
|
|
|
|
|
|
|
'site-template-name=s' => \$site_template_name, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
'border-width|bw=f' => \$border_width, |
|
|
|
|
|
|
|
'border-colour|border-color|bc=s' => \$border_colour, |
|
|
|
|
|
|
|
'show-coords|coords!' => \$show_coords, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
'interactive|s!' => \$interactive, |
|
|
|
|
|
|
|
'subregions!|sub' => \$do_subregions |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
my $grid = HexGrid->new(defaults => { |
|
|
|
my $grid = HexGrid->new(defaults => { |
|
|
@ -57,13 +67,24 @@ my $region_query_results = $mw->api |
|
|
|
my (@tile_pages, %background_pages); |
|
|
|
my (@tile_pages, %background_pages); |
|
|
|
foreach my $page (values %{$region_query_results->{query}{pages}}) |
|
|
|
foreach my $page (values %{$region_query_results->{query}{pages}}) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
next if $page->{title} =~ /^Category:/; |
|
|
|
my $region = $grid->make_region($page->{title}); |
|
|
|
my $region = $grid->make_region($page->{title}); |
|
|
|
my $parsed_template = MWTemplate::Parse($page->{revisions}[0]{'*'}, $region_template_name); |
|
|
|
my $parsed_template = MWTemplate::Parse($page->{revisions}[0]{'*'}, $region_template_name); |
|
|
|
$region->{defaults}{colour} = $parsed_template->{named_params}{colour}; |
|
|
|
$region->{defaults}{colour} = $parsed_template->{named_params}{colour}; |
|
|
|
$region_grids{$page->{title}} = HexGrid->new(defaults => { |
|
|
|
if($do_subregions) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
$region_grids{$page->{title}} = HexGrid->new |
|
|
|
|
|
|
|
( |
|
|
|
|
|
|
|
defaults => |
|
|
|
|
|
|
|
{ |
|
|
|
style => { 'stroke-width' => $border_width, stroke => $border_colour }, |
|
|
|
style => { 'stroke-width' => $border_width, stroke => $border_colour }, |
|
|
|
show_coords => $show_coords }); |
|
|
|
show_coords => $show_coords |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
height => 300, |
|
|
|
|
|
|
|
width => 300 |
|
|
|
|
|
|
|
); |
|
|
|
$region_grids{$page->{title}}->add_region($region); |
|
|
|
$region_grids{$page->{title}}->add_region($region); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
push @tile_pages, "$page->{title}/Tiles"; |
|
|
|
push @tile_pages, "$page->{title}/Tiles"; |
|
|
|
push @{$background_pages{"File:$parsed_template->{named_params}{background}"}}, $region; |
|
|
|
push @{$background_pages{"File:$parsed_template->{named_params}{background}"}}, $region; |
|
|
@ -85,11 +106,15 @@ my $subregion_query_results = $mw->api |
|
|
|
|
|
|
|
|
|
|
|
foreach my $page (values %{$subregion_query_results->{query}{pages}}) |
|
|
|
foreach my $page (values %{$subregion_query_results->{query}{pages}}) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
next if $page->{title} =~ /^Category:/; |
|
|
|
my $parsed_template = MWTemplate::Parse($page->{revisions}[0]{'*'}, $subregion_template_name); |
|
|
|
my $parsed_template = MWTemplate::Parse($page->{revisions}[0]{'*'}, $subregion_template_name); |
|
|
|
my $subregion = $grid->make_region($page->{title}); |
|
|
|
my $subregion = $grid->make_region($page->{title}); |
|
|
|
$subregion->{defaults}{colour} = $parsed_template->{named_params}{colour}; |
|
|
|
$subregion->{defaults}{colour} = $parsed_template->{named_params}{colour}; |
|
|
|
|
|
|
|
if($do_subregions) |
|
|
|
|
|
|
|
{ |
|
|
|
my $region_name = $parsed_template->{positional_params}[0]; |
|
|
|
my $region_name = $parsed_template->{positional_params}[0]; |
|
|
|
$region_grids{$region_name}->add_region($subregion); |
|
|
|
$region_grids{$region_name}->add_region($subregion); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
push @tile_pages, "$page->{title}/Tiles"; |
|
|
|
push @tile_pages, "$page->{title}/Tiles"; |
|
|
|
push @{$background_pages{"File:$parsed_template->{named_params}{background}"}}, $subregion; |
|
|
|
push @{$background_pages{"File:$parsed_template->{named_params}{background}"}}, $subregion; |
|
|
@ -106,10 +131,8 @@ my $background_query_results = $mw->api({ action => 'query', |
|
|
|
|
|
|
|
|
|
|
|
foreach my $page (values %{$background_query_results->{query}{pages}}) |
|
|
|
foreach my $page (values %{$background_query_results->{query}{pages}}) |
|
|
|
{ |
|
|
|
{ |
|
|
|
# say STDERR Dumper($page); |
|
|
|
|
|
|
|
if($page->{imageinfo}) |
|
|
|
if($page->{imageinfo}) |
|
|
|
{ |
|
|
|
{ |
|
|
|
# say STDERR Dumper($page->{title}); |
|
|
|
|
|
|
|
foreach my $region (@{$background_pages{$page->{title}}}) |
|
|
|
foreach my $region (@{$background_pages{$page->{title}}}) |
|
|
|
{ |
|
|
|
{ |
|
|
|
$region->{defaults}{image} = $page->{imageinfo}[0]{url}; |
|
|
|
$region->{defaults}{image} = $page->{imageinfo}[0]{url}; |
|
|
@ -158,36 +181,51 @@ my $location_query_results = $mw->api |
|
|
|
|
|
|
|
|
|
|
|
foreach my $page (values %{$location_query_results->{query}{pages}}) |
|
|
|
foreach my $page (values %{$location_query_results->{query}{pages}}) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
next if $page->{title} =~ /^Category:/; |
|
|
|
my $parsed_template = MWTemplate::Parse($page->{revisions}[0]{'*'}, $location_template_name); |
|
|
|
my $parsed_template = MWTemplate::Parse($page->{revisions}[0]{'*'}, $location_template_name); |
|
|
|
my $location = $grid->make_region($page->{title}); |
|
|
|
my $location = $grid->make_region($page->{title}); |
|
|
|
|
|
|
|
|
|
|
|
$region_grids{$location->{name}} = HexGrid->new(defaults => { |
|
|
|
my $location_with_context; |
|
|
|
|
|
|
|
if($do_subregions) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
$region_grids{$location->{name}} = HexGrid->new |
|
|
|
|
|
|
|
( |
|
|
|
|
|
|
|
defaults => |
|
|
|
|
|
|
|
{ |
|
|
|
style => { 'stroke-width' => $border_width, stroke => $border_colour }, |
|
|
|
style => { 'stroke-width' => $border_width, stroke => $border_colour }, |
|
|
|
show_coords => $show_coords }); |
|
|
|
show_coords => $show_coords |
|
|
|
my $location_with_context = $region_grids{$location->{name}}->make_region($location->{name}); |
|
|
|
}, |
|
|
|
|
|
|
|
height => 300, |
|
|
|
|
|
|
|
width => 300 |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
$location_with_context = $region_grids{$location->{name}}->make_region($location->{name}); |
|
|
|
|
|
|
|
|
|
|
|
$location_with_context->{defaults}{colour} = $location->{defaults}{colour} = $parsed_template->{named_params}{colour}; |
|
|
|
$location_with_context->{defaults}{colour} = $location->{defaults}{colour} = $parsed_template->{named_params}{colour}; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
# The below regex is a whitespace forgiving version of /^(-?\d+),(-?\d+)/, an int pair |
|
|
|
# The below regex is a whitespace forgiving version of /^(-?\d+),(-?\d+)/, an int pair |
|
|
|
if($parsed_template->{positional_params}[0] =~ /^\s*(-?\s*\d+)\s*,\s*(-?\s*\d+)\s*$/) |
|
|
|
if($parsed_template->{positional_params}[0] =~ /^\s*(-?\s*\d+)\s*,\s*(-?\s*\d+)\s*$/) |
|
|
|
{ |
|
|
|
{ |
|
|
|
$location->make_tile_at($1,$2); |
|
|
|
$location->make_tile_at($1,$2); |
|
|
|
|
|
|
|
if($do_subregions) |
|
|
|
|
|
|
|
{ |
|
|
|
$location_with_context->make_tile_at($1,$2); |
|
|
|
$location_with_context->make_tile_at($1,$2); |
|
|
|
foreach my $coords (split /;/, $parsed_template->{named_params}{context_tiles}) |
|
|
|
foreach my $coords (split /;/, $parsed_template->{named_params}{context_tiles}) |
|
|
|
{ |
|
|
|
{ |
|
|
|
# The below regex is a whitespace forgiving version of /^(-?\d+),(-?\d+)/, an int pair |
|
|
|
# The below regex is a whitespace forgiving version of /^(-?\d+),(-?\d+)/, an int pair |
|
|
|
do { carp "Skipping bad spec: $coords"; next; } |
|
|
|
do { carp "Skipping bad spec: $coords"; next; } |
|
|
|
unless $coords =~ /^\s*(-?\s*\d+)\s*,\s*(-?\s*\d+)\s*$/; |
|
|
|
unless $coords =~ /^\s*(-?\s*\d+)\s*,\s*(-?\s*\d+)\s*$/; |
|
|
|
# say STDERR Dumper($grid->get_tile_at($1, $2)); |
|
|
|
|
|
|
|
# say STDERR Dumper($grid->{regions}{$parsed_template->{positional_params}[1]}); |
|
|
|
|
|
|
|
$location_with_context->add_tile($grid->get_tile_at($1, $2)); |
|
|
|
$location_with_context->add_tile($grid->get_tile_at($1, $2)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if($do_subregions) |
|
|
|
|
|
|
|
{ |
|
|
|
my $region_name = $parsed_template->{positional_params}[1]; |
|
|
|
my $region_name = $parsed_template->{positional_params}[1]; |
|
|
|
$region_grids{$region_name}->add_region($location); |
|
|
|
$region_grids{$region_name}->add_region($location); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
# push @tile_pages, "$page->{title}/Tiles"; |
|
|
|
|
|
|
|
push @{$background_pages{"File:$parsed_template->{named_params}{background}"}}, $location; |
|
|
|
push @{$background_pages{"File:$parsed_template->{named_params}{background}"}}, $location; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -208,6 +246,7 @@ my $site_query_results = $mw->api |
|
|
|
# say STDERR "Sites found: " . join(" ,", map { $_->{title} } @$site_pages); |
|
|
|
# say STDERR "Sites found: " . join(" ,", map { $_->{title} } @$site_pages); |
|
|
|
foreach my $site_page_ref (values %{$site_query_results->{query}{pages}}) |
|
|
|
foreach my $site_page_ref (values %{$site_query_results->{query}{pages}}) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
next if $site_page_ref->{title} =~ /^Category:/; |
|
|
|
my $site_name = $site_page_ref->{title}; |
|
|
|
my $site_name = $site_page_ref->{title}; |
|
|
|
say STDERR "Processing Site $site_name"; |
|
|
|
say STDERR "Processing Site $site_name"; |
|
|
|
my $site_url = $site_page_ref->{canonicalurl}; |
|
|
|
my $site_url = $site_page_ref->{canonicalurl}; |
|
|
@ -251,7 +290,10 @@ sub wrap_in_html($grid) |
|
|
|
</script> |
|
|
|
</script> |
|
|
|
EOS |
|
|
|
EOS |
|
|
|
$html_builder .= "\n" . $grid->render; |
|
|
|
$html_builder .= "\n" . $grid->render; |
|
|
|
|
|
|
|
if ($do_subregions) |
|
|
|
|
|
|
|
{ |
|
|
|
$html_builder .= "\n" . $_->render for values %region_grids; |
|
|
|
$html_builder .= "\n" . $_->render for values %region_grids; |
|
|
|
|
|
|
|
} |
|
|
|
$html_builder .= "\n</body>\n</html>"; |
|
|
|
$html_builder .= "\n</body>\n</html>"; |
|
|
|
return $html_builder; |
|
|
|
return $html_builder; |
|
|
|
} |
|
|
|
} |
|
|
|