Changeset 71

Show
Ignore:
Timestamp:
03/30/07 02:01:30 (3 years ago)
Author:
eevee
Message:

Cleaned up locations list and added a map page displaying where a Pokemon appears. Not exactly beautiful, but it is functional.

Location:
veekun/trunk
Files:
8 added
2 modified
1 moved

Legend:

Unmodified
Added
Removed
  • veekun/trunk/lib/Vee/Controller/Dex.pm

    r66 r71  
    366366 
    367367    # locations! 
    368     my $encounters_rs = $row->encounters_rs(undef, { 
    369         prefetch  => 'location', 
    370         group_by  => [qw/ location_id section method /], 
    371  
    372         # this minor hackery will essentially collapse multiple rows for a method into one short one we care about 
    373         '+select' => [ 
    374             \ 'MIN(rarity) AS rarity', 
    375             \ 'MIN(min_level) AS min_level', 
    376             \ 'MAX(max_level) AS max_level', 
    377         ], 
    378         '+as'     => [qw/ rarity min_level max_level /], 
    379     } ); 
    380     my %locations; 
    381     while (my $encounter = $encounters_rs->next) { 
    382         my $level; 
    383         if (not $encounter->min_level) { 
    384             $level = ''; 
    385         } elsif ($encounter->min_level == $encounter->max_level) { 
    386             $level = $encounter->min_level; 
    387         } else { 
    388             $level = $encounter->min_level . ' - ' . $encounter->max_level; 
    389         } 
    390         $locations{ $encounter->location->name }{ $encounter->section }{ $encounter->method } = { level => $level, rarity => $encounter->rarity }; 
    391     } 
    392     $s->{encounters} = \%locations; 
     368    $s->{encounters} = get_locations($row); 
    393369 
    394370    # moves from here down 
     
    515491} 
    516492 
     493sub pokemon_chain : Chained('/') : PathPart('dex/pokemon') : CaptureArgs(1) {;} 
     494 
     495=head2 strategery 
     496 
     497=cut 
     498 
     499sub strategery : Chained('pokemon_chain') : Args(0) { 
     500    my ($self, $c) = @_; 
     501    my $s = $c->stash; 
     502     
     503    my $poke = $c->req->captures->[0]; 
     504    my $gen = 'dp';  # TODO: CHEAP HACK PLZ MAKE THIS WORK RITE -- do by generation but split if versions disagree? 
     505 
     506    my $row = get_row($c, 'Pokemon', $poke); 
     507    $c->vee_abort('There is no such Pokémon ', $poke, '.  If you are messing with my URLs, please stop.  If you came here via a link, please inform its owner that it is invalid.') unless $row; 
     508 
     509    $s->{generation} = my $generation = ( grep { $Generations[$_]{maxid} >= $row->id } 0 .. $#Generations )[0]; 
     510 
     511    calculate_stats($c, $row); 
     512     
     513    my $moves_rs = $c->model('DBIC::PokeMoves')->search({ pokeid => $row->id, -and => \ "FIND_IN_SET('$gen', version)" }); 
     514    my %moves; 
     515 
     516    while (my $move_row = $moves_rs->next) { 
     517        push @{ $moves{ $move_row->moveid } }, $move_row; 
     518    } 
     519    $s->{moves} = \%moves; 
     520     
     521    $s->{this} = $row; 
     522 
     523    $s->{page_title} = $row->name . ' - Strategic Overview'; 
     524    $s->{crumbs}     = [ 
     525        '<a href="' . $c->uri('Dex') . '">Pok&eacute;dex</a>', 
     526        '<a href="' . $c->uri('Dex', 'pokemon_list') . '">Pok&eacute;mon</a>', 
     527        '<a href="' . $c->uri('Dex', 'pokemon', lc $row->name) . '">' . $row->name . '</a>' 
     528    ]; 
     529 
     530    $s->{template} = 'dex/strategery.tt'; 
     531} 
     532 
     533=head2 map 
     534 
     535=cut 
     536 
     537sub map : Chained('pokemon_chain') : Args(0) { 
     538    my ($self, $c) = @_; 
     539    my $s = $c->stash; 
     540     
     541    my $poke = $c->req->captures->[0]; 
     542    my $gen = 'dp';  # TODO: CHEAP HACK PLZ MAKE THIS WORK RITE -- do by generation but split if versions disagree? 
     543 
     544    my $row = get_row($c, 'Pokemon', $poke); 
     545    $c->vee_abort('There is no such Pok&eacute;mon ', $poke, '.  If you are messing with my URLs, please stop.  If you came here via a link, please inform its owner that it is invalid.') unless $row; 
     546 
     547    $s->{encounters} = get_locations($row); 
     548    $s->{location_coords} = { 
     549        map { $_->name => $_->coordinates } 
     550            $c->model('DBIC::Locations')->search(undef) 
     551    }; 
     552 
     553    $s->{this} = $row; 
     554 
     555    $s->{page_title} = $row->name . ' - Location Map'; 
     556    $s->{crumbs}     = [ 
     557        '<a href="' . $c->uri('Dex') . '">Pok&eacute;dex</a>', 
     558        '<a href="' . $c->uri('Dex', 'pokemon_list') . '">Pok&eacute;mon</a>', 
     559        '<a href="' . $c->uri('Dex', 'pokemon', lc $row->name) . '">' . $row->name . '</a>', 
     560        'Location Map', 
     561    ]; 
     562 
     563    $s->{template} = 'dex/page/pokemon/map.tt'; 
     564} 
     565 
    517566################################################################################ 
    518567 
     
    612661################################################################################ 
    613662 
    614 =head2 strategery 
    615  
    616 =cut 
    617  
    618 sub pokemon_chain : Chained('/') : PathPart('dex/pokemon') : CaptureArgs(1) {;} 
    619  
    620 sub strategery : Chained('pokemon_chain') : Args(0) { 
    621     my ($self, $c) = @_; 
    622     my $s = $c->stash; 
    623      
    624     my $poke = $c->req->captures->[0]; 
    625     my $gen = 'dp';  # TODO: CHEAP HACK PLZ MAKE THIS WORK RITE -- do by generation but split if versions disagree? 
    626  
    627     my $row = get_row($c, 'Pokemon', $poke); 
    628     $c->vee_abort('There is no such Pok&eacute;mon ', $poke, '.  If you are messing with my URLs, please stop.  If you came here via a link, please inform its owner that it is invalid.') unless $row; 
    629  
    630     $s->{generation} = my $generation = ( grep { $Generations[$_]{maxid} >= $row->id } 0 .. $#Generations )[0]; 
    631  
    632     calculate_stats($c, $row); 
    633      
    634     my $moves_rs = $c->model('DBIC::PokeMoves')->search({ pokeid => $row->id, -and => \ "FIND_IN_SET('$gen', version)" }); 
    635     my %moves; 
    636  
    637     while (my $move_row = $moves_rs->next) { 
    638         push @{ $moves{ $move_row->moveid } }, $move_row; 
    639     } 
    640     $s->{moves} = \%moves; 
    641      
    642     $s->{this} = $row; 
    643  
    644     $s->{page_title} = $row->name . ' - Strategic Overview'; 
    645     $s->{crumbs}     = [ 
    646         '<a href="' . $c->uri('Dex') . '">Pok&eacute;dex</a>', 
    647         '<a href="' . $c->uri('Dex', 'pokemon_list') . '">Pok&eacute;mon</a>', 
    648         '<a href="' . $c->uri('Dex', 'pokemon', lc $row->name) . '">' . $row->name . '</a>' 
    649     ]; 
    650  
    651     $s->{template} = 'dex/strategery.tt'; 
    652 } 
    653  
    654 ################################################################################ 
    655  
    656663=head2 type_list 
    657664 
     
    834841} 
    835842 
     843=head2 get_locations 
     844 
     845Fetches the locations for a given Pokemon (row) and returns a hash. 
     846 
     847In: Pokemon db row 
     848 
     849Out: { location => { section => { method => { level => "a - b", rarity => x } } } } 
     850 
     851=cut 
     852 
     853sub get_locations { 
     854    my ($pokemon) = @_; 
     855 
     856    my $encounters_rs = $pokemon->encounters_rs(undef, { 
     857        prefetch  => 'location', 
     858        group_by  => [qw/ location_id section method /], 
     859 
     860        # this minor hackery will essentially collapse multiple rows for a method into one short one we care about 
     861        '+select' => [ 
     862            \ 'MIN(rarity) AS rarity', 
     863            \ 'MIN(min_level) AS min_level', 
     864            \ 'MAX(max_level) AS max_level', 
     865        ], 
     866        '+as'     => [qw/ rarity min_level max_level /], 
     867    } ); 
     868 
     869    my %locations; 
     870    while (my $encounter = $encounters_rs->next) { 
     871        my $level; 
     872        if (not $encounter->min_level) { 
     873            $level = ''; 
     874        } elsif ($encounter->min_level == $encounter->max_level) { 
     875            $level = $encounter->min_level; 
     876        } else { 
     877            $level = $encounter->min_level . ' - ' . $encounter->max_level; 
     878        } 
     879        $locations{ $encounter->location->name }{ $encounter->section }{ $encounter->method } = { level => $level, rarity => $encounter->rarity }; 
     880    } 
     881 
     882    return \%locations; 
     883} 
     884 
    836885=head2 add_evolution_desc 
    837886 
  • veekun/trunk/templates/dex/page/pokemon.tt

    r62 r71  
    260260    <td class="dex-locations-zone">[% location %]</td> <td class="dex-locations-zone">[% section %]</td> 
    261261    <td>[% methods.grass.level %]</td> <td>[% methods.surfing.level %]</td> <td>[% methods.${'old-rod'}.level %]</td><td>[% methods.${'good-rod'}.level %]</td><td>[% methods.${'super-rod'}.level %]</td> 
    262     <td>[% '*' IF methods.swarm %]</td> <td>[% '*' IF methods.morning %]</td><td>[% '*' IF methods.night %]</td> <td>[% '*' IF methods.poketore %]</td> 
     262    <td>[% IF methods.swarm %]<img src="/dex-images/items/teachy-tv.png" alt="swarm"/>[% END %]</td> 
     263    <td>[% IF methods.morning %]<img src="/dex-images/items/light-stone.png" alt="morning"/>[% END %]</td> 
     264    <td>[% IF methods.night %]<img src="/dex-images/items/dark-stone.png" alt="night"/>[% END %]</td> 
     265    <td>[% IF methods.poketore %]<img src="/dex-images/items/poketore.png" alt="poketore"/>[% END %]</td> 
    263266    <td class="dex-locations-ds">[% Icons.ru IF methods.${'ds-ruby'} %]</td> 
    264267    <td class="dex-locations-ds">[% Icons.sa IF methods.${'ds-sapphire'} %]</td>