diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2018-01-13 16:01:51 -0500 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2018-01-13 16:01:51 -0500 |
commit | 7e4b9ea0c23eb660ab36a6114a7a3046d8f1c5f6 (patch) | |
tree | d2e020ca045ce3d6f28a6d912bbc343db03265d2 /app/models | |
parent | d91e1d9a9ee98cc364bc62a4dd156500a189b99a (diff) | |
download | pokeviewer-7e4b9ea0c23eb660ab36a6114a7a3046d8f1c5f6.tar.gz pokeviewer-7e4b9ea0c23eb660ab36a6114a7a3046d8f1c5f6.tar.bz2 pokeviewer-7e4b9ea0c23eb660ab36a6114a7a3046d8f1c5f6.zip |
Moved species from Pokémon to revision
The migration will set all of the revisions of each Pokémon to have the species that that Pokémon was set to. If reversed, the migration sets the Pokémon's species to the first revision's species, which mimics the behavior of the engine from before this change, but do note that running the migration backwards like this can lose data. This change slightly affects the loading time of the front page. See #2. refs #3
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/pokeviewer/pokemon.rb | 66 | ||||
-rw-r--r-- | app/models/pokeviewer/revision.rb | 68 | ||||
-rw-r--r-- | app/models/pokeviewer/species.rb | 2 | ||||
-rw-r--r-- | app/models/pokeviewer/trainer.rb | 4 |
4 files changed, 72 insertions, 68 deletions
diff --git a/app/models/pokeviewer/pokemon.rb b/app/models/pokeviewer/pokemon.rb index 36ed8a8..db3da5a 100644 --- a/app/models/pokeviewer/pokemon.rb +++ b/app/models/pokeviewer/pokemon.rb | |||
@@ -3,8 +3,6 @@ module Pokeviewer | |||
3 | extend Enumerize | 3 | extend Enumerize |
4 | extend ActiveModel::Naming | 4 | extend ActiveModel::Naming |
5 | 5 | ||
6 | belongs_to :species | ||
7 | |||
8 | has_many :revisions, -> { order "sequential_id ASC" }, dependent: :destroy | 6 | has_many :revisions, -> { order "sequential_id ASC" }, dependent: :destroy |
9 | 7 | ||
10 | belongs_to :trainer, optional: true | 8 | belongs_to :trainer, optional: true |
@@ -78,60 +76,8 @@ module Pokeviewer | |||
78 | uuid | 76 | uuid |
79 | end | 77 | end |
80 | 78 | ||
81 | def icon_path | 79 | def current |
82 | form = "" | 80 | revisions.last |
83 | if species_id == 201 | ||
84 | # Handle Unown form | ||
85 | form = "-#{unown_letter}" | ||
86 | elsif species_id == 386 | ||
87 | # Handle Deoxys forms | ||
88 | if trainer.firered? | ||
89 | form = "-attack" | ||
90 | elsif trainer.leafgreen? | ||
91 | form = "-defense" | ||
92 | elsif trainer.emerald? | ||
93 | form = "-speed" | ||
94 | end | ||
95 | end | ||
96 | |||
97 | "pokeviewer/icons/#{species_id}#{form}.png" | ||
98 | end | ||
99 | |||
100 | def sprite_path | ||
101 | shininess = "normal" | ||
102 | if shiny | ||
103 | shininess = "shiny" | ||
104 | end | ||
105 | |||
106 | game = "ruby-sapphire" | ||
107 | unless trainer.nil? | ||
108 | if (trainer.firered? or trainer.leafgreen?) and (species_id <= 156 or species_id == 216 or species_id == 386) | ||
109 | game = "firered-leafgreen" | ||
110 | elsif trainer.emerald? | ||
111 | game = "emerald" | ||
112 | end | ||
113 | end | ||
114 | |||
115 | form = "" | ||
116 | if species_id == 201 | ||
117 | # Handle Unown forms | ||
118 | form = "-#{unown_letter}" | ||
119 | elsif species_id == 386 | ||
120 | # Handle Deoxys forms | ||
121 | if trainer.firered? | ||
122 | form = "-attack" | ||
123 | elsif trainer.leafgreen? | ||
124 | form = "-defense" | ||
125 | elsif trainer.emerald? | ||
126 | form = "-speed" | ||
127 | end | ||
128 | end | ||
129 | |||
130 | if game == "emerald" | ||
131 | "pokeviewer/sprites/emerald/#{shininess}/#{species_id}#{form}.gif" | ||
132 | else | ||
133 | "pokeviewer/sprites/#{game}/#{shininess}/#{species_id}#{form}.png" | ||
134 | end | ||
135 | end | 81 | end |
136 | 82 | ||
137 | def outsider? | 83 | def outsider? |
@@ -178,14 +124,6 @@ module Pokeviewer | |||
178 | "pokeviewer/items/#{Pokemon.pokeball.values.find_index(pokeball) + 1}.png" | 124 | "pokeviewer/items/#{Pokemon.pokeball.values.find_index(pokeball) + 1}.png" |
179 | end | 125 | end |
180 | 126 | ||
181 | def ability | ||
182 | if second_ability | ||
183 | species.ability_2 | ||
184 | else | ||
185 | species.ability_1 | ||
186 | end | ||
187 | end | ||
188 | |||
189 | def gift_ribbon_description(ribbon) | 127 | def gift_ribbon_description(ribbon) |
190 | if trainer.nil? | 128 | if trainer.nil? |
191 | "" | 129 | "" |
diff --git a/app/models/pokeviewer/revision.rb b/app/models/pokeviewer/revision.rb index e33ac4f..64b0e99 100644 --- a/app/models/pokeviewer/revision.rb +++ b/app/models/pokeviewer/revision.rb | |||
@@ -4,7 +4,7 @@ module Pokeviewer | |||
4 | class Revision < ApplicationRecord | 4 | class Revision < ApplicationRecord |
5 | include ActiveRecord::Diff | 5 | include ActiveRecord::Diff |
6 | 6 | ||
7 | diff :nickname, :level, :hp, :attack, :defense, | 7 | diff :species_id, :nickname, :level, :hp, :attack, :defense, |
8 | :special_attack, :special_defense, :speed, :coolness, :beauty, :cuteness, | 8 | :special_attack, :special_defense, :speed, :coolness, :beauty, :cuteness, |
9 | :smartness, :toughness, :sheen, :item_id, :move_1_id, :move_2_id, | 9 | :smartness, :toughness, :sheen, :item_id, :move_1_id, :move_2_id, |
10 | :move_3_id, :move_4_id, :move_1_pp_bonuses, :move_2_pp_bonuses, | 10 | :move_3_id, :move_4_id, :move_1_pp_bonuses, :move_2_pp_bonuses, |
@@ -17,6 +17,8 @@ module Pokeviewer | |||
17 | belongs_to :pokemon | 17 | belongs_to :pokemon |
18 | acts_as_sequenced scope: :pokemon_id | 18 | acts_as_sequenced scope: :pokemon_id |
19 | 19 | ||
20 | belongs_to :species | ||
21 | |||
20 | validates :nickname, presence: true | 22 | validates :nickname, presence: true |
21 | 23 | ||
22 | validates :experience, presence: true, | 24 | validates :experience, presence: true, |
@@ -140,6 +142,70 @@ module Pokeviewer | |||
140 | less_than_or_equal_to: 4, | 142 | less_than_or_equal_to: 4, |
141 | only_integer: true} | 143 | only_integer: true} |
142 | 144 | ||
145 | def icon_path | ||
146 | form = "" | ||
147 | if species_id == 201 | ||
148 | # Handle Unown form | ||
149 | form = "-#{pokemon.unown_letter}" | ||
150 | elsif species_id == 386 | ||
151 | # Handle Deoxys forms | ||
152 | if pokemon.trainer.firered? | ||
153 | form = "-attack" | ||
154 | elsif pokemon.trainer.leafgreen? | ||
155 | form = "-defense" | ||
156 | elsif pokemon.trainer.emerald? | ||
157 | form = "-speed" | ||
158 | end | ||
159 | end | ||
160 | |||
161 | "pokeviewer/icons/#{species_id}#{form}.png" | ||
162 | end | ||
163 | |||
164 | def sprite_path | ||
165 | shininess = "normal" | ||
166 | if pokemon.shiny | ||
167 | shininess = "shiny" | ||
168 | end | ||
169 | |||
170 | game = "ruby-sapphire" | ||
171 | unless pokemon.trainer.nil? | ||
172 | if (pokemon.trainer.firered? or pokemon.trainer.leafgreen?) and (species_id <= 156 or species_id == 216 or species_id == 386) | ||
173 | game = "firered-leafgreen" | ||
174 | elsif pokemon.trainer.emerald? | ||
175 | game = "emerald" | ||
176 | end | ||
177 | end | ||
178 | |||
179 | form = "" | ||
180 | if species_id == 201 | ||
181 | # Handle Unown forms | ||
182 | form = "-#{pokemon.unown_letter}" | ||
183 | elsif species_id == 386 | ||
184 | # Handle Deoxys forms | ||
185 | if pokemon.trainer.firered? | ||
186 | form = "-attack" | ||
187 | elsif pokemon.trainer.leafgreen? | ||
188 | form = "-defense" | ||
189 | elsif pokemon.trainer.emerald? | ||
190 | form = "-speed" | ||
191 | end | ||
192 | end | ||
193 | |||
194 | if game == "emerald" | ||
195 | "pokeviewer/sprites/emerald/#{shininess}/#{species_id}#{form}.gif" | ||
196 | else | ||
197 | "pokeviewer/sprites/#{game}/#{shininess}/#{species_id}#{form}.png" | ||
198 | end | ||
199 | end | ||
200 | |||
201 | def ability | ||
202 | if pokemon.second_ability | ||
203 | species.ability_2 | ||
204 | else | ||
205 | species.ability_1 | ||
206 | end | ||
207 | end | ||
208 | |||
143 | def move_1_pp | 209 | def move_1_pp |
144 | move_1.pp * (5 + move_1_pp_bonuses) / 5 | 210 | move_1.pp * (5 + move_1_pp_bonuses) / 5 |
145 | end | 211 | end |
diff --git a/app/models/pokeviewer/species.rb b/app/models/pokeviewer/species.rb index 429e762..aae66cc 100644 --- a/app/models/pokeviewer/species.rb +++ b/app/models/pokeviewer/species.rb | |||
@@ -2,7 +2,7 @@ module Pokeviewer | |||
2 | class Species < ApplicationRecord | 2 | class Species < ApplicationRecord |
3 | extend Enumerize | 3 | extend Enumerize |
4 | 4 | ||
5 | has_many :pokemon, dependent: :restrict_with_exception | 5 | has_many :revisions, dependent: :restrict_with_exception |
6 | 6 | ||
7 | validates :name, presence: true, uniqueness: true | 7 | validates :name, presence: true, uniqueness: true |
8 | 8 | ||
diff --git a/app/models/pokeviewer/trainer.rb b/app/models/pokeviewer/trainer.rb index b79547d..281e0aa 100644 --- a/app/models/pokeviewer/trainer.rb +++ b/app/models/pokeviewer/trainer.rb | |||
@@ -39,11 +39,11 @@ module Pokeviewer | |||
39 | validates :box_14_name, presence: true | 39 | validates :box_14_name, presence: true |
40 | 40 | ||
41 | def party | 41 | def party |
42 | pokemon.party.includes(:species, :revisions) | 42 | pokemon.party.includes(revisions: [:species]) |
43 | end | 43 | end |
44 | 44 | ||
45 | def box(n) | 45 | def box(n) |
46 | pokemon.box(n).includes(:species, :revisions) | 46 | pokemon.box(n).includes(revisions: [:species]) |
47 | end | 47 | end |
48 | 48 | ||
49 | def box_name(n) | 49 | def box_name(n) |