From f9c9b31089fa11616722d904ca0e482dd90ba84f Mon Sep 17 00:00:00 2001 From: Daniel Asher Resnick Date: Sat, 30 Dec 2023 14:29:38 -0600 Subject: [PATCH] Return null instead of dying when can't find tile --- HexGrid.pm | 14 ++++++++++++-- wiki-map.pl | 11 +++++++---- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/HexGrid.pm b/HexGrid.pm index 6715d32..4d0977b 100644 --- a/HexGrid.pm +++ b/HexGrid.pm @@ -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; diff --git a/wiki-map.pl b/wiki-map.pl index 1403639..ac85ab9 100644 --- a/wiki-map.pl +++ b/wiki-map.pl @@ -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);