Refactor grid object blueprints

This commit is contained in:
Justin Edmund 2025-02-07 01:51:34 -08:00
parent b71ca8e458
commit 4afccabaaf
3 changed files with 56 additions and 64 deletions

View file

@ -3,56 +3,47 @@
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, blueprint: CharacterBlueprint
end
view :nested do
include_view :mastery_bonuses
association :character, blueprint: CharacterBlueprint, view: :full
end
view :uncap do
association :party, blueprint: PartyBlueprint, view: :minimal
fields :position, :uncap_level
end
view :nested do
fields :position, :uncap_level, :perpetuity
view :destroyed do
fields :position, :created_at, :updated_at
end
field :transcendence_step, if: lambda { |_fn, obj, _opt|
obj.character.ulb
} do |c|
c.transcendence_step
end
field :awakening do |c|
view :mastery_bonuses do
field :awakening, if: ->(_field_name, gc, _options) { gc.association(:awakening).loaded? } do |gc|
{
type: AwakeningBlueprint.render_as_hash(c.awakening),
level: c.awakening_level
type: AwakeningBlueprint.render_as_hash(gc.awakening),
level: gc.awakening_level
}
end
field :over_mastery, if: lambda { |_fn, obj, _opt|
!obj.ring1['modifier'].nil? && !obj.ring2['modifier'].nil?
} do |c|
rings = []
rings.push(c.ring1) unless c.ring1['modifier'].nil?
rings.push(c.ring2) unless c.ring2['modifier'].nil?
rings.push(c.ring3) unless c.ring3['modifier'].nil?
rings.push(c.ring4) unless c.ring4['modifier'].nil?
rings
[c.ring1, c.ring2, c.ring3, c.ring4].reject { |ring| ring['modifier'].nil? }
end
field :aetherial_mastery, if: lambda { |_fn, obj, _opt|
!obj.earring['modifier'].nil?
} do |c|
c.earring
end
association :character, name: :object, blueprint: CharacterBlueprint
end
view :full do
include_view :nested
association :party, blueprint: PartyBlueprint, view: :minimal
end
view :destroyed do
fields :position, :created_at, :updated_at
}, &:earring
end
end
end

View file

@ -3,14 +3,14 @@
module Api
module V1
class GridSummonBlueprint < ApiBlueprint
view :uncap do
association :party, blueprint: PartyBlueprint, view: :minimal
fields :position, :uncap_level, :transcendence_step
fields :main, :friend, :position, :quick_summon, :uncap_level, :transcendence_step
view :preview do
association :summon, blueprint: SummonBlueprint
end
view :nested do
fields :main, :friend, :position, :quick_summon, :uncap_level, :transcendence_step
association :summon, name: :object, blueprint: SummonBlueprint
association :summon, blueprint: SummonBlueprint, view: :full
end
view :full do
@ -18,6 +18,11 @@ module Api
association :party, blueprint: PartyBlueprint, view: :minimal
end
view :uncap do
association :party, blueprint: PartyBlueprint, view: :minimal
fields :position, :uncap_level, :transcendence_step
end
view :destroyed do
fields :main, :friend, :position, :created_at, :updated_at
end

View file

@ -3,40 +3,31 @@
module Api
module V1
class GridWeaponBlueprint < ApiBlueprint
view :uncap do
association :party, blueprint: PartyBlueprint, view: :minimal
fields :position, :uncap_level
fields :mainhand, :position, :uncap_level, :transcendence_step, :element
view :preview do
association :weapon, blueprint: WeaponBlueprint
end
view :nested do
fields :mainhand, :position, :uncap_level, :transcendence_step, :element
association :weapon, name: :object, blueprint: WeaponBlueprint
association :weapon_keys,
blueprint: WeaponKeyBlueprint,
if: lambda { |_field_name, w, _options|
[2, 3, 17, 24, 34].include?(w.weapon.series)
}
field :ax, if: ->(_field_name, w, _options) { w.weapon.ax } do |w|
[
{
modifier: w.ax_modifier1,
strength: w.ax_strength1
},
{
modifier: w.ax_modifier2,
strength: w.ax_strength2
}
{ modifier: w.ax_modifier1, strength: w.ax_strength1 },
{ modifier: w.ax_modifier2, strength: w.ax_strength2 }
]
end
end
field :awakening, if: ->(_field_name, w, _options) { w.awakening_id } do |w|
{
type: AwakeningBlueprint.render_as_hash(w.awakening),
level: w.awakening_level
}
field :awakening, if: ->(_field_name, w, _options) { w.association(:awakening).loaded? } do |w|
{
type: AwakeningBlueprint.render_as_hash(w.awakening),
level: w.awakening_level
}
end
association :weapon, blueprint: WeaponBlueprint, view: :full
association :weapon_keys,
blueprint: WeaponKeyBlueprint,
if: ->(_field_name, w, _options) { [2, 3, 17, 24, 34].include?(w.weapon.series) }
end
view :full do
@ -44,6 +35,11 @@ module Api
association :party, blueprint: PartyBlueprint, view: :minimal
end
view :uncap do
association :party, blueprint: PartyBlueprint, view: :minimal
fields :position, :uncap_level
end
view :destroyed do
fields :mainhand, :position, :created_at, :updated_at
end