From 4e33477c650b668e27f18bbb9f6840a586d7f1ea Mon Sep 17 00:00:00 2001 From: Emi Matchu Date: Thu, 26 Sep 2024 19:33:16 -0700 Subject: [PATCH] Hide unconverted below the "Other" list for Rainbow Pool poses --- app/controllers/pet_types_controller.rb | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/app/controllers/pet_types_controller.rb b/app/controllers/pet_types_controller.rb index bee670dd..cb2cb498 100644 --- a/app/controllers/pet_types_controller.rb +++ b/app/controllers/pet_types_controller.rb @@ -31,19 +31,21 @@ class PetTypesController < ApplicationController # The `canonical` pet states are the main ones we want to show: the most # canonical state for each pose. The `other` pet states are, the others! # - # We put *all* the UNKNOWN pet states into `other`, unless it is the only - # pose available, in which case one will be in `canonical`. + # If no main poses are available, then we just make all the poses + # "canonical", and show the whole mish-mash! + MAIN_POSES = %w(HAPPY_FEM HAPPY_MASC SAD_FEM SAD_MASC SICK_FEM SICK_MASC) def group_pet_states(pet_states) pose_groups = pet_states.emotion_order.group_by(&:pose) - unknowns = if pose_groups.keys != ["UNKNOWN"] - pose_groups.delete("UNKNOWN") { [] } - else - [] + main_groups = pose_groups.select { |k| MAIN_POSES.include?(k) }.values + other_groups = pose_groups.reject { |k| MAIN_POSES.include?(k) }.values + + if main_groups.empty? + return {canonical: other_groups.flatten(1).sort_by(&:pose), other: []} end - canonical = pose_groups.values.map(&:first).sort_by(&:pose) - posed_others = pose_groups.values.map { |l| l.drop(1) }.flatten(1) - other = (posed_others + unknowns).sort_by(&:pose) + canonical = main_groups.map(&:first).sort_by(&:pose) + main_others = main_groups.map { |l| l.drop(1) }.flatten(1) + other = (main_others + other_groups.flatten(1)).sort_by(&:pose) {canonical:, other:} end