mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-24 06:52:40 -05:00
Add optional type param to export sprite API.
This commit is contained in:
parent
f06b8a3943
commit
55a5592ab6
1 changed files with 14 additions and 2 deletions
|
@ -281,7 +281,19 @@ class VirtualMachine extends EventEmitter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
exportSprite (targetId) {
|
/**
|
||||||
|
* Exports a sprite in the sprite3 format.
|
||||||
|
* @param {string} targetId ID of the target to export
|
||||||
|
* @param {string=} optZipType Optional type that the resulting
|
||||||
|
* zip should be outputted in. Options are: base64, binarystring,
|
||||||
|
* array, uint8array, arraybuffer, blob, or nodebuffer. Defaults to
|
||||||
|
* blob if argument not provided.
|
||||||
|
* See https://stuk.github.io/jszip/documentation/api_jszip/generate_async.html#type-option
|
||||||
|
* for more information about these options.
|
||||||
|
* @return {object} A generated zip of the sprite and its assets in the format
|
||||||
|
* specified by optZipType or blob by default.
|
||||||
|
*/
|
||||||
|
exportSprite (targetId, optZipType) {
|
||||||
const soundDescs = serializeSounds(this.runtime, targetId);
|
const soundDescs = serializeSounds(this.runtime, targetId);
|
||||||
const costumeDescs = serializeCostumes(this.runtime, targetId);
|
const costumeDescs = serializeCostumes(this.runtime, targetId);
|
||||||
const spriteJson = JSON.stringify(sb3.serialize(this.runtime, targetId));
|
const spriteJson = JSON.stringify(sb3.serialize(this.runtime, targetId));
|
||||||
|
@ -291,7 +303,7 @@ class VirtualMachine extends EventEmitter {
|
||||||
this._addFileDescsToZip(soundDescs.concat(costumeDescs), zip);
|
this._addFileDescsToZip(soundDescs.concat(costumeDescs), zip);
|
||||||
|
|
||||||
return zip.generateAsync({
|
return zip.generateAsync({
|
||||||
type: 'blob',
|
type: typeof optZipType === 'string' ? optZipType : 'blob',
|
||||||
compression: 'DEFLATE',
|
compression: 'DEFLATE',
|
||||||
compressionOptions: {
|
compressionOptions: {
|
||||||
level: 6
|
level: 6
|
||||||
|
|
Loading…
Reference in a new issue