Compare commits
5 commits
e1c598e591
...
341869fb17
Author | SHA1 | Date | |
---|---|---|---|
341869fb17 | |||
31c281390d | |||
a3bd841bb8 | |||
bd6b6450d9 | |||
3dab235335 |
4 changed files with 28 additions and 11 deletions
|
@ -134,10 +134,10 @@ class ItemsController < ApplicationController
|
||||||
# Also, PB items have some special handling: we group them by color, then
|
# 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.
|
# load example pet types for the colors that don't have paint brushes.
|
||||||
@pb_items_by_color = @pb_items.group_by(&:pb_color).
|
@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 =
|
colors_without_thumbnails = @pb_items_by_color.keys.
|
||||||
@pb_items_by_color.keys.reject(&:pb_item_thumbnail_url?)
|
select(&:present?).reject(&:pb_item_thumbnail_url?)
|
||||||
|
|
||||||
@pb_color_pet_types = colors_without_thumbnails.map do |color|
|
@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
|
# Infer the ideal species from the first item we can, then try to find a
|
||||||
|
|
|
@ -21,7 +21,8 @@ class Color < ApplicationRecord
|
||||||
end
|
end
|
||||||
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],
|
pet_types.order([Arel.sql("species_id = ? DESC"), preferred_species.id],
|
||||||
"species_id ASC").first
|
"species_id ASC").first
|
||||||
end
|
end
|
||||||
|
|
|
@ -208,7 +208,11 @@ class Item < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
# If this is a PB item, return the corresponding Color, inferred from the
|
# 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
|
def pb_color
|
||||||
return nil unless pb?
|
return nil unless pb?
|
||||||
|
|
||||||
|
@ -226,7 +230,10 @@ class Item < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
# If this is a PB item, return the corresponding Species, inferred from the
|
# 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
|
def pb_species
|
||||||
return nil unless pb?
|
return nil unless pb?
|
||||||
normalized_name = name.downcase
|
normalized_name = name.downcase
|
||||||
|
|
|
@ -64,27 +64,36 @@
|
||||||
%table.item-list{"data-group-type": "bundle"}
|
%table.item-list{"data-group-type": "bundle"}
|
||||||
%thead
|
%thead
|
||||||
%td.thumbnail-cell
|
%td.thumbnail-cell
|
||||||
- if color.pb_item_thumbnail_url?
|
- if color&.pb_item_thumbnail_url?
|
||||||
= image_tag color.pb_item_thumbnail_url,
|
= image_tag color.pb_item_thumbnail_url,
|
||||||
alt: "Item thumbnail for #{color.pb_item_name}"
|
alt: "Item thumbnail for #{color.pb_item_name}"
|
||||||
- else
|
- elsif color
|
||||||
= image_tag pet_type_image_url(@pb_color_pet_types[color], size: :face),
|
= 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"],
|
srcset: ["#{pet_type_image_url(@pb_color_pet_types[color], size: :face_2x)} 2x"],
|
||||||
alt: @pb_color_pet_types[color].human_name
|
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
|
%th
|
||||||
#{color.pb_item_name || color.name.humanize}
|
- if color
|
||||||
|
#{color.pb_item_name || color.name.humanize}
|
||||||
|
- else
|
||||||
|
Basic colors
|
||||||
(#{pluralize items.size, "item"})
|
(#{pluralize items.size, "item"})
|
||||||
%td.actions-cell
|
%td.actions-cell
|
||||||
- if color.pb_item_name?
|
- if color&.pb_item_name?
|
||||||
= button_link_to "Shops",
|
= button_link_to "Shops",
|
||||||
shop_wizard_url_for(color.pb_item_name),
|
shop_wizard_url_for(color.pb_item_name),
|
||||||
target: "_blank", icon: search_icon
|
target: "_blank", icon: search_icon
|
||||||
= button_link_to "Trades",
|
= button_link_to "Trades",
|
||||||
trading_post_url_for(color.pb_item_name),
|
trading_post_url_for(color.pb_item_name),
|
||||||
target: "_blank", icon: search_icon
|
target: "_blank", icon: search_icon
|
||||||
- else
|
- elsif color
|
||||||
.special-color-explanation
|
.special-color-explanation
|
||||||
Get via Lab Ray, morphing potions, etc.
|
Get via Lab Ray, morphing potions, etc.
|
||||||
|
- else
|
||||||
|
.special-color-explanation
|
||||||
|
Many colors, like Red, will grant these items.
|
||||||
%tbody
|
%tbody
|
||||||
- items.each do |item|
|
- items.each do |item|
|
||||||
= render "item_list_row", item:
|
= render "item_list_row", item:
|
||||||
|
|
Loading…
Reference in a new issue