forked from OpenNeo/impress
Default to compatible pet types in new item page preview
Just adapted from Impress 2020 logic again, easy peasy!
This commit is contained in:
parent
21a8a49f50
commit
fe6035d438
2 changed files with 19 additions and 4 deletions
|
@ -214,10 +214,7 @@ class ItemsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def load_default_preview_pet_type
|
def load_default_preview_pet_type
|
||||||
PetType.find_by_color_id_and_species_id(
|
@item.compatible_pet_type
|
||||||
Color.find_by_name("Blue"),
|
|
||||||
Species.find_by_name("Acara"),
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def validate_preview
|
def validate_preview
|
||||||
|
|
|
@ -489,6 +489,24 @@ class Item < ApplicationRecord
|
||||||
}.merge(options))
|
}.merge(options))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def compatible_body_ids
|
||||||
|
swf_assets.map(&:body_id).uniq
|
||||||
|
end
|
||||||
|
|
||||||
|
def compatible_pet_types
|
||||||
|
return PetType.all if compatible_body_ids.include?(0)
|
||||||
|
PetType.where(body_id: compatible_body_ids)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Return a pet type that can wear this item, preferring simple colors and
|
||||||
|
# early-alphabetically species.
|
||||||
|
def compatible_pet_type
|
||||||
|
compatible_pet_types.joins(:color, :species).order(:species_id).
|
||||||
|
merge(Color.order(basic: :desc, standard: :desc, name: :asc)).
|
||||||
|
merge(Species.order(name: :asc)).
|
||||||
|
first
|
||||||
|
end
|
||||||
|
|
||||||
def handle_assets!
|
def handle_assets!
|
||||||
if @parent_swf_asset_relationships_to_update && @current_body_id
|
if @parent_swf_asset_relationships_to_update && @current_body_id
|
||||||
new_swf_asset_ids = @parent_swf_asset_relationships_to_update.map(&:swf_asset_id)
|
new_swf_asset_ids = @parent_swf_asset_relationships_to_update.map(&:swf_asset_id)
|
||||||
|
|
Loading…
Reference in a new issue