@@ -4,22 +4,26 @@ const {loadSvgString, serializeSvgToString} = require('scratch-svg-renderer');
4
4
5
5
const loadVector_ = function ( costume , runtime , rotationCenter , optVersion ) {
6
6
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 */ ) ) ;
11
13
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
+ }
18
22
}
19
23
20
24
// createSVGSkin does the right thing if rotationCenter isn't provided, so it's okay if it's
21
25
// undefined here
22
- costume . skinId = runtime . renderer . createSVGSkin ( fixedSvgString , rotationCenter ) ;
26
+ costume . skinId = runtime . renderer . createSVGSkin ( svgString , rotationCenter ) ;
23
27
costume . size = runtime . renderer . getSkinSize ( costume . skinId ) ;
24
28
// Now we should have a rotationCenter even if we didn't before
25
29
if ( ! rotationCenter ) {
0 commit comments