mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-08-11 13:59:23 -04:00
Add updateSVG to tell the renderer about the updated drawing
This commit is contained in:
parent
5f5f7b1684
commit
e5208445ac
1 changed files with 34 additions and 14 deletions
|
@ -340,20 +340,6 @@ class VirtualMachine extends EventEmitter {
|
|||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an SVG string from the renderer.
|
||||
* @param {int} costumeIndex - the index of the sound to be got.
|
||||
* @return {string} the costume's SVG string, or null if it's not an SVG costume.
|
||||
*/
|
||||
getCostumeSVG (costumeIndex) {
|
||||
const id = this.editingTarget.sprite.costumes[costumeIndex].assetId;
|
||||
if (id && this.runtime && this.runtime.storage &&
|
||||
this.runtime.storage.get(id).dataFormat === 'svg') {
|
||||
return this.runtime.storage.get(id).decodeText();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a sound buffer.
|
||||
* @param {int} soundIndex - the index of the sound to be updated.
|
||||
|
@ -375,6 +361,40 @@ class VirtualMachine extends EventEmitter {
|
|||
this.editingTarget.deleteSound(soundIndex);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an SVG string from the renderer.
|
||||
* @param {int} costumeIndex - the index of the sound to be got.
|
||||
* @return {string} the costume's SVG string, or null if it's not an SVG costume.
|
||||
*/
|
||||
getCostumeSvg (costumeIndex) {
|
||||
const id = this.editingTarget.sprite.costumes[costumeIndex].assetId;
|
||||
if (id && this.runtime && this.runtime.storage &&
|
||||
this.runtime.storage.get(id).dataFormat === 'svg') {
|
||||
return this.runtime.storage.get(id).decodeText();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a costume with the given SVG
|
||||
* @param {int} costumeIndex - the index of the costume to be updated.
|
||||
* @param {string} svg - new SVG for the renderer.
|
||||
*/
|
||||
updateSvg (costumeIndex, svg) {
|
||||
const costume = this.editingTarget.sprite.costumes[costumeIndex];
|
||||
if (costume && this.runtime && this.runtime.renderer) {
|
||||
const rotationCenter = [
|
||||
costume.rotationCenterX / costume.bitmapResolution,
|
||||
costume.rotationCenterY / costume.bitmapResolution
|
||||
];
|
||||
|
||||
this.runtime.renderer.updateSVGSkin(costume.skinId, svg, rotationCenter);
|
||||
}
|
||||
// TODO: Also update storage in addition to renderer. Without storage, if you switch
|
||||
// costumes and switch back, you will lose your changes in the paint editor.
|
||||
// TODO: emitTargetsUpdate if we need to update the storage ID on the updated costume;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a backdrop to the stage.
|
||||
* @param {string} md5ext - the MD5 and extension of the backdrop to be loaded.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue