[WV2] Remove unnecessary worn/closeted state tracking from helper fn
This commit is contained in:
parent
d0acb1c7e5
commit
3582b3674b
2 changed files with 21 additions and 27 deletions
|
|
@ -52,33 +52,30 @@ module WardrobeHelper
|
||||||
end
|
end
|
||||||
|
|
||||||
# Group outfit items by zone, applying smart multi-zone simplification.
|
# Group outfit items by zone, applying smart multi-zone simplification.
|
||||||
# Returns an array of hashes: {zone_id:, zone_label:, items:}
|
# Returns an array of hashes: {zone_id:, zone_label:, items: [Item, ...]}
|
||||||
# Each item entry is {item:, state: :worn/:closeted}.
|
|
||||||
# This matches the logic from wardrobe-2020's getZonesAndItems function.
|
# This matches the logic from wardrobe-2020's getZonesAndItems function.
|
||||||
def outfit_items_by_zone(outfit)
|
def outfit_items_by_zone(outfit)
|
||||||
return [] if outfit.pet_type.nil?
|
return [] if outfit.pet_type.nil?
|
||||||
|
|
||||||
# Build a list of all items with their state (:worn or :closeted)
|
all_items = outfit.worn_items + outfit.closeted_items
|
||||||
all_items = outfit.worn_items.map { |i| {item: i, state: :worn} } +
|
|
||||||
outfit.closeted_items.map { |i| {item: i, state: :closeted} }
|
|
||||||
|
|
||||||
# Get item appearances for all items at once
|
# Get item appearances for all items at once
|
||||||
item_appearances = Item.appearances_for(
|
item_appearances = Item.appearances_for(
|
||||||
all_items.map { |e| e[:item] },
|
all_items,
|
||||||
outfit.pet_type,
|
outfit.pet_type,
|
||||||
swf_asset_includes: [:zone]
|
swf_asset_includes: [:zone]
|
||||||
)
|
)
|
||||||
|
|
||||||
# Separate compatible and incompatible items
|
# Separate compatible and incompatible items
|
||||||
compatible_entries = []
|
compatible = {}
|
||||||
incompatible_entries = []
|
incompatible_items = []
|
||||||
|
|
||||||
all_items.each do |entry|
|
all_items.each do |item|
|
||||||
appearance = item_appearances[entry[:item].id]
|
appearance = item_appearances[item.id]
|
||||||
if appearance&.present?
|
if appearance&.present?
|
||||||
compatible_entries << entry.merge(appearance: appearance)
|
compatible[item] = appearance
|
||||||
else
|
else
|
||||||
incompatible_entries << entry
|
incompatible_items << item
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -86,19 +83,19 @@ module WardrobeHelper
|
||||||
items_by_zone = Hash.new { |h, k| h[k] = [] }
|
items_by_zone = Hash.new { |h, k| h[k] = [] }
|
||||||
zones_by_id = {}
|
zones_by_id = {}
|
||||||
|
|
||||||
compatible_entries.each do |entry|
|
compatible.each do |item, appearance|
|
||||||
entry[:appearance].swf_assets.map(&:zone).uniq.each do |zone|
|
appearance.swf_assets.map(&:zone).uniq.each do |zone|
|
||||||
zones_by_id[zone.id] = zone
|
zones_by_id[zone.id] = zone
|
||||||
items_by_zone[zone.id] << {item: entry[:item], state: entry[:state]}
|
items_by_zone[zone.id] << item
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Create zone groups with sorted items
|
# Create zone groups with sorted items
|
||||||
zones_and_items = items_by_zone.map do |zone_id, entries|
|
zones_and_items = items_by_zone.map do |zone_id, items|
|
||||||
{
|
{
|
||||||
zone_id: zone_id,
|
zone_id: zone_id,
|
||||||
zone_label: zones_by_id[zone_id].label,
|
zone_label: zones_by_id[zone_id].label,
|
||||||
items: entries.sort_by { |e| e[:item].name.downcase }
|
items: items.sort_by { |item| item.name.downcase }
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -114,13 +111,11 @@ module WardrobeHelper
|
||||||
zones_and_items = disambiguate_zone_labels(zones_and_items)
|
zones_and_items = disambiguate_zone_labels(zones_and_items)
|
||||||
|
|
||||||
# Add incompatible items section if any
|
# Add incompatible items section if any
|
||||||
if incompatible_entries.any?
|
if incompatible_items.any?
|
||||||
zones_and_items << {
|
zones_and_items << {
|
||||||
zone_id: nil,
|
zone_id: nil,
|
||||||
zone_label: "Incompatible",
|
zone_label: "Incompatible",
|
||||||
items: incompatible_entries
|
items: incompatible_items.sort_by { |item| item.name.downcase }
|
||||||
.map { |e| {item: e[:item], state: e[:state]} }
|
|
||||||
.sort_by { |e| e[:item].name.downcase }
|
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -132,14 +127,13 @@ module WardrobeHelper
|
||||||
# Simplify zone groups by removing redundant single-item groups.
|
# Simplify zone groups by removing redundant single-item groups.
|
||||||
# Keep groups with multiple items (conflicts). For single-item groups,
|
# Keep groups with multiple items (conflicts). For single-item groups,
|
||||||
# only keep them if the item doesn't appear in a multi-item group.
|
# only keep them if the item doesn't appear in a multi-item group.
|
||||||
# Each item entry is {item:, state:}.
|
|
||||||
def simplify_multi_zone_groups(zones_and_items)
|
def simplify_multi_zone_groups(zones_and_items)
|
||||||
# Find groups with conflicts (multiple items)
|
# Find groups with conflicts (multiple items)
|
||||||
groups_with_conflicts = zones_and_items.select { |g| g[:items].length > 1 }
|
groups_with_conflicts = zones_and_items.select { |g| g[:items].length > 1 }
|
||||||
|
|
||||||
# Track which items appear in conflict groups
|
# Track which items appear in conflict groups
|
||||||
items_with_conflicts = Set.new(
|
items_with_conflicts = Set.new(
|
||||||
groups_with_conflicts.flat_map { |g| g[:items].map { |e| e[:item].id } }
|
groups_with_conflicts.flat_map { |g| g[:items].map(&:id) }
|
||||||
)
|
)
|
||||||
|
|
||||||
# Track which items we've already shown
|
# Track which items we've already shown
|
||||||
|
|
@ -149,13 +143,13 @@ module WardrobeHelper
|
||||||
zones_and_items.select do |group|
|
zones_and_items.select do |group|
|
||||||
# Always keep groups with multiple items
|
# Always keep groups with multiple items
|
||||||
if group[:items].length > 1
|
if group[:items].length > 1
|
||||||
group[:items].each { |e| items_we_have_seen.add(e[:item].id) }
|
group[:items].each { |item| items_we_have_seen.add(item.id) }
|
||||||
true
|
true
|
||||||
else
|
else
|
||||||
# For single-item groups, only keep if:
|
# For single-item groups, only keep if:
|
||||||
# - Item hasn't been seen yet AND
|
# - Item hasn't been seen yet AND
|
||||||
# - Item won't appear in a conflict group
|
# - Item won't appear in a conflict group
|
||||||
item_id = group[:items].first[:item].id
|
item_id = group[:items].first.id
|
||||||
|
|
||||||
if items_we_have_seen.include?(item_id) || items_with_conflicts.include?(item_id)
|
if items_we_have_seen.include?(item_id) || items_with_conflicts.include?(item_id)
|
||||||
false
|
false
|
||||||
|
|
|
||||||
|
|
@ -75,5 +75,5 @@
|
||||||
.zone-group
|
.zone-group
|
||||||
%h3.zone-label= zone_group[:zone_label]
|
%h3.zone-label= zone_group[:zone_label]
|
||||||
%ul.items-list
|
%ul.items-list
|
||||||
- zone_group[:items].each do |entry|
|
- zone_group[:items].each do |item|
|
||||||
= render "items/item_card", item: entry[:item]
|
= render "items/item_card", item: item
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue