Skip to content

Commit c1fed4c

Browse files
author
DD Liu
committed
Go back to only using svgrenderer to process vectors that we think are coming from scratch 2
1 parent d01f04b commit c1fed4c

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

src/import/load-costume.js

+18-11
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,30 @@ const log = require('../util/log');
33
const {loadSvgString, serializeSvgToString} = require('scratch-svg-renderer');
44

55
const loadVector_ = function (costume, runtime, rotationCenter, optVersion) {
6+
debugger;
67
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 */));
8+
let svgString = costume.asset.decodeText();
9+
// SVG Renderer load fixes "quirks" associated with Scratch 2 projects
10+
if (optVersion && optVersion === 2 && !runtime.v2SvgAdapter) {
11+
log.error('No V2 SVG adapter present; SVGs may not render correctly.');
12+
} else if (optVersion && optVersion === 2 && runtime.v2SvgAdapter) {
13+
// scratch-svg-renderer fixes syntax that causes loading issues,
14+
// and if optVersion is 2, fixes "quirks" associated with Scratch 2 SVGs,
15+
const fixedSvgString = serializeSvgToString(loadSvgString(svgString, true /* fromVersion2 */));
1116

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}`;
17+
// If the string changed, put back into storage
18+
if (svgString !== fixedSvgString) {
19+
svgString = fixedSvgString;
20+
const storage = runtime.storage;
21+
costume.asset.encodeTextData(fixedSvgString, storage.DataFormat.SVG, true);
22+
costume.assetId = costume.asset.assetId;
23+
costume.md5 = `${costume.assetId}.${costume.dataFormat}`;
24+
}
1825
}
1926

2027
// createSVGSkin does the right thing if rotationCenter isn't provided, so it's okay if it's
2128
// undefined here
22-
costume.skinId = runtime.renderer.createSVGSkin(fixedSvgString, rotationCenter);
29+
costume.skinId = runtime.renderer.createSVGSkin(svgString, rotationCenter);
2330
costume.size = runtime.renderer.getSkinSize(costume.skinId);
2431
// Now we should have a rotationCenter even if we didn't before
2532
if (!rotationCenter) {

0 commit comments

Comments
 (0)