This commit is contained in:
apple502j 2025-05-04 02:06:25 +00:00 committed by GitHub
commit 62eb172e8f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 47 additions and 1 deletions

View file

@ -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);
}

Binary file not shown.

View 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);
});
});
});