mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-23 14:32:59 -05:00
VM should do the heavy lifting of saving project to a zip file, and return a promise of the zip to gui.
This commit is contained in:
parent
c0afcd2ab3
commit
d6e248aab8
1 changed files with 17 additions and 6 deletions
|
@ -1,5 +1,6 @@
|
|||
const TextEncoder = require('text-encoding').TextEncoder;
|
||||
const EventEmitter = require('events');
|
||||
const JSZip = require('jszip');
|
||||
|
||||
const centralDispatch = require('./dispatch/central-dispatch');
|
||||
const ExtensionManager = require('./extension-support/extension-manager');
|
||||
|
@ -227,15 +228,25 @@ class VirtualMachine extends EventEmitter {
|
|||
* @returns {string} Project in a Scratch 3.0 JSON representation.
|
||||
*/
|
||||
saveProjectSb3 () {
|
||||
// @todo: Handle other formats, e.g., Scratch 1.4, Scratch 2.0.
|
||||
const soundDescs = serializeSounds(this.runtime);
|
||||
const costumeDescs = serializeCostumes(this.runtime);
|
||||
const projectJson = this.toJSON();
|
||||
|
||||
return {
|
||||
projectJson: this.toJSON(),
|
||||
sounds: soundDescs,
|
||||
costumes: costumeDescs
|
||||
};
|
||||
const zip = new JSZip();
|
||||
|
||||
// Put everything in a zip file
|
||||
// TODO compression?
|
||||
zip.file('project.json', projectJson);
|
||||
for (let i = 0; i < soundDescs.length; i++) {
|
||||
const currSound = soundDescs[i];
|
||||
zip.file(currSound.fileName, currSound.fileContent);
|
||||
}
|
||||
for (let i = 0; i < costumeDescs.length; i++) {
|
||||
const currCostume = costumeDescs[i];
|
||||
zip.file(currCostume.fileName, currCostume.fileContent);
|
||||
}
|
||||
|
||||
return zip.generateAsync({type: 'blob'});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue