|
|
|
@ -43,6 +43,7 @@ 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, |
|
|
|
@ -62,6 +63,7 @@ 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; |
|
|
|
@ -87,10 +89,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,15 +172,16 @@ foreach my $page (values %{$location_query_results->{query}{pages}}) |
|
|
|
|
|
|
|
|
|
next unless $parsed_template->{positional_params}[0] =~ $coords_regex; |
|
|
|
|
my ($nw, $sw) = ($1, $2); |
|
|
|
|
$location->make_tile_at($nw, $sw); |
|
|
|
|
|
|
|
|
|
if($regiondir) |
|
|
|
|
push @location_continuations, sub |
|
|
|
|
{ |
|
|
|
|
# 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 |
|
|
|
|
push @location_continuations, sub |
|
|
|
|
# We create the tile after the location region has its image set, which happens later |
|
|
|
|
$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}) |
|
|
|
|
{ |
|
|
|
@ -202,6 +205,10 @@ 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', |
|
|
|
@ -215,14 +222,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}), |
|
|
|
@ -234,6 +241,9 @@ 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 |
|
|
|
@ -284,7 +294,6 @@ 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; |
|
|
|
@ -327,10 +336,8 @@ 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}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -386,14 +393,16 @@ foreach my $site_page_ref (values %{$site_query_results->{query}{pages}}) |
|
|
|
|
$tile->pin($pin); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
# 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; |
|
|
|
|
my %region_grid_listings; # Maps a region name to the list of its subregions (including itself) |
|
|
|
|
while(my ($subregion, $region) = each %regions_by_subregion) |
|
|
|
|
{ |
|
|
|
|
push @{$region_grid_listings{$region}}, $subregion; |
|
|
|
@ -401,14 +410,11 @@ 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}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -418,7 +424,7 @@ if($regiondir) |
|
|
|
|
say $region_fh ($html_document ? wrap_in_html($region_grid) : $region_grid->render); |
|
|
|
|
close $region_fh; |
|
|
|
|
} |
|
|
|
|
# Location grids need to import images |
|
|
|
|
# TODO: Location grids need to import images |
|
|
|
|
while(my ($location_name, $location_grid) = each %location_grids) |
|
|
|
|
{ |
|
|
|
|
say STDERR "Rendering Location $location_name\'s grid"; |
|
|
|
@ -430,6 +436,8 @@ 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>"; |
|
|
|
|