Compare commits
No commits in common. "118ec6aa1a9305bc673776af3cc556c55e68bb82" and "566ac241a1a6e3029a59cc1f60d8d64ce4ef07a8" have entirely different histories.
118ec6aa1a
...
566ac241a1
9 changed files with 26 additions and 61 deletions
|
@ -116,7 +116,7 @@ class OutfitsController < ApplicationController
|
||||||
def outfit_params
|
def outfit_params
|
||||||
params.require(:outfit).permit(
|
params.require(:outfit).permit(
|
||||||
:name, :starred, :alt_style_id, item_ids: {worn: [], closeted: []},
|
:name, :starred, :alt_style_id, item_ids: {worn: [], closeted: []},
|
||||||
biology: [:species_id, :color_id, :pose, :pet_state_id])
|
biology: [:species_id, :color_id, :pose])
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_authorized_outfit
|
def find_authorized_outfit
|
||||||
|
|
|
@ -48,13 +48,6 @@ module OutfitsHelper
|
||||||
content_tag :li, :class => class_name, &block
|
content_tag :li, :class => class_name, &block
|
||||||
end
|
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)
|
def pet_attribute_select(name, collection, value=nil)
|
||||||
options = options_from_collection_for_select(collection, :id, :human_name, value)
|
options = options_from_collection_for_select(collection, :id, :human_name, value)
|
||||||
select_tag name, options, id: nil, class: name
|
select_tag name, options, id: nil, class: name
|
||||||
|
|
|
@ -69,7 +69,6 @@ function useOutfitSaving(outfitState, dispatchToOutfit) {
|
||||||
speciesId: outfitState.speciesId,
|
speciesId: outfitState.speciesId,
|
||||||
colorId: outfitState.colorId,
|
colorId: outfitState.colorId,
|
||||||
pose: outfitState.pose,
|
pose: outfitState.pose,
|
||||||
appearanceId: outfitState.appearanceId,
|
|
||||||
altStyleId: outfitState.altStyleId,
|
altStyleId: outfitState.altStyleId,
|
||||||
wornItemIds: [...outfitState.wornItemIds],
|
wornItemIds: [...outfitState.wornItemIds],
|
||||||
closetedItemIds: [...outfitState.closetedItemIds],
|
closetedItemIds: [...outfitState.closetedItemIds],
|
||||||
|
|
|
@ -447,7 +447,6 @@ function getOutfitStateFromOutfitData(outfit) {
|
||||||
speciesId: outfit.speciesId,
|
speciesId: outfit.speciesId,
|
||||||
colorId: outfit.colorId,
|
colorId: outfit.colorId,
|
||||||
pose: outfit.pose,
|
pose: outfit.pose,
|
||||||
appearanceId: outfit.appearanceId,
|
|
||||||
altStyleId: outfit.altStyleId,
|
altStyleId: outfit.altStyleId,
|
||||||
wornItemIds: new Set(outfit.wornItemIds),
|
wornItemIds: new Set(outfit.wornItemIds),
|
||||||
closetedItemIds: new Set(outfit.closetedItemIds),
|
closetedItemIds: new Set(outfit.closetedItemIds),
|
||||||
|
|
|
@ -58,7 +58,6 @@ async function saveOutfit({
|
||||||
speciesId,
|
speciesId,
|
||||||
colorId,
|
colorId,
|
||||||
pose,
|
pose,
|
||||||
appearanceId,
|
|
||||||
altStyleId,
|
altStyleId,
|
||||||
wornItemIds,
|
wornItemIds,
|
||||||
closetedItemIds,
|
closetedItemIds,
|
||||||
|
@ -70,7 +69,6 @@ async function saveOutfit({
|
||||||
species_id: speciesId,
|
species_id: speciesId,
|
||||||
color_id: colorId,
|
color_id: colorId,
|
||||||
pose: pose,
|
pose: pose,
|
||||||
pet_state_id: appearanceId,
|
|
||||||
},
|
},
|
||||||
alt_style_id: altStyleId,
|
alt_style_id: altStyleId,
|
||||||
item_ids: { worn: wornItemIds, closeted: closetedItemIds },
|
item_ids: { worn: wornItemIds, closeted: closetedItemIds },
|
||||||
|
@ -129,7 +127,6 @@ function normalizeOutfit(outfit) {
|
||||||
speciesId: String(outfit.species_id),
|
speciesId: String(outfit.species_id),
|
||||||
colorId: String(outfit.color_id),
|
colorId: String(outfit.color_id),
|
||||||
pose: outfit.pose,
|
pose: outfit.pose,
|
||||||
appearanceId: String(outfit.pet_state_id),
|
|
||||||
altStyleId: outfit.alt_style_id ? String(outfit.alt_style_id) : null,
|
altStyleId: outfit.alt_style_id ? String(outfit.alt_style_id) : null,
|
||||||
wornItemIds: (outfit.item_ids?.worn || []).map((id) => String(id)),
|
wornItemIds: (outfit.item_ids?.worn || []).map((id) => String(id)),
|
||||||
closetedItemIds: (outfit.item_ids?.closeted || []).map((id) =>
|
closetedItemIds: (outfit.item_ids?.closeted || []).map((id) =>
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
class ItemOutfitRelationship < ApplicationRecord
|
class ItemOutfitRelationship < ApplicationRecord
|
||||||
belongs_to :item
|
belongs_to :item
|
||||||
belongs_to :outfit, touch: true
|
belongs_to :outfit
|
||||||
|
|
||||||
validates_presence_of :item
|
validates_presence_of :item
|
||||||
end
|
end
|
||||||
|
|
|
@ -61,36 +61,18 @@ class Outfit < ApplicationRecord
|
||||||
OutfitImage.new(image_versions)
|
OutfitImage.new(image_versions)
|
||||||
end
|
end
|
||||||
|
|
||||||
IMAGE_URL_TEMPLATE = Addressable::Template.new(
|
|
||||||
Rails.configuration.x.impress_2020.origin +
|
|
||||||
"/api/outfitImage{?id,size,updatedAt}"
|
|
||||||
)
|
|
||||||
def image_versions
|
def image_versions
|
||||||
if Rails.env.production?
|
# Now, instead of using the saved outfit to S3, we're using out the
|
||||||
# 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
|
||||||
# DTI 2020 API + CDN cache version. We use openneo-assets.net to get
|
# around a bug on Neopets petpages with openneo.net URLs.
|
||||||
# around a bug on Neopets petpages with openneo.net URLs.
|
base_url = "https://outfits.openneo-assets.net/outfits" +
|
||||||
base_url = "https://outfits.openneo-assets.net/outfits" +
|
"/#{CGI.escape id.to_s}" +
|
||||||
"/#{CGI.escape id.to_s}" +
|
"/v/#{CGI.escape updated_at.to_i.to_s}"
|
||||||
"/v/#{CGI.escape updated_at.to_i.to_s}"
|
{
|
||||||
{
|
large: "#{base_url}/600.png",
|
||||||
large: "#{base_url}/600.png",
|
medium: "#{base_url}/300.png",
|
||||||
medium: "#{base_url}/300.png",
|
small: "#{base_url}/150.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!
|
# NOTE: Below is the previous code that uses the saved outfits!
|
||||||
# {}.tap do |versions|
|
# {}.tap do |versions|
|
||||||
|
@ -120,19 +102,15 @@ class Outfit < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def biology=(biology)
|
def biology=(biology)
|
||||||
@biology = biology.slice(:species_id, :color_id, :pose, :pet_state_id)
|
@biology = biology.slice(:species_id, :color_id, :pose)
|
||||||
|
|
||||||
begin
|
begin
|
||||||
if @biology[:pet_state_id]
|
pet_type = PetType.where(
|
||||||
self.pet_state = PetState.find(@biology[:pet_state_id])
|
species_id: @biology[:species_id],
|
||||||
else
|
color_id: @biology[:color_id],
|
||||||
pet_type = PetType.where(
|
).first!
|
||||||
species_id: @biology[:species_id],
|
self.pet_state = pet_type.pet_states.with_pose(@biology[:pose]).
|
||||||
color_id: @biology[:color_id],
|
emotion_order.first!
|
||||||
).first!
|
|
||||||
self.pet_state = pet_type.pet_states.with_pose(@biology[:pose]).
|
|
||||||
emotion_order.first!
|
|
||||||
end
|
|
||||||
rescue ActiveRecord::RecordNotFound
|
rescue ActiveRecord::RecordNotFound
|
||||||
# If there's no such pet state (which shouldn't happen normally in-app),
|
# 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.
|
# we don't set `pet_state` but we keep `@biology` for validation.
|
||||||
|
|
|
@ -85,12 +85,11 @@ class Pet < ApplicationRecord
|
||||||
|
|
||||||
def wardrobe_query
|
def wardrobe_query
|
||||||
{
|
{
|
||||||
name: self.name,
|
:name => self.name,
|
||||||
color: self.pet_type.color.id,
|
:color => self.pet_type.color.id,
|
||||||
species: self.pet_type.species.id,
|
:species => self.pet_type.species.id,
|
||||||
pose: self.pet_state.pose,
|
:state => self.pet_state.id,
|
||||||
state: self.pet_state.id,
|
:objects => self.items.map(&:id)
|
||||||
objects: self.items.map(&:id),
|
|
||||||
}.to_query
|
}.to_query
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
= outfit_li_for(outfit) do
|
= outfit_li_for(outfit) do
|
||||||
- if outfit.image?
|
- if outfit.image?
|
||||||
= link_to outfit_image_tag(outfit), outfit
|
= link_to image_tag(outfit.image.small.url), outfit
|
||||||
|
|
||||||
%header
|
%header
|
||||||
.outfit-star
|
.outfit-star
|
||||||
|
|
Loading…
Reference in a new issue