parent 1d574ccee6
commit cf59c89cf2
  1. 61
      wiki-map.pl

@ -59,8 +59,8 @@ my $grid = HexGrid->new(embed_images => $embed_images, defaults => {
# my %region_grids; # my %region_grids;
my %regions_by_subregion; my %regions_by_subregion;
my %region_grid_listings;
my %images_for_region_grids; my %images_for_region_grids;
my %location_grids;
my $mw = MediaWiki::API->new(); my $mw = MediaWiki::API->new();
$mw->{config}->{api_url} = $api_url; $mw->{config}->{api_url} = $api_url;
@ -90,7 +90,6 @@ foreach my $page (values %{$region_query_results->{query}{pages}})
$region->{defaults}{colour} = $parsed_template->{named_params}{colour}; $region->{defaults}{colour} = $parsed_template->{named_params}{colour};
if($regiondir) if($regiondir)
{ {
# $region_grid_listings{$region->{name}} = [$region->{name}];
$regions_by_subregion{$region->{name}} = $region->{name}; $regions_by_subregion{$region->{name}} = $region->{name};
} }
@ -166,25 +165,14 @@ foreach my $page (values %{$location_query_results->{query}{pages}})
$location->make_tile_at($nw, $sw); $location->make_tile_at($nw, $sw);
if($regiondir) if($regiondir)
{ {
# $region_grids{$region_name}->add_region($location); my @coords_list = ({ nw => $nw, sw => $sw});
foreach my $coords (split /;/, $parsed_template->{named_params}{context_tiles})
# $region_grids{$location->{name}} = HexGrid->new {
# ( do { carp "Skipping bad spec: $coords"; next; } unless $coords =~ $coords_regex;
# defaults =>
# {
# style => { 'stroke-width' => $border_width, stroke => $border_colour },
# show_coords => $show_coords
# },
# height => 300,
# width => 300
# );
# my $location_with_context = $region_grids{$location->{name}}->make_region($location->{name});
# $location_with_context->add_tile($grid->get_tile_at($nw, $sw));
# foreach my $coords (split /;/, $parsed_template->{named_params}{context_tiles})
# {
# do { carp "Skipping bad spec: $coords"; next; } unless $coords =~ $coords_regex;
# $location_with_context->add_tile($grid->get_tile_at($1, $2)); # $location_with_context->add_tile($grid->get_tile_at($1, $2));
# } push @coords_list, { nw => $1, sw => $2 };
}
$location_grids{$location->{name}} = $grid->subgrid_for_tiles(@coords_list);
} }
}; };
} }
@ -335,34 +323,17 @@ if($regiondir)
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);
close $region_fh; close $region_fh;
} }
# Location grids need to import images
while(my ($location_name, $location_grid) = each %location_grids)
{
open (my $location_fh, "> $location_name.$extension")
or croak "Couldn't open $location_name.extension for writing: $!";
say $location_fh ($html_document ? wrap_in_html($location_grid) : $location_grid->render);
close $location_fh;
}
} }
### Subgrid testing
# HexGrid::DEBUG();
# my $subgrid = $grid->subgrid_for_regions("Midhills", "Minev's Forest", "Naurardhon");
# my $subgrid = $grid->subgrid_for_tiles
# (
# { nw => 0, sw => 0 },
# { nw => 1, sw => 0 },
# { nw => 0, sw => 1 },
# # { nw => 1, sw => 1 },
# { nw => -1, sw => 0 },
# { nw => -1, sw => 1 },
# { nw => 1, sw => -1 }
# # { nw => 0, sw => -1 },
# # { nw => -1, sw => -1 }
# );
# my $svg = $subgrid->render;
# open SUBGRID, ">subgrid_test.svg";
# say SUBGRID $svg;
# close SUBGRID;
###
sub wrap_in_html($grid) sub wrap_in_html($grid)
{ {
my $html_builder = "<!DOCTYPE html>"; my $html_builder = "<!DOCTYPE html>";

Loading…
Cancel
Save