about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--app/jobs/pokeviewer/extract_save_data_job.rb20
-rw-r--r--app/models/pokeviewer/pokemon.rb4
-rw-r--r--db/migrate/20170924160524_add_storage_info_to_pokemon.rb6
-rw-r--r--test/dummy/db/schema.rb4
4 files changed, 28 insertions, 6 deletions
diff --git a/app/jobs/pokeviewer/extract_save_data_job.rb b/app/jobs/pokeviewer/extract_save_data_job.rb index 0a9b790..404716a 100644 --- a/app/jobs/pokeviewer/extract_save_data_job.rb +++ b/app/jobs/pokeviewer/extract_save_data_job.rb
@@ -22,7 +22,9 @@ module Pokeviewer
22 end 22 end
23 end 23 end
24 24
25 pokemons = args["pokemon"].map do |param| 25 game.pokemon.clear
26
27 args["pokemon"].each do |param|
26 pk = Pokemon.find_or_create_by!(key: param["key"]) do |r| 28 pk = Pokemon.find_or_create_by!(key: param["key"]) do |r|
27 r.species_id = param["species"] 29 r.species_id = param["species"]
28 r.ot_name = param["otName"] 30 r.ot_name = param["otName"]
@@ -47,6 +49,18 @@ module Pokeviewer
47 end 49 end
48 end 50 end
49 51
52 pk.trainer = game
53
54 if param["storage"] == "party"
55 pk.box = nil
56 elsif param["storage"] == "box"
57 pk.box = param["box"]
58 end
59
60 pk.slot = param["slot"]
61
62 pk.save!
63
50 rev = Revision.new(pokemon: pk) 64 rev = Revision.new(pokemon: pk)
51 rev.nickname = param["nickname"] 65 rev.nickname = param["nickname"]
52 rev.experience = param["experience"] 66 rev.experience = param["experience"]
@@ -85,11 +99,7 @@ module Pokeviewer
85 if pk.revisions.empty? or rev.diff?(pk.revisions.last) 99 if pk.revisions.empty? or rev.diff?(pk.revisions.last)
86 rev.save! 100 rev.save!
87 end 101 end
88
89 pk
90 end 102 end
91
92 game.pokemon = pokemons
93 end 103 end
94 end 104 end
95end 105end
diff --git a/app/models/pokeviewer/pokemon.rb b/app/models/pokeviewer/pokemon.rb index 1e3bfc8..3975550 100644 --- a/app/models/pokeviewer/pokemon.rb +++ b/app/models/pokeviewer/pokemon.rb
@@ -36,6 +36,10 @@ module Pokeviewer
36 enumerize :unown_letter, in: [:a, :b, :c, :d, :e, :f, :g, :h, :i, :j, :k, 36 enumerize :unown_letter, in: [:a, :b, :c, :d, :e, :f, :g, :h, :i, :j, :k,
37 :l, :m, :n, :o, :p, :q, :r, :s, :t, :u, :v, :w, :x, :y, :z, 37 :l, :m, :n, :o, :p, :q, :r, :s, :t, :u, :v, :w, :x, :y, :z,
38 :question, :exclamation] 38 :question, :exclamation]
39
40 validates :slot, presence: true,
41 uniqueness: { scope: [:trainer_id, :box] },
42 unless: Proc.new { |a| a.trainer.nil? }
39 43
40 def to_param 44 def to_param
41 uuid 45 uuid
diff --git a/db/migrate/20170924160524_add_storage_info_to_pokemon.rb b/db/migrate/20170924160524_add_storage_info_to_pokemon.rb new file mode 100644 index 0000000..b519b1b --- /dev/null +++ b/db/migrate/20170924160524_add_storage_info_to_pokemon.rb
@@ -0,0 +1,6 @@
1class AddStorageInfoToPokemon < ActiveRecord::Migration[5.1]
2 def change
3 add_column :pokeviewer_pokemon, :box, :integer, null: true
4 add_column :pokeviewer_pokemon, :slot, :integer, null: true
5 end
6end
diff --git a/test/dummy/db/schema.rb b/test/dummy/db/schema.rb index 9d6d773..9a13685 100644 --- a/test/dummy/db/schema.rb +++ b/test/dummy/db/schema.rb
@@ -10,7 +10,7 @@
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: 20170924152817) do 13ActiveRecord::Schema.define(version: 20170924160524) do
14 14
15 create_table "pokeviewer_moves", force: :cascade do |t| 15 create_table "pokeviewer_moves", force: :cascade do |t|
16 t.string "name", limit: 191, null: false 16 t.string "name", limit: 191, null: false
@@ -38,6 +38,8 @@ ActiveRecord::Schema.define(version: 20170924152817) do
38 t.datetime "created_at", null: false 38 t.datetime "created_at", null: false
39 t.datetime "updated_at", null: false 39 t.datetime "updated_at", null: false
40 t.string "ot_gender", default: "", null: false 40 t.string "ot_gender", default: "", null: false
41 t.integer "box"
42 t.integer "slot"
41 t.index ["key"], name: "index_pokeviewer_pokemon_on_key", unique: true 43 t.index ["key"], name: "index_pokeviewer_pokemon_on_key", unique: true
42 t.index ["species_id"], name: "index_pokeviewer_pokemon_on_species_id" 44 t.index ["species_id"], name: "index_pokeviewer_pokemon_on_species_id"
43 t.index ["trainer_id"], name: "index_pokeviewer_pokemon_on_trainer_id" 45 t.index ["trainer_id"], name: "index_pokeviewer_pokemon_on_trainer_id"