- **GridCharacterBlueprint:** - Removed `:minimal` view restriction on `party` association. - Improved nil checks for `ring1`, `ring2`, and `earring` to prevent errors. - Converted string values in `awakening_level`, `over_mastery`, and `aetherial_mastery` fields to integers for consistency. - Ensured `over_mastery` and `aetherial_mastery` only include valid entries, filtering out blank or zero-modifier values. - **GridWeaponBlueprint:** - Removed `:minimal` view restriction on `party` association. - Ensured `weapon` association exists before accessing `ax`, `series`, or `awakening`. - Improved conditional checks for `weapon_keys` to prevent errors when `weapon` or `series` is nil. - Converted `awakening_level` field to integer for consistency. - **GridCharacterBlueprint:** - Removed `:minimal` view restriction on `party` association.
66 lines
2 KiB
Ruby
66 lines
2 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module Api
|
|
module V1
|
|
class GridCharacterBlueprint < ApiBlueprint
|
|
fields :position, :uncap_level, :perpetuity
|
|
|
|
field :transcendence_step, if: ->(_field, gc, _options) { gc.character&.ulb } do |gc|
|
|
gc.transcendence_step
|
|
end
|
|
|
|
view :preview do
|
|
association :character, name: :object, blueprint: CharacterBlueprint
|
|
end
|
|
|
|
view :nested do
|
|
include_view :mastery_bonuses
|
|
association :character, name: :object, blueprint: CharacterBlueprint, view: :full
|
|
end
|
|
|
|
view :uncap do
|
|
association :party, blueprint: PartyBlueprint
|
|
fields :position, :uncap_level
|
|
end
|
|
|
|
view :destroyed do
|
|
fields :position, :created_at, :updated_at
|
|
end
|
|
|
|
view :mastery_bonuses do
|
|
field :awakening, if: ->(_field_name, gc, _options) { gc.association(:awakening).loaded? } do |gc|
|
|
{
|
|
type: AwakeningBlueprint.render_as_hash(gc.awakening),
|
|
level: gc.awakening_level.to_i
|
|
}
|
|
end
|
|
|
|
field :over_mastery, if: lambda { |_fn, obj, _opt|
|
|
obj.ring1.present? && obj.ring2.present? && !obj.ring1['modifier'].nil? && !obj.ring2['modifier'].nil?
|
|
} do |c|
|
|
mapped_rings = [c.ring1, c.ring2, c.ring3, c.ring4].each_with_object([]) do |ring, arr|
|
|
# Skip if the ring is nil or its modifier is blank.
|
|
next if ring.blank? || ring['modifier'].blank?
|
|
|
|
# Convert the string values to numbers.
|
|
mod = ring['modifier'].to_i
|
|
|
|
# Only include if modifier is non-zero.
|
|
next if mod.zero?
|
|
|
|
arr << { modifier: mod, strength: ring['strength'].to_i }
|
|
end
|
|
|
|
mapped_rings
|
|
end
|
|
|
|
field :aetherial_mastery, if: ->(_fn, obj, _opt) { obj.earring.present? && !obj.earring['modifier'].nil? } do |gc, _options|
|
|
{
|
|
modifier: gc.earring['modifier'].to_i,
|
|
strength: gc.earring['strength'].to_i
|
|
}
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|