diff options
Diffstat (limited to 'app/jobs')
-rw-r--r-- | app/jobs/pokeviewer/extract_save_data_job.rb | 41 |
1 files changed, 25 insertions, 16 deletions
diff --git a/app/jobs/pokeviewer/extract_save_data_job.rb b/app/jobs/pokeviewer/extract_save_data_job.rb index 99d71f1..14ba9a6 100644 --- a/app/jobs/pokeviewer/extract_save_data_job.rb +++ b/app/jobs/pokeviewer/extract_save_data_job.rb | |||
@@ -3,7 +3,7 @@ module Pokeviewer | |||
3 | queue_as :default | 3 | queue_as :default |
4 | 4 | ||
5 | def perform(args) | 5 | def perform(args) |
6 | game = Trainer.find_or_create_by!( | 6 | game = Trainer.find_or_initialize_by( |
7 | name: args["playerName"], | 7 | name: args["playerName"], |
8 | number: args["playerId"]) do |r| | 8 | number: args["playerId"]) do |r| |
9 | case args["gameId"].to_i | 9 | case args["gameId"].to_i |
@@ -22,41 +22,50 @@ module Pokeviewer | |||
22 | end | 22 | end |
23 | end | 23 | end |
24 | 24 | ||
25 | game.box_1_name = args["boxes"].shift | ||
26 | game.box_2_name = args["boxes"].shift | ||
27 | game.box_3_name = args["boxes"].shift | ||
28 | game.box_4_name = args["boxes"].shift | ||
29 | game.box_5_name = args["boxes"].shift | ||
30 | game.box_6_name = args["boxes"].shift | ||
31 | game.box_7_name = args["boxes"].shift | ||
32 | game.box_8_name = args["boxes"].shift | ||
33 | game.box_9_name = args["boxes"].shift | ||
34 | game.box_10_name = args["boxes"].shift | ||
35 | game.box_11_name = args["boxes"].shift | ||
36 | game.box_12_name = args["boxes"].shift | ||
37 | game.box_13_name = args["boxes"].shift | ||
38 | game.box_14_name = args["boxes"].shift | ||
39 | |||
25 | if args.key? "marineRibbon" | 40 | if args.key? "marineRibbon" |
26 | game.marine_ribbon = GiftRibbon.find_by_id(args["marineRibbon"]) | 41 | game.marine_ribbon_id = args["marineRibbon"] |
27 | end | 42 | end |
28 | 43 | ||
29 | if args.key? "landRibbon" | 44 | if args.key? "landRibbon" |
30 | game.land_ribbon = GiftRibbon.find_by_id(args["landRibbon"]) | 45 | game.land_ribbon_id = args["landRibbon"] |
31 | end | 46 | end |
32 | 47 | ||
33 | if args.key? "skyRibbon" | 48 | if args.key? "skyRibbon" |
34 | game.sky_ribbon = GiftRibbon.find_by_id(args["skyRibbon"]) | 49 | game.sky_ribbon_id = args["skyRibbon"] |
35 | end | 50 | end |
36 | 51 | ||
37 | if args.key? "countryRibbon" | 52 | if args.key? "countryRibbon" |
38 | game.country_ribbon = GiftRibbon.find_by_id(args["countryRibbon"]) | 53 | game.country_ribbon_id = args["countryRibbon"] |
39 | end | 54 | end |
40 | 55 | ||
41 | if args.key? "nationalRibbon" | 56 | if args.key? "nationalRibbon" |
42 | game.national_ribbon = GiftRibbon.find_by_id(args["nationalRibbon"]) | 57 | game.national_ribbon_id = args["nationalRibbon"] |
43 | end | 58 | end |
44 | 59 | ||
45 | if args.key? "earthRibbon" | 60 | if args.key? "earthRibbon" |
46 | game.earth_ribbon = GiftRibbon.find_by_id(args["earthRibbon"]) | 61 | game.earth_ribbon_id = args["earthRibbon"] |
47 | end | 62 | end |
48 | 63 | ||
49 | if args.key? "worldRibbon" | 64 | if args.key? "worldRibbon" |
50 | game.world_ribbon = GiftRibbon.find_by_id(args["worldRibbon"]) | 65 | game.world_ribbon_id = args["worldRibbon"] |
51 | end | 66 | end |
52 | 67 | ||
53 | game.save! if game.changed? | 68 | game.save! if game.new_record? or game.changed? |
54 | |||
55 | args["boxes"].each_with_index do |box_name,index| | ||
56 | box = Box.find_or_initialize_by(trainer: game, number: index) | ||
57 | box.name = box_name | ||
58 | box.save! | ||
59 | end | ||
60 | 69 | ||
61 | game.pokemon.clear | 70 | game.pokemon.clear |
62 | 71 | ||
@@ -97,7 +106,7 @@ module Pokeviewer | |||
97 | if param["storage"] == "party" | 106 | if param["storage"] == "party" |
98 | pk.box = nil | 107 | pk.box = nil |
99 | elsif param["storage"] == "box" | 108 | elsif param["storage"] == "box" |
100 | pk.box = param["box"] | 109 | pk.box = param["box"] + 1 |
101 | end | 110 | end |
102 | 111 | ||
103 | pk.slot = param["slot"] | 112 | pk.slot = param["slot"] |