Compare commits

...

5 commits

Author SHA1 Message Date
118ec6aa1a Oops, update outfit's updated_at when adding/removing items
This bug caused outfit thumbnails to get out of date, because the
outfit's `updated_at` field is used as a cache-busting part of the URL.
2024-02-08 10:32:53 -08:00
3ab6d1e3ae Oops, add some more wiring for pet state ID for saved outfits
There's an infinite loop happening in prod that I can't reproduce on
dev, but this missing piece feels like it could be related.
2024-02-08 10:15:31 -08:00
66f20747a9 Use higher-res outfit thumbnails if the device has at least 2x DPI 2024-02-08 10:07:09 -08:00
5d0848bf28 In development, use local Impress 2020 to generate outfit images
Just so we can see accurate stuff on the outfits page!
2024-02-08 10:03:10 -08:00
dc44b4dbb3 Oops, fix bug with saving outfits of pets loaded from Neopets.com
Okay right, the wardrobe-2020 app treats `state` as a bit of an
override thing, and `pose` is the main canonical field for how a pet
looks. We were missing a few pieces here:

1. After loading a pet, we weren't including the `pose` field in the
   initial query string for the wardrobe URL, but we _were_ including
   the `state` field, so the outfit would get set up with a conflicting
   pet state ID vs pose.
2. When saving an outfit, we weren't taking the `state` field into
   account at all. This could cause the saved outfit to not quite match
   how it actually looked in-app, because the default pet state for
   that species/color/pose trio could be different; and regardless, the
   outfit state would come back with `appearanceId` set to `null`,
   which wouldn't match the local outfit state, which would trigger an
   infinite loop.

Here, we complete the round-trip of the `state` field, from pet loading
to outfit saving to the outfit data that comes back after saving!
2024-02-08 09:51:31 -08:00
9 changed files with 61 additions and 26 deletions

View file

@ -116,7 +116,7 @@ class OutfitsController < ApplicationController
def outfit_params
params.require(:outfit).permit(
:name, :starred, :alt_style_id, item_ids: {worn: [], closeted: []},
biology: [:species_id, :color_id, :pose])
biology: [:species_id, :color_id, :pose, :pet_state_id])
end
def find_authorized_outfit

View file

@ -48,6 +48,13 @@ module OutfitsHelper
content_tag :li, :class => class_name, &block
end
def outfit_image_tag(outfit)
image_tag(
outfit.image.small.url,
srcset: [[outfit.image.medium.url, "2x"]],
)
end
def pet_attribute_select(name, collection, value=nil)
options = options_from_collection_for_select(collection, :id, :human_name, value)
select_tag name, options, id: nil, class: name

View file

@ -69,6 +69,7 @@ function useOutfitSaving(outfitState, dispatchToOutfit) {
speciesId: outfitState.speciesId,
colorId: outfitState.colorId,
pose: outfitState.pose,
appearanceId: outfitState.appearanceId,
altStyleId: outfitState.altStyleId,
wornItemIds: [...outfitState.wornItemIds],
closetedItemIds: [...outfitState.closetedItemIds],

View file

@ -447,6 +447,7 @@ function getOutfitStateFromOutfitData(outfit) {
speciesId: outfit.speciesId,
colorId: outfit.colorId,
pose: outfit.pose,
appearanceId: outfit.appearanceId,
altStyleId: outfit.altStyleId,
wornItemIds: new Set(outfit.wornItemIds),
closetedItemIds: new Set(outfit.closetedItemIds),

View file

@ -58,6 +58,7 @@ async function saveOutfit({
speciesId,
colorId,
pose,
appearanceId,
altStyleId,
wornItemIds,
closetedItemIds,
@ -69,6 +70,7 @@ async function saveOutfit({
species_id: speciesId,
color_id: colorId,
pose: pose,
pet_state_id: appearanceId,
},
alt_style_id: altStyleId,
item_ids: { worn: wornItemIds, closeted: closetedItemIds },
@ -127,6 +129,7 @@ function normalizeOutfit(outfit) {
speciesId: String(outfit.species_id),
colorId: String(outfit.color_id),
pose: outfit.pose,
appearanceId: String(outfit.pet_state_id),
altStyleId: outfit.alt_style_id ? String(outfit.alt_style_id) : null,
wornItemIds: (outfit.item_ids?.worn || []).map((id) => String(id)),
closetedItemIds: (outfit.item_ids?.closeted || []).map((id) =>

View file

@ -1,6 +1,6 @@
class ItemOutfitRelationship < ApplicationRecord
belongs_to :item
belongs_to :outfit
belongs_to :outfit, touch: true
validates_presence_of :item
end

View file

@ -61,18 +61,36 @@ class Outfit < ApplicationRecord
OutfitImage.new(image_versions)
end
IMAGE_URL_TEMPLATE = Addressable::Template.new(
Rails.configuration.x.impress_2020.origin +
"/api/outfitImage{?id,size,updatedAt}"
)
def image_versions
# Now, instead of using the saved outfit to S3, we're using out the
# DTI 2020 API + CDN cache version. We use openneo-assets.net to get
# around a bug on Neopets petpages with openneo.net URLs.
base_url = "https://outfits.openneo-assets.net/outfits" +
"/#{CGI.escape id.to_s}" +
"/v/#{CGI.escape updated_at.to_i.to_s}"
{
large: "#{base_url}/600.png",
medium: "#{base_url}/300.png",
small: "#{base_url}/150.png",
}
if Rails.env.production?
# Now, instead of using the saved outfit to S3, we're using out the
# DTI 2020 API + CDN cache version. We use openneo-assets.net to get
# around a bug on Neopets petpages with openneo.net URLs.
base_url = "https://outfits.openneo-assets.net/outfits" +
"/#{CGI.escape id.to_s}" +
"/v/#{CGI.escape updated_at.to_i.to_s}"
{
large: "#{base_url}/600.png",
medium: "#{base_url}/300.png",
small: "#{base_url}/150.png",
}
else
# In development, just talk to our local Impress 2020 directly.
build_url = -> size {
IMAGE_URL_TEMPLATE.expand(
id: id, size: size, updatedAt: updated_at.to_i
).to_s
}
{
large: build_url.call("600"),
medium: build_url.call("300"),
small: build_url.call("150"),
}
end
# NOTE: Below is the previous code that uses the saved outfits!
# {}.tap do |versions|
@ -102,15 +120,19 @@ class Outfit < ApplicationRecord
end
def biology=(biology)
@biology = biology.slice(:species_id, :color_id, :pose)
@biology = biology.slice(:species_id, :color_id, :pose, :pet_state_id)
begin
pet_type = PetType.where(
species_id: @biology[:species_id],
color_id: @biology[:color_id],
).first!
self.pet_state = pet_type.pet_states.with_pose(@biology[:pose]).
emotion_order.first!
if @biology[:pet_state_id]
self.pet_state = PetState.find(@biology[:pet_state_id])
else
pet_type = PetType.where(
species_id: @biology[:species_id],
color_id: @biology[:color_id],
).first!
self.pet_state = pet_type.pet_states.with_pose(@biology[:pose]).
emotion_order.first!
end
rescue ActiveRecord::RecordNotFound
# If there's no such pet state (which shouldn't happen normally in-app),
# we don't set `pet_state` but we keep `@biology` for validation.

View file

@ -85,11 +85,12 @@ class Pet < ApplicationRecord
def wardrobe_query
{
:name => self.name,
:color => self.pet_type.color.id,
:species => self.pet_type.species.id,
:state => self.pet_state.id,
:objects => self.items.map(&:id)
name: self.name,
color: self.pet_type.color.id,
species: self.pet_type.species.id,
pose: self.pet_state.pose,
state: self.pet_state.id,
objects: self.items.map(&:id),
}.to_query
end

View file

@ -1,6 +1,6 @@
= outfit_li_for(outfit) do
- if outfit.image?
= link_to image_tag(outfit.image.small.url), outfit
= link_to outfit_image_tag(outfit), outfit
%header
.outfit-star