Update src/virtual-machine.js
Browse files- src/virtual-machine.js +68 -9
src/virtual-machine.js
CHANGED
|
@@ -20,6 +20,7 @@ const StageLayering = require('./engine/stage-layering');
|
|
| 20 |
const Sprite = require('./sprites/sprite');
|
| 21 |
const Blocks = require('./engine/blocks');
|
| 22 |
const formatMessage = require('format-message');
|
|
|
|
| 23 |
|
| 24 |
const Variable = require('./engine/variable');
|
| 25 |
const newBlockIds = require('./util/new-block-ids');
|
|
@@ -242,7 +243,7 @@ class VirtualMachine extends EventEmitter {
|
|
| 242 |
this.addListener('workspaceUpdate', () => {
|
| 243 |
this.extensionManager.refreshDynamicCategorys();
|
| 244 |
});
|
| 245 |
-
|
| 246 |
/**
|
| 247 |
* Export some internal classes for extensions.
|
| 248 |
*/
|
|
@@ -259,8 +260,34 @@ class VirtualMachine extends EventEmitter {
|
|
| 259 |
StageLayering,
|
| 260 |
Variable,
|
| 261 |
Thread: require('./engine/thread.js'),
|
| 262 |
-
execute: require('./engine/execute.js')
|
|
|
|
| 263 |
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 264 |
}
|
| 265 |
|
| 266 |
/**
|
|
@@ -471,7 +498,7 @@ class VirtualMachine extends EventEmitter {
|
|
| 471 |
const decoder = new TextDecoder('UTF-8');
|
| 472 |
input = decoder.decode(input);
|
| 473 |
}
|
| 474 |
-
if (typeof input === 'string')
|
| 475 |
input = JSON.parse(input);
|
| 476 |
// generic objects return [object Object] on stringify
|
| 477 |
if (input.toString() === '[object Object]') {
|
|
@@ -769,19 +796,51 @@ class VirtualMachine extends EventEmitter {
|
|
| 769 |
targets = targets.filter(target => !!target);
|
| 770 |
|
| 771 |
return this._loadExtensions(extensions.extensionIDs, extensions.extensionURLs).then(() => {
|
|
|
|
| 772 |
for (const extension of extensions.extensionIDs) {
|
| 773 |
-
if (
|
| 774 |
-
|
| 775 |
-
|
| 776 |
-
|
| 777 |
-
|
|
|
|
|
|
|
| 778 |
}
|
|
|
|
| 779 |
}
|
|
|
|
|
|
|
|
|
|
| 780 |
targets.forEach(target => {
|
| 781 |
this.runtime.addTarget(target);
|
| 782 |
(/** @type RenderedTarget */ target).updateAllDrawableProperties();
|
| 783 |
// Ensure unique sprite name
|
| 784 |
if (target.isSprite()) this.renameSprite(target.id, target.getName());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 785 |
});
|
| 786 |
// Sort the executable targets by layerOrder.
|
| 787 |
// Remove layerOrder property after use.
|
|
@@ -2007,4 +2066,4 @@ class VirtualMachine extends EventEmitter {
|
|
| 2007 |
}
|
| 2008 |
}
|
| 2009 |
|
| 2010 |
-
module.exports = VirtualMachine;
|
|
|
|
| 20 |
const Sprite = require('./sprites/sprite');
|
| 21 |
const Blocks = require('./engine/blocks');
|
| 22 |
const formatMessage = require('format-message');
|
| 23 |
+
const ExtensionStorage = require('./util/deprecated-extension-storage.js');
|
| 24 |
|
| 25 |
const Variable = require('./engine/variable');
|
| 26 |
const newBlockIds = require('./util/new-block-ids');
|
|
|
|
| 243 |
this.addListener('workspaceUpdate', () => {
|
| 244 |
this.extensionManager.refreshDynamicCategorys();
|
| 245 |
});
|
| 246 |
+
|
| 247 |
/**
|
| 248 |
* Export some internal classes for extensions.
|
| 249 |
*/
|
|
|
|
| 260 |
StageLayering,
|
| 261 |
Variable,
|
| 262 |
Thread: require('./engine/thread.js'),
|
| 263 |
+
execute: require('./engine/execute.js'),
|
| 264 |
+
centralDispatch
|
| 265 |
};
|
| 266 |
+
|
| 267 |
+
/**
|
| 268 |
+
* For comptatibility with TurboWarp's
|
| 269 |
+
* i_will_not_ask_for_help_when_these_break export.
|
| 270 |
+
*/
|
| 271 |
+
this.exports.i_will_not_ask_for_help_when_these_break = () => {
|
| 272 |
+
console.info(
|
| 273 |
+
'Note on i_will_not_ask_for_help_when_these_break: this function is ' +
|
| 274 |
+
'only included for compatibility with TurboWarp, and you should avoid ' +
|
| 275 |
+
'using it when possible.\n' +
|
| 276 |
+
'All indexes are able to be accessed from the regular vm.exports ' +
|
| 277 |
+
'property. Below is a map of all elements here to their vm.exports ' +
|
| 278 |
+
'counterpart:\n' +
|
| 279 |
+
'IRGenerator -> IRGenerator\nJSGenerator -> JSGenerator\nThread -> Thread\n' +
|
| 280 |
+
'execute -> execute\n' +
|
| 281 |
+
'ScriptTreeGenerator -> IRGenerator.exports.ScriptTreeGenerator'
|
| 282 |
+
);
|
| 283 |
+
return {
|
| 284 |
+
IRGenerator,
|
| 285 |
+
JSGenerator,
|
| 286 |
+
ScriptTreeGenerator: IRGenerator.exports.ScriptTreeGenerator,
|
| 287 |
+
Thread: this.exports.Thread,
|
| 288 |
+
execute: this.exports.execute
|
| 289 |
+
}
|
| 290 |
+
}
|
| 291 |
}
|
| 292 |
|
| 293 |
/**
|
|
|
|
| 498 |
const decoder = new TextDecoder('UTF-8');
|
| 499 |
input = decoder.decode(input);
|
| 500 |
}
|
| 501 |
+
if (typeof input === 'string')
|
| 502 |
input = JSON.parse(input);
|
| 503 |
// generic objects return [object Object] on stringify
|
| 504 |
if (input.toString() === '[object Object]') {
|
|
|
|
| 796 |
targets = targets.filter(target => !!target);
|
| 797 |
|
| 798 |
return this._loadExtensions(extensions.extensionIDs, extensions.extensionURLs).then(() => {
|
| 799 |
+
const deprecated_extensionStorage = {};
|
| 800 |
for (const extension of extensions.extensionIDs) {
|
| 801 |
+
if (!extensions.extensionData[extension]) continue;
|
| 802 |
+
if (
|
| 803 |
+
`ext_${extension}` in this.runtime &&
|
| 804 |
+
typeof this.runtime[`ext_${extension}`].deserialize === 'function'
|
| 805 |
+
) {
|
| 806 |
+
this.runtime[`ext_${extension}`].deserialize(extensions.extensionData[extension]);
|
| 807 |
+
continue;
|
| 808 |
}
|
| 809 |
+
deprecated_extensionStorage[extension] = extensions.extensionData[extension];
|
| 810 |
}
|
| 811 |
+
if (deprecated_extensionStorage)
|
| 812 |
+
this.runtime.extensionStorage = ExtensionStorage(deprecated_extensionStorage);
|
| 813 |
+
|
| 814 |
targets.forEach(target => {
|
| 815 |
this.runtime.addTarget(target);
|
| 816 |
(/** @type RenderedTarget */ target).updateAllDrawableProperties();
|
| 817 |
// Ensure unique sprite name
|
| 818 |
if (target.isSprite()) this.renameSprite(target.id, target.getName());
|
| 819 |
+
|
| 820 |
+
if (!("extensionData" in target)) return;
|
| 821 |
+
|
| 822 |
+
const deprecated_extensionStorage_pertarget = {};
|
| 823 |
+
|
| 824 |
+
for (const extension of extensions.extensionIDs) {
|
| 825 |
+
if (!(extension in target.extensionData)) continue;
|
| 826 |
+
|
| 827 |
+
if (
|
| 828 |
+
`ext_${extension}` in this.runtime &&
|
| 829 |
+
typeof this.runtime[`ext_${extension}`].deserializeForTarget === 'function'
|
| 830 |
+
) {
|
| 831 |
+
this.runtime[`ext_${extension}`].deserializeForTarget(
|
| 832 |
+
target.extensionData[extension],
|
| 833 |
+
target,
|
| 834 |
+
);
|
| 835 |
+
continue;
|
| 836 |
+
}
|
| 837 |
+
deprecated_extensionStorage_pertarget[extension] = target.extensionData[extension];
|
| 838 |
+
}
|
| 839 |
+
|
| 840 |
+
if (deprecated_extensionStorage)
|
| 841 |
+
target.extensionStorage = ExtensionStorage(deprecated_extensionStorage_pertarget);
|
| 842 |
+
|
| 843 |
+
delete target["extensionData"]
|
| 844 |
});
|
| 845 |
// Sort the executable targets by layerOrder.
|
| 846 |
// Remove layerOrder property after use.
|
|
|
|
| 2066 |
}
|
| 2067 |
}
|
| 2068 |
|
| 2069 |
+
module.exports = VirtualMachine;
|