From a1d69612491993dd99dbff156a2bfeea21dae252 Mon Sep 17 00:00:00 2001 From: Emi Matchu Date: Thu, 26 Sep 2024 14:56:45 -0700 Subject: [PATCH] WIP: Placeholder page for Rainbow Pool pet type MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I'm experimenting with a Rainbow Pool ish UI, mainly as a support tool for exploring and labeling poses—but one we can probably just show to real users too! Right now, I just use pet type images as a placeholder, and I polished up some of the `pet_type_image` API. But we're probably gonna drop these for a full outfit viewer, now that I think of it. --- app/controllers/pet_types_controller.rb | 28 ++++++++++++++++++---- app/helpers/items_helper.rb | 31 ++++++++++++++++++------- app/views/pet_types/show.html.haml | 11 +++++++++ config/routes.rb | 1 + 4 files changed, 57 insertions(+), 14 deletions(-) create mode 100644 app/views/pet_types/show.html.haml diff --git a/app/controllers/pet_types_controller.rb b/app/controllers/pet_types_controller.rb index ed30e051..5a468c2a 100644 --- a/app/controllers/pet_types_controller.rb +++ b/app/controllers/pet_types_controller.rb @@ -1,10 +1,28 @@ class PetTypesController < ApplicationController def show - @pet_type = PetType. - where(species_id: params[:species_id]). - where(color_id: params[:color_id]). - first + @pet_type = find_pet_type - render json: @pet_type + respond_to do |format| + format.html { render } + format.json { render json: @pet_type } + end + end + + protected + + # The API-ish route uses IDs, but the human-facing route uses names. + def find_pet_type + if params[:species_id] && params[:color_id] + PetType.find_by!( + species_id: params[:species_id], + color_id: params[:color_id], + ) + elsif params[:name] + color_name, species_name = params[:name].split("-", 2) + raise ActiveRecord::RecordNotFound if species_name.blank? + PetType.matching_name(color_name, species_name).first! + else + raise "expected params: species_id and color_id, or name" + end end end diff --git a/app/helpers/items_helper.rb b/app/helpers/items_helper.rb index 9f0636bb..329ad4bf 100644 --- a/app/helpers/items_helper.rb +++ b/app/helpers/items_helper.rb @@ -14,19 +14,30 @@ module ItemsHelper } Sizes = { - face: 1, - thumb: 2, - zoom: 3, - full: 4, - face_2x: 6, + face: 1, # 50x50 + face_3x: 6, # 150x150 + + thumb: 2, # 150x150 + full: 4, # 300x300 + large: 5, # 500x500 + xlarge: 7, # 640x640 + + zoom: 3, # 80x80 + autocrop: 9, # + } + + SizeUpgrades = { + face: :face_3x, + thumb: :full, + full: :xlarge, } end def pet_type_image_url(pet_type, emotion: :happy, size: :face) PetTypeImage::Template.expand( hash: pet_type.basic_image_hash || pet_type.image_hash, - emotion: PetTypeImage::Emotions[emotion], - size: PetTypeImage::Sizes[size], + emotion: PetTypeImage::Emotions.fetch(emotion), + size: PetTypeImage::Sizes.fetch(size), ).to_s end @@ -246,8 +257,10 @@ module ItemsHelper def pet_type_image(pet_type, emotion, size, **options) src = pet_type_image_url(pet_type, emotion:, size:) - srcset = if size == :face - [[pet_type_image_url(pet_type, emotion:, size: :face_2x), "2x"]] + + size_2x = PetTypeImage::SizeUpgrades[size] + srcset = if size_2x + [[pet_type_image_url(pet_type, emotion:, size: size_2x), "2x"]] end image_tag(src, srcset:, **options) diff --git a/app/views/pet_types/show.html.haml b/app/views/pet_types/show.html.haml new file mode 100644 index 00000000..66bebc38 --- /dev/null +++ b/app/views/pet_types/show.html.haml @@ -0,0 +1,11 @@ +- title "#{@pet_type.human_name}" + +%dl + %dt Happy + %dd= pet_type_image @pet_type, :happy, :full + %dt Sad + %dd= pet_type_image @pet_type, :sad, :full + %dt Angry + %dd= pet_type_image @pet_type, :angry, :full + %dt Ill + %dd= pet_type_image @pet_type, :ill, :full diff --git a/config/routes.rb b/config/routes.rb index 01d0cf20..72e7d006 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -37,6 +37,7 @@ OpenneoImpressItems::Application.routes.draw do end resources :alt_styles, path: 'alt-styles', only: [:index] resources :swf_assets, path: 'swf-assets', only: [:show] + resources :pet_types, path: 'rainbow-pool', only: [:show], param: "name" # Loading and modeling pets! post '/pets/load' => 'pets#load', :as => :load_pet