Compare commits
5 commits
72c739ca0f
...
1e99376449
| Author | SHA1 | Date | |
|---|---|---|---|
| 1e99376449 | |||
| 244bb7627a | |||
| 285cf233f0 | |||
| b06e8a25c0 | |||
| c78d51ab01 |
3 changed files with 36 additions and 13 deletions
|
|
@ -1,3 +1,5 @@
|
||||||
|
require "addressable/template"
|
||||||
|
|
||||||
class AltStyle < ApplicationRecord
|
class AltStyle < ApplicationRecord
|
||||||
belongs_to :species
|
belongs_to :species
|
||||||
belongs_to :color
|
belongs_to :color
|
||||||
|
|
@ -6,6 +8,10 @@ class AltStyle < ApplicationRecord
|
||||||
has_many :swf_assets, through: :parent_swf_asset_relationships
|
has_many :swf_assets, through: :parent_swf_asset_relationships
|
||||||
has_many :contributions, as: :contributed, inverse_of: :contributed
|
has_many :contributions, as: :contributed, inverse_of: :contributed
|
||||||
|
|
||||||
|
validates :body_id, presence: true
|
||||||
|
|
||||||
|
before_create :infer_series_name
|
||||||
|
|
||||||
scope :matching_name, ->(series_name, color_name, species_name) {
|
scope :matching_name, ->(series_name, color_name, species_name) {
|
||||||
color = Color.find_by_name!(color_name)
|
color = Color.find_by_name!(color_name)
|
||||||
species = Species.find_by_name!(species_name)
|
species = Species.find_by_name!(species_name)
|
||||||
|
|
@ -35,11 +41,20 @@ class AltStyle < ApplicationRecord
|
||||||
"#{series_name} #{color.human_name}"
|
"#{series_name} #{color.human_name}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
THUMBNAIL_URL_TEMPLATE = Addressable::Template.new(
|
||||||
|
"https://images.neopets.com/items/{series}_{color}_{species}.gif"
|
||||||
|
)
|
||||||
|
DEFAULT_THUMBNAIL_URL = "https://images.neopets.com/items/mall_bg_circle.gif"
|
||||||
def thumbnail_url
|
def thumbnail_url
|
||||||
# HACK: Just assume this is a Nostalgic Alt Style, and that the thumbnail
|
return DEFAULT_THUMBNAIL_URL unless has_real_series_name?
|
||||||
# is named reliably!
|
|
||||||
"https://images.neopets.com/items/nostalgic_" +
|
# HACK: We're assuming this is the format long-term! But if it changes, we
|
||||||
"#{color.name.gsub(/\s+/, '').downcase}_#{species.name.downcase}.gif"
|
# may need to add it as a database field instead.
|
||||||
|
THUMBNAIL_URL_TEMPLATE.expand(
|
||||||
|
series: series_name.gsub(/\s+/, '').downcase,
|
||||||
|
color: color.name.gsub(/\s+/, '').downcase,
|
||||||
|
species: species.name.gsub(/\s+/, '').downcase,
|
||||||
|
).to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
def preview_image_url
|
def preview_image_url
|
||||||
|
|
@ -63,6 +78,19 @@ class AltStyle < ApplicationRecord
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Until the end of 2024, assume new alt styles are from the "Nostalgic"
|
||||||
|
# series. That way, we can stop having to manually label them all as they
|
||||||
|
# come out and get modeled (TNT is prolific rn!), but we aren't gonna get too
|
||||||
|
# greedy and forget about this and use Nostalgic for some far-future thing,
|
||||||
|
# in ways that will certainly be fixable but would also be confusing and
|
||||||
|
# embarrassing.
|
||||||
|
NOSTALGIC_FINAL_DAY = Date.new(2024, 12, 31)
|
||||||
|
def infer_series_name
|
||||||
|
if !has_real_series_name? && Date.today <= NOSTALGIC_FINAL_DAY
|
||||||
|
self.series_name = "Nostalgic"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# For convenience in the console!
|
# For convenience in the console!
|
||||||
def self.find_by_name(color_name, species_name)
|
def self.find_by_name(color_name, species_name)
|
||||||
color = Color.find_by_name(color_name)
|
color = Color.find_by_name(color_name)
|
||||||
|
|
|
||||||
|
|
@ -338,7 +338,7 @@ class SwfAsset < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
SwfAsset.transaction do
|
SwfAsset.transaction do
|
||||||
swf_assets.each(&:save!)
|
swf_assets.select(&:changed?).each(&:save!)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,14 +9,9 @@
|
||||||
name on the homepage! Thank you! 💖
|
name on the homepage! Thank you! 💖
|
||||||
|
|
||||||
%p
|
%p
|
||||||
Also, heads-up: Style tokens are pretty different from normal wearables, so
|
Also, heads-up: Because our system can only collect "item data" for normal
|
||||||
we haven't decided how to bring them into the customizer yet! Whatever we do,
|
wearable items, there's not a great way for us to get style tokens onto
|
||||||
it'll be a bit tricky and new 😅❗️
|
tradelists… this may change someday, but probably not soon, sorry!
|
||||||
|
|
||||||
%p
|
|
||||||
Also, second heads-up: Because our system can only collect "item data" for
|
|
||||||
normal wearable items, there's not a great way for us to get style tokens
|
|
||||||
onto tradelists… this may change someday, but probably not soon, sorry!
|
|
||||||
|
|
||||||
- @alt_styles.group_by(&:species).each do |species, species_styles|
|
- @alt_styles.group_by(&:species).each do |species, species_styles|
|
||||||
%h2.alt-styles-header= species.human_name
|
%h2.alt-styles-header= species.human_name
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue