Skip to content

Commit ef4fc63

Browse files
committed
Add isMetricsReady for use in bounds computation
Bounds computations don't need to get a fully updated copy of the skin's texture. It just needs to know the size and rotation center, which is what this method can check for. Default implementation defaults to !!getTexture([100, 100]) for compatibility with quirks relying on the old behavior. The getTexture() functions in scratch-render don't fall prey to issues such as TurboWarp/extensions#2207 so this default implementation is fine. (TextBubbleSkin almost does, but its drawables are non-interactive) Closes #16
1 parent 8d55eab commit ef4fc63

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/RenderWebGL.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1636,7 +1636,7 @@ class RenderWebGL extends EventEmitter {
16361636
const drawable = this._allDrawables[drawableID];
16371637

16381638
/** @todo remove this once URL-based skin setting is removed. */
1639-
if (!drawable.skin || !drawable.skin.getTexture([100, 100])) return null;
1639+
if (!drawable.skin || !drawable.skin.isMetricsReady()) return null;
16401640

16411641
const bounds = drawable.getFastBounds();
16421642

@@ -1911,7 +1911,7 @@ class RenderWebGL extends EventEmitter {
19111911
if (
19121912
!stampDrawable ||
19131913
!stampDrawable.skin ||
1914-
!stampDrawable.skin.getTexture([100, 100])
1914+
!stampDrawable.skin.isMetricsReady()
19151915
) {
19161916
return;
19171917
}

src/Skin.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,17 @@ class Skin {
115115
return this._emptyImageTexture;
116116
}
117117

118+
/**
119+
* Determine if the skin's size and rotation center properties are accurate.
120+
* Default implementation returns true if getTexture([100, 100]) succeeds
121+
* as this indicates that the skin is ready to be rendered. Child classes
122+
* should override appropriately if getTexture() is known to be slow.
123+
* @returns {boolean} true if size and rotation center are accurate.
124+
*/
125+
isMetricsReady () {
126+
return !!this.getTexture([100, 100]);
127+
}
128+
118129
/**
119130
* Get the bounds of the drawable for determining its fenced position.
120131
* @param {Array<number>} drawable - The Drawable instance this skin is using.

0 commit comments

Comments
 (0)