Skip to content

Commit 65f22c1

Browse files
authored
Merge pull request #3026 from fsih/onlyResaveSprite2Svgs
Go back to only using svgrenderer to process vectors that we think are coming from scratch 2
2 parents d01f04b + 529a87c commit 65f22c1

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

src/import/load-costume.js

+15-11
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,26 @@ const {loadSvgString, serializeSvgToString} = require('scratch-svg-renderer');
44

55
const loadVector_ = function (costume, runtime, rotationCenter, optVersion) {
66
return new Promise(resolve => {
7-
const svgString = costume.asset.decodeText();
8-
// scratch-svg-renderer fixes syntax that causes loading issues,
9-
// and if optVersion is 2, fixes "quirks" associated with Scratch 2 SVGs,
10-
const fixedSvgString = serializeSvgToString(loadSvgString(svgString, optVersion === 2/* fromVersion2 */));
7+
let svgString = costume.asset.decodeText();
8+
// SVG Renderer load fixes "quirks" associated with Scratch 2 projects
9+
if (optVersion && optVersion === 2) {
10+
// scratch-svg-renderer fixes syntax that causes loading issues,
11+
// and if optVersion is 2, fixes "quirks" associated with Scratch 2 SVGs,
12+
const fixedSvgString = serializeSvgToString(loadSvgString(svgString, true /* fromVersion2 */));
1113

12-
// If the string changed, put back into storage
13-
if (svgString !== fixedSvgString) {
14-
const storage = runtime.storage;
15-
costume.asset.encodeTextData(fixedSvgString, storage.DataFormat.SVG, true);
16-
costume.assetId = costume.asset.assetId;
17-
costume.md5 = `${costume.assetId}.${costume.dataFormat}`;
14+
// If the string changed, put back into storage
15+
if (svgString !== fixedSvgString) {
16+
svgString = fixedSvgString;
17+
const storage = runtime.storage;
18+
costume.asset.encodeTextData(fixedSvgString, storage.DataFormat.SVG, true);
19+
costume.assetId = costume.asset.assetId;
20+
costume.md5 = `${costume.assetId}.${costume.dataFormat}`;
21+
}
1822
}
1923

2024
// createSVGSkin does the right thing if rotationCenter isn't provided, so it's okay if it's
2125
// undefined here
22-
costume.skinId = runtime.renderer.createSVGSkin(fixedSvgString, rotationCenter);
26+
costume.skinId = runtime.renderer.createSVGSkin(svgString, rotationCenter);
2327
costume.size = runtime.renderer.getSkinSize(costume.skinId);
2428
// Now we should have a rotationCenter even if we didn't before
2529
if (!rotationCenter) {

0 commit comments

Comments
 (0)