Revert "Put Skin Alter Push Back In"

This commit is contained in:
Karishma Chadha
2019-09-26 09:39:05 -05:00
committed by GitHub
parent 303464ddd4
commit 11665299bc
8 changed files with 45 additions and 124 deletions

View File

@@ -30,24 +30,6 @@ class SVGSkin extends Skin {
/** @type {Number} */
this._maxTextureScale = 0;
/**
* The natural size, in Scratch units, of this skin.
* @type {Array<number>}
*/
this.size = [0, 0];
/**
* The viewbox offset of the svg.
* @type {Array<number>}
*/
this._viewOffset = [0, 0];
/**
* The rotation center before offset by _viewOffset.
* @type {Array<number>}
*/
this._rawRotationCenter = [NaN, NaN];
}
/**
@@ -61,17 +43,21 @@ class SVGSkin extends Skin {
super.dispose();
}
/**
* @return {Array<number>} the natural size, in Scratch units, of this skin.
*/
get size () {
return this._svgRenderer.size;
}
/**
* Set the origin, in object space, about which this Skin should rotate.
* @param {number} x - The x coordinate of the new rotation center.
* @param {number} y - The y coordinate of the new rotation center.
*/
setRotationCenter (x, y) {
if (x !== this._rawRotationCenter[0] || y !== this._rawRotationCenter[1]) {
this._rawRotationCenter[0] = x;
this._rawRotationCenter[1] = y;
super.setRotationCenter(x - this._viewOffset[0], y - this._viewOffset[1]);
}
const viewOffset = this._svgRenderer.viewOffset;
super.setRotationCenter(x - viewOffset[0], y - viewOffset[1]);
}
/**
@@ -114,17 +100,7 @@ class SVGSkin extends Skin {
* @fires Skin.event:WasAltered
*/
setSVG (svgData, rotationCenter) {
this._svgRenderer.loadString(svgData);
// Size must be updated synchronously because the VM sets the costume's
// `size` immediately after calling this.
this.size = this._svgRenderer.size;
this._viewOffset = this._svgRenderer.viewOffset;
// Reset rawRotationCenter when we update viewOffset. The rotation
// center used to render will be updated later.
this._rawRotationCenter = [NaN, NaN];
this._svgRenderer._draw(1, () => {
this._svgRenderer.fromString(svgData, 1, () => {
const gl = this._renderer.gl;
this._textureScale = this._maxTextureScale = 1;
@@ -158,8 +134,7 @@ class SVGSkin extends Skin {
}
if (typeof rotationCenter === 'undefined') rotationCenter = this.calculateRotationCenter();
this.setRotationCenter(rotationCenter[0], rotationCenter[1]);
this.setRotationCenter.apply(this, rotationCenter);
this.emit(Skin.Events.WasAltered);
});
}