about summary refs log tree commit diff stats
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/jobs/pokeviewer/extract_save_data_job.rb20
-rw-r--r--app/models/pokeviewer/pokemon.rb4
2 files changed, 19 insertions, 5 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