mirror of
https://github.com/scratchfoundation/scratch-render.git
synced 2025-07-30 08:00:04 -04:00
Merge pull request #122 from cwillisf/remove-url-handling
Remove `createSkinFromURL` and related code
This commit is contained in:
commit
1063f68572
3 changed files with 5 additions and 94 deletions
|
@ -44,7 +44,6 @@
|
|||
"travis-after-all": "^1.4.4",
|
||||
"twgl.js": "3.2.0",
|
||||
"webpack": "^2.2.1",
|
||||
"webpack-dev-server": "^2.4.1",
|
||||
"xhr": "2.4.0"
|
||||
"webpack-dev-server": "^2.4.1"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,4 @@
|
|||
/** @module RenderConstants */
|
||||
const DEFAULT_SKIN = {
|
||||
squirrel: 'https://cdn.assets.scratch.mit.edu/internalapi/asset/7e24c99c1b853e52f8e7f9004416fa34.png/get/',
|
||||
bus: 'https://cdn.assets.scratch.mit.edu/internalapi/asset/66895930177178ea01d9e610917f8acf.png/get/',
|
||||
scratch_cat: 'https://cdn.assets.scratch.mit.edu/internalapi/asset/09dc888b0b7df19f70d81588ae73420e.svg/get/',
|
||||
gradient: 'https://cdn.assets.scratch.mit.edu/internalapi/asset/a49ff276b9b8f997a1ae163992c2c145.png/get/'
|
||||
}.squirrel;
|
||||
|
||||
/**
|
||||
* Various constants meant for use throughout the renderer.
|
||||
|
@ -17,13 +11,6 @@ module.exports = {
|
|||
*/
|
||||
ID_NONE: -1,
|
||||
|
||||
/**
|
||||
* The URL to use as the default skin for a Drawable.
|
||||
* @todo Remove this in favor of falling back on a built-in skin.
|
||||
* @const {string}
|
||||
*/
|
||||
DEFAULT_SKIN: DEFAULT_SKIN,
|
||||
|
||||
/**
|
||||
* Optimize for fewer than this number of Drawables sharing the same Skin.
|
||||
* Going above this may cause middleware warnings or a performance penalty but should otherwise behave correctly.
|
||||
|
|
|
@ -2,7 +2,6 @@ const EventEmitter = require('events');
|
|||
|
||||
const hull = require('hull.js');
|
||||
const twgl = require('twgl.js');
|
||||
const xhr = require('xhr');
|
||||
|
||||
const BitmapSkin = require('./BitmapSkin');
|
||||
const Drawable = require('./Drawable');
|
||||
|
@ -84,9 +83,6 @@ class RenderWebGL extends EventEmitter {
|
|||
/** @type {module:twgl/m4.Mat4} */
|
||||
this._projection = twgl.m4.identity();
|
||||
|
||||
/** @type {Object.<string,int>} */
|
||||
this._skinUrlMap = {};
|
||||
|
||||
/** @type {ShaderManager} */
|
||||
this._shaderManager = new ShaderManager(gl);
|
||||
|
||||
|
@ -184,70 +180,6 @@ class RenderWebGL extends EventEmitter {
|
|||
this.emit(RenderConstants.Events.NativeSizeChanged, {newSize: this._nativeSize});
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a skin by loading a bitmap or vector image from a URL, or reuse an existing skin created this way.
|
||||
* WARNING: This method is deprecated and will be removed in the near future.
|
||||
* Use `createBitmapSkin` or `createSVGSkin` instead.
|
||||
* @param {!string} skinUrl The URL of the skin.
|
||||
* @param {!int} [costumeResolution] Optional: resolution for the skin. Ignored unless creating a new Bitmap skin.
|
||||
* @param {?Array<number>} rotationCenter Optional: rotation center of the skin. If not supplied, the center of the
|
||||
* skin will be used.
|
||||
* @returns {!int} The ID of the Skin.
|
||||
* @deprecated
|
||||
*/
|
||||
createSkinFromURL (skinUrl, costumeResolution, rotationCenter) {
|
||||
if (this._skinUrlMap.hasOwnProperty(skinUrl)) {
|
||||
const existingId = this._skinUrlMap[skinUrl];
|
||||
|
||||
// Make sure the "existing" skin hasn't been destroyed
|
||||
if (this._allSkins[existingId]) {
|
||||
return existingId;
|
||||
}
|
||||
}
|
||||
|
||||
const skinId = this._nextSkinId++;
|
||||
this._skinUrlMap[skinUrl] = skinId;
|
||||
|
||||
let newSkin;
|
||||
let isVector;
|
||||
|
||||
const ext = skinUrl.substring(skinUrl.lastIndexOf('.') + 1);
|
||||
switch (ext) {
|
||||
case 'svg':
|
||||
case 'svg/get/':
|
||||
case 'svgz':
|
||||
case 'svgz/get/':
|
||||
isVector = true;
|
||||
break;
|
||||
default:
|
||||
isVector = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if (isVector) {
|
||||
newSkin = new SVGSkin(skinId, this);
|
||||
xhr.get({
|
||||
useXDR: true,
|
||||
url: skinUrl
|
||||
}, (err, response, body) => {
|
||||
if (!err) {
|
||||
newSkin.setSVG(body, rotationCenter);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
newSkin = new BitmapSkin(skinId, this);
|
||||
const img = new Image();
|
||||
img.crossOrigin = 'anonymous';
|
||||
img.onload = () => {
|
||||
newSkin.setBitmap(img, costumeResolution, rotationCenter);
|
||||
};
|
||||
img.src = skinUrl;
|
||||
}
|
||||
|
||||
this._allSkins[skinId] = newSkin;
|
||||
return skinId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new bitmap skin from a snapshot of the provided bitmap data.
|
||||
* @param {ImageData|HTMLImageElement|HTMLCanvasElement|HTMLVideoElement} bitmapData - new contents for this skin.
|
||||
|
@ -306,12 +238,11 @@ class RenderWebGL extends EventEmitter {
|
|||
*/
|
||||
createDrawable () {
|
||||
const drawableID = this._nextDrawableId++;
|
||||
const drawable = new Drawable(drawableID, this);
|
||||
const drawable = new Drawable(drawableID);
|
||||
this._allDrawables[drawableID] = drawable;
|
||||
this._drawList.push(drawableID);
|
||||
|
||||
const defaultSkinId = this.createSkinFromURL(RenderConstants.DEFAULT_SKIN);
|
||||
drawable.skin = this._allSkins[defaultSkinId];
|
||||
drawable.skin = null;
|
||||
|
||||
return drawableID;
|
||||
}
|
||||
|
@ -816,12 +747,6 @@ class RenderWebGL extends EventEmitter {
|
|||
*/
|
||||
return;
|
||||
}
|
||||
/** @todo remove this after fully deprecating URL-based skin paths */
|
||||
if ('skin' in properties) {
|
||||
const {skin, costumeResolution, rotationCenter} = properties;
|
||||
const skinId = this.createSkinFromURL(skin, costumeResolution, rotationCenter);
|
||||
drawable.skin = this._allSkins[skinId];
|
||||
}
|
||||
if ('skinId' in properties) {
|
||||
drawable.skin = this._allSkins[properties.skinId];
|
||||
}
|
||||
|
@ -1051,8 +976,8 @@ class RenderWebGL extends EventEmitter {
|
|||
|
||||
const drawableScale = drawable.scale;
|
||||
|
||||
// If the texture isn't ready yet, skip it.
|
||||
if (!drawable.skin.getTexture(drawableScale)) continue;
|
||||
// If the skin or texture isn't ready yet, skip it.
|
||||
if (!drawable.skin || !drawable.skin.getTexture(drawableScale)) continue;
|
||||
|
||||
let effectBits = drawable.getEnabledEffects();
|
||||
effectBits &= opts.hasOwnProperty('effectMask') ? opts.effectMask : effectBits;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue