Update src/virtual-machine.js
Browse files- src/virtual-machine.js +33 -8
src/virtual-machine.js
CHANGED
|
@@ -19,6 +19,7 @@ const RenderedTarget = require('./sprites/rendered-target');
|
|
| 19 |
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 |
const ExtensionStorage = require('./util/deprecated-extension-storage.js');
|
| 24 |
|
|
@@ -257,6 +258,7 @@ class VirtualMachine extends EventEmitter {
|
|
| 257 |
loadCostume,
|
| 258 |
loadSound,
|
| 259 |
Blocks,
|
|
|
|
| 260 |
StageLayering,
|
| 261 |
Variable,
|
| 262 |
Thread: require('./engine/thread.js'),
|
|
@@ -493,18 +495,25 @@ class VirtualMachine extends EventEmitter {
|
|
| 493 |
return resolve([json, sb1.zip]);
|
| 494 |
}
|
| 495 |
|
| 496 |
-
|
| 497 |
-
if (tag.slice(0, 2) !== 'PK') {
|
| 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]') {
|
| 505 |
input.projectVersion = this.isSB2(input) ? 2 : 3;
|
| 506 |
return resolve([input, null]);
|
| 507 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 508 |
const zip = await JSZip.loadAsync(input);
|
| 509 |
const proj = zip.file('project.json');
|
| 510 |
if (!proj) return reject('No project.json file inside the given project');
|
|
@@ -570,6 +579,22 @@ class VirtualMachine extends EventEmitter {
|
|
| 570 |
for (const file of Object.values(zip.files)) {
|
| 571 |
file.date = date;
|
| 572 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 573 |
return zip;
|
| 574 |
}
|
| 575 |
|
|
@@ -1159,7 +1184,7 @@ class VirtualMachine extends EventEmitter {
|
|
| 1159 |
* @return {AudioBuffer} the sound's audio buffer.
|
| 1160 |
*/
|
| 1161 |
getSoundBuffer (soundIndex) {
|
| 1162 |
-
const id = this.editingTarget.sprite.sounds[soundIndex].soundId;
|
| 1163 |
if (id && this.runtime && this.runtime.audioEngine) {
|
| 1164 |
return this.editingTarget.sprite.soundBank.getSoundPlayer(id).buffer;
|
| 1165 |
}
|
|
|
|
| 19 |
const StageLayering = require('./engine/stage-layering');
|
| 20 |
const Sprite = require('./sprites/sprite');
|
| 21 |
const Blocks = require('./engine/blocks');
|
| 22 |
+
const Comment = require('./engine/comment.js');
|
| 23 |
const formatMessage = require('format-message');
|
| 24 |
const ExtensionStorage = require('./util/deprecated-extension-storage.js');
|
| 25 |
|
|
|
|
| 258 |
loadCostume,
|
| 259 |
loadSound,
|
| 260 |
Blocks,
|
| 261 |
+
Comment,
|
| 262 |
StageLayering,
|
| 263 |
Variable,
|
| 264 |
Thread: require('./engine/thread.js'),
|
|
|
|
| 495 |
return resolve([json, sb1.zip]);
|
| 496 |
}
|
| 497 |
|
| 498 |
+
if (typeof input === 'string') input = JSON.parse(input);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 499 |
// generic objects return [object Object] on stringify
|
| 500 |
if (input.toString() === '[object Object]') {
|
| 501 |
input.projectVersion = this.isSB2(input) ? 2 : 3;
|
| 502 |
return resolve([input, null]);
|
| 503 |
}
|
| 504 |
+
if (tag.slice(0, 2) !== 'PK') {
|
| 505 |
+
// if it isnt a zip, maby its the project.json in ArrayBuffer form
|
| 506 |
+
const decoder = new TextDecoder('UTF-8');
|
| 507 |
+
input = decoder.decode(input);
|
| 508 |
+
|
| 509 |
+
if (typeof input === 'string') input = JSON.parse(input);
|
| 510 |
+
// generic objects return [object Object] on stringify
|
| 511 |
+
if (input.toString() === '[object Object]') {
|
| 512 |
+
input.projectVersion = this.isSB2(input) ? 2 : 3;
|
| 513 |
+
return resolve([input, null]);
|
| 514 |
+
}
|
| 515 |
+
}
|
| 516 |
+
|
| 517 |
const zip = await JSZip.loadAsync(input);
|
| 518 |
const proj = zip.file('project.json');
|
| 519 |
if (!proj) return reject('No project.json file inside the given project');
|
|
|
|
| 579 |
for (const file of Object.values(zip.files)) {
|
| 580 |
file.date = date;
|
| 581 |
}
|
| 582 |
+
|
| 583 |
+
// Tell JSZip to only compress file formats where there will be a significant gain.
|
| 584 |
+
const COMPRESSABLE_FORMATS = [
|
| 585 |
+
'.json',
|
| 586 |
+
'.svg',
|
| 587 |
+
'.wav',
|
| 588 |
+
'.ttf',
|
| 589 |
+
'.otf'
|
| 590 |
+
];
|
| 591 |
+
for (const file of Object.values(zip.files)) {
|
| 592 |
+
if (COMPRESSABLE_FORMATS.some(ext => file.name.endsWith(ext))) {
|
| 593 |
+
file.options.compression = 'DEFLATE';
|
| 594 |
+
} else {
|
| 595 |
+
file.options.compression = 'STORE';
|
| 596 |
+
}
|
| 597 |
+
}
|
| 598 |
return zip;
|
| 599 |
}
|
| 600 |
|
|
|
|
| 1184 |
* @return {AudioBuffer} the sound's audio buffer.
|
| 1185 |
*/
|
| 1186 |
getSoundBuffer (soundIndex) {
|
| 1187 |
+
const id = this.editingTarget.sprite.sounds[soundIndex]?.soundId;
|
| 1188 |
if (id && this.runtime && this.runtime.audioEngine) {
|
| 1189 |
return this.editingTarget.sprite.soundBank.getSoundPlayer(id).buffer;
|
| 1190 |
}
|