@@ -4,22 +4,28 @@ 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 && ! runtime . v2SvgAdapter ) {
10
+ log . error ( 'No V2 SVG adapter present; SVGs may not render correctly.' ) ;
11
+ } else if ( optVersion && optVersion === 2 && runtime . v2SvgAdapter ) {
12
+ // scratch-svg-renderer fixes syntax that causes loading issues,
13
+ // and if optVersion is 2, fixes "quirks" associated with Scratch 2 SVGs,
14
+ const fixedSvgString = serializeSvgToString ( loadSvgString ( svgString , true /* fromVersion2 */ ) ) ;
11
15
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 } ` ;
16
+ // If the string changed, put back into storage
17
+ if ( svgString !== fixedSvgString ) {
18
+ svgString = fixedSvgString ;
19
+ const storage = runtime . storage ;
20
+ costume . asset . encodeTextData ( fixedSvgString , storage . DataFormat . SVG , true ) ;
21
+ costume . assetId = costume . asset . assetId ;
22
+ costume . md5 = `${ costume . assetId } .${ costume . dataFormat } ` ;
23
+ }
18
24
}
19
25
20
26
// createSVGSkin does the right thing if rotationCenter isn't provided, so it's okay if it's
21
27
// undefined here
22
- costume . skinId = runtime . renderer . createSVGSkin ( fixedSvgString , rotationCenter ) ;
28
+ costume . skinId = runtime . renderer . createSVGSkin ( svgString , rotationCenter ) ;
23
29
costume . size = runtime . renderer . getSkinSize ( costume . skinId ) ;
24
30
// Now we should have a rotationCenter even if we didn't before
25
31
if ( ! rotationCenter ) {
0 commit comments