Disable pet faces that the item doesn't fit, in new item previews

This commit is contained in:
Emi Matchu 2024-09-03 16:42:04 -07:00
parent a184c75575
commit 2b2bffd9da
4 changed files with 24 additions and 3 deletions

View file

@ -175,6 +175,12 @@ body.items-show
&:not(:checked) + img
opacity: .5
&:disabled + img
filter: grayscale(1)
label:has(input[type=radio]:disabled)
cursor: not-allowed
noscript
position: absolute
inset: 0

View file

@ -222,6 +222,10 @@ module ItemsHelper
cookies["DTIOutfitViewerIsPlaying"] == "true"
end
def item_fits?(pet_type, all_appearances)
all_appearances.any? { |a| a.fits? pet_type }
end
def item_zone_partial_fit?(appearances_in_zone, all_appearances)
appearances_in_zone.size < all_appearances.size
end

View file

@ -502,7 +502,7 @@ class Item < ApplicationRecord
Appearance = Struct.new(:item, :body, :swf_assets) do
include ActiveModel::Serializers::JSON
delegate :present?, :empty?, to: :swf_assets
delegate :species, to: :body
delegate :species, :fits?, to: :body
def attributes
{item:, body:, swf_assets:}
@ -522,6 +522,14 @@ class Item < ApplicationRecord
def attributes
{id:, species:}
end
def fits_all?
id == 0
end
def fits?(target)
fits_all? || target.body_id == id
end
end
def appearances

View file

@ -44,8 +44,11 @@
- @preview_pet_type_options.each do |pet_type|
%label
= radio_button_tag "species_face_id", pet_type.species_id,
checked: pet_type == @preview_outfit.pet_type
= pet_type_image pet_type, :happy, :face
checked: pet_type == @preview_outfit.pet_type,
disabled: !item_fits?(pet_type, @all_appearances)
= pet_type_image pet_type,
item_fits?(pet_type, @all_appearances) ? :happy : :sad,
:face
.item-zones-info
%section