mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-25 07:22:33 -05:00
Included a function to add sprite 3 to vm
This commit is contained in:
parent
cde801bc17
commit
d033271a1f
1 changed files with 26 additions and 0 deletions
|
@ -394,6 +394,32 @@ class VirtualMachine extends EventEmitter {
|
||||||
this.installTargets(targets, extensions, false));
|
this.installTargets(targets, extensions, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a single sb3 sprite.
|
||||||
|
* @param {string} json JSON string representing the sprite/target.
|
||||||
|
* @returns {Promise} Promise that resolves after the sprite is added
|
||||||
|
*/
|
||||||
|
addSprite3(target) {
|
||||||
|
// Validate & parse
|
||||||
|
if (typeof target !== 'string') {
|
||||||
|
log.error('Failed to parse sprite. Non-string supplied to addSprite3.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
target = JSON.parse(target);
|
||||||
|
if (typeof target !== 'object') {
|
||||||
|
log.error('Failed to parse sprite. JSON supplied to addSprite3 is not an object.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const jsonFormatted = {
|
||||||
|
targets: [target],
|
||||||
|
};
|
||||||
|
|
||||||
|
return sb3
|
||||||
|
.deserialize(jsonFormatted, this.runtime, null)
|
||||||
|
.then(({ targets, extensions }) => this.installTargets(targets, extensions, false));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a costume to the current editing target.
|
* Add a costume to the current editing target.
|
||||||
* @param {string} md5ext - the MD5 and extension of the costume to be loaded.
|
* @param {string} md5ext - the MD5 and extension of the costume to be loaded.
|
||||||
|
|
Loading…
Reference in a new issue