| 1 | package Gtk2::Hexgrid::Tile; | ||||||||||
| 2 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use Gtk2::Hexgrid::Sprite; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | # hexgrid->{tiles} # LoL of tiles | ||||||||||
| 7 | # tiles will have their color and coordinates, and tiles will be accessible through \@tiles | ||||||||||
| 8 | # tiles will have a list of sprites, sprites will reference their tile | ||||||||||
| 9 | # sprites will be accessable through \%sprites if they have a name(boat2,red1, etc) | ||||||||||
| 10 | |||||||||||
| 11 | 0 | ▶ | sub new{ | ||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 12 | 0 | my $class = shift; | |||||||||
| 13 | 0 | my ($hexgrid, $col, $row, $r, $g, $b) = @_; | |||||||||
| 14 | 0 | my $self = { | |||||||||
| 15 | hexgrid => $hexgrid, #constant | ||||||||||
| 16 | col => $col, #constant | ||||||||||
| 17 | row => $row, #constant | ||||||||||
| 18 | r => $r, | ||||||||||
| 19 | g => $g, | ||||||||||
| 20 | b => $b, | ||||||||||
| 21 | sprites => [] | ||||||||||
| 22 | }; | ||||||||||
| 23 | |||||||||||
| 24 | 0 | bless $self, $class; | |||||||||
| 25 | 0 | return $self; | |||||||||
| 26 | } | ||||||||||
| 27 | 0 | ▶ | sub draw{ | ||||||||
|
Subroutine
draw: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 28 | 0 | my ($self) = shift; | |||||||||
| 29 | 0 | $self->{hexgrid}->draw_tile_ref($self, @_) | |||||||||
| 30 | } | ||||||||||
| 31 | |||||||||||
| 32 | 0 | ▶ | sub has_sprite{ | ||||||||
|
Subroutine
has_sprite: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 33 | 0 | my ($self, $sprite) = @_; | |||||||||
| 34 | 0 | my $sprites = $self->{sprites}; | |||||||||
| 35 | 0 | return scalar grep {$_ == $sprite} @{$self->{sprites}}; | |||||||||
| 36 | } | ||||||||||
| 37 | |||||||||||
| 38 | 0 | ▶ | sub remove_sprite{ | ||||||||
|
Subroutine
remove_sprite: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 39 | 0 | my ($self, $sprite) = @_; | |||||||||
| 40 | 0 | my $numSprites = scalar @{$self->{sprites}}; | |||||||||
| 41 | 0 | @{$self->{sprites}} = grep {$_ != $sprite} @{$self->{sprites}}; | |||||||||
| 42 | 0 | ▶ | if($numSprites == @{$self->{sprites}}) {#make sure that an sprite was actually removed | ||||||||
|
Branch: 1 branch
| |||||||||||
| 43 | 0 | carp ("remove_sprite called with an sprite that was not attached to tile " . $self->col . ", " . $self->row); | |||||||||
| 44 | 0 | return; | |||||||||
| 45 | } | ||||||||||
| 46 | 0 | $sprite->_set_tile(undef); | |||||||||
| 47 | } | ||||||||||
| 48 | |||||||||||
| 49 | 0 | ▶ | sub add_sprite{ | ||||||||
|
Subroutine
add_sprite: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 50 | 0 | my ($self, $sprite) = @_; | |||||||||
| 51 | 0 | $sprite->_set_tile($self); | |||||||||
| 52 | 0 | push @{$self->{sprites}}, $sprite; | |||||||||
| 53 | #sort sprites into order of drawing | ||||||||||
| 54 | 0 | @{$self->{sprites}} = | |||||||||
| 55 | 0 | sort{$a->{priority} <=> $b->{priority}} | |||||||||
| 56 | 0 | @{$self->{sprites}}; | |||||||||
| 57 | } | ||||||||||
| 58 | |||||||||||
| 59 | 0 | ▶ | sub destroy_text{ | ||||||||
|
Subroutine
destroy_text: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 60 | 0 | my ($self) = shift; | |||||||||
| 61 | 0 | @{$self->{sprites}} = grep {$_->type() ne "text"} @{$self->{sprites}}; | |||||||||
| 62 | } | ||||||||||
| 63 | 0 | ▶ | sub destroy_background{ | ||||||||
|
Subroutine
destroy_background: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 64 | 0 | my ($self) = shift; | |||||||||
| 65 | 0 | @{$self->{sprites}} = grep {$_->priority() != -21.21} @{$self->{sprites}}; | |||||||||
| 66 | } | ||||||||||
| 67 | |||||||||||
| 68 | 0 | ▶ | sub set_text{ | ||||||||
|
Subroutine
set_text: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 69 | 0 | my ($self, $text, $size) = @_; | |||||||||
| 70 | # $self->destroy_text; | ||||||||||
| 71 | 0 | my $sprite = new Gtk2::Hexgrid::Sprite('text', $text, $size); | |||||||||
| 72 | 0 | $sprite->set_priority(21.21); | |||||||||
| 73 | 0 | $self->add_sprite($sprite); | |||||||||
| 74 | 0 | return $sprite; | |||||||||
| 75 | } | ||||||||||
| 76 | |||||||||||
| 77 | 0 | ▶ | sub set_background{ | ||||||||
|
Subroutine
set_background: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 78 | 0 | my ($self, $filename) = @_; | |||||||||
| 79 | 0 | my $imagename = $filename.'~scaled'; | |||||||||
| 80 | 0 | $self->{hexgrid}->load_image ($imagename, $filename, 1); | |||||||||
| 81 | 0 | my $sprite = new Gtk2::Hexgrid::Sprite ('image', $imagename); | |||||||||
| 82 | 0 | $sprite->set_priority(-21.21); | |||||||||
| 83 | 0 | $self->destroy_background; | |||||||||
| 84 | 0 | $self->add_sprite($sprite); | |||||||||
| 85 | 0 | return $sprite; | |||||||||
| 86 | } | ||||||||||
| 87 | |||||||||||
| 88 | 0 | ▶ | sub get_adjacent{ | ||||||||
|
Subroutine
get_adjacent: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 89 | 0 | my $self = shift; | |||||||||
| 90 | 0 | return $self->{hexgrid}->get_adjacent_tiles($self->colrow); | |||||||||
| 91 | } | ||||||||||
| 92 | 0 | ▶ | sub get_center{ | ||||||||
|
Subroutine
get_center: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 93 | 0 | my $self = shift; | |||||||||
| 94 | 0 | return $self->{hexgrid}->get_tile_center($self->colrow); | |||||||||
| 95 | } | ||||||||||
| 96 | |||||||||||
| 97 | 0 | ▶ | sub set_color{ | ||||||||
|
Subroutine
set_color: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 98 | 0 | my ($self, $r, $g, $b) = @_; | |||||||||
| 99 | 0 | @{$self}{qw/r g b/} = ($r, $g, $b); | |||||||||
| 100 | } | ||||||||||
| 101 | |||||||||||
| 102 | 0 | ▶ | sub next_by_direction{ | ||||||||
|
Subroutine
next_by_direction: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 103 | 0 | my $self= shift; | |||||||||
| 104 | 0 | my $dir = shift; | |||||||||
| 105 | 0 | $self->{hexgrid}->next_tile_by_direction($self->{col}, $self->{row}, $dir); | |||||||||
| 106 | } | ||||||||||
| 107 | |||||||||||
| 108 | 0 | ▶ | sub ne{ #northeast | ||||||||
|
Subroutine
ne: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 109 | 0 | my $self= shift; | |||||||||
| 110 | 0 | $self->{hexgrid}->next_tile_by_direction($self->{col}, $self->{row}, 0); | |||||||||
| 111 | } | ||||||||||
| 112 | 0 | ▶ | sub se{ #southeast | ||||||||
|
Subroutine
se: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 113 | 0 | my $self= shift; | |||||||||
| 114 | 0 | $self->{hexgrid}->next_tile_by_direction($self->{col}, $self->{row}, 1); | |||||||||
| 115 | } | ||||||||||
| 116 | 0 | ▶ | sub s{ | ||||||||
|
Subroutine
s: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 117 | 0 | my $self= shift; | |||||||||
| 118 | 0 | $self->{hexgrid}->next_tile_by_direction($self->{col}, $self->{row}, 2); | |||||||||
| 119 | } | ||||||||||
| 120 | 0 | ▶ | sub sw{ | ||||||||
|
Subroutine
sw: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 121 | 0 | my $self= shift; | |||||||||
| 122 | 0 | $self->{hexgrid}->next_tile_by_direction($self->{col}, $self->{row}, 3); | |||||||||
| 123 | } | ||||||||||
| 124 | 0 | ▶ | sub nw{ | ||||||||
|
Subroutine
nw: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 125 | 0 | my $self= shift; | |||||||||
| 126 | 0 | $self->{hexgrid}->next_tile_by_direction($self->{col}, $self->{row}, 4); | |||||||||
| 127 | } | ||||||||||
| 128 | 0 | ▶ | sub n{ | ||||||||
|
Subroutine
n: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 129 | 0 | my $self= shift; | |||||||||
| 130 | 0 | $self->{hexgrid}->next_tile_by_direction($self->{col}, $self->{row}, 5); | |||||||||
| 131 | } | ||||||||||
| 132 | 1 | *north = *n; | |||||||||
| 133 | 1 | *northeast = *ne; | |||||||||
| 134 | 1 | *southeast = *se; | |||||||||
| 135 | 1 | *south = *s; | |||||||||
| 136 | 1 | *southwest = *sw; | |||||||||
| 137 | 1 | *northwest = *nw; | |||||||||
| 138 | |||||||||||
| 139 | 0 | ▶ | sub col{ | ||||||||
|
Subroutine
col: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 140 | shift->{col} | ||||||||||
| 141 | 0 | } | |||||||||
| 142 | 0 | ▶ | sub row{ | ||||||||
|
Subroutine
row: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 143 | shift->{row} | ||||||||||
| 144 | 0 | } | |||||||||
| 145 | 0 | ▶ | sub colrow{ | ||||||||
|
Subroutine
colrow: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 146 | 0 | @{shift()}{qw/col row/} | |||||||||
| 147 | } | ||||||||||
| 148 | 0 | ▶ | sub rgb{ | ||||||||
|
Subroutine
rgb: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 149 | 0 | @{shift()}{qw/r g b/} | |||||||||
| 150 | } | ||||||||||
| 151 | 0 | ▶ | sub sprites{ | ||||||||
|
Subroutine
sprites: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 152 | shift->{sprites} | ||||||||||
| 153 | 0 | } | |||||||||
| 154 | 0 | ▶ | sub hexgrid{ | ||||||||
|
Subroutine
hexgrid: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 155 | shift->{hexgrid} | ||||||||||
| 156 | 0 | } | |||||||||
| 157 | 0 | ▶ | sub background{ | ||||||||
|
Subroutine
background: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 158 | 0 | return shift->sprites->[0]->imageName; | |||||||||
| 159 | } | ||||||||||
| 160 | |||||||||||
| 161 | 1 | q ! positively! | |||||||||
| 162 | __END__ | ||||||||||