Compare commits

...

4 Commits

Author SHA1 Message Date
rschamp
0e76810c0d Bump scratch-svg-renderer 2020-10-14 10:18:16 -04:00
rschamp
1bec88a4e2 Handle async blank costumes 2020-10-14 10:16:41 -04:00
picklesrus
1d019ad8ed Bump svg-renderer 2020-10-14 07:03:31 -04:00
Christopher Willis-Ford
0ec6f4f6f0 expose the async nature of createSVGSkin and updateSVGSkin 2020-10-13 17:57:27 -07:00
3 changed files with 16 additions and 8 deletions

View File

@@ -53,7 +53,7 @@
"minilog": "3.1.0",
"raw-loader": "^0.5.1",
"scratch-storage": "^1.0.0",
"scratch-svg-renderer": "0.2.0-prerelease.20200610220938",
"scratch-svg-renderer": "0.2.0-prerelease.20201014130133",
"twgl.js": "4.4.0"
}
}

View File

@@ -350,12 +350,13 @@ class RenderWebGL extends EventEmitter {
* @param {!string} svgData - new SVG to use.
* @param {?Array<number>} rotationCenter Optional: rotation center of the skin. If not supplied, the center of the
* skin will be used
* @param {function} [onSkinReady] - Optional: if present, will be called after the skin loads
* @returns {!int} the ID for the new skin.
*/
createSVGSkin (svgData, rotationCenter) {
createSVGSkin (svgData, rotationCenter, onSkinReady) {
const skinId = this._nextSkinId++;
const newSkin = new SVGSkin(skinId, this);
newSkin.setSVG(svgData, rotationCenter);
newSkin.setSVG(svgData, rotationCenter, onSkinReady);
this._allSkins[skinId] = newSkin;
return skinId;
}
@@ -393,6 +394,7 @@ class RenderWebGL extends EventEmitter {
* @param {!string} svgData - new SVG to use.
* @param {?Array<number>} rotationCenter Optional: rotation center of the skin. If not supplied, the center of the
* skin will be used
* @returns {Promise} - a promise which resolves after the skin has updated
*/
updateSVGSkin (skinId, svgData, rotationCenter) {
if (this._allSkins[skinId] instanceof SVGSkin) {
@@ -401,8 +403,9 @@ class RenderWebGL extends EventEmitter {
}
const newSkin = new SVGSkin(skinId, this);
newSkin.setSVG(svgData, rotationCenter);
this._reskin(skinId, newSkin);
return newSkin.setSVG(svgData, rotationCenter).then(() => {
this._reskin(skinId, newSkin);
});
}
/**

View File

@@ -140,13 +140,15 @@ class SVGSkin extends Skin {
* Set the contents of this skin to a snapshot of the provided SVG data.
* @param {string} svgData - new SVG to use.
* @param {Array<number>} [rotationCenter] - Optional rotation center for the SVG.
* @param {function} [onSkinReady] - Optional: if present, will be called after the skin loads
* @returns {Promise} - a promise which resolves after the SVG is loaded and ready
*/
setSVG (svgData, rotationCenter) {
this._svgRenderer.loadSVG(svgData, false, () => {
setSVG (svgData, rotationCenter, onSkinReady) {
return this._svgRenderer.loadSVG(svgData, false, () => {
const svgSize = this._svgRenderer.size;
if (svgSize[0] === 0 || svgSize[1] === 0) {
super.setEmptyImageData();
return;
return onSkinReady && onSkinReady();
}
const maxDimension = Math.ceil(Math.max(this.size[0], this.size[1]));
@@ -163,6 +165,9 @@ class SVGSkin extends Skin {
this._rotationCenter[1] = rotationCenter[1] - viewOffset[1];
this.emit(Skin.Events.WasAltered);
if (onSkinReady) {
onSkinReady();
}
});
}