Compare commits
4 Commits
0.1.0-prer
...
0.1.0-prer
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0e76810c0d | ||
|
|
1bec88a4e2 | ||
|
|
1d019ad8ed | ||
|
|
0ec6f4f6f0 |
@@ -53,7 +53,7 @@
|
|||||||
"minilog": "3.1.0",
|
"minilog": "3.1.0",
|
||||||
"raw-loader": "^0.5.1",
|
"raw-loader": "^0.5.1",
|
||||||
"scratch-storage": "^1.0.0",
|
"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"
|
"twgl.js": "4.4.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -350,12 +350,13 @@ class RenderWebGL extends EventEmitter {
|
|||||||
* @param {!string} svgData - new SVG to use.
|
* @param {!string} svgData - new SVG to use.
|
||||||
* @param {?Array<number>} rotationCenter Optional: rotation center of the skin. If not supplied, the center of the
|
* @param {?Array<number>} rotationCenter Optional: rotation center of the skin. If not supplied, the center of the
|
||||||
* skin will be used
|
* 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.
|
* @returns {!int} the ID for the new skin.
|
||||||
*/
|
*/
|
||||||
createSVGSkin (svgData, rotationCenter) {
|
createSVGSkin (svgData, rotationCenter, onSkinReady) {
|
||||||
const skinId = this._nextSkinId++;
|
const skinId = this._nextSkinId++;
|
||||||
const newSkin = new SVGSkin(skinId, this);
|
const newSkin = new SVGSkin(skinId, this);
|
||||||
newSkin.setSVG(svgData, rotationCenter);
|
newSkin.setSVG(svgData, rotationCenter, onSkinReady);
|
||||||
this._allSkins[skinId] = newSkin;
|
this._allSkins[skinId] = newSkin;
|
||||||
return skinId;
|
return skinId;
|
||||||
}
|
}
|
||||||
@@ -393,6 +394,7 @@ class RenderWebGL extends EventEmitter {
|
|||||||
* @param {!string} svgData - new SVG to use.
|
* @param {!string} svgData - new SVG to use.
|
||||||
* @param {?Array<number>} rotationCenter Optional: rotation center of the skin. If not supplied, the center of the
|
* @param {?Array<number>} rotationCenter Optional: rotation center of the skin. If not supplied, the center of the
|
||||||
* skin will be used
|
* skin will be used
|
||||||
|
* @returns {Promise} - a promise which resolves after the skin has updated
|
||||||
*/
|
*/
|
||||||
updateSVGSkin (skinId, svgData, rotationCenter) {
|
updateSVGSkin (skinId, svgData, rotationCenter) {
|
||||||
if (this._allSkins[skinId] instanceof SVGSkin) {
|
if (this._allSkins[skinId] instanceof SVGSkin) {
|
||||||
@@ -401,8 +403,9 @@ class RenderWebGL extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const newSkin = new SVGSkin(skinId, this);
|
const newSkin = new SVGSkin(skinId, this);
|
||||||
newSkin.setSVG(svgData, rotationCenter);
|
return newSkin.setSVG(svgData, rotationCenter).then(() => {
|
||||||
this._reskin(skinId, newSkin);
|
this._reskin(skinId, newSkin);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -140,13 +140,15 @@ class SVGSkin extends Skin {
|
|||||||
* Set the contents of this skin to a snapshot of the provided SVG data.
|
* Set the contents of this skin to a snapshot of the provided SVG data.
|
||||||
* @param {string} svgData - new SVG to use.
|
* @param {string} svgData - new SVG to use.
|
||||||
* @param {Array<number>} [rotationCenter] - Optional rotation center for the SVG.
|
* @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) {
|
setSVG (svgData, rotationCenter, onSkinReady) {
|
||||||
this._svgRenderer.loadSVG(svgData, false, () => {
|
return this._svgRenderer.loadSVG(svgData, false, () => {
|
||||||
const svgSize = this._svgRenderer.size;
|
const svgSize = this._svgRenderer.size;
|
||||||
if (svgSize[0] === 0 || svgSize[1] === 0) {
|
if (svgSize[0] === 0 || svgSize[1] === 0) {
|
||||||
super.setEmptyImageData();
|
super.setEmptyImageData();
|
||||||
return;
|
return onSkinReady && onSkinReady();
|
||||||
}
|
}
|
||||||
|
|
||||||
const maxDimension = Math.ceil(Math.max(this.size[0], this.size[1]));
|
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._rotationCenter[1] = rotationCenter[1] - viewOffset[1];
|
||||||
|
|
||||||
this.emit(Skin.Events.WasAltered);
|
this.emit(Skin.Events.WasAltered);
|
||||||
|
if (onSkinReady) {
|
||||||
|
onSkinReady();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user