From 39405132442d2d903e6d273b7ebcae1e8272ad3b Mon Sep 17 00:00:00 2001 From: Emi Matchu Date: Thu, 2 Jan 2025 19:39:53 -0800 Subject: [PATCH] Oops, fix silly mistake when combining zones by label on the item page Oh, right, silly: my previous version of this change still grouped by zone, then mapped the zones to their labels. This didn't *merge* the lists of appearances for zones that share the same label; just one of the zones would win, and the others would disappear. In this change, I just go upstream and actually group them by label in the first place, instead of grouping by zone then trying to merge and transform them. --- app/controllers/items_controller.rb | 3 +-- app/models/item.rb | 13 +++++-------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/app/controllers/items_controller.rb b/app/controllers/items_controller.rb index 179343e1..582ce5e9 100644 --- a/app/controllers/items_controller.rb +++ b/app/controllers/items_controller.rb @@ -99,8 +99,7 @@ class ItemsController < ApplicationController @all_appearances = @item.appearances @appearances_by_occupied_zone_label = - @item.appearances_by_occupied_zone. - transform_keys(&:label).sort_by { |l, a| l } + @item.appearances_by_occupied_zone_label.sort_by { |l, a| l } @selected_item_appearance = @preview_outfit.item_appearances.first @preview_pet_type_options = PetType.where(color: @preview_outfit.color). diff --git a/app/models/item.rb b/app/models/item.rb index 7fcce27a..f6d55344 100644 --- a/app/models/item.rb +++ b/app/models/item.rb @@ -592,22 +592,19 @@ class Item < ApplicationRecord Item.appearances_for([self], target, ...)[id] end - def appearances_by_occupied_zone_id + def appearances_by_occupied_zone_label + zones_by_id = occupied_zones.to_h { |z| [z.id, z] } {}.tap do |h| appearances.each do |appearance| appearance.occupied_zone_ids.each do |zone_id| - h[zone_id] ||= [] - h[zone_id] << appearance + zone_label = zones_by_id[zone_id].label + h[zone_label] ||= [] + h[zone_label] << appearance end end end end - def appearances_by_occupied_zone - zones_by_id = occupied_zones.to_h { |z| [z.id, z] } - appearances_by_occupied_zone_id.transform_keys { |zid| zones_by_id[zid] } - end - # Given a list of items, return how they look on the given target (either a # pet type or an alt style). def self.appearances_for(items, target, swf_asset_includes: [])