From 2721f3768ebd4d279caa967bee210249d93f92cb Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Sun, 24 Sep 2017 18:14:24 -0400 Subject: Worked on PC display page --- app/models/pokeviewer/pokemon.rb | 19 +++++++++++++++++-- app/models/pokeviewer/trainer.rb | 27 +++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) (limited to 'app/models') diff --git a/app/models/pokeviewer/pokemon.rb b/app/models/pokeviewer/pokemon.rb index 3975550..d14ea87 100644 --- a/app/models/pokeviewer/pokemon.rb +++ b/app/models/pokeviewer/pokemon.rb @@ -36,7 +36,7 @@ module Pokeviewer enumerize :unown_letter, in: [:a, :b, :c, :d, :e, :f, :g, :h, :i, :j, :k, :l, :m, :n, :o, :p, :q, :r, :s, :t, :u, :v, :w, :x, :y, :z, :question, :exclamation] - + validates :slot, presence: true, uniqueness: { scope: [:trainer_id, :box] }, unless: Proc.new { |a| a.trainer.nil? } @@ -46,7 +46,22 @@ module Pokeviewer end def icon_path - "pokeviewer/icons/#{species_id}.png" + 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 diff --git a/app/models/pokeviewer/trainer.rb b/app/models/pokeviewer/trainer.rb index edfbd25..d3a5b91 100644 --- a/app/models/pokeviewer/trainer.rb +++ b/app/models/pokeviewer/trainer.rb @@ -14,5 +14,32 @@ module Pokeviewer validates :game, presence: true enumerize :game, in: [:ruby, :sapphire, :firered, :leafgreen, :emerald], predicates: true + + def display_number + number.to_s.rjust(5, '0') + end + + def party + pokemon.where(box: nil).order("slot ASC") + end + + def boxes + (0..13).map { |i| box(i) } + end + + def box(number) + pokes = pokemon.where(box: number).order("slot ASC").to_a + + result = [] + (0..29).each do |i| + if pokes.empty? or (pokes.first.slot == i) + result << pokes.shift + else + result << nil + end + end + + result + end end end -- cgit 1.4.1