Export isSlimSkin function

This commit is contained in:
yushijinhun 2018-07-05 13:33:07 +08:00
parent a4bd8bc706
commit b0230472d5
No known key found for this signature in database
GPG Key ID: 5BC167F73EA558E4
4 changed files with 39 additions and 11 deletions

View File

@ -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";

View File

@ -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 };

View File

@ -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";

1
types/utils.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export function isSlimSkin(skinImage: HTMLImageElement): boolean;