diff --git a/app/controllers/contributions_controller.rb b/app/controllers/contributions_controller.rb index 018c270c..a3466637 100644 --- a/app/controllers/contributions_controller.rb +++ b/app/controllers/contributions_controller.rb @@ -11,7 +11,8 @@ class ContributionsController < ApplicationController @contributions, :scopes => { 'Item' => Item.includes(:translations), - 'PetType' => PetType.includes(:species, :color) + 'PetType' => PetType.includes(:species, :color), + 'AltStyle' => AltStyle.includes(:species, :color), } ) end diff --git a/app/helpers/contribution_helper.rb b/app/helpers/contribution_helper.rb index eb01776f..300ce6c7 100644 --- a/app/helpers/contribution_helper.rb +++ b/app/helpers/contribution_helper.rb @@ -9,6 +9,8 @@ module ContributionHelper contributed_pet_type('pet_type', contributed, show_image) when PetState contributed_pet_type('pet_state', contributed.pet_type, show_image) + when AltStyle + contributed_alt_style(contributed, show_image) end end @@ -36,6 +38,20 @@ module ContributionHelper output << image_tag(sprintf(PET_TYPE_IMAGE_FORMAT, pet_type.image_hash)) if show_image output end + + def contributed_alt_style(alt_style, show_image) + span = content_tag(:span, alt_style.name, class: 'contributed-name') + output = translate("contributions.contributed_description.main.alt_style_html", + alt_style_name: span) + # HACK: Just assume this is a Nostalgic Alt Style, and that the thumbnail + # is named reliably! + if show_image + thumbnail_url = "https://images.neopets.com/items/nostalgic_" + + "#{alt_style.color.name.downcase}_#{alt_style.species.name.downcase}.gif" + output << image_tag(thumbnail_url) + end + output + end private diff --git a/app/models/alt_style.rb b/app/models/alt_style.rb index 30741ed8..3df2b400 100644 --- a/app/models/alt_style.rb +++ b/app/models/alt_style.rb @@ -4,6 +4,12 @@ class AltStyle < ApplicationRecord has_many :parent_swf_asset_relationships, as: :parent has_many :swf_assets, through: :parent_swf_asset_relationships + has_many :contributions, as: :contributed, inverse_of: :contributed + + def name + I18n.translate('pet_types.human_name', color_human_name: color.human_name, + species_human_name: species.human_name) + end def biology=(biology) # TODO: This is very similar to what `PetState` does, but likeā€¦ much much diff --git a/app/models/contribution.rb b/app/models/contribution.rb index 1c502ecc..3b865fea 100644 --- a/app/models/contribution.rb +++ b/app/models/contribution.rb @@ -3,7 +3,8 @@ class Contribution < ApplicationRecord 'Item' => 3, 'SwfAsset' => 2, 'PetType' => 15, - 'PetState' => 10 + 'PetState' => 10, + 'AltStyle' => 30, } belongs_to :contributed, :polymorphic => true @@ -24,7 +25,7 @@ class Contribution < ApplicationRecord 'SwfAsset' => 'Item', 'PetState' => 'PetType' } - CONTRIBUTED_CHILDREN = CONTRIBUTED_RELATIONSHIPS.keys + CONTRIBUTED_CHILDREN = CONTRIBUTED_RELATIONSHIPS.keys + ['AltStyle'] CONTRIBUTED_TYPES = CONTRIBUTED_CHILDREN + CONTRIBUTED_RELATIONSHIPS.values def self.preload_contributeds_and_parents(contributions, options={}) options[:scopes] ||= {} diff --git a/app/models/pet.rb b/app/models/pet.rb index dfaee1ff..d262ea3c 100644 --- a/app/models/pet.rb +++ b/app/models/pet.rb @@ -79,7 +79,7 @@ class Pet < ApplicationRecord end def contributables - contributables = [pet_type, @pet_state] + contributables = [pet_type, @pet_state, @alt_style].filter(&:present?) items.each do |item| contributables << item contributables += item.pending_swf_assets diff --git a/config/locales/en.yml b/config/locales/en.yml index 6122ed8f..91942e88 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -232,6 +232,7 @@ en: swf_asset_html: "%{item_description} on a new body type" pet_type_html: "%{pet_type_description} for the first time" pet_state_html: "a new pose for %{pet_type_description}" + alt_style_html: "a new Alt Style of the %{alt_style_name}" contribution: description_html: "%{user_link} showed us %{contributed_description}"