diff --git a/src/engine/runtime.js b/src/engine/runtime.js index 92cd2f6b4..f1e056c7f 100644 --- a/src/engine/runtime.js +++ b/src/engine/runtime.js @@ -1557,14 +1557,6 @@ class Runtime extends EventEmitter { this.renderer.setLayerGroupOrdering(StageLayering.LAYER_GROUPS); } - /** - * Set the svg adapter, which converts scratch 2 svgs to scratch 3 svgs - * @param {!SvgRenderer} svgAdapter The adapter to attach - */ - attachV2SVGAdapter (svgAdapter) { - this.v2SvgAdapter = svgAdapter; - } - /** * Set the bitmap adapter for the VM/runtime, which converts scratch 2 * bitmaps to scratch 3 bitmaps. (Scratch 3 bitmaps are all bitmap resolution 2) diff --git a/src/import/load-costume.js b/src/import/load-costume.js index 2db12e13b..7323260d4 100644 --- a/src/import/load-costume.js +++ b/src/import/load-costume.js @@ -1,21 +1,22 @@ const StringUtil = require('../util/string-util'); const log = require('../util/log'); +const {loadSvgString, serializeSvgToString} = require('scratch-svg-renderer'); const loadVector_ = function (costume, runtime, rotationCenter, optVersion) { return new Promise(resolve => { let svgString = costume.asset.decodeText(); - // SVG Renderer load fixes "quirks" associated with Scratch 2 projects - if (optVersion && optVersion === 2 && !runtime.v2SvgAdapter) { - log.error('No V2 SVG adapter present; SVGs may not render correctly.'); - } else if (optVersion && optVersion === 2 && runtime.v2SvgAdapter) { - runtime.v2SvgAdapter.loadString(svgString, true /* fromVersion2 */); - svgString = runtime.v2SvgAdapter.toString(); - // Put back into storage + // scratch-svg-renderer fixes syntax that causes loading issues, + // and if optVersion is 2, fixes "quirks" associated with Scratch 2 SVGs, + const svgText = serializeSvgToString(loadSvgString(svgString, optVersion === 2/* fromVersion2 */)); + + // If the string changed, put back into storage + if (svgString !== svgText) { const storage = runtime.storage; - costume.asset.encodeTextData(svgString, storage.DataFormat.SVG, true); + costume.asset.encodeTextData(svgText, storage.DataFormat.SVG, true); costume.assetId = costume.asset.assetId; costume.md5 = `${costume.assetId}.${costume.dataFormat}`; } + // createSVGSkin does the right thing if rotationCenter isn't provided, so it's okay if it's // undefined here costume.skinId = runtime.renderer.createSVGSkin(svgString, rotationCenter); diff --git a/src/virtual-machine.js b/src/virtual-machine.js index 4fbd20281..f894c4eb1 100644 --- a/src/virtual-machine.js +++ b/src/virtual-machine.js @@ -1087,14 +1087,6 @@ class VirtualMachine extends EventEmitter { return this.runtime && this.runtime.renderer; } - /** - * Set the svg adapter for the VM/runtime, which converts scratch 2 svgs to scratch 3 svgs - * @param {!SvgRenderer} svgAdapter The adapter to attach - */ - attachV2SVGAdapter (svgAdapter) { - this.runtime.attachV2SVGAdapter(svgAdapter); - } - /** * Set the bitmap adapter for the VM/runtime, which converts scratch 2 * bitmaps to scratch 3 bitmaps. (Scratch 3 bitmaps are all bitmap resolution 2)