From f6d0afa02998e967c49bdc47da26c01cc968afe6 Mon Sep 17 00:00:00 2001 From: Daniel Asher Resnick Date: Mon, 7 Aug 2023 17:04:56 -0500 Subject: [PATCH] . --- HexGrid.pm | 25 +++++++++++++++++++++++++ HexGrid/Pin.pm | 7 ++++--- HexGrid/Tile.pm | 4 ++-- wiki-map.pl | 19 +++++++++++++++++-- 4 files changed, 48 insertions(+), 7 deletions(-) diff --git a/HexGrid.pm b/HexGrid.pm index e021190..2204850 100644 --- a/HexGrid.pm +++ b/HexGrid.pm @@ -65,6 +65,30 @@ sub get_tile_at($this, $nw, $sw) croak "No tile at $nw,$sw"; } +# Clones basic settings +# Grid defaults and regions (and by extension tiles) are tied to $this +sub subgrid_for_regions($this, @region_names) +{ + my $subgrid = HexGrid->new + ( + sideLength => $this->{sideLength}, + width => $this->{width}, + height => $this->{height}, + defaults => $this->{defaults}, + make_popups => $this->{make_popups}, + popup_class => $this->{popup_class}, + hidden_popups => $this->{hidden_popups}, + embed_images => $this->{embed_images} + ); + $subgrid->add_region($this->{regions}{$_}) for @region_names; + say STDERR Dumper($subgrid) if $DEBUG; + return $subgrid; +} + +sub subgrid_for_tiles($this, @coords) +{ +} + sub render($this) { my ($min_x,$min_y,$max_x,$max_y) = qw(Inf Inf -Inf -Inf); @@ -120,4 +144,5 @@ sub translate_coords($this, $nw, $sw) sub to_id($string) { $string =~ s/\W/-/g && return $string; } +sub DEBUG { $DEBUG = 1; } 1; diff --git a/HexGrid/Pin.pm b/HexGrid/Pin.pm index bdd3a9a..79d5d1d 100644 --- a/HexGrid/Pin.pm +++ b/HexGrid/Pin.pm @@ -16,9 +16,10 @@ has popup_class => (is => 'rw', default => 'pin-popup'); sub render($this, $pin_container, $x, $y, $w, $h, $laters = undef) { - my $element = $pin_container->image(href => $this->{icon}, + my $group = $pin_container->g(); + my $element = $group->use(href => "#$this->{icon}_symbol", x => $x, y => $y, width => $w, height => $h); - $element->{id} = "$this->{id}-img"; + $element->{id} = "$this->{id}-use"; $element->{onclick} = "clickPin('$this->{id}', '$pin_container->{id}');"; my $center_x = $x + $w/2; my $center_y = $y + $h/2; @@ -28,7 +29,7 @@ sub render($this, $pin_container, $x, $y, $w, $h, $laters = undef) push @$laters, sub ($popup_container) { $this->render_popup($popup_container, $pin_container->{transform}, $center_x, $center_y); }; } - return $element; + return $group; } sub render_popup($this, $popup_container, $transform, $x_shift, $y_shift) diff --git a/HexGrid/Tile.pm b/HexGrid/Tile.pm index fb23fde..c2a7a09 100644 --- a/HexGrid/Tile.pm +++ b/HexGrid/Tile.pm @@ -140,8 +140,8 @@ sub render($this, $container, $width, $height, $laters = undef) my $y = $height * $docks{$key}->{y}; my $h = $height * $docks{$key}->{h}; - my $image_element = $this->{pins}{$key}->render($g, $x, $y, $w, $h, $laters); - $image_element->{"clip-path"} = "url(#$clipPath->{id})"; + my $pin_element = $this->{pins}{$key}->render($g, $x, $y, $w, $h, $laters); + $pin_element->{"clip-path"} = "url(#$clipPath->{id})"; } } return $g; diff --git a/wiki-map.pl b/wiki-map.pl index 275c847..efdf7e9 100644 --- a/wiki-map.pl +++ b/wiki-map.pl @@ -291,12 +291,13 @@ foreach my $site_page_ref (values %{$site_query_results->{query}{pages}}) }) || 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 => "${site_name}_pin", - icon => $image_url, + id => HexGrid::to_id($site_name), + icon => HexGrid::to_id($parsed_template->{named_params}{icon}), link => $site_url, description => $parsed_template->{named_params}{abstract} ); @@ -321,6 +322,20 @@ if($regiondir) } } + +### Subgrid testing + +HexGrid::DEBUG(); +my $subgrid = $grid->subgrid_for_regions("Midhills", "Minev's Forest", "Naurardhon"); +my $svg = $subgrid->render; +open SUBGRID, ">subgrid_test.svg"; +say SUBGRID $svg; +close SUBGRID; + +### + + + sub wrap_in_html($grid) { my $html_builder = "";