From 394cc212b305113f489025aead618ad9951fead1 Mon Sep 17 00:00:00 2001 From: Emi Matchu Date: Wed, 24 Jan 2024 06:53:37 -0800 Subject: [PATCH] Add Styling Studio page to show the styles we already have modeled --- app/assets/stylesheets/alt_styles/_index.sass | 10 +++++++++ app/assets/stylesheets/application.css.sass | 1 + app/controllers/alt_styles_controller.rb | 6 +++++ app/helpers/alt_styles_helper.rb | 2 ++ app/helpers/contribution_helper.rb | 8 +------ app/models/alt_style.rb | 22 +++++++++++++++++++ app/views/alt_styles/_alt_style.html.haml | 4 ++++ app/views/alt_styles/index.html.haml | 11 ++++++++++ app/views/outfits/new.html.haml | 6 ++--- config/routes.rb | 1 + 10 files changed, 61 insertions(+), 10 deletions(-) create mode 100644 app/assets/stylesheets/alt_styles/_index.sass create mode 100644 app/controllers/alt_styles_controller.rb create mode 100644 app/helpers/alt_styles_helper.rb create mode 100644 app/views/alt_styles/_alt_style.html.haml create mode 100644 app/views/alt_styles/index.html.haml diff --git a/app/assets/stylesheets/alt_styles/_index.sass b/app/assets/stylesheets/alt_styles/_index.sass new file mode 100644 index 00000000..ad81bfa4 --- /dev/null +++ b/app/assets/stylesheets/alt_styles/_index.sass @@ -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 diff --git a/app/assets/stylesheets/application.css.sass b/app/assets/stylesheets/application.css.sass index 695e469b..73c0a1f2 100644 --- a/app/assets/stylesheets/application.css.sass +++ b/app/assets/stylesheets/application.css.sass @@ -7,6 +7,7 @@ @import partials/jquery.jgrowl +@import alt_styles/index @import campaigns/show @import closet_hangers/index @import closet_hangers/petpage diff --git a/app/controllers/alt_styles_controller.rb b/app/controllers/alt_styles_controller.rb new file mode 100644 index 00000000..2f4a6b57 --- /dev/null +++ b/app/controllers/alt_styles_controller.rb @@ -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 diff --git a/app/helpers/alt_styles_helper.rb b/app/helpers/alt_styles_helper.rb new file mode 100644 index 00000000..88c60fa9 --- /dev/null +++ b/app/helpers/alt_styles_helper.rb @@ -0,0 +1,2 @@ +module AltStylesHelper +end diff --git a/app/helpers/contribution_helper.rb b/app/helpers/contribution_helper.rb index 300ce6c7..b574e639 100644 --- a/app/helpers/contribution_helper.rb +++ b/app/helpers/contribution_helper.rb @@ -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 diff --git a/app/models/alt_style.rb b/app/models/alt_style.rb index 23386ddc..9ff615e3 100644 --- a/app/models/alt_style.rb +++ b/app/models/alt_style.rb @@ -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/(?.+)/(?[0-9]+)(?_[^/]+)?/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 diff --git a/app/views/alt_styles/_alt_style.html.haml b/app/views/alt_styles/_alt_style.html.haml new file mode 100644 index 00000000..af12ea5d --- /dev/null +++ b/app/views/alt_styles/_alt_style.html.haml @@ -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 \ No newline at end of file diff --git a/app/views/alt_styles/index.html.haml b/app/views/alt_styles/index.html.haml new file mode 100644 index 00000000..cd25be0c --- /dev/null +++ b/app/views/alt_styles/index.html.haml @@ -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 diff --git a/app/views/outfits/new.html.haml b/app/views/outfits/new.html.haml index 1337512b..f006ae3a 100644 --- a/app/views/outfits/new.html.haml +++ b/app/views/outfits/new.html.haml @@ -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' diff --git a/config/routes.rb b/config/routes.rb index a4ddd281..e9c264cc 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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