From 7e4b9ea0c23eb660ab36a6114a7a3046d8f1c5f6 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Sat, 13 Jan 2018 16:01:51 -0500 Subject: Moved species from Pokémon to revision MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- app/models/pokeviewer/pokemon.rb | 66 ++----------------------------------- app/models/pokeviewer/revision.rb | 68 ++++++++++++++++++++++++++++++++++++++- app/models/pokeviewer/species.rb | 2 +- app/models/pokeviewer/trainer.rb | 4 +-- 4 files changed, 72 insertions(+), 68 deletions(-) (limited to 'app/models') 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 extend Enumerize extend ActiveModel::Naming - belongs_to :species - has_many :revisions, -> { order "sequential_id ASC" }, dependent: :destroy belongs_to :trainer, optional: true @@ -78,60 +76,8 @@ module Pokeviewer uuid end - def icon_path - form = "" - if species_id == 201 - # Handle Unown form - form = "-#{unown_letter}" - elsif species_id == 386 - # Handle Deoxys forms - if trainer.firered? - form = "-attack" - elsif trainer.leafgreen? - form = "-defense" - elsif trainer.emerald? - form = "-speed" - end - end - - "pokeviewer/icons/#{species_id}#{form}.png" - end - - def sprite_path - shininess = "normal" - if shiny - shininess = "shiny" - end - - game = "ruby-sapphire" - unless trainer.nil? - if (trainer.firered? or trainer.leafgreen?) and (species_id <= 156 or species_id == 216 or species_id == 386) - game = "firered-leafgreen" - elsif trainer.emerald? - game = "emerald" - end - end - - form = "" - if species_id == 201 - # Handle Unown forms - form = "-#{unown_letter}" - elsif species_id == 386 - # Handle Deoxys forms - if trainer.firered? - form = "-attack" - elsif trainer.leafgreen? - form = "-defense" - elsif trainer.emerald? - form = "-speed" - end - end - - if game == "emerald" - "pokeviewer/sprites/emerald/#{shininess}/#{species_id}#{form}.gif" - else - "pokeviewer/sprites/#{game}/#{shininess}/#{species_id}#{form}.png" - end + def current + revisions.last end def outsider? @@ -178,14 +124,6 @@ module Pokeviewer "pokeviewer/items/#{Pokemon.pokeball.values.find_index(pokeball) + 1}.png" end - def ability - if second_ability - species.ability_2 - else - species.ability_1 - end - end - def gift_ribbon_description(ribbon) if trainer.nil? "" 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 class Revision < ApplicationRecord include ActiveRecord::Diff - diff :nickname, :level, :hp, :attack, :defense, + diff :species_id, :nickname, :level, :hp, :attack, :defense, :special_attack, :special_defense, :speed, :coolness, :beauty, :cuteness, :smartness, :toughness, :sheen, :item_id, :move_1_id, :move_2_id, :move_3_id, :move_4_id, :move_1_pp_bonuses, :move_2_pp_bonuses, @@ -17,6 +17,8 @@ module Pokeviewer belongs_to :pokemon acts_as_sequenced scope: :pokemon_id + belongs_to :species + validates :nickname, presence: true validates :experience, presence: true, @@ -140,6 +142,70 @@ module Pokeviewer less_than_or_equal_to: 4, only_integer: true} + def icon_path + form = "" + if species_id == 201 + # Handle Unown form + form = "-#{pokemon.unown_letter}" + elsif species_id == 386 + # Handle Deoxys forms + if pokemon.trainer.firered? + form = "-attack" + elsif pokemon.trainer.leafgreen? + form = "-defense" + elsif pokemon.trainer.emerald? + form = "-speed" + end + end + + "pokeviewer/icons/#{species_id}#{form}.png" + end + + def sprite_path + shininess = "normal" + if pokemon.shiny + shininess = "shiny" + end + + game = "ruby-sapphire" + unless pokemon.trainer.nil? + if (pokemon.trainer.firered? or pokemon.trainer.leafgreen?) and (species_id <= 156 or species_id == 216 or species_id == 386) + game = "firered-leafgreen" + elsif pokemon.trainer.emerald? + game = "emerald" + end + end + + form = "" + if species_id == 201 + # Handle Unown forms + form = "-#{pokemon.unown_letter}" + elsif species_id == 386 + # Handle Deoxys forms + if pokemon.trainer.firered? + form = "-attack" + elsif pokemon.trainer.leafgreen? + form = "-defense" + elsif pokemon.trainer.emerald? + form = "-speed" + end + end + + if game == "emerald" + "pokeviewer/sprites/emerald/#{shininess}/#{species_id}#{form}.gif" + else + "pokeviewer/sprites/#{game}/#{shininess}/#{species_id}#{form}.png" + end + end + + def ability + if pokemon.second_ability + species.ability_2 + else + species.ability_1 + end + end + def move_1_pp move_1.pp * (5 + move_1_pp_bonuses) / 5 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 class Species < ApplicationRecord extend Enumerize - has_many :pokemon, dependent: :restrict_with_exception + has_many :revisions, dependent: :restrict_with_exception validates :name, presence: true, uniqueness: true 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 validates :box_14_name, presence: true def party - pokemon.party.includes(:species, :revisions) + pokemon.party.includes(revisions: [:species]) end def box(n) - pokemon.box(n).includes(:species, :revisions) + pokemon.box(n).includes(revisions: [:species]) end def box_name(n) -- cgit 1.4.1