mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-06-13 22:11:14 -04:00
Merge 45334fe892
into f207757ef0
This commit is contained in:
commit
62eb172e8f
3 changed files with 47 additions and 1 deletions
src/serialization
test
|
@ -1108,6 +1108,12 @@ const parseScratchObject = function (object, runtime, extensions, zip, assets) {
|
|||
};
|
||||
|
||||
const deserializeMonitor = function (monitorData, runtime, targets, extensions) {
|
||||
// Do not add hidden monitors from extensions.
|
||||
// Extension monitors do not have state except positions,
|
||||
// and if it's hidden, the positions should not matter.
|
||||
const extensionID = getExtensionIdForOpcode(monitorData.opcode);
|
||||
if (extensionID && !monitorData.visible) return;
|
||||
|
||||
// If the serialized monitor has spriteName defined, look up the sprite
|
||||
// by name in the given list of targets and update the monitor's targetId
|
||||
// to match the sprite's id.
|
||||
|
@ -1206,7 +1212,6 @@ const deserializeMonitor = function (monitorData, runtime, targets, extensions)
|
|||
runtime.monitorBlocks.createBlock(monitorBlock);
|
||||
|
||||
// If the block is from an extension, record it.
|
||||
const extensionID = getExtensionIdForOpcode(monitorBlock.opcode);
|
||||
if (extensionID) {
|
||||
extensions.extensionIDs.add(extensionID);
|
||||
}
|
||||
|
|
BIN
test/fixtures/extension_monitors_deserialization.sb3
vendored
Normal file
BIN
test/fixtures/extension_monitors_deserialization.sb3
vendored
Normal file
Binary file not shown.
41
test/integration/extension_monitors_deserialization.js
Normal file
41
test/integration/extension_monitors_deserialization.js
Normal file
|
@ -0,0 +1,41 @@
|
|||
const path = require('path');
|
||||
const test = require('tap').test;
|
||||
const makeTestStorage = require('../fixtures/make-test-storage');
|
||||
const readFileToBuffer = require('../fixtures/readProjectFile').readFileToBuffer;
|
||||
const VirtualMachine = require('../../src/index');
|
||||
|
||||
const uri = path.resolve(__dirname, '../fixtures/extension_monitors_deserialization.sb3');
|
||||
const project = readFileToBuffer(uri);
|
||||
|
||||
test('hidden extension monitors should not be deserialized', t => {
|
||||
const vm = new VirtualMachine();
|
||||
vm.attachStorage(makeTestStorage());
|
||||
|
||||
// Evaluate playground data and exit
|
||||
vm.on('playgroundData', () => {
|
||||
const monitors = vm.runtime.getMonitorState();
|
||||
// Variable monitor should be deserialized, as it is not extension monitor
|
||||
t.ok(monitors.some(monitor => monitor.mode === 'large' && monitor.opcode === 'data_variable'));
|
||||
// Tempo monitor should be deserialized, as it is visible
|
||||
t.ok(monitors.some(monitor => monitor.opcode === 'music_getTempo'));
|
||||
// Language monitor should NOT be deserialized
|
||||
t.notOk(monitors.some(monitor => monitor.opcode === 'translate_getViewerLanguage'));
|
||||
t.end();
|
||||
process.nextTick(process.exit);
|
||||
});
|
||||
|
||||
// Start VM, load project, and run
|
||||
t.doesNotThrow(() => {
|
||||
vm.start();
|
||||
vm.clear();
|
||||
vm.setCompatibilityMode(false);
|
||||
vm.setTurboMode(false);
|
||||
vm.loadProject(project).then(() => {
|
||||
vm.greenFlag();
|
||||
setTimeout(() => {
|
||||
vm.getPlaygroundData();
|
||||
vm.stopAll();
|
||||
}, 100);
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue