| 1 | package Weaving::Tablet::Twill::Card; | ||
| 2 | |||
| 3 | use Moose; | ||
| 4 | use namespace::autoclean; | ||
| 5 | |||
| 6 | extends 'Weaving::Tablet::Card'; | ||
| 7 | |||
| 8 | has 'cells' => ( isa => 'ArrayRef[]', is => 'ro', default => sub { [] } ); | ||
| 9 | |||
| 10 | our $VERSION = '0.009.004'; | ||
| 11 | |||
| 12 | sub initialize_cells | ||
| 13 | { | ||
| 14 | my $self = shift; | ||
| 15 | $self->color_card; | ||
| 16 | my $curr_color = $self->color->[0]; | ||
| 17 | my $cell_start = 0; | ||
| 18 | my $cell = Weaving::Tablet::Twill::Cell->new( | ||
| 19 | color => $curr_color, | ||
| 20 | turns => [ $self->turns->[0] ] | ||
| 21 | ); | ||
| 22 | for my $pick ( 1 .. $self->number_of_turns - 1 ) | ||
| 23 | { | ||
| 24 | if ( $self->color->[$pick] != $curr_color ) | ||
| 25 | { | ||
| 26 | # color change forces start of new cell | ||
| 27 | $curr_color = $self->color->[$pick]; | ||
| 28 | $cell_start = $pick; | ||
| 29 | $self->add_cell($cell); | ||
| 30 | my $cell = Weaving::Tablet::Twill::Cell->new( | ||
| 31 | color => $curr_color, | ||
| 32 | turns => [ $self->turns->[$pick] ] | ||
| 33 | ); | ||
| 34 | next; | ||
| 35 | } | ||
| 36 | if ($self->turns->[$pick] eq '|') | ||
| 37 | { | ||
| 38 | # idle always part of current cell | ||
| 39 | $cell->add_turn($self->turns->[$pick], $pick); | ||
| 40 | next; | ||
| 41 | } | ||
| 42 | if ($cell->cell_size > 1) | ||
| 43 | { | ||
| 44 | # if it's not the first pick, we call it done | ||
| 45 | $curr_color = $self->color->[$pick]; | ||
| 46 | $cell_start = $pick; | ||
| 47 | $self->add_cell($cell); | ||
| 48 | my $cell = Weaving::Tablet::Twill::Cell->new( | ||
| 49 | color => $curr_color, | ||
| 50 | turns => [ $self->turns->[$pick] ] | ||
| 51 | ); | ||
| 52 | next; | ||
| 53 | } | ||
| 54 | |||
| 55 | } | ||
| 56 | } | ||
| 57 | |||
| 58 | sub add_cell | ||
| 59 | { | ||
| 60 | my $self = shift; | ||
| 61 | my ($cell, $after) = @_; | ||
| 62 | if (defined $after) | ||
| 63 | { | ||
| 64 | die "add_cell does not do the after thing yet"; | ||
| 65 | } | ||
| 66 | else | ||
| 67 | { | ||
| 68 | push @{$self->cells}, $cell; | ||
| 69 | } | ||
| 70 | } | ||
| 71 | } | ||
| 72 | __PACKAGE__->meta->make_immutable; | ||
| 73 | |||
| 74 | 1; | ||
| 75 | |||
| 76 | __END__ |