From 9c022576fa053fd32aaebc7acb2bb44884a623d7 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Sat, 30 Sep 2017 19:01:56 -0400 Subject: Added hold items MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit An items model was created, but the seed only contains items that can be held, which excludes key items and HMs. Berry Juice, while unobtainable, is still included. The item model contains three description fields: one for Ruby/Sapphire, one for FireRed/LeafGreen, and one for Emerald. This is because the descriptions for items are different between the games. In a lot of cases, the Emerald description is the same as the Ruby/Sapphire one, so in those cases, the Emerald description is nil. The purpose of having the different descriptions is so that when a Pokémon holds an item, the website can display the description that is accurate to the game that that Pokémon is currently in. In order to fully support TMs, the move model was improved to additionally contain type and also the three description fields which operate similarly to those of the item model. For TMs, the description fields on the item are usually nil. However, some TMs in Ruby/Sapphire, as well as Emerald, have different descriptions than the moves that they correspond with. In these cases, those descriptions are in the item model, and override the move descriptions when the move is looked at as a TM. --- app/models/pokeviewer/item.rb | 43 +++++++++++++++++++++++++++++++++++++++ app/models/pokeviewer/move.rb | 21 +++++++++++++++++++ app/models/pokeviewer/revision.rb | 4 +++- 3 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 app/models/pokeviewer/item.rb (limited to 'app/models') diff --git a/app/models/pokeviewer/item.rb b/app/models/pokeviewer/item.rb new file mode 100644 index 0000000..d03c584 --- /dev/null +++ b/app/models/pokeviewer/item.rb @@ -0,0 +1,43 @@ +module Pokeviewer + class Item < ApplicationRecord + validates :name, presence: true + + belongs_to :move, optional: true + validates :move, presence: true, if: :tm? + + validates :rs_description, presence: true, unless: :tm? + validates :frlg_description, presence: true, unless: :tm? + + def description(game) + if game == :emerald + if not emerald_description.nil? + emerald_description + elsif not rs_description.nil? + rs_description + else + move.description game + end + elsif game == :firered or game == :leafgreen + if not frlg_description.nil? + frlg_description + else + move.description game + end + else + if not rs_description.nil? + rs_description + else + move.description game + end + end + end + + def icon_path + if tm? + "pokeviewer/items/tms/#{move.move_type}.png" + else + "pokeviewer/items/#{id}.png" + end + end + end +end diff --git a/app/models/pokeviewer/move.rb b/app/models/pokeviewer/move.rb index 337ac11..3ef6a9c 100644 --- a/app/models/pokeviewer/move.rb +++ b/app/models/pokeviewer/move.rb @@ -1,10 +1,31 @@ module Pokeviewer class Move < ApplicationRecord + extend Enumerize + has_many :revision_moves has_many :revisions, through: :revision_moves validates :name, presence: true, uniqueness: true + validates :pp, presence: true, numericality: { greater_than_or_equal_to: 1, only_integer: true } + + validates :move_type, presence: true + enumerize :move_type, in: [:normal, :fighting, :flying, :poison, :ground, + :rock, :bug, :ghost, :steel, :mystery, :fire, :water, :grass, :electric, + :psychic, :ice, :dragon, :dark], predicates: true + + validates :rs_description, presence: true + validates :frlg_description, presence: true + + def description(game) + if game == :emerald and not emerald_description.nil? + emerald_description + elsif game == :firered or game == :leafgreen + frlg_description + else + rs_description + end + end end end diff --git a/app/models/pokeviewer/revision.rb b/app/models/pokeviewer/revision.rb index ab4dfd3..b77bb1f 100644 --- a/app/models/pokeviewer/revision.rb +++ b/app/models/pokeviewer/revision.rb @@ -6,7 +6,7 @@ module Pokeviewer diff :nickname, :level, :hp, :attack, :defense, :special_attack, :special_defense, :speed, :coolness, :beauty, :cuteness, - :smartness, :toughness, :sheen, :hold_item, :move_1_id, :move_2_id, + :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, :move_3_pp_bonuses, :move_4_pp_bonuses, :cool_ribbons, :beauty_ribbons, :cute_ribbons, :smart_ribbons, :tough_ribbons, :champion_ribbon, @@ -79,6 +79,8 @@ module Pokeviewer less_than_or_equal_to: 10, only_integer: true } + belongs_to :item, optional: true + belongs_to :move_1, class_name: "Move" belongs_to :move_2, class_name: "Move", optional: true belongs_to :move_3, class_name: "Move", optional: true -- cgit 1.4.1