From 407c4b38a5b6052c444e5f6a114146b1491d1b23 Mon Sep 17 00:00:00 2001 From: Emi Matchu Date: Sun, 1 Dec 2024 10:28:58 -0800 Subject: [PATCH] Add link to reference pet type when labeling pet appearances Sometimes I forget like, what the masc/fem variants of a given pet actually look like? Some are super obvious about things like eyelashes, and others use more subtle eye differences. This is a cheap lil hack to make it easier to open a reference! Ideally I think it would be neat to like, when you hover over an option, have it show you the reference variant of that pose? But this is good enough I think! --- app/assets/stylesheets/pet_states/edit.sass | 10 ++++++++++ app/controllers/pet_states_controller.rb | 1 + app/models/pet_type.rb | 4 ++++ app/views/pet_states/edit.html.haml | 5 +++++ 4 files changed, 20 insertions(+) diff --git a/app/assets/stylesheets/pet_states/edit.sass b/app/assets/stylesheets/pet_states/edit.sass index 727d4ed56..616176379 100644 --- a/app/assets/stylesheets/pet_states/edit.sass +++ b/app/assets/stylesheets/pet_states/edit.sass @@ -3,3 +3,13 @@ outfit-viewer .fields li[data-type=radio-grid] --num-columns: 3 + +.reference-link + display: flex + align-items: center + gap: .5em + padding-inline: .5em + + img + height: 2em + width: auto diff --git a/app/controllers/pet_states_controller.rb b/app/controllers/pet_states_controller.rb index bc9aed56d..cd988d9c9 100644 --- a/app/controllers/pet_states_controller.rb +++ b/app/controllers/pet_states_controller.rb @@ -19,6 +19,7 @@ class PetStatesController < ApplicationController def find_pet_state @pet_type = PetType.find_by_param!(params[:pet_type_name]) @pet_state = @pet_type.pet_states.find(params[:id]) + @reference_pet_type = @pet_type.reference end def pet_state_params diff --git a/app/models/pet_type.rb b/app/models/pet_type.rb index 3c6dda412..08606c4a3 100644 --- a/app/models/pet_type.rb +++ b/app/models/pet_type.rb @@ -137,6 +137,10 @@ class PetType < ApplicationRecord pet_states.count { |ps| ps.pose == "UNKNOWN" } end + def reference + PetType.where(species_id: species).basic.merge(Color.alphabetical).first + end + def self.find_by_param!(param) raise ActiveRecord::RecordNotFound unless param.include?("-") color_param, _, species_param = param.rpartition("-") diff --git a/app/views/pet_states/edit.html.haml b/app/views/pet_states/edit.html.haml index 9a407baed..79d302c0d 100644 --- a/app/views/pet_states/edit.html.haml +++ b/app/views/pet_states/edit.html.haml @@ -26,6 +26,11 @@ = f.radio_field do = f.radio_button :pose, pose = pose_name(pose) + - if @reference_pet_type + = link_to @reference_pet_type, target: "_blank", class: "reference-link" do + = pet_type_image @reference_pet_type, :happy, :face + %span Reference: #{@reference_pet_type.human_name} + = external_link_icon = f.field do = f.label :glitched, "Gliched?"