Add Styling Studio page to show the styles we already have modeled

This commit is contained in:
Emi Matchu 2024-01-24 06:53:37 -08:00
parent ba45de583f
commit 394cc212b3
10 changed files with 61 additions and 10 deletions

View file

@ -0,0 +1,10 @@
body.alt_styles-index
.alt-styles-list
list-style: none
display: flex
justify-content: center
gap: 1em
flex-wrap: wrap
.alt-style
text-align: center

View file

@ -7,6 +7,7 @@
@import partials/jquery.jgrowl
@import alt_styles/index
@import campaigns/show
@import closet_hangers/index
@import closet_hangers/petpage

View file

@ -0,0 +1,6 @@
class AltStylesController < ApplicationController
def index
@alt_styles = AltStyle.includes(:species, :color, :swf_assets).
order(:species_id, :color_id).all
end
end

View file

@ -0,0 +1,2 @@
module AltStylesHelper
end

View file

@ -43,13 +43,7 @@ module ContributionHelper
span = content_tag(:span, alt_style.name, class: 'contributed-name')
output = translate("contributions.contributed_description.main.alt_style_html",
alt_style_name: span)
# HACK: Just assume this is a Nostalgic Alt Style, and that the thumbnail
# is named reliably!
if show_image
thumbnail_url = "https://images.neopets.com/items/nostalgic_" +
"#{alt_style.color.name.downcase}_#{alt_style.species.name.downcase}.gif"
output << image_tag(thumbnail_url)
end
output << image_tag(alt_style.thumbnail_url) if show_image
output
end

View file

@ -11,6 +11,28 @@ class AltStyle < ApplicationRecord
species_human_name: species.human_name)
end
def thumbnail_url
# HACK: Just assume this is a Nostalgic Alt Style, and that the thumbnail
# is named reliably!
"https://images.neopets.com/items/nostalgic_" +
"#{color.name.downcase}_#{species.name.downcase}.gif"
end
MANIFEST_PATTERN = %r{^https://images.neopets.com/(?<prefix>.+)/(?<id>[0-9]+)(?<hash_part>_[^/]+)?/manifest\.json}
def preview_image_url
swf_asset = swf_assets.first
return nil if swf_asset.nil?
# HACK: Just assuming all of these were well-formed by the same process,
# and infer the image URL from the manifest URL! But strictly speaking we
# should be reading the manifest to check!
match = swf_asset.manifest_url.match(MANIFEST_PATTERN)
return nil if match.nil?
"https://images.neopets.com/#{match[:prefix]}/" +
"#{match[:id]}#{match[:hash_part]}/#{match[:id]}.png"
end
def biology=(biology)
# TODO: This is very similar to what `PetState` does, but like… much much
# more compact? Idk if I'm missing something, or if I was just that much

View file

@ -0,0 +1,4 @@
%li.alt-style
= link_to alt_style.preview_image_url do
= image_tag alt_style.thumbnail_url, class: 'alt-style-thumbnail'
.alt-style-name= alt_style.name

View file

@ -0,0 +1,11 @@
- title "Styling Studio"
%p
We're getting set up with the new NC Pet Styles! They're not ready in the app
yet, but here's what we have so far!
%p
If you have one we don't, please model it by entering your pet's name on the
homepage! Thank you! 💖
%ul.alt-styles-list= render partial: "alt_style", collection: @alt_styles

View file

@ -4,10 +4,10 @@
.notice
%strong Happy NC UC day!
We're still working on Alt Styles support, but other pets can be loaded as
usual!
We're working on Styling Studio support,
= link_to("here's what we have so far", alt_styles_path) + "!"
%br
Excited to have them for you soon!
Thank you for helping us model the new styles, we appreciate it lots!!! 💖
%p#pet-not-found.alert= t 'pets.load.not_found'

View file

@ -35,6 +35,7 @@ OpenneoImpressItems::Application.routes.draw do
resources :colors, only: [] do
resources :pet_types, only: [:index]
end
resources :alt_styles, path: 'alt-styles', only: [:index]
# Loading and modeling pets!
post '/pets/load' => 'pets#load', :as => :load_pet