From 67bc6b64e878c95e72727a00d1442018abf2d5c6 Mon Sep 17 00:00:00 2001 From: Daniel Asher Resnick Date: Wed, 27 Dec 2023 16:41:21 -0600 Subject: [PATCH] Give tiles a style by default --- HexGrid/Tile.pm | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/HexGrid/Tile.pm b/HexGrid/Tile.pm index c2a7a09..5533d72 100644 --- a/HexGrid/Tile.pm +++ b/HexGrid/Tile.pm @@ -15,7 +15,7 @@ no warnings "experimental::signatures"; has nw => (is => 'ro', required => 1); has sw => (is => 'ro', required => 1); -has style => (is => 'rw'); +has style => (is => 'rw', default => sub { {} }); has colour => (is => 'rw', alias => 'color'); has opacity => (is => 'rw'); has images => (is => 'rw', alias => [qw(image background backgrounds)]); @@ -42,6 +42,7 @@ sub hex_path($w, $h) { # More readable for me at least as a sequence of points than as two sequences my @points = ([0, $h/2], [$w*1/4, 0], [$w*3/4, 0], [$w, $h/2], [$w*3/4, $h], [$w*1/4, $h]); + # Join pairs with a comma, and sequence with spaces return join " ", (map {join ",", @$_} @points); } @@ -103,7 +104,7 @@ sub render($this, $container, $width, $height, $laters = undef) ); # $g->{onclick} = "say('($this->{nw},$this->{sw})')"; my $hex = $g->polygon(points => hex_path($width, $height), - id => "$this->{nw}_$this->{sw}_inner_hex", style => $this->{style} || {}); + id => "$this->{nw}_$this->{sw}_inner_hex", style => $this->style); my $clipPath = $g->clipPath(id => "$this->{nw}_$this->{sw}_clip"); $clipPath->use(href => "#$hex->{id}");