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