WIP: Placeholder page for Rainbow Pool pet type

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.
This commit is contained in:
Emi Matchu 2024-09-26 14:56:45 -07:00
parent e7148ffae3
commit a1d6961249
4 changed files with 57 additions and 14 deletions

View file

@ -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

View file

@ -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, # <varies>
}
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)

View file

@ -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

View file

@ -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