about summary refs log tree commit diff stats
path: root/app/models
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2017-09-30 19:01:56 -0400
committerKelly Rauchenberger <fefferburbia@gmail.com>2017-09-30 19:01:56 -0400
commit9c022576fa053fd32aaebc7acb2bb44884a623d7 (patch)
tree6aa6d47da389082eab25fa5a49fae1d07ff56c02 /app/models
parenta7060addea52af313ed85336dc37949ad8e69f05 (diff)
downloadpokeviewer-9c022576fa053fd32aaebc7acb2bb44884a623d7.tar.gz
pokeviewer-9c022576fa053fd32aaebc7acb2bb44884a623d7.tar.bz2
pokeviewer-9c022576fa053fd32aaebc7acb2bb44884a623d7.zip
Added hold items
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.
Diffstat (limited to 'app/models')
-rw-r--r--app/models/pokeviewer/item.rb43
-rw-r--r--app/models/pokeviewer/move.rb21
-rw-r--r--app/models/pokeviewer/revision.rb4
3 files changed, 67 insertions, 1 deletions
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 @@
1module Pokeviewer
2 class Item < ApplicationRecord
3 validates :name, presence: true
4
5 belongs_to :move, optional: true
6 validates :move, presence: true, if: :tm?
7
8 validates :rs_description, presence: true, unless: :tm?
9 validates :frlg_description, presence: true, unless: :tm?
10
11 def description(game)
12 if game == :emerald
13 if not emerald_description.nil?
14 emerald_description
15 elsif not rs_description.nil?
16 rs_description
17 else
18 move.description game
19 end
20 elsif game == :firered or game == :leafgreen
21 if not frlg_description.nil?
22 frlg_description
23 else
24 move.description game
25 end
26 else
27 if not rs_description.nil?
28 rs_description
29 else
30 move.description game
31 end
32 end
33 end
34
35 def icon_path
36 if tm?
37 "pokeviewer/items/tms/#{move.move_type}.png"
38 else
39 "pokeviewer/items/#{id}.png"
40 end
41 end
42 end
43end
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 @@
1module Pokeviewer 1module Pokeviewer
2 class Move < ApplicationRecord 2 class Move < ApplicationRecord
3 extend Enumerize
4
3 has_many :revision_moves 5 has_many :revision_moves
4 has_many :revisions, through: :revision_moves 6 has_many :revisions, through: :revision_moves
5 7
6 validates :name, presence: true, uniqueness: true 8 validates :name, presence: true, uniqueness: true
9
7 validates :pp, presence: true, 10 validates :pp, presence: true,
8 numericality: { greater_than_or_equal_to: 1, only_integer: true } 11 numericality: { greater_than_or_equal_to: 1, only_integer: true }
12
13 validates :move_type, presence: true
14 enumerize :move_type, in: [:normal, :fighting, :flying, :poison, :ground,
15 :rock, :bug, :ghost, :steel, :mystery, :fire, :water, :grass, :electric,
16 :psychic, :ice, :dragon, :dark], predicates: true
17
18 validates :rs_description, presence: true
19 validates :frlg_description, presence: true
20
21 def description(game)
22 if game == :emerald and not emerald_description.nil?
23 emerald_description
24 elsif game == :firered or game == :leafgreen
25 frlg_description
26 else
27 rs_description
28 end
29 end
9 end 30 end
10end 31end
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
6 6
7 diff :nickname, :level, :hp, :attack, :defense, 7 diff :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, :hold_item, :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,
11 :move_3_pp_bonuses, :move_4_pp_bonuses, :cool_ribbons, :beauty_ribbons, 11 :move_3_pp_bonuses, :move_4_pp_bonuses, :cool_ribbons, :beauty_ribbons,
12 :cute_ribbons, :smart_ribbons, :tough_ribbons, :champion_ribbon, 12 :cute_ribbons, :smart_ribbons, :tough_ribbons, :champion_ribbon,
@@ -79,6 +79,8 @@ module Pokeviewer
79 less_than_or_equal_to: 10, 79 less_than_or_equal_to: 10,
80 only_integer: true } 80 only_integer: true }
81 81
82 belongs_to :item, optional: true
83
82 belongs_to :move_1, class_name: "Move" 84 belongs_to :move_1, class_name: "Move"
83 belongs_to :move_2, class_name: "Move", optional: true 85 belongs_to :move_2, class_name: "Move", optional: true
84 belongs_to :move_3, class_name: "Move", optional: true 86 belongs_to :move_3, class_name: "Move", optional: true