From 1b03c2caed6c1e9f27ad9f5e27c29cf52e4d1f11 Mon Sep 17 00:00:00 2001 From: Matchu Date: Wed, 22 May 2024 15:41:46 -0700 Subject: [PATCH] Add more PB item info and links to Item Getting Guide I add some infrastructural support for inferring an item's paintbrush color (if any), and a field to the database to manually track an item's paint brush item name! This is both useful for tracking which colors are even *available* via paint brush, and also for working with colors with unusual paint brush names, like the "Get Off My Lawn Paint Brush" (for Elderly pets). Here's the script I ran to backfill this for current colors and their paint brushes! ```rb Color.find_by_name("Baby").update!(pb_item_name: "Baby Paint Brush") Color.find_by_name("Biscuit").update!(pb_item_name: "Biscuit Paint Brush") Color.find_by_name("Blue").update!(pb_item_name: "Blue Paint Brush") Color.find_by_name("Brown").update!(pb_item_name: "Brown Paint Brush") Color.find_by_name("Camouflage").update!(pb_item_name: "Camouflage Paint Brush") Color.find_by_name("Candy").update!(pb_item_name: "Candy Paint Brush") Color.find_by_name("Checkered").update!(pb_item_name: "Checkered Paint Brush") Color.find_by_name("Christmas").update!(pb_item_name: "Christmas Paint Brush") Color.find_by_name("Cloud").update!(pb_item_name: "Cloud Paint Brush") Color.find_by_name("Darigan").update!(pb_item_name: "Darigan Paint Brush") Color.find_by_name("Dimensional").update!(pb_item_name: "Dimensional Paint Brush") Color.find_by_name("Disco").update!(pb_item_name: "Disco Fever Paint Brush") Color.find_by_name("Electric").update!(pb_item_name: "Electric Blue Paint Brush") Color.find_by_name("Eventide").update!(pb_item_name: "Eventide Paint Brush") Color.find_by_name("Faerie").update!(pb_item_name: "Faerie Paint Brush") Color.find_by_name("Fire").update!(pb_item_name: "Fire, Fire, Your Pants On Fire Paint Brush") Color.find_by_name("Elderlyboy").update!(pb_item_name: "Get Off My Lawn Paint Brush") Color.find_by_name("Elderlygirl").update!(pb_item_name: "Get Off My Lawn Paint Brush") Color.find_by_name("Ghost").update!(pb_item_name: "Ghost Paint Brush") Color.find_by_name("Glowing").update!(pb_item_name: "Glowing Paint Brush") Color.find_by_name("Gold").update!(pb_item_name: "Golden Paint Brush") Color.find_by_name("Green").update!(pb_item_name: "Green Paint Brush") Color.find_by_name("Grey").update!(pb_item_name: "Grey Paint Brush") Color.find_by_name("Halloween").update!(pb_item_name: "Halloween Paint Brush") Color.find_by_name("Invisible").update!(pb_item_name: "Invisible Paint Brush") Color.find_by_name("Desert").update!(pb_item_name: "Lost Desert Paint Brush") Color.find_by_name("Maractite").update!(pb_item_name: "Maractite Paint Brush") Color.find_by_name("Maraquan").update!(pb_item_name: "Maraquan Paint Brush") Color.find_by_name("Marble").update!(pb_item_name: "Marble Paint Brush") Color.find_by_name("Island").update!(pb_item_name: "Mystery Island Paint Brush") Color.find_by_name("Oil Paint").update!(pb_item_name: "Oil Paint Brush") Color.find_by_name("Orange").update!(pb_item_name: "Orange Paint Brush") Color.find_by_name("Origami").update!(pb_item_name: "Origami Paint Brush") Color.find_by_name("Pastel").update!(pb_item_name: "Pastel Paint Brush") Color.find_by_name("Pink").update!(pb_item_name: "Pink Paint Brush") Color.find_by_name("Pirate").update!(pb_item_name: "Pirate Paint Brush") Color.find_by_name("Plushie").update!(pb_item_name: "Plushie Paint Brush") Color.find_by_name("Polka Dot").update!(pb_item_name: "Polka Dot Paint Brush") Color.find_by_name("Purple").update!(pb_item_name: "Purple Paint Brush") Color.find_by_name("Rainbow").update!(pb_item_name: "Rainbow Paint Brush") Color.find_by_name("Red").update!(pb_item_name: "Red Paint Brush") Color.find_by_name("Relic").update!(pb_item_name: "Relic Paint Brush") Color.find_by_name("Royalboy").update!(pb_item_name: "Royal Paint Brush") Color.find_by_name("Royalgirl").update!(pb_item_name: "Royal Paint Brush") Color.find_by_name("Sketch").update!(pb_item_name: "Scritchy Sketchy Paint Brush") Color.find_by_name("Shadow").update!(pb_item_name: "Shadow Paint Brush") Color.find_by_name("Silver").update!(pb_item_name: "Silver Paint Brush") Color.find_by_name("Skunk").update!(pb_item_name: "Skunk Paint Brush") Color.find_by_name("Snow").update!(pb_item_name: "Snow Paint Brush") Color.find_by_name("Speckled").update!(pb_item_name: "Speckled Paint Brush") Color.find_by_name("Split").update!(pb_item_name: "Split Paint Brush") Color.find_by_name("Spotted").update!(pb_item_name: "Spotted Paint Brush") Color.find_by_name("Starry").update!(pb_item_name: "Starry Paint Brush") Color.find_by_name("Stealthy").update!(pb_item_name: "Stealth Paint Brush") Color.find_by_name("Steampunk").update!(pb_item_name: "Steampunk Paint Brush") Color.find_by_name("Strawberry").update!(pb_item_name: "Strawberry Fields Forever Paint Brush") Color.find_by_name("Striped").update!(pb_item_name: "Striped Paint Brush") Color.find_by_name("Swamp Gas").update!(pb_item_name: "Swamp Gas Paint Brush") Color.find_by_name("Toy").update!(pb_item_name: "Toy Paint Brush") Color.find_by_name("Transparent").update!(pb_item_name: "Transparent Paint Brush") Color.find_by_name("Tyrannian").update!(pb_item_name: "Tyrannian Paint Brush") Color.find_by_name("Usuki Boy").update!(pb_item_name: "Usuki Paint Brush") Color.find_by_name("Usuki Girl").update!(pb_item_name: "Usuki Paint Brush") Color.find_by_name("Valentine").update!(pb_item_name: "Valentine Paint Brush") Color.find_by_name("Water").update!(pb_item_name: "Water Paint Brush") Color.find_by_name("White").update!(pb_item_name: "White Paint Brush") Color.find_by_name("Woodland").update!(pb_item_name: "Woodland Paint Brush") Color.find_by_name("Wraith").update!(pb_item_name: "Wraith Paint Brush") Color.find_by_name("Yellow").update!(pb_item_name: "Yellow Paint Brush") Color.find_by_name("Zombie").update!(pb_item_name: "Zombie Paint Brush") ``` --- app/assets/stylesheets/items/sources.sass | 4 ++++ app/helpers/items_helper.rb | 10 ++++---- app/models/item.rb | 22 +++++++++++++++++ app/views/items/sources.html.haml | 24 ++++++++++++++++--- ...240522222040_add_pb_item_name_to_colors.rb | 5 ++++ db/schema.rb | 3 ++- 6 files changed, 60 insertions(+), 8 deletions(-) create mode 100644 db/migrate/20240522222040_add_pb_item_name_to_colors.rb diff --git a/app/assets/stylesheets/items/sources.sass b/app/assets/stylesheets/items/sources.sass index 9ace7135..6c536c14 100644 --- a/app/assets/stylesheets/items/sources.sass +++ b/app/assets/stylesheets/items/sources.sass @@ -52,3 +52,7 @@ .actions-cell button /* Bootstrap's Purple 600 */ +awesome-button-color(#59359a) + + .special-color-explanation + text-wrap: balance + font-style: italic diff --git a/app/helpers/items_helper.rb b/app/helpers/items_helper.rb index d86ad3c2..ad0d42b2 100644 --- a/app/helpers/items_helper.rb +++ b/app/helpers/items_helper.rb @@ -97,8 +97,9 @@ module ItemsHelper SHOP_WIZARD_URL_TEMPLATE = Addressable::Template.new( "https://www.neopets.com/shops/wizard.phtml{?string}" ) - def shop_wizard_url_for(item) - SHOP_WIZARD_URL_TEMPLATE.expand(string: item.name).to_s + def shop_wizard_url_for(item_or_name) + item_or_name = item_or_name.name if item_or_name.is_a? Item + SHOP_WIZARD_URL_TEMPLATE.expand(string: item_or_name).to_s end SUPER_SHOP_WIZARD_URL_TEMPLATE = Addressable::Template.new( @@ -111,8 +112,9 @@ module ItemsHelper TRADING_POST_URL_TEMPLATE = Addressable::Template.new( "https://www.neopets.com/island/tradingpost.phtml?type=browse&criteria=item_exact{&search_string}" ) - def trading_post_url_for(item) - TRADING_POST_URL_TEMPLATE.expand(search_string: item.name).to_s + def trading_post_url_for(item_or_name) + item_or_name = item_or_name.name if item_or_name.is_a? Item + TRADING_POST_URL_TEMPLATE.expand(search_string: item_or_name).to_s end AUCTION_GENIE_URL_TEMPLATE = Addressable::Template.new( diff --git a/app/models/item.rb b/app/models/item.rb index 15f7dc18..1c70ae5d 100644 --- a/app/models/item.rb +++ b/app/models/item.rb @@ -179,6 +179,28 @@ class Item < ApplicationRecord nc_mall_record&.current_price end + # If this is a PB item, return the corresponding Color, inferred from the + # item name. If it's not a PB item, or we fail to infer, return nil. + def pb_color + return nil unless pb? + + # NOTE: To handle colors like "Royalboy", where the items aren't consistent + # with the color name regarding whether or not there's spaces, we remove + # all spaces from the item name and color name when matching. We also + # hackily handle the fact that "Elderlyboy" color has items named "Elderly + # Male" (and same for Girl/Female) by replacing those words, too. These + # hacks could cause false matches in theory, but I'm not aware of any rn! + normalized_name = name.downcase.gsub("female", "girl").gsub("male", "boy"). + gsub(/\s/, "") + + Color.order(:name). + find { |c| normalized_name.include?(c.name.downcase.gsub(/\s/, "")) } + end + + def pb_item_name + pb_color&.pb_item_name + end + def restricted_zones(options={}) options[:scope] ||= Zone.all options[:scope].find(restricted_zone_ids) diff --git a/app/views/items/sources.html.haml b/app/views/items/sources.html.haml index 4e523423..23e45426 100644 --- a/app/views/items/sources.html.haml +++ b/app/views/items/sources.html.haml @@ -54,13 +54,31 @@ target: "_blank", icon: search_icon - if @pb_items.present? - %h2 Paintbrush items + %h2 Paint Brush items :markdown - These items are part of a paintbrush set. Once you paint your pet, + These items are part of a paint brush set. Once you paint your pet, these items will be semi-permanently added to your Closet, even if your pet changes color again! You can use this to mix-and-match styles for "cross-paint" outfits. - = render @pb_items + %table.item-list + %thead + %td + %th{colspan: 2} + Total: #{pluralize @pb_items.size, "item"} + %tbody + - @pb_items.each do |item| + = render "item_list_row", item: do + - if item.pb_item_name.present? + = button_link_to "Shops", + shop_wizard_url_for(item.pb_item_name), + target: "_blank", icon: search_icon + = button_link_to "Trades", + trading_post_url_for(item.pb_item_name), + target: "_blank", icon: search_icon + - else + .special-color-explanation + No Paint Brush for this color. Get via Lab + Ray, morphing potions, etc. - if @other_nc_items.present? %h2 Neocash items (Capsules, Dyeworks, events, retired, etc.) diff --git a/db/migrate/20240522222040_add_pb_item_name_to_colors.rb b/db/migrate/20240522222040_add_pb_item_name_to_colors.rb new file mode 100644 index 00000000..961713e0 --- /dev/null +++ b/db/migrate/20240522222040_add_pb_item_name_to_colors.rb @@ -0,0 +1,5 @@ +class AddPbItemNameToColors < ActiveRecord::Migration[7.1] + def change + add_column :colors, :pb_item_name, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 3afd9d56..ac34a581 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2024_05_11_003019) do +ActiveRecord::Schema[7.1].define(version: 2024_05_22_222040) do create_table "alt_styles", charset: "utf8mb4", collation: "utf8mb4_unicode_520_ci", force: :cascade do |t| t.integer "species_id", null: false t.integer "color_id", null: false @@ -76,6 +76,7 @@ ActiveRecord::Schema[7.1].define(version: 2024_05_11_003019) do t.boolean "standard" t.boolean "prank", default: false, null: false t.string "name", null: false + t.string "pb_item_name" end create_table "contributions", id: :integer, charset: "utf8mb4", collation: "utf8mb4_unicode_520_ci", force: :cascade do |t|