about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2017-09-24 19:15:55 -0400
committerKelly Rauchenberger <fefferburbia@gmail.com>2017-09-24 19:15:55 -0400
commit687299b33934d25017a226ba6b979e44f0b1f441 (patch)
treeb013bbc0384ac691fcb359a78e7e0234c3eb34f5
parent2721f3768ebd4d279caa967bee210249d93f92cb (diff)
downloadpokeviewer-687299b33934d25017a226ba6b979e44f0b1f441.tar.gz
pokeviewer-687299b33934d25017a226ba6b979e44f0b1f441.tar.bz2
pokeviewer-687299b33934d25017a226ba6b979e44f0b1f441.zip
Added box names
-rw-r--r--app/jobs/pokeviewer/extract_save_data_job.rb6
-rw-r--r--app/models/pokeviewer/box.rb29
-rw-r--r--app/models/pokeviewer/trainer.rb20
-rw-r--r--app/views/pokeviewer/pokemon/index.html.haml6
-rw-r--r--db/migrate/20170924224550_create_pokeviewer_boxes.rb15
-rw-r--r--test/dummy/db/schema.rb12
6 files changed, 65 insertions, 23 deletions
diff --git a/app/jobs/pokeviewer/extract_save_data_job.rb b/app/jobs/pokeviewer/extract_save_data_job.rb index 404716a..3409a5f 100644 --- a/app/jobs/pokeviewer/extract_save_data_job.rb +++ b/app/jobs/pokeviewer/extract_save_data_job.rb
@@ -22,6 +22,12 @@ module Pokeviewer
22 end 22 end
23 end 23 end
24 24
25 args["boxes"].each_with_index do |box_name,index|
26 box = Box.find_or_initialize_by(trainer: game, number: index)
27 box.name = box_name
28 box.save!
29 end
30
25 game.pokemon.clear 31 game.pokemon.clear
26 32
27 args["pokemon"].each do |param| 33 args["pokemon"].each do |param|
diff --git a/app/models/pokeviewer/box.rb b/app/models/pokeviewer/box.rb new file mode 100644 index 0000000..090175e --- /dev/null +++ b/app/models/pokeviewer/box.rb
@@ -0,0 +1,29 @@
1module Pokeviewer
2 class Box < ApplicationRecord
3 belongs_to :trainer
4
5 validates :name, presence: true
6
7 validates :number, presence: true,
8 numericality: {
9 greater_than_or_equal_to: 0,
10 less_than: 14,
11 only_integer: true },
12 uniqueness: { scope: :trainer_id }
13
14 def contents
15 pokes = trainer.pokemon.where(box: number).order("slot ASC").to_a
16
17 result = []
18 (0..29).each do |i|
19 if pokes.empty? or (pokes.first.slot == i)
20 result << pokes.shift
21 else
22 result << nil
23 end
24 end
25
26 result
27 end
28 end
29end
diff --git a/app/models/pokeviewer/trainer.rb b/app/models/pokeviewer/trainer.rb index d3a5b91..f890d61 100644 --- a/app/models/pokeviewer/trainer.rb +++ b/app/models/pokeviewer/trainer.rb
@@ -3,6 +3,7 @@ module Pokeviewer
3 extend Enumerize 3 extend Enumerize
4 4
5 has_many :pokemon, dependent: :nullify 5 has_many :pokemon, dependent: :nullify
6 has_many :boxes, -> { order("number ASC") }, dependent: :destroy
6 7
7 validates :number, presence: true, 8 validates :number, presence: true,
8 numericality: { greater_than_or_equal_to: 0, only_integer: true } 9 numericality: { greater_than_or_equal_to: 0, only_integer: true }
@@ -22,24 +23,5 @@ module Pokeviewer
22 def party 23 def party
23 pokemon.where(box: nil).order("slot ASC") 24 pokemon.where(box: nil).order("slot ASC")
24 end 25 end
25
26 def boxes
27 (0..13).map { |i| box(i) }
28 end
29
30 def box(number)
31 pokes = pokemon.where(box: number).order("slot ASC").to_a
32
33 result = []
34 (0..29).each do |i|
35 if pokes.empty? or (pokes.first.slot == i)
36 result << pokes.shift
37 else
38 result << nil
39 end
40 end
41
42 result
43 end
44 end 26 end
45end 27end
diff --git a/app/views/pokeviewer/pokemon/index.html.haml b/app/views/pokeviewer/pokemon/index.html.haml index 69b6a68..e536080 100644 --- a/app/views/pokeviewer/pokemon/index.html.haml +++ b/app/views/pokeviewer/pokemon/index.html.haml
@@ -10,11 +10,11 @@
10 %li 10 %li
11 %span.party-icon= image_tag p.icon_path 11 %span.party-icon= image_tag p.icon_path
12 %span.party-name= link_to p.revisions.last.nickname, p 12 %span.party-name= link_to p.revisions.last.nickname, p
13 - trainer.boxes.each_with_index do |box,bid| 13 - trainer.boxes.each do |box|
14 .pc-box 14 .pc-box
15 %h3= "Box #{bid+1}" 15 %h3= box.name
16 %table.pc-contents 16 %table.pc-contents
17 - box.each_slice(6) do |row| 17 - box.contents.each_slice(6) do |row|
18 %tr 18 %tr
19 - row.each do |p| 19 - row.each do |p|
20 %td.pc-pokemon 20 %td.pc-pokemon
diff --git a/db/migrate/20170924224550_create_pokeviewer_boxes.rb b/db/migrate/20170924224550_create_pokeviewer_boxes.rb new file mode 100644 index 0000000..02f6fa9 --- /dev/null +++ b/db/migrate/20170924224550_create_pokeviewer_boxes.rb
@@ -0,0 +1,15 @@
1class CreatePokeviewerBoxes < ActiveRecord::Migration[5.1]
2 def change
3 create_table :pokeviewer_boxes do |t|
4 t.references :trainer, null: false
5 t.integer :number, null: false
6 t.string :name, null: false
7
8 t.timestamps
9 end
10
11 add_foreign_key :pokeviewer_boxes, :pokeviewer_trainer, column: :trainer_id
12
13 add_index :pokeviewer_boxes, [:trainer_id, :number], unique: true
14 end
15end
diff --git a/test/dummy/db/schema.rb b/test/dummy/db/schema.rb index 9a13685..e7322e9 100644 --- a/test/dummy/db/schema.rb +++ b/test/dummy/db/schema.rb
@@ -10,7 +10,17 @@
10# 10#
11# It's strongly recommended that you check this file into your version control system. 11# It's strongly recommended that you check this file into your version control system.
12 12
13ActiveRecord::Schema.define(version: 20170924160524) do 13ActiveRecord::Schema.define(version: 20170924224550) do
14
15 create_table "pokeviewer_boxes", force: :cascade do |t|
16 t.integer "trainer_id", null: false
17 t.integer "number", null: false
18 t.string "name", null: false
19 t.datetime "created_at", null: false
20 t.datetime "updated_at", null: false
21 t.index ["trainer_id", "number"], name: "index_pokeviewer_boxes_on_trainer_id_and_number", unique: true
22 t.index ["trainer_id"], name: "index_pokeviewer_boxes_on_trainer_id"
23 end
14 24
15 create_table "pokeviewer_moves", force: :cascade do |t| 25 create_table "pokeviewer_moves", force: :cascade do |t|
16 t.string "name", limit: 191, null: false 26 t.string "name", limit: 191, null: false