mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-07-15 16:58:45 -04:00
Attach the svg renderer instead of providing it in order to fix VM tests
This commit is contained in:
parent
aae1e083bc
commit
589dd7d5e0
4 changed files with 20 additions and 6 deletions
|
@ -61,11 +61,11 @@
|
||||||
"scratch-parser": "^4.1.0",
|
"scratch-parser": "^4.1.0",
|
||||||
"scratch-render": "latest",
|
"scratch-render": "latest",
|
||||||
"scratch-storage": "^0.4.0",
|
"scratch-storage": "^0.4.0",
|
||||||
"scratch-svg-renderer": "0.1.0-prerelease.20180423193917",
|
|
||||||
"script-loader": "0.7.2",
|
"script-loader": "0.7.2",
|
||||||
"socket.io-client": "2.0.4",
|
"socket.io-client": "2.0.4",
|
||||||
"stats.js": "^0.17.0",
|
"stats.js": "^0.17.0",
|
||||||
"tap": "^11.0.1",
|
"tap": "^11.0.1",
|
||||||
|
"text-encoding": "0.6.4",
|
||||||
"tiny-worker": "^2.1.1",
|
"tiny-worker": "^2.1.1",
|
||||||
"webpack": "^4.8.0",
|
"webpack": "^4.8.0",
|
||||||
"webpack-cli": "^2.0.15",
|
"webpack-cli": "^2.0.15",
|
||||||
|
|
|
@ -917,6 +917,14 @@ class Runtime extends EventEmitter {
|
||||||
this.renderer = renderer;
|
this.renderer = renderer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attach the storage module
|
* Attach the storage module
|
||||||
* @param {!ScratchStorage} storage The storage module to attach
|
* @param {!ScratchStorage} storage The storage module to attach
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
const StringUtil = require('../util/string-util');
|
const StringUtil = require('../util/string-util');
|
||||||
const log = require('../util/log');
|
const log = require('../util/log');
|
||||||
const SvgRenderer = require('scratch-svg-renderer').SVGRenderer;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize a costume from an asset asynchronously.
|
* Initialize a costume from an asset asynchronously.
|
||||||
|
@ -34,10 +33,9 @@ const loadCostumeFromAsset = function (costume, costumeAsset, runtime, optVersio
|
||||||
if (costumeAsset.assetType === AssetType.ImageVector) {
|
if (costumeAsset.assetType === AssetType.ImageVector) {
|
||||||
let svgString = costumeAsset.decodeText();
|
let svgString = costumeAsset.decodeText();
|
||||||
// SVG Renderer load fixes "quirks" associated with Scratch 2 projects
|
// SVG Renderer load fixes "quirks" associated with Scratch 2 projects
|
||||||
if (optVersion && optVersion === 2) {
|
if (optVersion && optVersion === 2 && runtime.v2SvgAdapter) {
|
||||||
const svgRenderer = new SvgRenderer();
|
runtime.v2SvgAdapter.loadString(svgString);
|
||||||
svgRenderer.loadString(svgString);
|
svgString = runtime.v2SvgAdapter.toString();
|
||||||
svgString = svgRenderer.toString();
|
|
||||||
// Put back into storage
|
// Put back into storage
|
||||||
const storage = runtime.storage;
|
const storage = runtime.storage;
|
||||||
costumeAsset.encodeTextData(svgString, storage.DataFormat.SVG);
|
costumeAsset.encodeTextData(svgString, storage.DataFormat.SVG);
|
||||||
|
|
|
@ -828,6 +828,14 @@ class VirtualMachine extends EventEmitter {
|
||||||
this.runtime.attachRenderer(renderer);
|
this.runtime.attachRenderer(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 storage module for the VM/runtime
|
* Set the storage module for the VM/runtime
|
||||||
* @param {!ScratchStorage} storage The storage module to attach
|
* @param {!ScratchStorage} storage The storage module to attach
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue