From 012b083cbd74ab687d5529258ff045319265e594 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Sun, 24 Sep 2017 12:39:17 -0400 Subject: Added storage location information to Pokémon MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/jobs/pokeviewer/extract_save_data_job.rb | 20 +++++++++++++++----- app/models/pokeviewer/pokemon.rb | 4 ++++ 2 files changed, 19 insertions(+), 5 deletions(-) (limited to 'app') 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 end end - pokemons = args["pokemon"].map do |param| + game.pokemon.clear + + args["pokemon"].each do |param| pk = Pokemon.find_or_create_by!(key: param["key"]) do |r| r.species_id = param["species"] r.ot_name = param["otName"] @@ -47,6 +49,18 @@ module Pokeviewer end end + pk.trainer = game + + if param["storage"] == "party" + pk.box = nil + elsif param["storage"] == "box" + pk.box = param["box"] + end + + pk.slot = param["slot"] + + pk.save! + rev = Revision.new(pokemon: pk) rev.nickname = param["nickname"] rev.experience = param["experience"] @@ -85,11 +99,7 @@ module Pokeviewer if pk.revisions.empty? or rev.diff?(pk.revisions.last) rev.save! end - - pk end - - game.pokemon = pokemons end end end 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 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? } def to_param uuid -- cgit 1.4.1