mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-01-11 10:39:56 -05:00
Merge pull request #2954 from fsih/removev2SvgAdapter
Remove v2SvgAdapter
This commit is contained in:
commit
d01f04bd3e
6 changed files with 66 additions and 54 deletions
76
package-lock.json
generated
76
package-lock.json
generated
|
@ -9593,7 +9593,6 @@
|
|||
"align-text": {
|
||||
"version": "0.1.4",
|
||||
"bundled": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"kind-of": "^3.0.2",
|
||||
"longest": "^1.0.1",
|
||||
|
@ -9893,13 +9892,11 @@
|
|||
},
|
||||
"camelcase": {
|
||||
"version": "1.2.1",
|
||||
"bundled": true,
|
||||
"optional": true
|
||||
"bundled": true
|
||||
},
|
||||
"center-align": {
|
||||
"version": "0.1.3",
|
||||
"bundled": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"align-text": "^0.1.3",
|
||||
"lazy-cache": "^1.0.3"
|
||||
|
@ -9946,7 +9943,6 @@
|
|||
"cliui": {
|
||||
"version": "2.1.0",
|
||||
"bundled": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"center-align": "^0.1.1",
|
||||
"right-align": "^0.1.1",
|
||||
|
@ -9955,8 +9951,7 @@
|
|||
"dependencies": {
|
||||
"wordwrap": {
|
||||
"version": "0.0.2",
|
||||
"bundled": true,
|
||||
"optional": true
|
||||
"bundled": true
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -10697,8 +10692,7 @@
|
|||
},
|
||||
"lazy-cache": {
|
||||
"version": "1.0.4",
|
||||
"bundled": true,
|
||||
"optional": true
|
||||
"bundled": true
|
||||
},
|
||||
"lcid": {
|
||||
"version": "1.0.0",
|
||||
|
@ -10738,8 +10732,7 @@
|
|||
},
|
||||
"longest": {
|
||||
"version": "1.0.1",
|
||||
"bundled": true,
|
||||
"optional": true
|
||||
"bundled": true
|
||||
},
|
||||
"loose-envify": {
|
||||
"version": "1.3.1",
|
||||
|
@ -11218,7 +11211,6 @@
|
|||
"right-align": {
|
||||
"version": "0.1.3",
|
||||
"bundled": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"align-text": "^0.1.1"
|
||||
}
|
||||
|
@ -11851,7 +11843,6 @@
|
|||
"yargs": {
|
||||
"version": "3.10.0",
|
||||
"bundled": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"camelcase": "^1.0.2",
|
||||
"cliui": "^2.1.0",
|
||||
|
@ -11983,8 +11974,7 @@
|
|||
},
|
||||
"window-size": {
|
||||
"version": "0.1.0",
|
||||
"bundled": true,
|
||||
"optional": true
|
||||
"bundled": true
|
||||
},
|
||||
"wordwrap": {
|
||||
"version": "0.0.3",
|
||||
|
@ -13350,9 +13340,9 @@
|
|||
}
|
||||
},
|
||||
"scratch-blocks": {
|
||||
"version": "0.1.0-prerelease.20210324033606",
|
||||
"resolved": "https://registry.npmjs.org/scratch-blocks/-/scratch-blocks-0.1.0-prerelease.20210324033606.tgz",
|
||||
"integrity": "sha512-zCf7mN64RLME1tA9t2HcDEnf5h5+ziMyksbQj3gsWOUylYLrrYksMBw7wprVEMdPBJwz+4HhpcpkkrCQV1NVnw==",
|
||||
"version": "0.1.0-prerelease.20210331033330",
|
||||
"resolved": "https://registry.npmjs.org/scratch-blocks/-/scratch-blocks-0.1.0-prerelease.20210331033330.tgz",
|
||||
"integrity": "sha512-7Z4R0vwBPr4fJHonj4PIlMhoNMxiDdJzLv0elBeVIqS/eblOkicilmkinTxSWdUdAifMHBTnMOUZmA3jF1+htA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"exports-loader": "0.6.3",
|
||||
|
@ -13438,9 +13428,9 @@
|
|||
}
|
||||
},
|
||||
"scratch-render": {
|
||||
"version": "0.1.0-prerelease.20210317200605",
|
||||
"resolved": "https://registry.npmjs.org/scratch-render/-/scratch-render-0.1.0-prerelease.20210317200605.tgz",
|
||||
"integrity": "sha512-HbWHTOX9X/jlZw0HINKfHkZ8H7GHiyqR8Cj3jKowHrH2r8bTn7K8DfT3Ql81fepMxVqqeKFPPnpvHwvDEaYWKg==",
|
||||
"version": "0.1.0-prerelease.20210325231800",
|
||||
"resolved": "https://registry.npmjs.org/scratch-render/-/scratch-render-0.1.0-prerelease.20210325231800.tgz",
|
||||
"integrity": "sha512-hjiIHRR8SuP/8UKKZ4O+TIJaCZ2wSN6uoEM49jwNjZecAaflBvd5t/OLL3NFQp3q7Ra6ncDi+B7URy7WRdm2fg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"grapheme-breaker": "0.3.2",
|
||||
|
@ -13452,12 +13442,43 @@
|
|||
"scratch-storage": "^1.0.0",
|
||||
"scratch-svg-renderer": "0.2.0-prerelease.20210317184701",
|
||||
"twgl.js": "4.4.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"base64-js": {
|
||||
"version": "1.2.1",
|
||||
"resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.2.1.tgz",
|
||||
"integrity": "sha512-dwVUVIXsBZXwTuwnXI9RK8sBmgq09NDHzyR9SAph9eqk76gKK2JSQmZARC2zRC81JC2QTtxD0ARU5qTS25gIGw==",
|
||||
"dev": true
|
||||
},
|
||||
"scratch-render-fonts": {
|
||||
"version": "1.0.0-prerelease.20200507182347",
|
||||
"resolved": "https://registry.npmjs.org/scratch-render-fonts/-/scratch-render-fonts-1.0.0-prerelease.20200507182347.tgz",
|
||||
"integrity": "sha512-tVt2s7lxsBhme9WKIZTnluMerdJVGEc80QSrDdIIzUvHXGCIYkLh6j7ytwXcyq2UsA34d93op9+I9Bh1SPkQkA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"base64-loader": "1.0.0"
|
||||
}
|
||||
},
|
||||
"scratch-svg-renderer": {
|
||||
"version": "0.2.0-prerelease.20210317184701",
|
||||
"resolved": "https://registry.npmjs.org/scratch-svg-renderer/-/scratch-svg-renderer-0.2.0-prerelease.20210317184701.tgz",
|
||||
"integrity": "sha512-drHD8kRTU//Rqgs8F6oWmBIQi6TunI86Skvp7BfM+mqalds3GzaPjZHKSCFkdkXbHO4i/zAPLvkQtMDdLm4Y6g==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"base64-js": "1.2.1",
|
||||
"base64-loader": "1.0.0",
|
||||
"dompurify": "2.1.1",
|
||||
"minilog": "3.1.0",
|
||||
"scratch-render-fonts": "1.0.0-prerelease.20200507182347",
|
||||
"transformation-matrix": "1.15.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"scratch-render-fonts": {
|
||||
"version": "1.0.0-prerelease.20200507182347",
|
||||
"resolved": "https://registry.npmjs.org/scratch-render-fonts/-/scratch-render-fonts-1.0.0-prerelease.20200507182347.tgz",
|
||||
"integrity": "sha512-tVt2s7lxsBhme9WKIZTnluMerdJVGEc80QSrDdIIzUvHXGCIYkLh6j7ytwXcyq2UsA34d93op9+I9Bh1SPkQkA==",
|
||||
"version": "1.0.0-prerelease.20210401210003",
|
||||
"resolved": "https://registry.npmjs.org/scratch-render-fonts/-/scratch-render-fonts-1.0.0-prerelease.20210401210003.tgz",
|
||||
"integrity": "sha512-sgU+LIXTLKk4f7FZOv/B61dpvmfpnlXFf912T6T4GpOfzx99JPRhXPyErZWuwPz8NEzthkhpO7iF2AqgzUxJfA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"base64-loader": "1.0.0"
|
||||
|
@ -13501,16 +13522,15 @@
|
|||
}
|
||||
},
|
||||
"scratch-svg-renderer": {
|
||||
"version": "0.2.0-prerelease.20210317184701",
|
||||
"resolved": "https://registry.npmjs.org/scratch-svg-renderer/-/scratch-svg-renderer-0.2.0-prerelease.20210317184701.tgz",
|
||||
"integrity": "sha512-drHD8kRTU//Rqgs8F6oWmBIQi6TunI86Skvp7BfM+mqalds3GzaPjZHKSCFkdkXbHO4i/zAPLvkQtMDdLm4Y6g==",
|
||||
"version": "0.2.0-prerelease.20210325225314",
|
||||
"resolved": "https://registry.npmjs.org/scratch-svg-renderer/-/scratch-svg-renderer-0.2.0-prerelease.20210325225314.tgz",
|
||||
"integrity": "sha512-I8UObiVUlaxXOfmKTjXqvLZRmPwgn34vaerXKSv3h2B+AXT6sbkV8PtVqbYAIES2Oq0LFPJ9Vk+gmBzKq6Te+w==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"base64-js": "1.2.1",
|
||||
"base64-loader": "1.0.0",
|
||||
"dompurify": "2.1.1",
|
||||
"minilog": "3.1.0",
|
||||
"scratch-render-fonts": "1.0.0-prerelease.20200507182347",
|
||||
"transformation-matrix": "1.15.0"
|
||||
},
|
||||
"dependencies": {
|
||||
|
|
|
@ -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",
|
||||
|
@ -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",
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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 () {
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue