From 3310394fb86bf8129d6f7bf15e0183d45353f4ac Mon Sep 17 00:00:00 2001 From: Emi Matchu Date: Sun, 9 Jun 2024 19:22:34 -0700 Subject: [PATCH] Improve Owls value presentation in Item Getting Guide --- app/assets/stylesheets/items/sources.sass | 3 +- app/helpers/items_helper.rb | 33 +++++++++++++++++++++ app/views/items/sources.html.haml | 36 ++++++++++++++++------- 3 files changed, 61 insertions(+), 11 deletions(-) diff --git a/app/assets/stylesheets/items/sources.sass b/app/assets/stylesheets/items/sources.sass index 13e6fcf6..117e2cb8 100644 --- a/app/assets/stylesheets/items/sources.sass +++ b/app/assets/stylesheets/items/sources.sass @@ -85,10 +85,11 @@ color: inherit .owls-info-link + cursor: help + .owls-info-label text-decoration-line: underline text-decoration-style: dotted - cursor: help /* For wearable items that belong to a specific set that all come together, * like a Paint Brush. */ diff --git a/app/helpers/items_helper.rb b/app/helpers/items_helper.rb index 28cea014..d28ae9e0 100644 --- a/app/helpers/items_helper.rb +++ b/app/helpers/items_helper.rb @@ -156,6 +156,39 @@ module ItemsHelper "Last updated: #{date_str} (#{time_ago_str} ago)" end + NC_TRADE_VALUE_ESTIMATE_PATTERN = %r{ + ^\s* + (?: + # Case 1: A single number + (?[0-9]+) + | + # Case 2: A range from low to high + (?[0-9]+) + \p{Dash_Punctuation} + (?[0-9]+) + ) + \s*$ + }x + def nc_trade_value_is_estimate(nc_trade_value) + nc_trade_value.value_text.match?(NC_TRADE_VALUE_ESTIMATE_PATTERN) + end + + # Try to parse the NC trade value's text into something styled a bit more + # nicely for our use case. + def nc_trade_value_estimate_text(nc_trade_value) + match = nc_trade_value.value_text.match(NC_TRADE_VALUE_ESTIMATE_PATTERN) + return nc_trade_value if match.nil? + + match => {single:, low:, high:} + if single.present? + pluralize single.to_i, "capsule" + elsif low.present? && high.present? + "#{low}–#{high} capsules" + else + nc_trade_value + end + end + def nc_total_for(items) items.map(&:current_nc_price).sum end diff --git a/app/views/items/sources.html.haml b/app/views/items/sources.html.haml index 90a6b3a8..1ce5aa1e 100644 --- a/app/views/items/sources.html.haml +++ b/app/views/items/sources.html.haml @@ -156,13 +156,20 @@ - if @other_nc_items.present? %h2 Neocash items (Capsules, events, retired, etc.) :markdown - These items are part of the Neocash economy and can't be purchased with - Neopoints. We don't track all the details of how to get these items - right now! Sometimes they're available via packs or capsules or events - in the [NC Mall][mall]. Sometimes they're retired and can't be - purchased at all anymore, and can only be obtained via gifts or trades. + These items are part of the Neocash economy, but not directly for sale. + Sometimes they're available in the [NC Mall][mall], via special + bundles or events. Sometimes they're retired, and can only be obtained via + gifts or trades. [mall]: https://ncmall.neopets.com/ + + - if @other_nc_items.any?(&:nc_trade_value) + :markdown + The [Owls Value Guide][owls] often has more details about how to get + these items, and how much they're usually worth in the NC Trading + community. We've loaded their info here for you, too! Thanks, Owls team! + + [owls]: https://www.neopets.com/~owls %table.item-list %thead @@ -174,11 +181,20 @@ = render "item_list_row", item: do - content_for :subtitle, flush: true do - if item.nc_trade_value.present? - = link_to "https://www.neopets.com/~owls", - class: "owls-info-link", target: "_blank", - title: 'Owls keeps track of approximate "capsule" values of NC items for trading. Items with similar values can often be traded for one another. This is an estimate, not a rule!' do - %span.owls-info-label Owls listing: - #{item.nc_trade_value.value_text} + - if nc_trade_value_is_estimate(item.nc_trade_value) + = link_to "https://www.neopets.com/~owls", + class: "owls-info-link", target: "_blank", + title: 'Owls keeps track of approximate "capsule" values of NC items for trading. Items with similar values can often be traded for one another. This is an estimate, not a rule!' do + %span.owls-info-label [Owls] + Estimated value: + = nc_trade_value_estimate_text(item.nc_trade_value) + - else + = link_to "https://www.neopets.com/~owls", + class: "owls-info-link", target: "_blank", + title: "Owls keeps track of how to get certain special items, even when there isn't a clear NC trade estimate." do + %span.owls-info-label [Owls] + Trade info: + #{item.nc_trade_value.value_text} = button_link_to "NC Trades", item_trades_path(item, type: "offering"),