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 | |
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
-rw-r--r-- | app/controllers/pokeviewer/pokemon_controller.rb | 8 | ||||
-rw-r--r-- | app/jobs/pokeviewer/extract_save_data_job.rb | 4 | ||||
-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 | ||||
-rw-r--r-- | app/views/pokeviewer/pokemon/index.html.haml | 12 | ||||
-rw-r--r-- | app/views/pokeviewer/pokemon/show.html.haml | 54 | ||||
-rw-r--r-- | db/migrate/20180113200119_move_species_to_revision.rb | 39 | ||||
-rw-r--r-- | test/dummy/db/schema.rb | 6 |
10 files changed, 152 insertions, 111 deletions
diff --git a/app/controllers/pokeviewer/pokemon_controller.rb b/app/controllers/pokeviewer/pokemon_controller.rb index 49a743c..7a1b9f9 100644 --- a/app/controllers/pokeviewer/pokemon_controller.rb +++ b/app/controllers/pokeviewer/pokemon_controller.rb | |||
@@ -10,9 +10,7 @@ module Pokeviewer | |||
10 | order(slot: :asc). | 10 | order(slot: :asc). |
11 | order("pokeviewer_revisions.sequential_id DESC"). | 11 | order("pokeviewer_revisions.sequential_id DESC"). |
12 | group("pokeviewer_pokemon.uuid"). | 12 | group("pokeviewer_pokemon.uuid"). |
13 | select(:box, :slot, :uuid, :trainer_id, :species_id). | 13 | includes(:revisions). |
14 | select(:ot_gender, :ot_name, :unown_letter). | ||
15 | select("pokeviewer_revisions.nickname AS nickname"). | ||
16 | chunk do |p| | 14 | chunk do |p| |
17 | if p.trainer_id.nil? | 15 | if p.trainer_id.nil? |
18 | -1 | 16 | -1 |
@@ -71,8 +69,8 @@ module Pokeviewer | |||
71 | 69 | ||
72 | def show | 70 | def show |
73 | @pokemon = Pokemon.includes( | 71 | @pokemon = Pokemon.includes( |
74 | :trainer, :species, :location, | 72 | :trainer, :location, |
75 | revisions: [:item, :move_1, :move_2, :move_3, :move_4] | 73 | revisions: [:species, :item, :move_1, :move_2, :move_3, :move_4] |
76 | ).find_by_uuid! params[:id] | 74 | ).find_by_uuid! params[:id] |
77 | end | 75 | end |
78 | end | 76 | end |
diff --git a/app/jobs/pokeviewer/extract_save_data_job.rb b/app/jobs/pokeviewer/extract_save_data_job.rb index e9e0231..d1968af 100644 --- a/app/jobs/pokeviewer/extract_save_data_job.rb +++ b/app/jobs/pokeviewer/extract_save_data_job.rb | |||
@@ -71,7 +71,6 @@ module Pokeviewer | |||
71 | 71 | ||
72 | args["pokemon"].each do |param| | 72 | args["pokemon"].each do |param| |
73 | pk = Pokemon.find_or_create_by!(key: param["key"]) do |r| | 73 | pk = Pokemon.find_or_create_by!(key: param["key"]) do |r| |
74 | r.species_id = param["species"] | ||
75 | r.ot_name = param["otName"] | 74 | r.ot_name = param["otName"] |
76 | r.ot_number = param["otId"] | 75 | r.ot_number = param["otId"] |
77 | r.ot_gender = param["otGender"] | 76 | r.ot_gender = param["otGender"] |
@@ -99,7 +98,7 @@ module Pokeviewer | |||
99 | r.pokeball = Pokemon.pokeball.values[param["pokeball"] - 1] | 98 | r.pokeball = Pokemon.pokeball.values[param["pokeball"] - 1] |
100 | 99 | ||
101 | # Handle Unown form | 100 | # Handle Unown form |
102 | if r.species_id == 201 | 101 | if param["species"] == 201 |
103 | r.unown_letter = Pokemon.unown_letter.values[param["unownLetter"]] | 102 | r.unown_letter = Pokemon.unown_letter.values[param["unownLetter"]] |
104 | end | 103 | end |
105 | end | 104 | end |
@@ -117,6 +116,7 @@ module Pokeviewer | |||
117 | pk.save! | 116 | pk.save! |
118 | 117 | ||
119 | rev = Revision.new(pokemon: pk) | 118 | rev = Revision.new(pokemon: pk) |
119 | rev.species_id = param["species"] | ||
120 | rev.nickname = param["nickname"] | 120 | rev.nickname = param["nickname"] |
121 | rev.experience = param["experience"] | 121 | rev.experience = param["experience"] |
122 | rev.level = param["level"] | 122 | rev.level = param["level"] |
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) |
diff --git a/app/views/pokeviewer/pokemon/index.html.haml b/app/views/pokeviewer/pokemon/index.html.haml index e1793dc..67ea2cf 100644 --- a/app/views/pokeviewer/pokemon/index.html.haml +++ b/app/views/pokeviewer/pokemon/index.html.haml | |||
@@ -8,8 +8,8 @@ | |||
8 | %h3 Party | 8 | %h3 Party |
9 | - party.each do |p| | 9 | - party.each do |p| |
10 | %li | 10 | %li |
11 | %span.party-icon= image_tag p.icon_path | 11 | %span.party-icon= image_tag p.current.icon_path |
12 | %span.party-name= link_to p.nickname, p | 12 | %span.party-name= link_to p.current.nickname, p |
13 | - boxes.each do |box| | 13 | - boxes.each do |box| |
14 | .pc-box | 14 | .pc-box |
15 | %h3= box[:name] | 15 | %h3= box[:name] |
@@ -21,9 +21,9 @@ | |||
21 | - if p.nil? | 21 | - if p.nil? |
22 | .spacer | 22 | .spacer |
23 | - else | 23 | - else |
24 | = link_to image_tag(p.icon_path), p | 24 | = link_to image_tag(p.current.icon_path), p |
25 | .pc-data.pkv-hover | 25 | .pc-data.pkv-hover |
26 | .pc-data-name= p.nickname | 26 | .pc-data-name= p.current.nickname |
27 | .pc-data-ot | 27 | .pc-data-ot |
28 | OT/ | 28 | OT/ |
29 | %span{ class: p.ot_gender }>= p.ot_name | 29 | %span{ class: p.ot_gender }>= p.ot_name |
@@ -34,9 +34,9 @@ | |||
34 | %ul.pokemon-list | 34 | %ul.pokemon-list |
35 | - @unaccounted.each do |p| | 35 | - @unaccounted.each do |p| |
36 | %li.pc-pokemon.pkv-has-hover | 36 | %li.pc-pokemon.pkv-has-hover |
37 | = link_to image_tag(p.icon_path), p | 37 | = link_to image_tag(p.current.icon_path), p |
38 | .pc-data.pkv-hover | 38 | .pc-data.pkv-hover |
39 | .pc-data-name= p.nickname | 39 | .pc-data-name= p.current.nickname |
40 | .pc-data-ot | 40 | .pc-data-ot |
41 | OT/ | 41 | OT/ |
42 | %span{ class: p.ot_gender }>= p.ot_name | 42 | %span{ class: p.ot_gender }>= p.ot_name |
diff --git a/app/views/pokeviewer/pokemon/show.html.haml b/app/views/pokeviewer/pokemon/show.html.haml index 0daabb0..3f2750c 100644 --- a/app/views/pokeviewer/pokemon/show.html.haml +++ b/app/views/pokeviewer/pokemon/show.html.haml | |||
@@ -2,44 +2,44 @@ | |||
2 | .pokemon-basics | 2 | .pokemon-basics |
3 | .pokemon-nameline | 3 | .pokemon-nameline |
4 | = image_tag(@pokemon.pokeball_icon_path, class: "pokemon-ball") | 4 | = image_tag(@pokemon.pokeball_icon_path, class: "pokemon-ball") |
5 | %span.pokemon-name= @pokemon.revisions.last.nickname | 5 | %span.pokemon-name= @pokemon.current.nickname |
6 | %span.pokemon-gender{ class: @pokemon.gender }= @pokemon.gender_symbol | 6 | %span.pokemon-gender{ class: @pokemon.gender }= @pokemon.gender_symbol |
7 | .pokemon-level= "Lv. #{@pokemon.revisions.last.level}" | 7 | .pokemon-level= "Lv. #{@pokemon.current.level}" |
8 | .pokemon-image | 8 | .pokemon-image |
9 | .pokemon-image-wrap | 9 | .pokemon-image-wrap |
10 | = image_tag @pokemon.sprite_path, class: "pokemon-sprite" | 10 | = image_tag @pokemon.current.sprite_path, class: "pokemon-sprite" |
11 | - if @pokemon.shiny? | 11 | - if @pokemon.shiny? |
12 | = image_tag "pokeviewer/ShinyIVStar.png", class: "pkv-shiny-star" | 12 | = image_tag "pokeviewer/ShinyIVStar.png", class: "pkv-shiny-star" |
13 | - if @pokemon.revisions.last.item.nil? | 13 | - if @pokemon.current.item.nil? |
14 | .pokemon-item-label Item | 14 | .pokemon-item-label Item |
15 | .pokemon-item None | 15 | .pokemon-item None |
16 | - else | 16 | - else |
17 | .pokemon-item-label.with-item Item | 17 | .pokemon-item-label.with-item Item |
18 | .pokemon-item.pkv-has-hover | 18 | .pokemon-item.pkv-has-hover |
19 | = image_tag(@pokemon.revisions.last.item.icon_path) | 19 | = image_tag(@pokemon.current.item.icon_path) |
20 | = @pokemon.revisions.last.item.name | 20 | = @pokemon.current.item.name |
21 | .pkv-hover | 21 | .pkv-hover |
22 | .pc-data-name= @pokemon.revisions.last.item.name | 22 | .pc-data-name= @pokemon.current.item.name |
23 | - if @pokemon.revisions.last.item.tm? | 23 | - if @pokemon.current.item.tm? |
24 | .pc-move-name= @pokemon.revisions.last.item.move.name | 24 | .pc-move-name= @pokemon.current.item.move.name |
25 | = @pokemon.revisions.last.item.description(@pokemon.trainer.game) | 25 | = @pokemon.current.item.description(@pokemon.trainer.game) |
26 | .pokemon-tab.pokemon-details | 26 | .pokemon-tab.pokemon-details |
27 | %table | 27 | %table |
28 | %tr | 28 | %tr |
29 | %th Pokédex No. | 29 | %th Pokédex No. |
30 | %td | 30 | %td |
31 | .table-bubble.tb-top= @pokemon.species_id | 31 | .table-bubble.tb-top= @pokemon.current.species_id |
32 | %tr | 32 | %tr |
33 | %th Name | 33 | %th Name |
34 | %td | 34 | %td |
35 | .table-bubble= @pokemon.species.name | 35 | .table-bubble= @pokemon.current.species.name |
36 | %tr | 36 | %tr |
37 | %th Type | 37 | %th Type |
38 | %td | 38 | %td |
39 | .table-bubble | 39 | .table-bubble |
40 | = image_for_type @pokemon.species.type_1 | 40 | = image_for_type @pokemon.current.species.type_1 |
41 | - if @pokemon.species.type_2 | 41 | - if @pokemon.current.species.type_2 |
42 | = image_for_type @pokemon.species.type_2 | 42 | = image_for_type @pokemon.current.species.type_2 |
43 | %tr | 43 | %tr |
44 | %th OT | 44 | %th OT |
45 | %td.ot-gender{ class: @pokemon.ot_gender } | 45 | %td.ot-gender{ class: @pokemon.ot_gender } |
@@ -58,7 +58,7 @@ | |||
58 | %tr | 58 | %tr |
59 | %th HP | 59 | %th HP |
60 | %td | 60 | %td |
61 | .table-bubble.tb-top= @pokemon.revisions.last.hp | 61 | .table-bubble.tb-top= @pokemon.current.hp |
62 | %tr | 62 | %tr |
63 | %th | 63 | %th |
64 | Attack | 64 | Attack |
@@ -67,7 +67,7 @@ | |||
67 | - if @pokemon.nature_hinders?(:attack) | 67 | - if @pokemon.nature_hinders?(:attack) |
68 | %span.nature-hinder - | 68 | %span.nature-hinder - |
69 | %td | 69 | %td |
70 | .table-bubble= @pokemon.revisions.last.attack | 70 | .table-bubble= @pokemon.current.attack |
71 | %tr | 71 | %tr |
72 | %th | 72 | %th |
73 | Defense | 73 | Defense |
@@ -76,7 +76,7 @@ | |||
76 | - if @pokemon.nature_hinders?(:defense) | 76 | - if @pokemon.nature_hinders?(:defense) |
77 | %span.nature-hinder - | 77 | %span.nature-hinder - |
78 | %td | 78 | %td |
79 | .table-bubble= @pokemon.revisions.last.defense | 79 | .table-bubble= @pokemon.current.defense |
80 | %tr | 80 | %tr |
81 | %th | 81 | %th |
82 | Sp. Atk | 82 | Sp. Atk |
@@ -85,7 +85,7 @@ | |||
85 | - if @pokemon.nature_hinders?(:special_attack) | 85 | - if @pokemon.nature_hinders?(:special_attack) |
86 | %span.nature-hinder - | 86 | %span.nature-hinder - |
87 | %td | 87 | %td |
88 | .table-bubble= @pokemon.revisions.last.special_attack | 88 | .table-bubble= @pokemon.current.special_attack |
89 | %tr | 89 | %tr |
90 | %th | 90 | %th |
91 | Sp. Def | 91 | Sp. Def |
@@ -94,7 +94,7 @@ | |||
94 | - if @pokemon.nature_hinders?(:special_defense) | 94 | - if @pokemon.nature_hinders?(:special_defense) |
95 | %span.nature-hinder - | 95 | %span.nature-hinder - |
96 | %td | 96 | %td |
97 | .table-bubble= @pokemon.revisions.last.special_defense | 97 | .table-bubble= @pokemon.current.special_defense |
98 | %tr | 98 | %tr |
99 | %th | 99 | %th |
100 | Speed | 100 | Speed |
@@ -103,7 +103,7 @@ | |||
103 | - if @pokemon.nature_hinders?(:speed) | 103 | - if @pokemon.nature_hinders?(:speed) |
104 | %span.nature-hinder - | 104 | %span.nature-hinder - |
105 | %td | 105 | %td |
106 | .table-bubble.tb-bottom= @pokemon.revisions.last.speed | 106 | .table-bubble.tb-bottom= @pokemon.current.speed |
107 | %tr.pokemon-nature-label | 107 | %tr.pokemon-nature-label |
108 | %th{ colspan: 2 } Nature | 108 | %th{ colspan: 2 } Nature |
109 | %tr | 109 | %tr |
@@ -116,18 +116,18 @@ | |||
116 | %th | 116 | %th |
117 | %td | 117 | %td |
118 | .tb-only.pkv-has-hover | 118 | .tb-only.pkv-has-hover |
119 | = @pokemon.ability.name | 119 | = @pokemon.current.ability.name |
120 | .pkv-hover | 120 | .pkv-hover |
121 | .pc-data-name= @pokemon.ability.name | 121 | .pc-data-name= @pokemon.current.ability.name |
122 | = @pokemon.ability.description | 122 | = @pokemon.current.ability.description |
123 | .pokemon-tab.pokemon-moves | 123 | .pokemon-tab.pokemon-moves |
124 | %table | 124 | %table |
125 | - (1..4).each do |i| | 125 | - (1..4).each do |i| |
126 | = move_details @pokemon.revisions.last, i | 126 | = move_details @pokemon.current, i |
127 | .pokemon-tab.pokemon-contest= condition_diagram @pokemon.revisions.last | 127 | .pokemon-tab.pokemon-contest= condition_diagram @pokemon.current |
128 | .pokemon-tab.pokemon-ribbons | 128 | .pokemon-tab.pokemon-ribbons |
129 | %ul | 129 | %ul |
130 | - @pokemon.revisions.last.ribbons.each do |ribbon| | 130 | - @pokemon.current.ribbons.each do |ribbon| |
131 | %li.pkv-has-hover | 131 | %li.pkv-has-hover |
132 | = image_tag("pokeviewer/ribbons/#{ribbon[:filename]}") | 132 | = image_tag("pokeviewer/ribbons/#{ribbon[:filename]}") |
133 | .pkv-hover | 133 | .pkv-hover |
diff --git a/db/migrate/20180113200119_move_species_to_revision.rb b/db/migrate/20180113200119_move_species_to_revision.rb new file mode 100644 index 0000000..8b94d48 --- /dev/null +++ b/db/migrate/20180113200119_move_species_to_revision.rb | |||
@@ -0,0 +1,39 @@ | |||
1 | class MoveSpeciesToRevision < ActiveRecord::Migration[5.1] | ||
2 | def up | ||
3 | change_table :pokeviewer_revisions do |t| | ||
4 | t.references :species, null: true | ||
5 | end | ||
6 | |||
7 | Pokeviewer::Revision.all.each do |r| | ||
8 | r.species_id = r.pokemon.species_id | ||
9 | r.save! | ||
10 | end | ||
11 | |||
12 | remove_column :pokeviewer_pokemon, :species_id | ||
13 | |||
14 | change_column_null :pokeviewer_revisions, :species_id, false | ||
15 | |||
16 | add_foreign_key :pokeviewer_revisions, :pokeviewer_species, | ||
17 | column: :species_id | ||
18 | end | ||
19 | |||
20 | def down | ||
21 | def up | ||
22 | change_table :pokeviewer_pokemon do |t| | ||
23 | t.references :species, null: true | ||
24 | end | ||
25 | |||
26 | Pokeviewer::Pokemon.all.each do |p| | ||
27 | p.species_id = p.revisions.first.species_id | ||
28 | p.save! | ||
29 | end | ||
30 | |||
31 | remove_column :pokeviewer_revisions, :species_id | ||
32 | |||
33 | change_column_null :pokeviewer_pokemon, :species_id, false | ||
34 | |||
35 | add_foreign_key :pokeviewer_pokemon, :pokeviewer_species, | ||
36 | column: :species_id | ||
37 | end | ||
38 | end | ||
39 | end | ||
diff --git a/test/dummy/db/schema.rb b/test/dummy/db/schema.rb index a527d06..9752892 100644 --- a/test/dummy/db/schema.rb +++ b/test/dummy/db/schema.rb | |||
@@ -10,7 +10,7 @@ | |||
10 | # | 10 | # |
11 | # It's strongly recommended that you check this file into your version control system. | 11 | # It's strongly recommended that you check this file into your version control system. |
12 | 12 | ||
13 | ActiveRecord::Schema.define(version: 20171011015648) do | 13 | ActiveRecord::Schema.define(version: 20180113200119) do |
14 | 14 | ||
15 | create_table "pokeviewer_abilities", force: :cascade do |t| | 15 | create_table "pokeviewer_abilities", force: :cascade do |t| |
16 | t.string "name", limit: 191, null: false | 16 | t.string "name", limit: 191, null: false |
@@ -58,7 +58,6 @@ ActiveRecord::Schema.define(version: 20171011015648) do | |||
58 | 58 | ||
59 | create_table "pokeviewer_pokemon", force: :cascade do |t| | 59 | create_table "pokeviewer_pokemon", force: :cascade do |t| |
60 | t.string "uuid", limit: 191, null: false | 60 | t.string "uuid", limit: 191, null: false |
61 | t.integer "species_id", null: false | ||
62 | t.integer "trainer_id" | 61 | t.integer "trainer_id" |
63 | t.string "key", limit: 191 | 62 | t.string "key", limit: 191 |
64 | t.string "ot_name", null: false | 63 | t.string "ot_name", null: false |
@@ -78,7 +77,6 @@ ActiveRecord::Schema.define(version: 20171011015648) do | |||
78 | t.integer "location_id" | 77 | t.integer "location_id" |
79 | t.string "pokeball", null: false | 78 | t.string "pokeball", null: false |
80 | t.index ["key"], name: "index_pokeviewer_pokemon_on_key", unique: true | 79 | t.index ["key"], name: "index_pokeviewer_pokemon_on_key", unique: true |
81 | t.index ["species_id"], name: "index_pokeviewer_pokemon_on_species_id" | ||
82 | t.index ["trainer_id"], name: "index_pokeviewer_pokemon_on_trainer_id" | 80 | t.index ["trainer_id"], name: "index_pokeviewer_pokemon_on_trainer_id" |
83 | t.index ["uuid"], name: "index_pokeviewer_pokemon_on_uuid", unique: true | 81 | t.index ["uuid"], name: "index_pokeviewer_pokemon_on_uuid", unique: true |
84 | end | 82 | end |
@@ -129,12 +127,14 @@ ActiveRecord::Schema.define(version: 20171011015648) do | |||
129 | t.boolean "national_ribbon", default: false | 127 | t.boolean "national_ribbon", default: false |
130 | t.boolean "earth_ribbon", default: false | 128 | t.boolean "earth_ribbon", default: false |
131 | t.boolean "world_ribbon", default: false | 129 | t.boolean "world_ribbon", default: false |
130 | t.integer "species_id", null: false | ||
132 | t.index ["move_1_id"], name: "index_pokeviewer_revisions_on_move_1_id" | 131 | t.index ["move_1_id"], name: "index_pokeviewer_revisions_on_move_1_id" |
133 | t.index ["move_2_id"], name: "index_pokeviewer_revisions_on_move_2_id" | 132 | t.index ["move_2_id"], name: "index_pokeviewer_revisions_on_move_2_id" |
134 | t.index ["move_3_id"], name: "index_pokeviewer_revisions_on_move_3_id" | 133 | t.index ["move_3_id"], name: "index_pokeviewer_revisions_on_move_3_id" |
135 | t.index ["move_4_id"], name: "index_pokeviewer_revisions_on_move_4_id" | 134 | t.index ["move_4_id"], name: "index_pokeviewer_revisions_on_move_4_id" |
136 | t.index ["pokemon_id", "sequential_id"], name: "index_pokeviewer_revisions_on_pokemon_id_and_sequential_id", unique: true | 135 | t.index ["pokemon_id", "sequential_id"], name: "index_pokeviewer_revisions_on_pokemon_id_and_sequential_id", unique: true |
137 | t.index ["pokemon_id"], name: "index_pokeviewer_revisions_on_pokemon_id" | 136 | t.index ["pokemon_id"], name: "index_pokeviewer_revisions_on_pokemon_id" |
137 | t.index ["species_id"], name: "index_pokeviewer_revisions_on_species_id" | ||
138 | end | 138 | end |
139 | 139 | ||
140 | create_table "pokeviewer_species", force: :cascade do |t| | 140 | create_table "pokeviewer_species", force: :cascade do |t| |