Update SummonProcessor to work like the others
This commit is contained in:
parent
e5ecfbd95f
commit
ebb3218c29
3 changed files with 13 additions and 11 deletions
|
|
@ -33,7 +33,7 @@ module Processors
|
||||||
end
|
end
|
||||||
|
|
||||||
@data = @data.with_indifferent_access
|
@data = @data.with_indifferent_access
|
||||||
characters_data = @data['deck']['npc']
|
characters_data = @data.dig('deck', 'npc')
|
||||||
|
|
||||||
grid_characters = process_characters(characters_data)
|
grid_characters = process_characters(characters_data)
|
||||||
grid_characters.each do |grid_character|
|
grid_characters.each do |grid_character|
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ module Processors
|
||||||
# Initializes a new SummonProcessor.
|
# Initializes a new SummonProcessor.
|
||||||
#
|
#
|
||||||
# @param party [Party] the Party record.
|
# @param party [Party] the Party record.
|
||||||
# @param data [Array<Hash>] an array of summon data hashes.
|
# @param data [Hash] the deck hash.
|
||||||
# @param type [Symbol] the type of summon (:normal, :friend, or :sub).
|
# @param type [Symbol] the type of summon (:normal, :friend, or :sub).
|
||||||
# @param quick_summon_id [String, nil] (optional) the quick summon identifier.
|
# @param quick_summon_id [String, nil] (optional) the quick summon identifier.
|
||||||
# @param options [Hash] additional options.
|
# @param options [Hash] additional options.
|
||||||
|
|
@ -37,21 +37,23 @@ module Processors
|
||||||
#
|
#
|
||||||
# @return [void]
|
# @return [void]
|
||||||
def process
|
def process
|
||||||
# Guard: ensure the data is in the expected format.
|
|
||||||
unless @data.is_a?(Hash)
|
unless @data.is_a?(Hash)
|
||||||
Rails.logger.error "[SUMMON] Invalid data format: expected a Hash, got #{@data.class}"
|
Rails.logger.error "[SUMMON] Invalid data format: expected a Hash, got #{@data.class}"
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
return unless @data.key?('summons') &&
|
unless @data.key?('deck') && @data['deck'].key?('pc')
|
||||||
@data.key?('sub_summons') &&
|
Rails.logger.error '[SUMMON] Missing npc data in deck JSON'
|
||||||
@data.key?('damage_info')
|
return
|
||||||
|
end
|
||||||
|
|
||||||
@data = @data.with_indifferent_access if @data.is_a?(Hash)
|
@data = @data.with_indifferent_access
|
||||||
|
summons_data = @data.dig('deck', 'pc', 'summons')
|
||||||
|
sub_summons_data = @data.dig('deck', 'pc', 'sub_summons')
|
||||||
|
|
||||||
grid_summons = process_summons(@data['summons'], sub: false)
|
grid_summons = process_summons(summons_data, sub: false)
|
||||||
friend_summon = process_friend_summon
|
friend_summon = process_friend_summon
|
||||||
sub_summons = process_summons(@data['sub_summons'], sub: true)
|
sub_summons = process_summons(sub_summons_data, sub: true)
|
||||||
|
|
||||||
summons = [*grid_summons, friend_summon, *sub_summons]
|
summons = [*grid_summons, friend_summon, *sub_summons]
|
||||||
|
|
||||||
|
|
@ -106,7 +108,7 @@ module Processors
|
||||||
#
|
#
|
||||||
# @return [GridSummon]
|
# @return [GridSummon]
|
||||||
def process_friend_summon
|
def process_friend_summon
|
||||||
summon_name = @data['damage_info']['summon_name']
|
summon_name = @data.dig('deck', 'pc', 'damage_info', 'summon_name')
|
||||||
summon = Summon.find_by('name_en = ? OR name_jp = ?', summon_name, summon_name)
|
summon = Summon.find_by('name_en = ? OR name_jp = ?', summon_name, summon_name)
|
||||||
|
|
||||||
GridSummon.new({
|
GridSummon.new({
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ RSpec.describe Processors::SummonProcessor, type: :model do
|
||||||
let(:party) { create(:party) }
|
let(:party) { create(:party) }
|
||||||
let(:deck_data) do
|
let(:deck_data) do
|
||||||
file_path = Rails.root.join('spec', 'fixtures', 'deck_sample.json')
|
file_path = Rails.root.join('spec', 'fixtures', 'deck_sample.json')
|
||||||
JSON.parse(File.read(file_path))['deck']['pc']
|
JSON.parse(File.read(file_path))
|
||||||
end
|
end
|
||||||
|
|
||||||
subject { described_class.new(party, deck_data, language: 'en') }
|
subject { described_class.new(party, deck_data, language: 'en') }
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue