mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-23 22:42:27 -05:00
VM receives input buffer representing project to load and unpacks it as zip. This functionality will eventually move to storage.
This commit is contained in:
parent
d6e248aab8
commit
d59a4ffd55
1 changed files with 12 additions and 11 deletions
|
@ -189,21 +189,22 @@ class VirtualMachine extends EventEmitter {
|
||||||
/**
|
/**
|
||||||
* Load a project from a Scratch 3.0 sb3 file containing a project json
|
* Load a project from a Scratch 3.0 sb3 file containing a project json
|
||||||
* and all of the sound and costume files.
|
* and all of the sound and costume files.
|
||||||
* @param {JSZip} sb3File The sb3 file representing the project to load.
|
* @param {Buffer} inputBuffer A buffer representing the project to load.
|
||||||
* @return {!Promise} Promise that resolves after targets are installed.
|
* @return {!Promise} Promise that resolves after targets are installed.
|
||||||
*/
|
*/
|
||||||
loadProjectLocal (sb3File) {
|
loadProjectLocal (inputBuffer) {
|
||||||
// TODO need to handle sb2 files as well, and will possibly merge w/
|
// TODO need to handle sb2 files as well, and will possibly merge w/
|
||||||
// above function
|
// above function
|
||||||
return sb3File.file('project.json').async('string')
|
return JSZip.loadAsync(inputBuffer)
|
||||||
.then(json => {
|
.then(sb3File => {
|
||||||
// TODO look at promise documentation to do this on success,
|
sb3File.file('project.json').async('string')
|
||||||
// but something else on error
|
.then(json => {
|
||||||
|
// TODO error handling for unpacking zip/not finding project.json
|
||||||
json = JSON.parse(json); // TODO catch errors here (validation)
|
json = JSON.parse(json); // TODO catch errors here (validation)
|
||||||
return sb3.deserialize(json, this.runtime, sb3File)
|
return sb3.deserialize(json, this.runtime, sb3File)
|
||||||
.then(({targets, extensions}) =>
|
.then(({targets, extensions}) =>
|
||||||
this.installTargets(targets, extensions, true));
|
this.installTargets(targets, extensions, true));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue