|
|
@ -54,6 +54,8 @@ GetOptions |
|
|
|
'regiondir=s' => \$regiondir |
|
|
|
'regiondir=s' => \$regiondir |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# HexGrid::DEBUG(); |
|
|
|
|
|
|
|
|
|
|
|
$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(embed_images => $embed_images, defaults => { |
|
|
|
my $grid = HexGrid->new(embed_images => $embed_images, defaults => { |
|
|
@ -203,7 +205,6 @@ 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(\%background_pages); |
|
|
|
|
|
|
|
foreach my $page (values %{$background_query_results->{query}{pages}}) |
|
|
|
foreach my $page (values %{$background_query_results->{query}{pages}}) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if($page->{imageinfo}) |
|
|
|
if($page->{imageinfo}) |
|
|
@ -252,64 +253,6 @@ foreach my $page (values %{$tile_query_results->{query}{pages}}) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
say STDERR "Continuing Location processing"; |
|
|
|
|
|
|
|
$_->() for @location_continuations; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
say STDERR "Getting Site pages"; |
|
|
|
|
|
|
|
my $site_query_results = $mw->api |
|
|
|
|
|
|
|
( { |
|
|
|
|
|
|
|
action => 'query', |
|
|
|
|
|
|
|
generator => 'categorymembers', |
|
|
|
|
|
|
|
prop => 'info|revisions', |
|
|
|
|
|
|
|
gcmtitle => 'Category:Sites', |
|
|
|
|
|
|
|
gcmlimit => 'max', |
|
|
|
|
|
|
|
rvprop => 'content', |
|
|
|
|
|
|
|
inprop => 'url', |
|
|
|
|
|
|
|
} ) || croak $mw->{error}->{code} . ': ' . $mw->{error}->{details}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
say STDERR "Processing Site $site_name"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
my $site_url = $site_page_ref->{canonicalurl}; |
|
|
|
|
|
|
|
my $site_content = $site_page_ref->{revisions}[0]{'*'}; |
|
|
|
|
|
|
|
my $parsed_template = MWTemplate::Parse($site_content, $site_template_name); |
|
|
|
|
|
|
|
next unless $parsed_template; |
|
|
|
|
|
|
|
my ($nw,$sw) = split /,/, $parsed_template->{named_params}{coords}; |
|
|
|
|
|
|
|
my $tile = $grid->get_tile_at($nw, $sw); |
|
|
|
|
|
|
|
unless($tile) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
carp "Coordinates of Site $site_name do not appear in the grid, skipping."; |
|
|
|
|
|
|
|
next; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
|
|
|
|
|
|
|
( |
|
|
|
|
|
|
|
name => $site_name, |
|
|
|
|
|
|
|
id => HexGrid::to_id($site_name), |
|
|
|
|
|
|
|
icon => HexGrid::to_id($parsed_template->{named_params}{icon}), |
|
|
|
|
|
|
|
link => $site_url, |
|
|
|
|
|
|
|
description => $parsed_template->{named_params}{abstract} |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
$tile->pin($pin); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
my (%path_specs); |
|
|
|
my (%path_specs); |
|
|
|
say STDERR "Getting Path pages"; |
|
|
|
say STDERR "Getting Path pages"; |
|
|
|
my $path_query_results = $mw->api |
|
|
|
my $path_query_results = $mw->api |
|
|
@ -337,16 +280,18 @@ foreach my $path_page_ref (values %{$path_query_results->{query}{pages}}) |
|
|
|
|
|
|
|
|
|
|
|
$path_specs{$path_name} = |
|
|
|
$path_specs{$path_name} = |
|
|
|
{ |
|
|
|
{ |
|
|
|
id => "$path_name-path", |
|
|
|
id => HexGrid::to_id($path_name) . "-path", |
|
|
|
tile_page => "$path_name/Tiles", |
|
|
|
tile_page => "$path_name/Tiles", |
|
|
|
colour => $parsed_template->{named_params}{colour}, |
|
|
|
colour => $parsed_template->{named_params}{colour}, |
|
|
|
stroke_width => $parsed_template->{named_params}{stroke_width} |
|
|
|
stroke_width => $parsed_template->{named_params}{stroke_width} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
$path_specs{$path_name}{starts_from} = $parsed_template->{named_params}{starts_from} |
|
|
|
|
|
|
|
if $parsed_template->{named_params}{starts_from}; |
|
|
|
|
|
|
|
$path_specs{$path_name}{ends_to} = $parsed_template->{named_params}{ends_to} |
|
|
|
|
|
|
|
if $parsed_template->{named_params}{ends_to}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
say STDERR "Getting Path Tile pages"; |
|
|
|
say STDERR "Getting Path Tile pages"; |
|
|
|
my $path_tile_query_results = $mw->api |
|
|
|
my $path_tile_query_results = $mw->api |
|
|
|
( { |
|
|
|
( { |
|
|
@ -368,11 +313,74 @@ foreach my $page (values %{$path_tile_query_results->{query}{pages}}) |
|
|
|
do { carp "Skipping bad spec: $coords"; next; } unless $coords =~ $coords_regex; |
|
|
|
do { carp "Skipping bad spec: $coords"; next; } unless $coords =~ $coords_regex; |
|
|
|
push @path_coords, [$1,$2]; |
|
|
|
push @path_coords, [$1,$2]; |
|
|
|
} |
|
|
|
} |
|
|
|
$grid->make_path_from($path_spec{id}, \@path_coords, css_class => 'path', colour => $path_spec{colour}, |
|
|
|
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 }); |
|
|
|
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}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
say STDERR "Continuing Location processing"; |
|
|
|
|
|
|
|
$_->() for @location_continuations; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
say STDERR "Getting Site pages"; |
|
|
|
|
|
|
|
my $site_query_results = $mw->api |
|
|
|
|
|
|
|
( { |
|
|
|
|
|
|
|
action => 'query', |
|
|
|
|
|
|
|
generator => 'categorymembers', |
|
|
|
|
|
|
|
prop => 'info|revisions', |
|
|
|
|
|
|
|
gcmtitle => 'Category:Sites', |
|
|
|
|
|
|
|
gcmlimit => 'max', |
|
|
|
|
|
|
|
rvprop => 'content', |
|
|
|
|
|
|
|
inprop => 'url', |
|
|
|
|
|
|
|
} ) || croak $mw->{error}->{code} . ': ' . $mw->{error}->{details}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
say STDERR "Processing Site $site_name"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
my $site_url = $site_page_ref->{canonicalurl}; |
|
|
|
|
|
|
|
my $site_content = $site_page_ref->{revisions}[0]{'*'}; |
|
|
|
|
|
|
|
my $parsed_template = MWTemplate::Parse($site_content, $site_template_name); |
|
|
|
|
|
|
|
next unless $parsed_template; |
|
|
|
|
|
|
|
my ($nw,$sw) = split /,/, $parsed_template->{named_params}{coords}; |
|
|
|
|
|
|
|
my $tile = $grid->get_tile_at($nw, $sw); |
|
|
|
|
|
|
|
unless($tile) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
carp "Coordinates of Site $site_name do not appear in the grid, skipping."; |
|
|
|
|
|
|
|
next; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
|
|
|
|
|
|
|
( |
|
|
|
|
|
|
|
name => $site_name, |
|
|
|
|
|
|
|
id => HexGrid::to_id($site_name), |
|
|
|
|
|
|
|
icon => HexGrid::to_id($parsed_template->{named_params}{icon}), |
|
|
|
|
|
|
|
link => $site_url, |
|
|
|
|
|
|
|
description => $parsed_template->{named_params}{abstract} |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
$tile->pin($pin); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
open (my $fh, "> $outfile") or croak "Couldn't open $outfile for writing: $!"; |
|
|
|
open (my $fh, "> $outfile") or croak "Couldn't open $outfile for writing: $!"; |
|
|
|
say $fh ($html_document ? wrap_in_html($grid) : $grid->render); |
|
|
|
say $fh ($html_document ? wrap_in_html($grid) : $grid->render); |
|
|
|
close $fh; |
|
|
|
close $fh; |
|
|
@ -399,6 +407,7 @@ if($regiondir) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
say STDERR "Rendering Region's $region grid"; |
|
|
|
open (my $region_fh, "> $region.$extension") |
|
|
|
open (my $region_fh, "> $region.$extension") |
|
|
|
or croak "Couldn't open $region.extension for writing: $!"; |
|
|
|
or croak "Couldn't open $region.extension for writing: $!"; |
|
|
|
say $region_fh ($html_document ? wrap_in_html($region_grid) : $region_grid->render); |
|
|
|
say $region_fh ($html_document ? wrap_in_html($region_grid) : $region_grid->render); |
|
|
@ -407,6 +416,7 @@ if($regiondir) |
|
|
|
# Location grids need to import images |
|
|
|
# Location grids need to import images |
|
|
|
while(my ($location_name, $location_grid) = each %location_grids) |
|
|
|
while(my ($location_name, $location_grid) = each %location_grids) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
say STDERR "Rendering Location's $location_name grid"; |
|
|
|
open (my $location_fh, "> $location_name.$extension") |
|
|
|
open (my $location_fh, "> $location_name.$extension") |
|
|
|
or croak "Couldn't open $location_name.extension for writing: $!"; |
|
|
|
or croak "Couldn't open $location_name.extension for writing: $!"; |
|
|
|
say $location_fh ($html_document ? wrap_in_html($location_grid) : $location_grid->render); |
|
|
|
say $location_fh ($html_document ? wrap_in_html($location_grid) : $location_grid->render); |
|
|
|