1
0
Fork 0
forked from OpenNeo/impress

Add SVG support to alt styles

Just moving our hacks around and adapting them to the SVG case lol!
This commit is contained in:
Emi Matchu 2024-01-31 03:02:19 -08:00
parent ab8c9f6242
commit b50bf6ceb8
4 changed files with 36 additions and 13 deletions

View file

@ -12,7 +12,12 @@ 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(
include: {swf_assets: {include: [:zone], methods: [:image_url]}}, include: {
swf_assets: {
include: [:zone],
methods: [:html5_image_url, :html5_svg_url],
}
},
methods: [:series_name, :adjective_name, :thumbnail_url], methods: [:series_name, :adjective_name, :thumbnail_url],
) )
} }

View file

@ -73,10 +73,9 @@ function normalizeSwfAssetToLayer(swfAssetData) {
// HACK: We're just simplifying this adapter, but it would be better to // HACK: We're just simplifying this adapter, but it would be better to
// actually check what file formats the manifest says! // actually check what file formats the manifest says!
// TODO: For example, these do generally have SVGs, we could use them! svgUrl: swfAssetData.html5_svg_url,
svgUrl: null,
canvasMovieLibraryUrl: null, canvasMovieLibraryUrl: null,
imageUrl: swfAssetData.image_url, imageUrl: swfAssetData.html5_image_url,
swfUrl: swfAssetData.url, swfUrl: swfAssetData.url,
}; };
} }

View file

@ -34,19 +34,11 @@ class AltStyle < ApplicationRecord
"#{color.name.gsub(/\s+/, '').downcase}_#{species.name.downcase}.gif" "#{color.name.gsub(/\s+/, '').downcase}_#{species.name.downcase}.gif"
end end
MANIFEST_PATTERN = %r{^https://images.neopets.com/(?<prefix>.+)/(?<id>[0-9]+)(?<hash_part>_[^/]+)?/manifest\.json}
def preview_image_url def preview_image_url
swf_asset = swf_assets.first swf_asset = swf_assets.first
return nil if swf_asset.nil? return nil if swf_asset.nil?
# HACK: Just assuming all of these were well-formed by the same process, swf_asset.html5_image_url
# and infer the image URL from the manifest URL! But strictly speaking we
# should be reading the manifest to check!
match = swf_asset.manifest_url.match(MANIFEST_PATTERN)
return nil if match.nil?
"https://images.neopets.com/#{match[:prefix]}/" +
"#{match[:id]}#{match[:hash_part]}/#{match[:id]}.png"
end end
def biology=(biology) def biology=(biology)

View file

@ -110,6 +110,33 @@ class SwfAsset < ApplicationRecord
} }
end end
MANIFEST_PATTERN = %r{^https://images.neopets.com/(?<prefix>.+)/(?<id>[0-9]+)(?<hash_part>_[^/]+)?/manifest\.json}
def html5_image_url
return nil if manifest_url.nil?
# HACK: Just assuming all of these were well-formed by the same process,
# and infer the image URL from the manifest URL! But strictly speaking we
# should be reading the manifest to check!
match = manifest_url.match(MANIFEST_PATTERN)
return nil if match.nil?
"https://images.neopets.com/#{match[:prefix]}/" +
"#{match[:id]}#{match[:hash_part]}/#{match[:id]}.png"
end
def html5_svg_url
return nil if manifest_url.nil?
# HACK: Just assuming all of these were well-formed by the same process,
# and infer the image URL from the manifest URL! But strictly speaking we
# should be reading the manifest to check!
match = manifest_url.match(MANIFEST_PATTERN)
return nil if match.nil?
"https://images.neopets.com/#{match[:prefix]}/" +
"#{match[:id]}#{match[:hash_part]}/#{match[:id]}.svg"
end
def known_glitches def known_glitches
self[:known_glitches].split(',') self[:known_glitches].split(',')
end end