Compare commits

...

3 commits

Author SHA1 Message Date
56d550e86c Skip loading alt styles on item preview page
Ah yeah, if you're not on the wardrobe page (so we don't need the Alt
Styles UI), and the outfit's `altStyleId` is null (as is the case for
the item preview page), then there's no need to load the alt styles for
that species.

So before this change, going to `/items/123` would include an XHR
request to `/species/<id>/alt-styles.json`, which would not be used for
anything. After this change, that request is no longer sent. Hooray!
2024-02-24 17:23:57 -08:00
7af1a97161 Read known_glitches when loading alt styles SWF assets
I'm not sure why I had marked this as TODO before? Maybe I'm missing
something? But for now I'll just wire it in, I guess!
2024-02-24 16:31:05 -08:00
c5cd1f2f3d Remove SwfAsset#html5_*_url in favor of SwfAsset#urls
The alt styles controller is the one place we use this right now, but
I'm planning to generalize this to loading appearances during item
search, too!

I also add more `only` fields to the alt styles `as_json` call, because
idk it feels like good practice to both 1) say what we need in this
endpoint, rather than rely on default behavior upstream, and 2) to
avoid leaking fields we didn't realize were on there. (And also to
preserve bandwidth, too!)
2024-02-24 16:29:47 -08:00
3 changed files with 14 additions and 17 deletions

View file

@ -16,10 +16,13 @@ class AltStylesController < ApplicationController
format.html { render } format.html { render }
format.json { format.json {
render json: @alt_styles.includes(swf_assets: [:zone]).as_json( render json: @alt_styles.includes(swf_assets: [:zone]).as_json(
only: [:id, :species_id, :color_id, :body_id, :series_name,
:adjective_name, :thumbnail_url],
include: { include: {
swf_assets: { swf_assets: {
only: [:id, :body_id],
include: [:zone], include: [:zone],
methods: [:html5_image_url, :html5_svg_url], methods: [:urls, :known_glitches],
} }
}, },
methods: [:series_name, :adjective_name, :thumbnail_url], methods: [:series_name, :adjective_name, :thumbnail_url],

View file

@ -12,7 +12,10 @@ export function useAltStylesForSpecies(speciesId, options = {}) {
// NOTE: This is actually just a wrapper for `useAltStylesForSpecies`, to share // NOTE: This is actually just a wrapper for `useAltStylesForSpecies`, to share
// the same cache key! // the same cache key!
export function useAltStyle(id, speciesId, options = {}) { export function useAltStyle(id, speciesId, options = {}) {
const query = useAltStylesForSpecies(speciesId, options); const query = useAltStylesForSpecies(speciesId, {
...options,
enabled: (options.enabled ?? true) && id != null,
});
return { return {
...query, ...query,
@ -70,13 +73,11 @@ function normalizeSwfAssetToLayer(swfAssetData) {
label: swfAssetData.zone.label, label: swfAssetData.zone.label,
}, },
bodyId: swfAssetData.body_id, bodyId: swfAssetData.body_id,
knownGlitches: [], // TODO knownGlitches: swfAssetData.known_glitches,
// HACK: We're just simplifying this adapter, but it would be better to svgUrl: swfAssetData.urls.svg,
// actually check what file formats the manifest says! canvasMovieLibraryUrl: swfAssetData.urls.canvas_library,
svgUrl: swfAssetData.html5_svg_url, imageUrl: swfAssetData.urls.png,
canvasMovieLibraryUrl: null, swfUrl: swfAssetData.urls.swf,
imageUrl: swfAssetData.html5_image_url,
swfUrl: swfAssetData.url,
}; };
} }

View file

@ -45,6 +45,7 @@ class SwfAsset < ApplicationRecord
swf: url, swf: url,
png: image_url, png: image_url,
svg: manifest_asset_urls[:svg], svg: manifest_asset_urls[:svg],
canvas_library: manifest_asset_urls[:js],
manifest: manifest_url, manifest: manifest_url,
} }
end end
@ -147,14 +148,6 @@ class SwfAsset < ApplicationRecord
).to_s ).to_s
end end
def html5_image_url
manifest_asset_urls[:png]
end
def html5_svg_url
manifest_asset_urls[:svg]
end
def known_glitches def known_glitches
self[:known_glitches].split(',') self[:known_glitches].split(',')
end end