Compare commits

..

4 commits

Author SHA1 Message Date
43d650a5d4 Better alt styles page layout
I had tested this with less variety in the list of styles, now that I'm
seeing it live I realize we need more consistency and more space!
2024-01-24 07:03:28 -08:00
394cc212b3 Add Styling Studio page to show the styles we already have modeled 2024-01-24 06:53:37 -08:00
ba45de583f Oops, don't update body_id when there's an alt style! 2024-01-24 06:12:35 -08:00
40278afd0c Add find_by_name method to AltStyle 2024-01-24 06:12:03 -08:00
11 changed files with 88 additions and 14 deletions

View file

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

View file

@ -7,6 +7,7 @@
@import partials/jquery.jgrowl @import partials/jquery.jgrowl
@import alt_styles/index
@import campaigns/show @import campaigns/show
@import closet_hangers/index @import closet_hangers/index
@import closet_hangers/petpage @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') span = content_tag(:span, alt_style.name, class: 'contributed-name')
output = translate("contributions.contributed_description.main.alt_style_html", output = translate("contributions.contributed_description.main.alt_style_html",
alt_style_name: span) alt_style_name: span)
# HACK: Just assume this is a Nostalgic Alt Style, and that the thumbnail output << image_tag(alt_style.thumbnail_url) if show_image
# 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 output
end end

View file

@ -11,6 +11,28 @@ class AltStyle < ApplicationRecord
species_human_name: species.human_name) species_human_name: species.human_name)
end 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) def biology=(biology)
# TODO: This is very similar to what `PetState` does, but like… much much # 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 # more compact? Idk if I'm missing something, or if I was just that much
@ -19,4 +41,11 @@ class AltStyle < ApplicationRecord
SwfAsset.from_biology_data(self.body_id, asset_data) SwfAsset.from_biology_data(self.body_id, asset_data)
end end
end end
# For convenience in the console!
def self.find_by_name(color_name, species_name)
color = Color.find_by_name(color_name)
species = Species.find_by_name(species_name)
where(color_id: color, species_id: species).first
end
end end

View file

@ -37,20 +37,35 @@ class Pet < ApplicationRecord
raise UnexpectedDataFormat unless pet_data[:color_id] raise UnexpectedDataFormat unless pet_data[:color_id]
raise UnexpectedDataFormat unless pet_data[:body_id] raise UnexpectedDataFormat unless pet_data[:body_id]
has_alt_style = pet_data[:alt_style].present?
self.pet_type = PetType.find_or_initialize_by( self.pet_type = PetType.find_or_initialize_by(
species_id: pet_data[:species_id].to_i, species_id: pet_data[:species_id].to_i,
color_id: pet_data[:color_id].to_i color_id: pet_data[:color_id].to_i
) )
self.pet_type.body_id = pet_data[:body_id]
self.pet_type.origin_pet = self self.pet_type.origin_pet = self
pet_state_biology = pet_data[:alt_style] ? # With an alt style, `body_id` in the biology data refers to the body ID of
pet_data[:original_biology] : pet_data[:biology_by_zone] # the *alt* style, not the usual pet type. (We have `original_biology` for
# *some* of the pet type's situation, but not it's body ID!)
#
# So, in the alt style case, don't update `body_id` - but if this is our
# first time seeing this pet type and it doesn't *have* a `body_id` yet,
# let's not be creating it without one. We'll need to model it without the
# alt style first. (I don't bother with a clear error message though 😅)
self.pet_type.body_id = pet_data[:body_id] unless has_alt_style
if self.pet_type.body_id.nil?
raise UnexpectedDataFormat,
"can't process alt style on first occurrence of pet type"
end
pet_state_biology = has_alt_style ? pet_data[:original_biology] :
pet_data[:biology_by_zone]
raise UnexpectedDataFormat if pet_state_biology.empty? raise UnexpectedDataFormat if pet_state_biology.empty?
pet_state_biology[0] = nil # remove effects if present pet_state_biology[0] = nil # remove effects if present
@pet_state = self.pet_type.add_pet_state_from_biology! pet_state_biology @pet_state = self.pet_type.add_pet_state_from_biology! pet_state_biology
if pet_data[:alt_style] if has_alt_style
raise UnexpectedDataFormat unless pet_data[:alt_color] raise UnexpectedDataFormat unless pet_data[:alt_color]
raise UnexpectedDataFormat if pet_data[:biology_by_zone].empty? raise UnexpectedDataFormat if pet_data[:biology_by_zone].empty?

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 .notice
%strong Happy NC UC day! %strong Happy NC UC day!
We're still working on Alt Styles support, but other pets can be loaded as We're working on Styling Studio support,
usual! = link_to("here's what we have so far", alt_styles_path) + "!"
%br %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' %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 :colors, only: [] do
resources :pet_types, only: [:index] resources :pet_types, only: [:index]
end end
resources :alt_styles, path: 'alt-styles', only: [:index]
# Loading and modeling pets! # Loading and modeling pets!
post '/pets/load' => 'pets#load', :as => :load_pet post '/pets/load' => 'pets#load', :as => :load_pet