Changeset 393

Show
Ignore:
Timestamp:
12/29/07 21:29:06 (11 months ago)
Author:
eevee
Message:

Locations mini-commit.
- Redid location pages to match the new format.
- Removed incorrect header text from Pokemon pages.
- Fixed up EncounterSet?->simplest_method to return more display-friendly data (thus merging together buckets with the same rarity), and corrected the old documentation. Also removed old inaccessible code.
- Refactored sections into their own database table.
- Refactored method-cell code into its own macro.

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

Legend:

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

    r390 r393  
    993993 
    994994    my %encounters; 
    995     my $encounters_rs = $row->encounters_rs({ 
    996         method => { '!=' => [qw/ surfing old-rod good-rod super-rod /] },  # temporary 
    997     }, { 
    998         order_by => 'section ASC, method = "grass" DESC', 
    999     }); 
    1000     while (my $encounter_row = $encounters_rs->next) { 
    1001         my $arrayref = $encounters{ $encounter_row->section } 
    1002                                 ->{ $encounter_row->method  } ||= []; 
    1003      
    1004         # copy the grass values over for replacement rows whose mechanics we're 
    1005         # pretty sure about 
    1006         @$arrayref = @{ dclone $encounters{ $encounter_row->section }{grass} } 
    1007             if not @$arrayref and 
    1008                 (grep { $encounter_row->method eq $_ } qw/ daytime night poketore swarm / 
    1009                 or $encounter_row->method =~ /^ds-/); 
    1010  
    1011         if (defined $arrayref->[ $encounter_row->rarity ]) { 
    1012             $arrayref->[ $encounter_row->rarity ]{pokemon} = 
    1013                 $encounter_row->pokemon_id; 
    1014         } else { 
    1015             $arrayref->[ $encounter_row->rarity ] = { 
    1016                 pokemon => $encounter_row->pokemon_id, 
    1017                 level   => $encounter_row->level, 
    1018             }; 
    1019         } 
    1020     } 
    1021  
    1022     my %pokemon; 
    1023 #    my $rarity_key = ($method =~ /rod|surfing/) ? 'locsurfpercents' : 'locpercents'; 
    1024     my $rarity_ct = scalar @{ $Generations[-1]{locpercents} }; 
    1025     for my $section (keys %encounters) { 
    1026         for my $method (keys %{ $encounters{$section} }) { 
    1027             my @poke_list = @{ $encounters{$section}{$method} }; 
    1028  
    1029             # if this isn't a full list, leave it alone and return 
    1030             if (@poke_list != $rarity_ct or not defined $poke_list[0]) { 
    1031 # WRONG:                $pokemon{$section}{$method} = [ uniq map { $_->{pokemon} } grep { $_ } @poke_list ]; 
    1032                 next; 
    1033             } 
    1034  
    1035             for my $index (0 .. $rarity_ct - 1) { 
    1036                 $pokemon{$section}{ $poke_list[$index]{pokemon} } 
    1037                          { $poke_list[$index]{level} }{$method} += 
    1038                     $Generations[-1]{locpercents}[$index]; 
    1039             } 
    1040         } 
    1041     } 
    1042         
     995 
     996    my $sections_rs = $row->sections_rs; 
     997    while (my $section = $sections_rs->next) { 
     998        my $grouped_pokemon_rs = $section->encounters_rs( { 
     999            version  => 'diamond', 
     1000        }, { 
     1001            group_by => 'pokemon_id', 
     1002        } ); 
     1003 
     1004        while (my $enc_pokemon = $grouped_pokemon_rs->next) { 
     1005            my $encounters_rs = $section->encounters_rs( { 
     1006                version     => 'diamond', 
     1007                pokemon_id  => $enc_pokemon->pokemon->id, 
     1008            } ); 
     1009            $encounters_rs->reset; 
     1010 
     1011            push @{ $encounters{$section->name} }, Vee::Dex::EncounterSet->new( 
     1012                $encounters_rs, 
     1013                $enc_pokemon->pokemon, 
     1014            ); 
     1015        } 
     1016 
     1017        @{ $encounters{$section->name} } = sort { 
     1018            $a->pokemon->name cmp $b->pokemon->name 
     1019        } @{ $encounters{$section->name} }; 
     1020    } 
     1021 
    10431022    $s->{this}       = $row; 
    1044     $s->{encounters} = \%pokemon; 
     1023    $s->{encounters} = \%encounters; 
    10451024} 
    10461025 
  • veekun/trunk/lib/Vee/Dex/EncounterSet.pm

    r388 r393  
    77 
    88use List::Util qw/sum/; 
     9use List::MoreUtils qw/uniq/; 
    910 
    1011use Vee::Dex; 
     
    153154    $self->pokemon($pokemon); 
    154155    my $arbitrary_row = $rs->first; 
    155     $self->location($arbitrary_row->location); 
     156    $self->location($arbitrary_row->section->location); 
    156157    $self->section($arbitrary_row->section); 
    157158    $rs->reset; 
     
    170171    # } 
    171172 
     173#    warn $self->location->name, ' [', $self->section->name, "]\n"; 
    172174    while (my $enc = $rs->next) { 
     175#        warn join ' ', $enc->method, $enc->pokemon->name, $enc->rarity, $enc->level; 
    173176        my ($slot_category, $slot_bucket); 
    174177        if ($WaterMethods{ $enc->method }) { 
     
    277280follows: 
    278281 
    279     level  => [ $min, $max ], 
    280     rarity => $rarity, 
    281     method => { $category => $bucket }, 
     282    level    => [ $min, $max ], 
     283    category => $category, 
     284    rarities => [ 
     285        { rarity => $rarity, buckets => \@buckets }, 
     286        ... 
     287    ], 
     288    buckets  => { 
     289        $bucket => $rarity, 
     290        ... 
     291    }, 
    282292 
    283293C<$min> and C<$max> are the minimum and maximum levels at which the Pokemon 
    284294can appear with this method. 
    285295 
    286 C<$category> and C<$bucket> are the category and bucket, respectively, in which 
    287 this Pokemon most simply appears.  Note that in the case of C<$category> being 
    288 C<'time'> or C<'dual-slot'>, C<$bucket> may be an arrayref. 
    289  
    290 C<$rarity> is the total rarity for this Pokemon with the given method(s). 
    291  
    292 Pokemon and an arrayref of the level range at which it appears, in the form 
    293 C<[$lo, $hi]>.  If a tie between methods should arise, the first item will be 
    294 an arrayref. 
    295  
    296 If the Pokemon appears at all three times of day while walking around, C<undef> 
    297 will be returned as the method name. 
     296C<$category> is the method category in which this Pokemon most simply appears. 
     297 
     298The C<buckets> key contains a hashref mapping buckets to rarities. 
     299 
     300The C<rarities> key contains an arrayref of hashrefs, each containing a rarity 
     301and a list of buckets with that rarity, in order from most common to rarest. 
     302This is convenient for compact display. 
    298303 
    299304=cut 
     
    332337 
    333338        if (%bucket_rarities) { 
     339            my @grouped_rarities; 
     340 
     341            # Show these in order of most likely to least likely, and group any 
     342            # that have the same rarity 
     343            for my $rarity (sort { $b <=> $a } uniq values %bucket_rarities) { 
     344                my @buckets = grep { 
     345                    $bucket_rarities{$_} == $rarity 
     346                } keys %bucket_rarities; 
     347 
     348                # Sort buckets by the order defined in @SimpleMethods 
     349                my $o = 0; 
     350                my %order = map { $_ => $o++ } @$buckets; 
     351                @buckets = sort { $order{$a} <=> $order{$b} } @buckets; 
     352                 
     353                push @grouped_rarities, { 
     354                    buckets => \@buckets, 
     355                    rarity  => $rarity, 
     356                }; 
     357            } 
     358 
    334359            return { 
    335360                level    => [ $all_min, $all_max ], 
    336361                category => $category, 
    337                 rarities => \%bucket_rarities, 
     362                rarities => \@grouped_rarities, 
     363                buckets  => \%bucket_rarities, 
    338364            }; 
    339         } 
    340     } 
    341  
    342     return; 
    343  
    344     my %time_rarities; 
    345     for my $time (qw/ morning daytime night /) { 
    346         $time_rarities{$time} = $self->rarity(time => $time); 
    347     } 
    348  
    349     my $times_ct = grep { $_ } values %time_rarities; 
    350     if ($times_ct == 3) { 
    351         return undef, 100; 
    352     } elsif ($times_ct) { 
    353         my @times = grep { $time_rarities{$_} } keys %time_rarities; 
    354         my $times_ref = @times > 1 ? \@times : $times[0]; 
    355         return $times_ref, 100; 
    356     } 
    357  
    358     my @attempts = ( 
    359         [ swarm => 1 ], 
    360         [ radar => 1 ], 
    361     ); 
    362  
    363     for my $att (@attempts) { 
    364         my $rarity = $self->rarity(@$att); 
    365         if ($rarity) { 
    366             return $att->[0], $rarity; 
    367365        } 
    368366    } 
  • veekun/trunk/lib/Vee/Schema/LocationEncounters.pm

    r350 r393  
    1313__PACKAGE__->load_components('Core'); 
    1414__PACKAGE__->table('location_encounters'); 
    15 __PACKAGE__->add_columns(qw/ location_id rarity version section pokemon_id method min_level max_level /); 
    16 __PACKAGE__->set_primary_key(qw/ location_id rarity /); 
     15__PACKAGE__->add_columns(qw/ section_id rarity version pokemon_id method min_level max_level /); 
     16__PACKAGE__->set_primary_key(qw/ section_id rarity /); 
    1717 
    1818__PACKAGE__->belongs_to(pokemon => 'Vee::Schema::Pokemon', 'pokemon_id'); 
    19 __PACKAGE__->belongs_to(location => 'Vee::Schema::Locations', 'location_id'); 
     19__PACKAGE__->belongs_to(section => 'Vee::Schema::LocationSections', 'section_id'); 
    2020 
    2121=head1 METHODS 
     
    3030sub level { 
    3131    my ($self) = @_; 
    32      
     32 
    3333    my $level; 
    3434    my ($min, $max) = ($self->min_level, $self->max_level); 
  • veekun/trunk/lib/Vee/Schema/Locations.pm

    r350 r393  
    1616__PACKAGE__->set_primary_key('id'); 
    1717 
    18 __PACKAGE__->has_many(encounters => 'Vee::Schema::LocationEncounters', 'location_id'); 
     18__PACKAGE__->has_many(sections => 'Vee::Schema::LocationSections', 'location_id'); 
    1919 
    2020=head1 SEE ALSO 
  • veekun/trunk/lib/Vee/Schema/Pokemon.pm

    r389 r393  
    162162    my @encounter_sets; 
    163163 
    164     my $sections_rs = $self->encounters_rs( undef, { 
    165         group_by => 'location_id, section', 
     164    my $grouped_sections_rs = $self->encounters_rs( undef, { 
     165        group_by => 'section_id', 
    166166    } ); 
    167167 
    168     while (my $section = $sections_rs->next) { 
    169         my $encounters_rs = $section->location->encounters_rs( { 
     168    while (my $enc_section = $grouped_sections_rs->next) { 
     169        my $encounters_rs = $enc_section->section->encounters_rs( { 
    170170            version     => 'diamond', 
    171             section     => $section->section, 
     171            section_id  => $enc_section->section->id, 
    172172        } ); 
    173173 
  • veekun/trunk/templates/dex/common.tt

    r359 r393  
    118118[%- END %] 
    119119 
     120[%# n.b.: this takes the structure returned from EncSet->simplest_method %] 
     121[% MACRO simple_method_cells(simple_method) BLOCK %] 
     122    <td> [% simple_method.level.0 %][% IF simple_method.level.0 != simple_method.level.1; ' - '; simple_method.level.1; END %] </td> 
     123[%     category = simple_method.category %] 
     124<td> 
     125[%     FOR hashref IN simple_method.rarities %] 
     126[%         FOR bucket IN hashref.buckets %] 
     127[%             SWITCH category %] 
     128[%             CASE 'time' %]<img src="/dex-images/gameui/[% bucket %].png" alt="[% bucket | ucfirst %]" title="[% bucket | ucfirst %]"/> 
     129[%             CASE 'swarm' %]<img src="/dex-images/items/teachy-tv.png" alt="Swarm" title="Swarm"/> 
     130[%             CASE 'water' %]<img src="/dex-images/items/[% bucket == 'surfing' ? 'hm-water' : bucket %].png" alt="[% bucket %]" title="[% bucket %]"/> 
     131[%             CASE 'pokeradar' %]<img src="/dex-images/items/poke-radar.png" alt="Pok&eacute; Radar" title="Pok&eacute; Radar"/> 
     132[%             CASE 'dualslot' %][% Icons.$bucket %] 
     133[%             END %] 
     134[%             ' ' %] 
     135[%         END %] 
     136[%         hashref.rarity %]% 
     137[%         '; ' UNLESS loop.last %] 
     138[%     END %] 
     139</td> 
    120140[% END %] 
     141 
     142[% END %] 
  • veekun/trunk/templates/dex/page/location.tt

    r143 r393  
    44 
    55<h1>[% this.name %] Pok&eacute;mon</h1> 
    6 <p><strong>ATTN:</strong> This page sucks at the moment, doesn't include everything, and does weird things for places where the Diamond and Pearl encounters are different.  It should suffice for most uses, but be wary.</p> 
    7 <p>Radar, swarm, and dual slot percentages assume that it is morning.</p> 
    8 [% FOR section IN encounters.keys.sort %] 
    9 [%     IF section %] 
     6 
     7<p>Sorry, Pearl players!  Only Diamond for the moment.</p> 
     8 
     9[% FOREACH section IN encounters.keys %] 
     10 
    1011<h2>[% section %]</h2> 
    11 [%     END %] 
    12 <table class="dex-table dex-locations" cellspacing="0" 
     12<table cellspacing="0" cellpadding="3" class="dex-table dex-locations"> 
    1313<tr class="heading"> 
    14     <th class="name">Pok&eacute;mon</th> 
    15     <th class="levels">Lv</th> 
    16 [%     FOR method_pair IN known_methods %] 
    17     <th>[% method_pair.1 %]</th> 
    18 [%     END %] 
     14    <th> Pok&eacute;mon </th> 
     15    <th> Level </th> 
     16    <th> Method </th> 
    1917</tr> 
    2018[%     color = 1 %] 
    21 [%     last_pokemon = 0 %] 
    22 [%     FOR p IN encounters.$section.keys.nsort %] 
    23 [%         FOR level IN encounters.$section.$p.keys.nsort %] 
    24 [%             IF p != encounters.$section.keys.nsort.0 AND loop.first %] 
    25 <tr> <td colspan="[% 2 + known_methods.size %]" class="hbar"></td> </tr> 
    26 [%             END %] 
     19[%     FOREACH enc IN encounters.$section %] 
    2720<tr class="color[% color %]"> 
    28     <td class="name">[% IF loop.first %]<a href="[% dex_uri('pokemon', PokemonNames.$p) %]">[% PokemonNames.$p %]</a>[% END %]</td> 
    29     <td class="levels">[% level %]</td> 
    30 [%             FOR method_pair IN known_methods %] 
    31     <td>[% chance = encounters.$section.$p.$level.${ method_pair.0 }; chance _ '%' IF chance %]</td> 
    32 [%             END %] 
     21    <td> <a href="[% dex_uri('pokemon', enc.pokemon.name) %]">[% enc.pokemon.name %]</a> </td> 
     22[%         simple_method_cells(enc.simplest_method.hash) %] 
    3323</tr> 
    34 [%             color = 3 - color %] 
    35 [%         END %] 
     24[%         color = 3 - color %] 
    3625[%     END %] 
    3726</table> 
    3827[% END %] 
     28 
  • veekun/trunk/templates/dex/page/pokemon.tt

    r388 r393  
    276276 
    277277<h1>Locations</h1> 
    278 <!--<p><a href="[% dex_uri('pokemon', this.name) %]/map"><img src="/images/see-also.png" alt="See also:"/> Location map</a></p>--> 
    279 <p>Location map returning eventually...</p> 
    280 [%# TODO: this is kinda hacky! %] 
    281 <p>Numbers are levels.  Bars are relative rarity.  Hover for a percentage.</p> 
    282 <p>Swarms, the Pok&eacute;radar, and dual-slot icons are shown if [% this.name %] shows up during the event but <em>not</em> normally.  See the location page for gritty details.</p> 
    283  
    284 <table cellspacing="0" cellpadding="3" class="dex-table dex-locations" style="display: inline-table;"> 
     278[%# TODO fix ghastly links %] 
     279<p><a href="[% dex_uri('pokemon', this.name) %]/map"><img src="/images/see-also.png" alt="See also:"/> Location map</a></p> 
     280 
     281<p>Sorry, Pearl players!  Only Diamond for the moment.</p> 
     282 
     283<table cellspacing="0" cellpadding="3" class="dex-table dex-locations"> 
    285284<tr class="heading"> 
    286285    <th> Area </th> 
    287286    <th> Section </th> 
    288287    <th> Level </th> 
    289     <th> Morn </th> 
    290     <th> Day </th> 
    291     <th> Night </th> 
     288    <th> Method </th> 
    292289</tr> 
    293290[% color = 1 %] 
    294291[% FOREACH enc IN new_encounters %] 
    295292<tr class="color[% color %]"> 
    296     <td> [% enc.location.name %] </td> 
    297     <td> [% enc.section %] </td> 
    298 [%     SET simple_method = enc.simplest_method.hash %] 
    299     <td> [% simple_method.level.0 %][% IF simple_method.level.0 != simple_method.level.1; ' - '; simple_method.level.1; END %] </td> 
    300 [%     category = simple_method.category %] 
    301 [%     SWITCH category %] 
    302 [%     CASE 'time' %] 
    303     <td> [% simple_method.rarities.morning %]% </td> 
    304     <td> [% simple_method.rarities.daytime %]% </td> 
    305     <td> [% simple_method.rarities.night %]% </td> 
    306 [%     CASE 'swarm' %] 
    307     <td colspan="3"><img src="/dex-images/items/teachy-tv.png" alt="Swarm" title="Swarm"/> [% simple_method.rarities.1 %]%</td> 
    308 [%     CASE 'water' %] 
    309     <td colspan="3">[% FOR rod IN simple_method.rarities.keys %]<img src="/dex-images/items/[% rod == 'surfing' ? 'hm-water' : rod %].png" alt="[% rod %]" title="[% rod %]"/> [% simple_method.rarities.$rod %]%[% '; ' UNLESS loop.last %][% END %] </td> 
    310 [%     CASE 'pokeradar' %] 
    311     <td colspan="3"><img src="/dex-images/items/poke-radar.png" alt="Radar" title="Radar"/> [% simple_method.rarities.1 %]%</td> 
    312 [%     CASE 'dualslot' %] 
    313     <td colspan="3">[% FOR ver IN simple_method.rarities.keys %][% Icons.$ver %] [%+ simple_method.rarities.$ver %]%[% '; ' UNLESS loop.last %][% END %]</td> 
    314 [%     CASE %] 
    315     <td colspan="3">unknown: [% category %]: [% simple_method.rarities.keys.sort.join %]</td> 
    316 [%     END %] 
     293    <td> <a href="[% dex_uri('locations', enc.location.name) %]">[% enc.location.name %]</a> </td> 
     294    <td> [% enc.section.name %] </td> 
     295[%     simple_method_cells(enc.simplest_method.hash) %] 
    317296</tr> 
    318297[%     color = 3 - color %]