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