Return null instead of dying when can't find tile

main
Daniel Asher Resnick 11 months ago
parent bc9e7d5477
commit f9c9b31089
  1. 14
      HexGrid.pm
  2. 11
      wiki-map.pl

@ -90,7 +90,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 tile at $nw,$sw";
return;
}
sub get_tile_and_region_at($this, $nw, $sw)
{
@ -98,7 +98,7 @@ sub get_tile_and_region_at($this, $nw, $sw)
{
return ($region->{tiles}{$nw}{$sw}, $region) if exists $region->{tiles}{$nw}{$sw};
}
croak "No tile at $nw,$sw";
return;
}
# Clones settings
@ -138,6 +138,16 @@ sub subgrid_for_tiles($this, @coords_list)
foreach my $coords (@coords_list)
{
my ($tile, $region) = $this->get_tile_and_region_at($coords->{nw}, $coords->{sw});
unless ($tile)
{
carp "No tile at " . $coords->{nw} . "," . $coords->{sw}, skipping.
next;
}
unless ($region)
{
carp "No region at " . $coords->{nw} . "," . $coords->{sw}, skipping.
next;
}
unless(exists $subgrid->{regions}{$region->{name}})
{
my $clone = $region->clone;

@ -177,7 +177,6 @@ foreach my $page (values %{$location_query_results->{query}{pages}})
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));
push @coords_list, { nw => $1, sw => $2 };
}
my $location_grid = $grid->subgrid_for_tiles(@coords_list);
@ -197,8 +196,6 @@ foreach my $page (values %{$location_query_results->{query}{pages}})
# HexGrid::Image::DEBUG();
say STDERR "Getting Background image pages";
my $background_query_results = $mw->api({ action => 'query',
prop => 'imageinfo',
@ -286,6 +283,12 @@ foreach my $site_page_ref (values %{$site_query_results->{query}{pages}})
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',
@ -304,7 +307,7 @@ foreach my $site_page_ref (values %{$site_query_results->{query}{pages}})
link => $site_url,
description => $parsed_template->{named_params}{abstract}
);
$grid->get_tile_at($nw, $sw)->pin($pin);
$tile->pin($pin);
}
my (%path_specs);

Loading…
Cancel
Save