root/veekun/trunk/lib/Vee/Schema/Moves.pm

Revision 406, 2.9 KB (checked in by eevee, 2 years ago)

Database refactoring. Renamed columns and tables to be more consistent and more readable. (#58)

Line 
1package Vee::Schema::Moves;
2
3use strict;
4use warnings;
5use base 'DBIx::Class';
6
7=head1 NAME
8
9Vee::Schema::Moves - DBIC class for the C<moves> table
10
11=cut
12
13__PACKAGE__->load_components('Core');
14__PACKAGE__->table('moves');
15__PACKAGE__->add_columns(qw/
16    id
17    name
18    name_jp
19    name_romaji
20    type
21    power
22    pp
23    accuracy
24    target
25    class
26    flags
27    combos
28    effect_chance
29    kind
30    status
31    move_effect_id
32    blurb_rusa
33    blurb_dp
34    contest_type
35    contest_effect_id
36    notes
37/);
38__PACKAGE__->set_primary_key('id');
39
40__PACKAGE__->belongs_to(contest_effect => 'Vee::Schema::ContestEffects', 'contest_effect_id');
41__PACKAGE__->belongs_to(effect => 'Vee::Schema::MoveEffects', 'move_effect_id');
42__PACKAGE__->has_many(pokemon_moves => 'Vee::Schema::PokemonMoves', 'move_id');
43
44=head1 METHODS
45
46=head2 priority
47
48Returns the priority of the given move.  Only exists for consistency, as this
49is the only data commonly accessed via C<%MoveData> that is actually a column
50of C<move_effects>.
51
52=cut
53
54sub priority {
55    my ($self) = @_;
56    return $self->effect->priority;
57}
58
59=head2 description
60
61Returns the full description for this move.  Applies C<_format_description>
62effects, and converts tab-delimited tables to HTML.
63
64=cut
65
66sub description {
67    my ($self) = @_;
68
69    my $desc = $self->_format_description( $self->effect->description );
70    my @lines = split /\n/, $desc;
71
72    my $table_open = 0;
73    for my $line (@lines) {
74        if ($line =~ /\t/) {
75            $line =~ s[\t][</td><td>]g;
76            $line = "<tr><td>$line</td></tr>";
77            $line = "<table>\n$line" if not $table_open;
78            $table_open = 1;
79        } else {
80            $line = "<p>$line</p>";
81            $line = "</table>\n$line" if $table_open;
82            $table_open = 0;
83        }
84    }
85    push @lines, "</table>" if $table_open;
86
87    return join "\n", @lines;
88}
89
90=head2 short_description
91
92Returns a short description for this move, suitable for putting in a move table.
93Applies C<_format_description> effects.
94
95=cut
96
97sub short_description {
98    my ($self) = @_;
99
100    return $self->_format_description( $self->effect->short_description );
101}
102
103=head2 _format_description($text)
104
105Inserts this move's effect chance and priority into the provided string, if
106applicable.  Used by C<description> and C<short_description>.
107
108=cut
109
110sub _format_description {
111    my ($self, $text) = @_;
112
113    # effect chance
114    $text =~ s/a chance to/a ${\( $self->effect_chance )}% chance to/g
115        if $self->effect_chance;
116
117    if ($self->effect->priority < 0) {
118        $text = "Goes last.  $text";
119    } elsif ($self->effect->priority > 0) {
120        $text = "Goes first.  $text";
121    }
122
123    return $text;
124}
125
126=head1 SEE ALSO
127
128L<Vee::Schema>, L<DBIx::Class>
129
130=head1 AUTHOR
131
132Maintainer: Alex "Eevee" Munroe (C<veekun@veekun.com>)
133
134See the included F<AUTHORS> file for a full list of contributers.
135
136=head1 LICENSE
137
138See the included F<LICENSE> file.
139
140=cut
141
1421;
Note: See TracBrowser for help on using the browser.