From 2b2bffd9daf5b6d0ae0af92bf6438426421ad5f1 Mon Sep 17 00:00:00 2001 From: Emi Matchu Date: Tue, 3 Sep 2024 16:42:04 -0700 Subject: [PATCH] Disable pet faces that the item doesn't fit, in new item previews --- app/assets/stylesheets/items/_show.sass | 6 ++++++ app/helpers/items_helper.rb | 4 ++++ app/models/item.rb | 10 +++++++++- app/views/items/show.html.haml | 7 +++++-- 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/app/assets/stylesheets/items/_show.sass b/app/assets/stylesheets/items/_show.sass index 81decc33..2899c2c6 100644 --- a/app/assets/stylesheets/items/_show.sass +++ b/app/assets/stylesheets/items/_show.sass @@ -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 diff --git a/app/helpers/items_helper.rb b/app/helpers/items_helper.rb index 02829402..186c6554 100644 --- a/app/helpers/items_helper.rb +++ b/app/helpers/items_helper.rb @@ -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 diff --git a/app/models/item.rb b/app/models/item.rb index 8f74aa10..21232069 100644 --- a/app/models/item.rb +++ b/app/models/item.rb @@ -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 diff --git a/app/views/items/show.html.haml b/app/views/items/show.html.haml index 436f9e88..07fe0caa 100644 --- a/app/views/items/show.html.haml +++ b/app/views/items/show.html.haml @@ -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