|
|
@ -14,7 +14,7 @@ use Data::Dumper; |
|
|
|
use feature "signatures"; |
|
|
|
use feature "signatures"; |
|
|
|
no warnings "experimental::signatures"; |
|
|
|
no warnings "experimental::signatures"; |
|
|
|
|
|
|
|
|
|
|
|
# The below regex is a whitespace forgiving version of /^(-?\d+),(-?\d+)/, an int pair |
|
|
|
# This regex is a whitespace forgiving version of /^(-?\d+),(-?\d+)/, an int pair |
|
|
|
my $coords_regex = qr/^\s*(-?\s*\d+)\s*,\s*(-?\s*\d+)\s*$/; |
|
|
|
my $coords_regex = qr/^\s*(-?\s*\d+)\s*,\s*(-?\s*\d+)\s*$/; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -27,6 +27,7 @@ my $site_template_name = "MapSite"; |
|
|
|
my $border_width = 1; |
|
|
|
my $border_width = 1; |
|
|
|
my $border_colour = 'black'; |
|
|
|
my $border_colour = 'black'; |
|
|
|
my $show_coords = 0; |
|
|
|
my $show_coords = 0; |
|
|
|
|
|
|
|
my $embed_images = 1; |
|
|
|
|
|
|
|
|
|
|
|
my $html_document = 1; |
|
|
|
my $html_document = 1; |
|
|
|
my $outfile = '-'; |
|
|
|
my $outfile = '-'; |
|
|
@ -43,6 +44,7 @@ GetOptions |
|
|
|
'border-width|bw=f' => \$border_width, |
|
|
|
'border-width|bw=f' => \$border_width, |
|
|
|
'border-colour|border-color|bc=s' => \$border_colour, |
|
|
|
'border-colour|border-color|bc=s' => \$border_colour, |
|
|
|
'show-coords|coords!' => \$show_coords, |
|
|
|
'show-coords|coords!' => \$show_coords, |
|
|
|
|
|
|
|
'embed-images!' => \$embed_images, |
|
|
|
|
|
|
|
|
|
|
|
'html-document!' => \$html_document, |
|
|
|
'html-document!' => \$html_document, |
|
|
|
'outfile=s' => \$outfile, |
|
|
|
'outfile=s' => \$outfile, |
|
|
@ -51,10 +53,11 @@ GetOptions |
|
|
|
|
|
|
|
|
|
|
|
$api_url // croak "Base API URL is required! Use --api-url to set"; |
|
|
|
$api_url // croak "Base API URL is required! Use --api-url to set"; |
|
|
|
|
|
|
|
|
|
|
|
my $grid = HexGrid->new(defaults => { |
|
|
|
my $grid = HexGrid->new(embed_images => $embed_images, 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 %region_grids; |
|
|
|
my %region_grids; |
|
|
|
|
|
|
|
my %region_grids_by_subregion; |
|
|
|
my $mw = MediaWiki::API->new(); |
|
|
|
my $mw = MediaWiki::API->new(); |
|
|
|
$mw->{config}->{api_url} = $api_url; |
|
|
|
$mw->{config}->{api_url} = $api_url; |
|
|
|
|
|
|
|
|
|
|
@ -91,7 +94,8 @@ foreach my $page (values %{$region_query_results->{query}{pages}}) |
|
|
|
show_coords => $show_coords |
|
|
|
show_coords => $show_coords |
|
|
|
}, |
|
|
|
}, |
|
|
|
height => 300, |
|
|
|
height => 300, |
|
|
|
width => 300 |
|
|
|
width => 300, |
|
|
|
|
|
|
|
embed_images => $embed_images |
|
|
|
); |
|
|
|
); |
|
|
|
$region_grids{$page->{title}}->add_region($region); |
|
|
|
$region_grids{$page->{title}}->add_region($region); |
|
|
|
} |
|
|
|
} |
|
|
@ -126,6 +130,7 @@ foreach my $page (values %{$subregion_query_results->{query}{pages}}) |
|
|
|
{ |
|
|
|
{ |
|
|
|
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); |
|
|
|
|
|
|
|
$region_grids_by_subregion{$subregion->{name}} = $region_grids{$region_name}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
push @tile_pages, "$page->{title}/Tiles"; |
|
|
|
push @tile_pages, "$page->{title}/Tiles"; |
|
|
@ -165,8 +170,6 @@ foreach my $page (values %{$location_query_results->{query}{pages}}) |
|
|
|
if($regiondir) |
|
|
|
if($regiondir) |
|
|
|
{ |
|
|
|
{ |
|
|
|
$region_grids{$region_name}->add_region($location); |
|
|
|
$region_grids{$region_name}->add_region($location); |
|
|
|
my $region_name = $parsed_template->{positional_params}[1]; |
|
|
|
|
|
|
|
$region_grids{$region_name}->add_region($location); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$region_grids{$location->{name}} = HexGrid->new |
|
|
|
$region_grids{$location->{name}} = HexGrid->new |
|
|
|
( |
|
|
|
( |
|
|
@ -191,6 +194,8 @@ foreach my $page (values %{$location_query_results->{query}{pages}}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
HexGrid::Image::DEBUG(); |
|
|
|
|
|
|
|
|
|
|
|
say STDERR "Getting Background image pages"; |
|
|
|
say STDERR "Getting Background image pages"; |
|
|
|
my $background_query_results = $mw->api({ action => 'query', |
|
|
|
my $background_query_results = $mw->api({ action => 'query', |
|
|
|
prop => 'imageinfo', |
|
|
|
prop => 'imageinfo', |
|
|
@ -198,6 +203,7 @@ my $background_query_results = $mw->api({ action => 'query', |
|
|
|
iiprop => 'url' |
|
|
|
iiprop => 'url' |
|
|
|
}) || carp $mw->{error}->{code} . ': ' . $mw->{error}->{details}; |
|
|
|
}) || carp $mw->{error}->{code} . ': ' . $mw->{error}->{details}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# say STDERR Dumper(\%region_grids); |
|
|
|
foreach my $page (values %{$background_query_results->{query}{pages}}) |
|
|
|
foreach my $page (values %{$background_query_results->{query}{pages}}) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if($page->{imageinfo}) |
|
|
|
if($page->{imageinfo}) |
|
|
@ -207,6 +213,18 @@ foreach my $page (values %{$background_query_results->{query}{pages}}) |
|
|
|
foreach my $region (@{$background_pages{$page->{title}}}) |
|
|
|
foreach my $region (@{$background_pages{$page->{title}}}) |
|
|
|
{ |
|
|
|
{ |
|
|
|
$region->{defaults}{image} = HexGrid::to_id($page->{title}); |
|
|
|
$region->{defaults}{image} = HexGrid::to_id($page->{title}); |
|
|
|
|
|
|
|
if($regiondir) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
# say STDERR $region->{name}; |
|
|
|
|
|
|
|
if(exists $region_grids{$region->{name}}) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
$region_grids{$region->{name}}->add_image(HexGrid::to_id($page->{title}), $page->{imageinfo}[0]{url}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
elsif(exists $region_grids_by_subregion{$region->{name}}) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
$region_grids_by_subregion{$region->{name}}->add_image(HexGrid::to_id($page->{title}), $page->{imageinfo}[0]{url}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|