Compare commits

...

2 commits

Author SHA1 Message Date
cb90b79efe Remove logic to auto-detect Unconverted pets (fixes Baby Pteri bug)
Two motivations here:

1. Unconverted pets should no longer exist on Neopets.com (and we
   especially don't expect new ones), so this logic helps no one.
2. The Baby Pteri keeps getting overridden to be marked as Unconverted
   because it has only one asset, which is incorrect.

A decent heuristic for a bygone era, goodbye!
2024-02-01 01:40:50 -08:00
b50bf6ceb8 Add SVG support to alt styles
Just moving our hacks around and adapting them to the SVG case lol!
2024-01-31 03:02:19 -08:00
5 changed files with 36 additions and 14 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

@ -169,7 +169,6 @@ class PetState < ApplicationRecord
end end
end end
pet_state.parent_swf_asset_relationships_to_update = relationships pet_state.parent_swf_asset_relationships_to_update = relationships
pet_state.unconverted = (relationships.size == 1)
pet_state pet_state
end end
end end

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