Skip to content

Commit

Permalink
Merge pull request scratchfoundation#2954 from fsih/removev2SvgAdapter
Browse files Browse the repository at this point in the history
Remove v2SvgAdapter
  • Loading branch information
fsih authored Apr 1, 2021
2 parents 4337b09 + 5559c72 commit d01f04b
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 54 deletions.
76 changes: 48 additions & 28 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
"text-encoding": "0.7.0",
"worker-loader": "^1.1.1"
},
"peerDependencies": {
"scratch-svg-renderer": "^0.2.0-prerelease"
},
"devDependencies": {
"@babel/core": "^7.1.2",
"@babel/preset-env": "^7.1.0",
Expand All @@ -71,8 +74,9 @@
"scratch-blocks": "latest",
"scratch-l10n": "^3.1.20181129221712",
"scratch-render": "latest",
"scratch-render-fonts": "^1.0.0-prerelease.20210401210003",
"scratch-storage": "^1.1.0",
"scratch-svg-renderer": "latest",
"scratch-svg-renderer": "^0.2.0-prerelease.20210325225314",
"script-loader": "0.7.2",
"stats.js": "^0.17.0",
"tap": "^12.0.1",
Expand Down
8 changes: 0 additions & 8 deletions src/engine/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -1566,14 +1566,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)
Expand Down
21 changes: 11 additions & 10 deletions src/import/load-costume.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
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
const svgString = costume.asset.decodeText();
// scratch-svg-renderer fixes syntax that causes loading issues,
// and if optVersion is 2, fixes "quirks" associated with Scratch 2 SVGs,
const fixedSvgString = serializeSvgToString(loadSvgString(svgString, optVersion === 2/* fromVersion2 */));

// If the string changed, put back into storage
if (svgString !== fixedSvgString) {
const storage = runtime.storage;
costume.asset.encodeTextData(svgString, storage.DataFormat.SVG, true);
costume.asset.encodeTextData(fixedSvgString, 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);
costume.skinId = runtime.renderer.createSVGSkin(fixedSvgString, rotationCenter);
costume.size = runtime.renderer.getSkinSize(costume.skinId);
// Now we should have a rotationCenter even if we didn't before
if (!rotationCenter) {
Expand Down
1 change: 0 additions & 1 deletion src/playground/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,6 @@ const runBenchmark = function () {
vm.attachRenderer(renderer);
const audioEngine = new AudioEngine();
vm.attachAudioEngine(audioEngine);
vm.attachV2SVGAdapter(new ScratchSVGRenderer.SVGRenderer());
vm.attachV2BitmapAdapter(new ScratchSVGRenderer.BitmapAdapter());

// Feed mouse events as VM I/O events.
Expand Down
8 changes: 2 additions & 6 deletions src/virtual-machine.js
Original file line number Diff line number Diff line change
Expand Up @@ -1090,12 +1090,8 @@ 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);
// @deprecated
attachV2SVGAdapter () {
}

/**
Expand Down

0 comments on commit d01f04b

Please sign in to comment.