diff options
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/pokeviewer/item.rb | 43 | ||||
-rw-r--r-- | app/models/pokeviewer/move.rb | 21 | ||||
-rw-r--r-- | app/models/pokeviewer/revision.rb | 4 |
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 @@ | |||
1 | module 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 | ||
43 | 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 @@ | |||
1 | module Pokeviewer | 1 | module 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 |
10 | end | 31 | 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 | |||
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 |