Merge pull request #3026 from fsih/onlyResaveSprite2Svgs

Go back to only using svgrenderer to process vectors that we think are coming from scratch 2
This commit is contained in:
DD Liu 2021-04-12 14:09:25 -04:00 committed by GitHub
commit 65f22c15f3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -4,22 +4,26 @@ const {loadSvgString, serializeSvgToString} = require('scratch-svg-renderer');
const loadVector_ = function (costume, runtime, rotationCenter, optVersion) { const loadVector_ = function (costume, runtime, rotationCenter, optVersion) {
return new Promise(resolve => { return new Promise(resolve => {
const svgString = costume.asset.decodeText(); let svgString = costume.asset.decodeText();
// scratch-svg-renderer fixes syntax that causes loading issues, // SVG Renderer load fixes "quirks" associated with Scratch 2 projects
// and if optVersion is 2, fixes "quirks" associated with Scratch 2 SVGs, if (optVersion && optVersion === 2) {
const fixedSvgString = serializeSvgToString(loadSvgString(svgString, optVersion === 2/* fromVersion2 */)); // scratch-svg-renderer fixes syntax that causes loading issues,
// and if optVersion is 2, fixes "quirks" associated with Scratch 2 SVGs,
const fixedSvgString = serializeSvgToString(loadSvgString(svgString, true /* fromVersion2 */));
// If the string changed, put back into storage // If the string changed, put back into storage
if (svgString !== fixedSvgString) { if (svgString !== fixedSvgString) {
const storage = runtime.storage; svgString = fixedSvgString;
costume.asset.encodeTextData(fixedSvgString, storage.DataFormat.SVG, true); const storage = runtime.storage;
costume.assetId = costume.asset.assetId; costume.asset.encodeTextData(fixedSvgString, storage.DataFormat.SVG, true);
costume.md5 = `${costume.assetId}.${costume.dataFormat}`; costume.assetId = costume.asset.assetId;
costume.md5 = `${costume.assetId}.${costume.dataFormat}`;
}
} }
// createSVGSkin does the right thing if rotationCenter isn't provided, so it's okay if it's // createSVGSkin does the right thing if rotationCenter isn't provided, so it's okay if it's
// undefined here // undefined here
costume.skinId = runtime.renderer.createSVGSkin(fixedSvgString, rotationCenter); costume.skinId = runtime.renderer.createSVGSkin(svgString, rotationCenter);
costume.size = runtime.renderer.getSkinSize(costume.skinId); costume.size = runtime.renderer.getSkinSize(costume.skinId);
// Now we should have a rotationCenter even if we didn't before // Now we should have a rotationCenter even if we didn't before
if (!rotationCenter) { if (!rotationCenter) {