|
|
|
@ -43,7 +43,6 @@ GetOptions |
|
|
|
|
'subregion-template-name=s' => \$subregion_template_name, |
|
|
|
|
'location-template-name=s' => \$location_template_name, |
|
|
|
|
'site-template-name=s' => \$site_template_name, |
|
|
|
|
'path-template-name=s' => \$path_template_name, |
|
|
|
|
|
|
|
|
|
'border-width|bw=f' => \$border_width, |
|
|
|
|
'border-colour|border-color|bc=s' => \$border_colour, |
|
|
|
@ -63,7 +62,6 @@ my $grid = HexGrid->new(embed_images => $embed_images, defaults => { |
|
|
|
|
style => { 'stroke-width' => $border_width, stroke => $border_colour }, |
|
|
|
|
show_coords => $show_coords}); |
|
|
|
|
|
|
|
|
|
# Used in producing region subgrids, maps each subregion to its parent region |
|
|
|
|
my %regions_by_subregion; |
|
|
|
|
my %images_for_region_grids; |
|
|
|
|
my %location_grids; |
|
|
|
@ -89,10 +87,10 @@ my (@tile_pages, %background_pages); |
|
|
|
|
foreach my $page (values %{$region_query_results->{query}{pages}}) |
|
|
|
|
{ |
|
|
|
|
next if $page->{title} =~ /^Category:/; |
|
|
|
|
my $region = $grid->make_region($page->{title}); |
|
|
|
|
my $parsed_template = MWTemplate::Parse($page->{revisions}[0]{'*'}, $region_template_name); |
|
|
|
|
next unless $parsed_template; |
|
|
|
|
say STDERR "Processing region: $page->{title}"; |
|
|
|
|
my $region = $grid->make_region($page->{title}); |
|
|
|
|
$region->{defaults}{colour} = $parsed_template->{named_params}{colour}; |
|
|
|
|
$region->{defaults}{coords_colour} = $parsed_template->{named_params}{coordinates_colour} |
|
|
|
|
if $parsed_template->{named_params}{coordinates_colour}; |
|
|
|
@ -170,18 +168,13 @@ foreach my $page (values %{$location_query_results->{query}{pages}}) |
|
|
|
|
my $region_name = $parsed_template->{positional_params}[1]; |
|
|
|
|
$regions_by_subregion{$location->{name}} = $region_name; |
|
|
|
|
|
|
|
|
|
next unless $parsed_template->{positional_params}[0] =~ $coords_regex; |
|
|
|
|
my ($nw, $sw) = ($1, $2); |
|
|
|
|
|
|
|
|
|
push @location_continuations, sub |
|
|
|
|
{ |
|
|
|
|
# We create the tile after the location region has its image set, which happens later |
|
|
|
|
return unless $parsed_template->{positional_params}[0] =~ $coords_regex; |
|
|
|
|
my ($nw, $sw) = ($1, $2); |
|
|
|
|
$location->make_tile_at($nw, $sw); |
|
|
|
|
if($regiondir) |
|
|
|
|
{ |
|
|
|
|
# Locations can have their own images rendered, given a list of context tiles |
|
|
|
|
# To reference these tiles, they must exist in the parent grid, |
|
|
|
|
# so the remainder of the processing must happen after the region tile pages are processed |
|
|
|
|
my @coords_list = ({ nw => $nw, sw => $sw}); |
|
|
|
|
foreach my $coords (split /;/, $parsed_template->{named_params}{context_tiles}) |
|
|
|
|
{ |
|
|
|
@ -205,10 +198,6 @@ foreach my $page (values %{$location_query_results->{query}{pages}}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# To minimize API calls, and since some images may be referenced by more than one region, |
|
|
|
|
# all background images for all regions are put in one request. |
|
|
|
|
# The list of pages to get was constructed in the region, subregion, and location processing. |
|
|
|
|
|
|
|
|
|
say STDERR "Getting Background image pages"; |
|
|
|
|
my $background_query_results = $mw->api({ action => 'query', |
|
|
|
|
prop => 'imageinfo', |
|
|
|
@ -222,14 +211,14 @@ foreach my $page (values %{$background_query_results->{query}{pages}}) |
|
|
|
|
{ |
|
|
|
|
say STDERR "Processing image: $page->{title}"; |
|
|
|
|
$grid->add_image(HexGrid::to_id($page->{title}), $page->{imageinfo}[0]{url}); |
|
|
|
|
# For every region which declared this image its background |
|
|
|
|
foreach my $subregion (@{$background_pages{$page->{title}}}) |
|
|
|
|
{ |
|
|
|
|
$subregion->{defaults}{image} = HexGrid::to_id($page->{title}); |
|
|
|
|
if($regiondir) |
|
|
|
|
{ |
|
|
|
|
# If we make subgrids for the regions, we'll need to add this image to the region's subgrid |
|
|
|
|
my $region_name = $regions_by_subregion{$subregion->{name}}; |
|
|
|
|
# say STDERR $page->{title} unless $region_name; |
|
|
|
|
# say STDERR "$region_name"; |
|
|
|
|
push @{$images_for_region_grids{$region_name}}, |
|
|
|
|
{ |
|
|
|
|
name => HexGrid::to_id($page->{title}), |
|
|
|
@ -241,9 +230,6 @@ foreach my $page (values %{$background_query_results->{query}{pages}}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# As above, get all tile pages in one request. |
|
|
|
|
# By doing so, we lose context as to which page corresponds to which region, |
|
|
|
|
# so we extract it from the title of the page. |
|
|
|
|
|
|
|
|
|
say STDERR "Getting Tile pages"; |
|
|
|
|
my $tile_query_results = $mw->api |
|
|
|
@ -294,6 +280,7 @@ foreach my $path_page_ref (values %{$path_query_results->{query}{pages}}) |
|
|
|
|
|
|
|
|
|
say STDERR "Processing Path $path_name"; |
|
|
|
|
|
|
|
|
|
my $path_url = $path_page_ref->{canonicalurl}; |
|
|
|
|
my $path_content = $path_page_ref->{revisions}[0]{'*'}; |
|
|
|
|
my $parsed_template = MWTemplate::Parse($path_content, $path_template_name); |
|
|
|
|
next unless $parsed_template; |
|
|
|
@ -336,8 +323,10 @@ foreach my $page (values %{$path_tile_query_results->{query}{pages}}) |
|
|
|
|
my $path = $grid->make_path_from($path_spec{id}, \@path_coords, css_class => 'path', |
|
|
|
|
colour => $path_spec{colour}, |
|
|
|
|
style => { 'stroke-width' => $path_spec{stroke_width} // $default_path_stroke_width }); |
|
|
|
|
$path->{starts_from} = $HexGrid::DIR{$path_spec{starts_from}} if $path_spec{starts_from}; |
|
|
|
|
$path->{ends_to} = $HexGrid::DIR{$path_spec{ends_to}} if $path_spec{ends_to}; |
|
|
|
|
$path->{starts_from} = $HexGrid::DIR{$path_spec{starts_from}} |
|
|
|
|
if $path_spec{starts_from}; |
|
|
|
|
$path->{ends_to} = $HexGrid::DIR{$path_spec{ends_to}} |
|
|
|
|
if $path_spec{ends_to}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -353,7 +342,6 @@ my $site_query_results = $mw->api |
|
|
|
|
inprop => 'url', |
|
|
|
|
} ) || croak $mw->{error}->{code} . ': ' . $mw->{error}->{details}; |
|
|
|
|
|
|
|
|
|
my %site_icon_pages; |
|
|
|
|
foreach my $site_page_ref (values %{$site_query_results->{query}{pages}}) |
|
|
|
|
{ |
|
|
|
|
next if $site_page_ref->{title} =~ /^Category:/; |
|
|
|
@ -373,17 +361,14 @@ foreach my $site_page_ref (values %{$site_query_results->{query}{pages}}) |
|
|
|
|
next; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$site_icon_pages{"File:$parsed_template->{named_params}{icon}"} = |
|
|
|
|
$parsed_template->{named_params}{icon}; |
|
|
|
|
|
|
|
|
|
# my $imageinfo_query_results = $mw->api({ action => 'query', |
|
|
|
|
# prop => 'imageinfo', |
|
|
|
|
# titles => "File:$parsed_template->{named_params}{icon}", |
|
|
|
|
# iiprop => 'url' |
|
|
|
|
# }) || carp $mw->{error}->{code} . ': ' . $mw->{error}->{details}; |
|
|
|
|
# my %image_pages = %{$imageinfo_query_results->{query}{pages}}; |
|
|
|
|
# my $image_url = (values %image_pages)[0]{imageinfo}[0]{url}; |
|
|
|
|
# $grid->add_image(HexGrid::to_id($parsed_template->{named_params}{icon}), $image_url); |
|
|
|
|
my $imageinfo_query_results = $mw->api({ action => 'query', |
|
|
|
|
prop => 'imageinfo', |
|
|
|
|
titles => "File:$parsed_template->{named_params}{icon}", |
|
|
|
|
iiprop => 'url' |
|
|
|
|
}) || carp $mw->{error}->{code} . ': ' . $mw->{error}->{details}; |
|
|
|
|
my %image_pages = %{$imageinfo_query_results->{query}{pages}}; |
|
|
|
|
my $image_url = (values %image_pages)[0]{imageinfo}[0]{url}; |
|
|
|
|
$grid->add_image(HexGrid::to_id($parsed_template->{named_params}{icon}), $image_url); |
|
|
|
|
|
|
|
|
|
my $pin = HexGrid::Pin->new |
|
|
|
|
( |
|
|
|
@ -397,36 +382,14 @@ foreach my $site_page_ref (values %{$site_query_results->{query}{pages}}) |
|
|
|
|
$tile->pin($pin); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
say STDERR "Getting Site icon image pages"; |
|
|
|
|
my $site_icon_query_results = $mw->api({ action => 'query', |
|
|
|
|
prop => 'imageinfo', |
|
|
|
|
titles => join('|', keys %site_icon_pages), |
|
|
|
|
iiprop => 'url' |
|
|
|
|
}) || carp $mw->{error}->{code} . ': ' . $mw->{error}->{details}; |
|
|
|
|
|
|
|
|
|
foreach my $page (values %{$site_icon_query_results->{query}{pages}}) |
|
|
|
|
{ |
|
|
|
|
if($page->{imageinfo}) |
|
|
|
|
{ |
|
|
|
|
say STDERR "Processing image: $page->{title}"; |
|
|
|
|
$grid->add_image |
|
|
|
|
( |
|
|
|
|
HexGrid::to_id($site_icon_pages{$page->{title}}), |
|
|
|
|
$page->{imageinfo}[0]{url} |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
# Render and output |
|
|
|
|
open (my $fh, "> $outfile") or croak "Couldn't open $outfile for writing: $!"; |
|
|
|
|
say $fh ($html_document ? wrap_in_html($grid) : $grid->render); |
|
|
|
|
close $fh; |
|
|
|
|
|
|
|
|
|
if($regiondir) |
|
|
|
|
{ |
|
|
|
|
chdir $regiondir || croak "Couldn't chdir to $regiondir: $!"; |
|
|
|
|
my $extension = $html_document ? 'html' : 'svg'; |
|
|
|
|
my %region_grid_listings; # Maps a region name to the list of its subregions (including itself) |
|
|
|
|
my %region_grid_listings; |
|
|
|
|
while(my ($subregion, $region) = each %regions_by_subregion) |
|
|
|
|
{ |
|
|
|
|
push @{$region_grid_listings{$region}}, $subregion; |
|
|
|
@ -434,11 +397,14 @@ if($regiondir) |
|
|
|
|
while(my ($region, $subregions) = each %region_grid_listings) |
|
|
|
|
{ |
|
|
|
|
my $region_grid = $grid->subgrid_for_regions(@$subregions); |
|
|
|
|
# say STDERR Dumper($images_for_region_grids{$region}); |
|
|
|
|
if(exists $images_for_region_grids{$region}) |
|
|
|
|
{ |
|
|
|
|
foreach my $image (@{$images_for_region_grids{$region}}) |
|
|
|
|
{ |
|
|
|
|
# say STDERR Dumper($image); |
|
|
|
|
$region_grid->{images}{$image->{name}} = $grid->{images}{$image->{name}}; |
|
|
|
|
# $region_grid->add_image($image->{name}, $image->{source}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -448,7 +414,7 @@ if($regiondir) |
|
|
|
|
say $region_fh ($html_document ? wrap_in_html($region_grid) : $region_grid->render); |
|
|
|
|
close $region_fh; |
|
|
|
|
} |
|
|
|
|
# TODO: Location grids need to import images |
|
|
|
|
# Location grids need to import images |
|
|
|
|
while(my ($location_name, $location_grid) = each %location_grids) |
|
|
|
|
{ |
|
|
|
|
say STDERR "Rendering Location $location_name\'s grid"; |
|
|
|
@ -460,8 +426,6 @@ if($regiondir) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Puts the rendered SVG inside an html document, |
|
|
|
|
# along with a bit of javascript to show popups for sites and to toggle coordinates visibility |
|
|
|
|
sub wrap_in_html($grid) |
|
|
|
|
{ |
|
|
|
|
my $html_builder = "<!DOCTYPE html>"; |
|
|
|
|