Refactor grid blueprints
- **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.
This commit is contained in:
parent
be91c2c033
commit
8f77a1f613
3 changed files with 37 additions and 15 deletions
|
|
@ -19,7 +19,7 @@ module Api
|
||||||
end
|
end
|
||||||
|
|
||||||
view :uncap do
|
view :uncap do
|
||||||
association :party, blueprint: PartyBlueprint, view: :minimal
|
association :party, blueprint: PartyBlueprint
|
||||||
fields :position, :uncap_level
|
fields :position, :uncap_level
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -31,19 +31,35 @@ module Api
|
||||||
field :awakening, if: ->(_field_name, gc, _options) { gc.association(:awakening).loaded? } do |gc|
|
field :awakening, if: ->(_field_name, gc, _options) { gc.association(:awakening).loaded? } do |gc|
|
||||||
{
|
{
|
||||||
type: AwakeningBlueprint.render_as_hash(gc.awakening),
|
type: AwakeningBlueprint.render_as_hash(gc.awakening),
|
||||||
level: gc.awakening_level
|
level: gc.awakening_level.to_i
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
field :over_mastery, if: lambda { |_fn, obj, _opt|
|
field :over_mastery, if: lambda { |_fn, obj, _opt|
|
||||||
!obj.ring1['modifier'].nil? && !obj.ring2['modifier'].nil?
|
obj.ring1.present? && obj.ring2.present? && !obj.ring1['modifier'].nil? && !obj.ring2['modifier'].nil?
|
||||||
} do |c|
|
} do |c|
|
||||||
[c.ring1, c.ring2, c.ring3, c.ring4].reject { |ring| ring['modifier'].nil? }
|
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
|
end
|
||||||
|
|
||||||
field :aetherial_mastery, if: lambda { |_fn, obj, _opt|
|
field :aetherial_mastery, if: ->(_fn, obj, _opt) { obj.earring.present? && !obj.earring['modifier'].nil? } do |gc, _options|
|
||||||
!obj.earring['modifier'].nil?
|
{
|
||||||
}, &:earring
|
modifier: gc.earring['modifier'].to_i,
|
||||||
|
strength: gc.earring['strength'].to_i
|
||||||
|
}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -15,11 +15,11 @@ module Api
|
||||||
|
|
||||||
view :full do
|
view :full do
|
||||||
include_view :nested
|
include_view :nested
|
||||||
association :party, blueprint: PartyBlueprint, view: :minimal
|
association :party, blueprint: PartyBlueprint
|
||||||
end
|
end
|
||||||
|
|
||||||
view :uncap do
|
view :uncap do
|
||||||
association :party, blueprint: PartyBlueprint, view: :minimal
|
association :party, blueprint: PartyBlueprint
|
||||||
fields :position, :uncap_level, :transcendence_step
|
fields :position, :uncap_level, :transcendence_step
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,33 +10,39 @@ module Api
|
||||||
end
|
end
|
||||||
|
|
||||||
view :nested do
|
view :nested do
|
||||||
field :ax, if: ->(_field_name, w, _options) { w.weapon.ax } do |w|
|
field :ax, if: ->(_field_name, w, _options) { w.weapon.present? && w.weapon.ax } do |w|
|
||||||
[
|
[
|
||||||
{ modifier: w.ax_modifier1, strength: w.ax_strength1 },
|
{ modifier: w.ax_modifier1, strength: w.ax_strength1 },
|
||||||
{ modifier: w.ax_modifier2, strength: w.ax_strength2 }
|
{ modifier: w.ax_modifier2, strength: w.ax_strength2 }
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
field :awakening, if: ->(_field_name, w, _options) { w.association(:awakening).loaded? } do |w|
|
field :awakening, if: ->(_field_name, w, _options) { w.awakening.present? } do |w|
|
||||||
{
|
{
|
||||||
type: AwakeningBlueprint.render_as_hash(w.awakening),
|
type: AwakeningBlueprint.render_as_hash(w.awakening),
|
||||||
level: w.awakening_level
|
level: w.awakening_level
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
association :weapon, name: :object, blueprint: WeaponBlueprint, view: :full
|
association :weapon, name: :object, blueprint: WeaponBlueprint, view: :full,
|
||||||
|
if: ->(_field_name, w, _options) { w.weapon.present? }
|
||||||
|
|
||||||
association :weapon_keys,
|
association :weapon_keys,
|
||||||
blueprint: WeaponKeyBlueprint,
|
blueprint: WeaponKeyBlueprint,
|
||||||
if: ->(_field_name, w, _options) { [2, 3, 17, 24, 34].include?(w.weapon.series) }
|
if: ->(_field_name, w, _options) {
|
||||||
|
w.weapon.present? &&
|
||||||
|
w.weapon.series.present? &&
|
||||||
|
[2, 3, 17, 24, 34].include?(w.weapon.series)
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
view :full do
|
view :full do
|
||||||
include_view :nested
|
include_view :nested
|
||||||
association :party, blueprint: PartyBlueprint, view: :minimal
|
association :party, blueprint: PartyBlueprint
|
||||||
end
|
end
|
||||||
|
|
||||||
view :uncap do
|
view :uncap do
|
||||||
association :party, blueprint: PartyBlueprint, view: :minimal
|
association :party, blueprint: PartyBlueprint
|
||||||
fields :position, :uncap_level
|
fields :position, :uncap_level
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue