parent 4967e57243
commit f4f1d84ba6
  1. 2
      HexGrid.pm
  2. 83
      wiki-tile.pl

@ -43,7 +43,7 @@ sub get_tile_at($this, $nw, $sw)
{
return $this->{regions}{$region}{tiles}{$nw}{$sw} if exists $this->{regions}{$region}{tiles}{$nw}{$sw};
}
croak "No pin at $nw,$sw";
croak "No tile at $nw,$sw";
}
sub render($this)

@ -16,6 +16,8 @@ no warnings "experimental::signatures";
my $api_url = "https://wiki.tensor.green/w/api.php";
my $region_template_name = "MapRegion";
my $subregion_template_name = "MapSubregion";
my $location_template_name = "MapLocation";
my $site_template_name = "MapSite";
my $border_width = 1;
@ -34,6 +36,7 @@ GetOptions(
my $grid = HexGrid->new(defaults => {
style => { 'stroke-width' => $border_width, stroke => $border_colour },
show_coords => $show_coords });
my %region_grids;
my $mw = MediaWiki::API->new();
$mw->{config}->{api_url} = $api_url;
@ -57,6 +60,10 @@ foreach my $page (values %{$region_query_results->{query}{pages}})
my $region = $grid->make_region($page->{title});
my $parsed_template = MWTemplate::Parse($page->{revisions}[0]{'*'}, $region_template_name);
$region->{defaults}{colour} = $parsed_template->{named_params}{colour};
$region_grids{$page->{title}} = HexGrid->new(defaults => {
style => { 'stroke-width' => $border_width, stroke => $border_colour },
show_coords => $show_coords });
$region_grids{$page->{title}}->add_region($region);
push @tile_pages, "$page->{title}/Tiles";
push @{$background_pages{"File:$parsed_template->{named_params}{background}"}}, $region;
@ -64,6 +71,32 @@ foreach my $page (values %{$region_query_results->{query}{pages}})
say STDERR "Getting Subregion pages";
my $subregion_query_results = $mw->api
( {
action => 'query',
generator => 'categorymembers',
gcmtitle => 'Category:Subregions',
gcmlimit => 'max',
prop => 'info|revisions',
rvprop => 'content',
inprop => 'url',
} ) || croak $mw->{error}->{code} . ': ' . $mw->{error}->{details};
foreach my $page (values %{$subregion_query_results->{query}{pages}})
{
my $parsed_template = MWTemplate::Parse($page->{revisions}[0]{'*'}, $subregion_template_name);
my $subregion = $grid->make_region($page->{title});
$subregion->{defaults}{colour} = $parsed_template->{named_params}{colour};
my $region_name = $parsed_template->{positional_params}[0];
$region_grids{$region_name}->add_region($subregion);
push @tile_pages, "$page->{title}/Tiles";
push @{$background_pages{"File:$parsed_template->{named_params}{background}"}}, $subregion;
}
say STDERR "Getting Background image pages";
my $background_query_results = $mw->api({ action => 'query',
prop => 'imageinfo',
@ -111,6 +144,55 @@ foreach my $page (values %{$tile_query_results->{query}{pages}})
say STDERR "Getting Location pages";
my $location_query_results = $mw->api
( {
action => 'query',
generator => 'categorymembers',
gcmtitle => 'Category:Locations',
gcmlimit => 'max',
prop => 'info|revisions',
rvprop => 'content',
inprop => 'url',
} ) || croak $mw->{error}->{code} . ': ' . $mw->{error}->{details};
foreach my $page (values %{$location_query_results->{query}{pages}})
{
my $parsed_template = MWTemplate::Parse($page->{revisions}[0]{'*'}, $location_template_name);
my $location = $grid->make_region($page->{title});
$region_grids{$location->{name}} = HexGrid->new(defaults => {
style => { 'stroke-width' => $border_width, stroke => $border_colour },
show_coords => $show_coords });
my $location_with_context = $region_grids{$location->{name}}->make_region($location->{name});
$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
if($parsed_template->{positional_params}[0] =~ /^\s*(-?\s*\d+)\s*,\s*(-?\s*\d+)\s*$/)
{
$location->make_tile_at($1,$2);
$location_with_context->make_tile_at($1,$2);
foreach my $coords (split /;/, $parsed_template->{named_params}{context_tiles})
{
# The below regex is a whitespace forgiving version of /^(-?\d+),(-?\d+)/, an int pair
do { carp "Skipping bad spec: $coords"; next; }
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));
}
}
my $region_name = $parsed_template->{positional_params}[1];
$region_grids{$region_name}->add_region($location);
# push @tile_pages, "$page->{title}/Tiles";
push @{$background_pages{"File:$parsed_template->{named_params}{background}"}}, $location;
}
say STDERR "Getting Site pages";
my $site_query_results = $mw->api
( {
@ -169,6 +251,7 @@ sub wrap_in_html($grid)
</script>
EOS
$html_builder .= "\n" . $grid->render;
$html_builder .= "\n" . $_->render for values %region_grids;
$html_builder .= "\n</body>\n</html>";
return $html_builder;
}

Loading…
Cancel
Save