Compare commits

...

5 commits

Author SHA1 Message Date
341869fb17 Oops, say "these items" plural for basic colors in Item Getting Guide
We could do a whole thing about like, checking singular vs plural, but
I'd rather just keep it simpler; I think it's clear from context that
we're talking about a category, so plural is fine even if it's not
actually more than one.
2024-06-05 19:51:11 -07:00
31c281390d Add explanations for why Item#pb_{species,color} would return nil 2024-06-05 19:46:12 -07:00
a3bd841bb8 Fix handling of basic PB items in Item Getting Guide
Okay so, like 30 minutes ago I added fallback behavior for cases where
we can't correctly infer the color from a PB item's name… and then I
pulled it up in the color and found that, oh, right, there are already
3 PB items that *correctly* return `nil` for `Item#pb_color`: Aisha
Collar, Elephante Hat, and Ixi Collar.

This is because they're common items that apply to many colors, like
the basics, but also many other less-special or older color variants.
They are the most likely case where we'll return `nil`.

So, I've updated our fallback UI to, instead of talk vaguely about
missing data, just assume that we're dealing with basic items. In the
rare window of time where a new color is released, and we have PB items
for it but no manual color data yet, this can just incorrectly say
"Basic Colors" and that's fine.
2024-06-05 19:45:39 -07:00
bd6b6450d9 Handle newly-released species in Item Getting Guide
This is less likely than the newly-released color case for PB items,
but I figure let's be resilient anyway, especially since it's so easy
to—and also I figure this is less likely to be triggered by an *actual*
new species, and more likely to be triggered by a surprise in an item's
naming conventions.

But yeah, if `Item#pb_species` returns `nil` upstream, it'll be passed
to `Color#example_pet_type`, which will crash trying to read its ID. So
in this change, we update `Color#example_pet_type` to accept a `nil`
value, and fall back to the first Species (Acara) in that case.

This means that, if you e.g. take the Mutant Aisha Collar and delete
the word "Aisha" from the name, then load it in the Item Getting Guide,
you'll see a thumbnail of a Mutant Acara. Good enough!
2024-06-05 19:27:38 -07:00
3dab235335 Handle newly-released PB items in Item Getting Guide
Oh right, it's possible for `Item#pb?` to return true, but
`Item#pb_color` to return `nil`, if the item has the paintbrush item
description but we can't find a color whose name matches the item name.
This would be expected if a new color were added to Neopets, and PB
items for it were modeled by the community, but we hadn't manually
added the color to the database yet.

Previously, the Item Getting Guide would crash in this scenario. Now,
it correctly handles the possibility of a `nil` value for `pb_color`,
and shows some placeholder info.

To test this, I temporarily edited some item names to not contain the
color name anymore (e.g. "P-rate Elephante Shirt and Vest"), then
loaded the guide and made changes until it no longer crashed.
2024-06-05 19:23:57 -07:00
4 changed files with 28 additions and 11 deletions

View file

@ -134,10 +134,10 @@ class ItemsController < ApplicationController
# Also, PB items have some special handling: we group them by color, then
# load example pet types for the colors that don't have paint brushes.
@pb_items_by_color = @pb_items.group_by(&:pb_color).
sort_by { |color, items| color.name }.to_h
sort_by { |color, items| color&.name }.to_h
colors_without_thumbnails =
@pb_items_by_color.keys.reject(&:pb_item_thumbnail_url?)
colors_without_thumbnails = @pb_items_by_color.keys.
select(&:present?).reject(&:pb_item_thumbnail_url?)
@pb_color_pet_types = colors_without_thumbnails.map do |color|
# Infer the ideal species from the first item we can, then try to find a

View file

@ -21,7 +21,8 @@ class Color < ApplicationRecord
end
end
def example_pet_type(preferred_species: Species.first)
def example_pet_type(preferred_species: nil)
preferred_species ||= Species.first
pet_types.order([Arel.sql("species_id = ? DESC"), preferred_species.id],
"species_id ASC").first
end

View file

@ -208,7 +208,11 @@ class Item < ApplicationRecord
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.
# item name. If it's not a PB item, or we fail to infer a specific color,
# return nil. (This is expected to be nil for some PB items, like the "Aisha
# Collar", which belong to many colors. It can also be nil for PB items for
# new colors we haven't manually added to the database yet, or if a PB item
# is named strangely in the future.)
def pb_color
return nil unless pb?
@ -226,7 +230,10 @@ class Item < ApplicationRecord
end
# If this is a PB item, return the corresponding Species, inferred from the
# item name. If it's not a PB item, or we fail to infer, return nil.
# item name. If it's not a PB item, or we fail to infer a specific species,
# return nil. (This is not expected to be nil in general, but could be for PB
# items for new species we haven't manually added to the database yet, or if
# a PB item is named strangely in the future.)
def pb_species
return nil unless pb?
normalized_name = name.downcase

View file

@ -64,27 +64,36 @@
%table.item-list{"data-group-type": "bundle"}
%thead
%td.thumbnail-cell
- if color.pb_item_thumbnail_url?
- if color&.pb_item_thumbnail_url?
= image_tag color.pb_item_thumbnail_url,
alt: "Item thumbnail for #{color.pb_item_name}"
- else
- elsif color
= image_tag pet_type_image_url(@pb_color_pet_types[color], size: :face),
srcset: ["#{pet_type_image_url(@pb_color_pet_types[color], size: :face_2x)} 2x"],
alt: @pb_color_pet_types[color].human_name
- else
= image_tag "https://images.neopets.com/items/starter_red_pb.gif",
alt: "Item thumbnail for Starter Red Paint Brush"
%th
- if color
#{color.pb_item_name || color.name.humanize}
- else
Basic colors
(#{pluralize items.size, "item"})
%td.actions-cell
- if color.pb_item_name?
- if color&.pb_item_name?
= button_link_to "Shops",
shop_wizard_url_for(color.pb_item_name),
target: "_blank", icon: search_icon
= button_link_to "Trades",
trading_post_url_for(color.pb_item_name),
target: "_blank", icon: search_icon
- else
- elsif color
.special-color-explanation
Get via Lab Ray, morphing potions, etc.
- else
.special-color-explanation
Many colors, like Red, will grant these items.
%tbody
- items.each do |item|
= render "item_list_row", item: