Export isSlimSkin function
This commit is contained in:
parent
a4bd8bc706
commit
b0230472d5
|
|
@ -1,6 +1,18 @@
|
|||
export { SkinObject, CapeObject, PlayerObject } from "./model";
|
||||
export { SkinViewer } from "./viewer";
|
||||
export { OrbitControls, createOrbitControls } from "./orbit_controls";
|
||||
export {
|
||||
SkinObject,
|
||||
CapeObject,
|
||||
PlayerObject
|
||||
} from "./model";
|
||||
|
||||
export {
|
||||
SkinViewer
|
||||
} from "./viewer";
|
||||
|
||||
export {
|
||||
OrbitControls,
|
||||
createOrbitControls
|
||||
} from "./orbit_controls";
|
||||
|
||||
export {
|
||||
invokeAnimation,
|
||||
CompositeAnimation,
|
||||
|
|
@ -8,3 +20,7 @@ export {
|
|||
RunningAnimation,
|
||||
RotatingAnimation
|
||||
} from "./animation";
|
||||
|
||||
export {
|
||||
isSlimSkin
|
||||
} from "./utils";
|
||||
|
|
|
|||
26
src/utils.js
26
src/utils.js
|
|
@ -115,7 +115,7 @@ function loadCapeToCanvas(canvas, image) {
|
|||
context.drawImage(image, 0, 0, image.width, image.height);
|
||||
}
|
||||
|
||||
function isSlimSkin(canvas) {
|
||||
function isSlimSkin(canvasOrImage) {
|
||||
// Detects whether the skin is default or slim.
|
||||
//
|
||||
// The right arm area of *default* skins:
|
||||
|
|
@ -157,13 +157,23 @@ function isSlimSkin(canvas) {
|
|||
// If there is a transparent pixel in any of the 4 unused areas, the skin must be slim,
|
||||
// as transparent pixels are not allowed in the first layer.
|
||||
|
||||
let scale = computeSkinScale(canvas.width);
|
||||
let context = canvas.getContext("2d");
|
||||
let checkArea = (x, y, w, h) => hasTransparency(context, x * scale, y * scale, w * scale, h * scale);
|
||||
return checkArea(50, 16, 2, 4) ||
|
||||
checkArea(54, 20, 2, 12) ||
|
||||
checkArea(42, 48, 2, 4) ||
|
||||
checkArea(46, 52, 2, 12);
|
||||
if (canvasOrImage instanceof HTMLCanvasElement) {
|
||||
let canvas = canvasOrImage;
|
||||
let scale = computeSkinScale(canvas.width);
|
||||
let context = canvas.getContext("2d");
|
||||
let checkArea = (x, y, w, h) => hasTransparency(context, x * scale, y * scale, w * scale, h * scale);
|
||||
return checkArea(50, 16, 2, 4) ||
|
||||
checkArea(54, 20, 2, 12) ||
|
||||
checkArea(42, 48, 2, 4) ||
|
||||
checkArea(46, 52, 2, 12);
|
||||
} else if (canvasOrImage instanceof HTMLImageElement) {
|
||||
let image = canvasOrImage;
|
||||
let canvas = document.createElement("canvas");
|
||||
loadSkinToCanvas(canvas, image);
|
||||
return isSlimSkin(canvas);
|
||||
} else {
|
||||
throw `Illegal argument: ${canvasOrImage}`;
|
||||
}
|
||||
}
|
||||
|
||||
export { isSlimSkin, loadSkinToCanvas, loadCapeToCanvas };
|
||||
|
|
|
|||
|
|
@ -2,3 +2,4 @@ export * from "./model";
|
|||
export * from "./animation";
|
||||
export * from "./viewer";
|
||||
export * from "./orbit_controls";
|
||||
export * from "./utils";
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
export function isSlimSkin(skinImage: HTMLImageElement): boolean;
|
||||
Loading…
Reference in New Issue