mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-25 07:22:33 -05:00
Modifying apis to accomodate existing tests.
This commit is contained in:
parent
22be2b15f3
commit
0d55e4c74f
1 changed files with 17 additions and 1 deletions
|
@ -178,10 +178,15 @@ class VirtualMachine extends EventEmitter {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load a Scratch project from a .sb, .sb2, .sb3 or json string.
|
* Load a Scratch project from a .sb, .sb2, .sb3 or json string.
|
||||||
* @param {Buffer} input A buffe or json string representing the project to load.
|
* @param {string | object} input A json string, object, or ArrayBuffer representing the project to load.
|
||||||
* @return {!Promise} Promise that resolves after targets are installed.
|
* @return {!Promise} Promise that resolves after targets are installed.
|
||||||
*/
|
*/
|
||||||
loadProject (input) {
|
loadProject (input) {
|
||||||
|
if (typeof input === 'object' && !(input instanceof ArrayBuffer)) {
|
||||||
|
// validate expects a string or buffer as input
|
||||||
|
input = JSON.stringify(input);
|
||||||
|
}
|
||||||
|
|
||||||
// Clear the current runtime
|
// Clear the current runtime
|
||||||
this.clear();
|
this.clear();
|
||||||
|
|
||||||
|
@ -248,6 +253,17 @@ class VirtualMachine extends EventEmitter {
|
||||||
return JSON.stringify(sb3.serialize(this.runtime));
|
return JSON.stringify(sb3.serialize(this.runtime));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO do we still need this function? Keeping it here so as not to introduce
|
||||||
|
// a breaking change.
|
||||||
|
/**
|
||||||
|
* Load a project from a Scratch JSON representation.
|
||||||
|
* @param {string} json JSON string representing a project.
|
||||||
|
* @returns {Promise} Promise that resolves after the project has loaded
|
||||||
|
*/
|
||||||
|
fromJSON (json) {
|
||||||
|
return this.loadProject(json);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load a project from a Scratch JSON representation.
|
* Load a project from a Scratch JSON representation.
|
||||||
* @param {string} projectJSON JSON string representing a project.
|
* @param {string} projectJSON JSON string representing a project.
|
||||||
|
|
Loading…
Reference in a new issue