diff --git a/app/controllers/items_controller.rb b/app/controllers/items_controller.rb index b3c0bba6..fc720a04 100644 --- a/app/controllers/items_controller.rb +++ b/app/controllers/items_controller.rb @@ -122,14 +122,19 @@ class ItemsController < ApplicationController return end + # For Dyeworks items whose base is currently in the NC Mall, preload their + # trade values. We'll use this to determine which ones are fully buyable rn + # (because Owls tracks this data and we don't). + Item.preload_nc_trade_values(@items.select(&:dyeworks_base_buyable?)) + # Group the items by category! @nc_mall_items = @items.select(&:currently_in_mall?). - reject(&:dyeworks_active?) - @active_dyeworks_items = @items.select(&:dyeworks_active?) + reject(&:dyeworks_buyable?) + @buyable_dyeworks_items = @items.select(&:dyeworks_buyable?) @np_items = @items.select(&:np?) @pb_items = @items.select(&:pb?) @other_nc_items = @items.select(&:nc?).reject(&:currently_in_mall?). - reject(&:dyeworks_active?) + reject(&:dyeworks_buyable?) # Start loading the NC trade values for the non-Mall NC items. trade_values_task = Async { Item.preload_nc_trade_values(@other_nc_items) } diff --git a/app/models/item.rb b/app/models/item.rb index c5168e8e..48009725 100644 --- a/app/models/item.rb +++ b/app/models/item.rb @@ -203,11 +203,27 @@ class Item < ApplicationRecord end # Whether this is a Dyeworks item whose base item can currently be purchased - # in the NC Mall, then dyed via Dyeworks. - def dyeworks_active? + # in the NC Mall. It may or may not currently be *dyeable* in the NC Mall, + # because Dyeworks eligibility is often a limited-time event. + def dyeworks_base_buyable? dyeworks_base_item.present? && dyeworks_base_item.currently_in_mall? end + # Whether this is one of the few Dyeworks items that can be dyed in the NC + # Mall at any time, rather than as part of a limited-time event. (Owls tracks + # this, not us!) + def dyeworks_permanent? + nc_trade_value.value_text.include?("Permanent Dyeworks") + end + + # Whether this is a Dyeworks item whose base item can currently be purchased + # in the NC Mall, then dyed via Dyeworks. (Owls tracks this last part!) + def dyeworks_buyable? + # TODO: Add support for limited-time Dyeworks items. Does Owls offer this + # info too? (At time of writing, there are no active Dyeworks events.) + dyeworks_base_buyable? && dyeworks_permanent? + end + DYEWORKS_NAME_PATTERN = %r{ ^( # Most Dyeworks items have a colon in the name. diff --git a/app/views/items/sources.html.haml b/app/views/items/sources.html.haml index bbcb0353..d27e0c8b 100644 --- a/app/views/items/sources.html.haml +++ b/app/views/items/sources.html.haml @@ -29,7 +29,7 @@ = cart_icon alt: "" Buy (#{item.current_nc_price} NC) -- if @active_dyeworks_items.present? +- if @buyable_dyeworks_items.present? %h2 Dyeworks items :markdown These are recolored "Dyeworks" variants of items. First get the "base" @@ -37,9 +37,6 @@ [Dyeworks][dyeworks] section of the NC Mall! Potions can also be bought in bundles of 5 or 10. - TODO: This is currently incorrect! Dyeworks items can't always be dyed, we - need to keep track of which ones actually can be right now! - [dyeworks]: https://www.neopets.com/mall/dyeworks/ %table.item-list %thead @@ -47,23 +44,23 @@ = image_tag "https://images.neopets.com/items/mall_80x80_cleaning.gif", alt: "Dyeworks Hue Brew Potion" %th - Total: #{dyeworks_nc_total_for @active_dyeworks_items} NC + Total: #{dyeworks_nc_total_for @buyable_dyeworks_items} NC = surround "(", ")" do %span.price-breakdown{ - title: "#{dyeworks_items_nc_total_for(@active_dyeworks_items)} NC" + title: "#{dyeworks_items_nc_total_for(@buyable_dyeworks_items)} NC" }< - #{pluralize @active_dyeworks_items.size, "item"} + #{pluralize @buyable_dyeworks_items.size, "item"} + %span.price-breakdown{ - title: dyeworks_potions_nc_summary(@active_dyeworks_items.size) + title: dyeworks_potions_nc_summary(@buyable_dyeworks_items.size) }< - #{pluralize @active_dyeworks_items.size, "potion"} + #{pluralize @buyable_dyeworks_items.size, "potion"} %td.actions-cell %button{onclick: "alert('Todo!')"} = cart_icon alt: "" Buy all in NC Mall %tbody - - @active_dyeworks_items.each do |item| + - @buyable_dyeworks_items.each do |item| = render "item_list_row", item:, subtitle: dyeworks_explanation_subtitle_for(item) do %button{onclick: "alert('Todo!')"}