Add explicit function return types
This commit is contained in:
parent
9baa4d9989
commit
8a474cbc8c
|
@ -8,5 +8,4 @@ extends:
|
|||
- 'plugin:@typescript-eslint/recommended'
|
||||
rules:
|
||||
'@typescript-eslint/no-inferrable-types': off
|
||||
'@typescript-eslint/explicit-function-return-type': off
|
||||
'@typescript-eslint/interface-name-prefix': off
|
||||
|
|
|
@ -9,7 +9,7 @@ export type AnimationFn = (player: PlayerObject, time: number) => void;
|
|||
|
||||
export type Animation = AnimationFn | IAnimation;
|
||||
|
||||
export function invokeAnimation(animation: Animation, player: PlayerObject, time: number) {
|
||||
export function invokeAnimation(animation: Animation, player: PlayerObject, time: number): void {
|
||||
if (animation instanceof Function) {
|
||||
animation(player, time);
|
||||
} else {
|
||||
|
@ -47,7 +47,7 @@ class AnimationWrapper implements SubAnimationHandle, IAnimation {
|
|||
this.animation = animation;
|
||||
}
|
||||
|
||||
play(player: PlayerObject, time: number) {
|
||||
play(player: PlayerObject, time: number): void {
|
||||
if (this.toResetAndRemove) {
|
||||
invokeAnimation(this.animation, player, 0);
|
||||
this.remove();
|
||||
|
@ -68,15 +68,15 @@ class AnimationWrapper implements SubAnimationHandle, IAnimation {
|
|||
invokeAnimation(this.animation, player, this.progress);
|
||||
}
|
||||
|
||||
reset() {
|
||||
reset(): void {
|
||||
this.progress = 0;
|
||||
}
|
||||
|
||||
remove() {
|
||||
remove(): void {
|
||||
// stub get's overriden
|
||||
}
|
||||
|
||||
resetAndRemove() {
|
||||
resetAndRemove(): void {
|
||||
this.toResetAndRemove = true;
|
||||
}
|
||||
}
|
||||
|
@ -87,14 +87,14 @@ export class CompositeAnimation implements IAnimation {
|
|||
|
||||
add(animation: Animation): AnimationHandle {
|
||||
const handle = new AnimationWrapper(animation);
|
||||
handle.remove = () => {
|
||||
handle.remove = (): void => {
|
||||
this.handles.delete(handle);
|
||||
};
|
||||
this.handles.add(handle);
|
||||
return handle;
|
||||
}
|
||||
|
||||
play(player: PlayerObject, time: number) {
|
||||
play(player: PlayerObject, time: number): void {
|
||||
this.handles.forEach(handle => handle.play(player, time));
|
||||
}
|
||||
}
|
||||
|
@ -104,15 +104,15 @@ export class RootAnimation extends CompositeAnimation implements AnimationHandle
|
|||
progress: number = 0.0;
|
||||
readonly clock: Clock = new Clock(true);
|
||||
|
||||
get animation() {
|
||||
get animation(): RootAnimation {
|
||||
return this;
|
||||
}
|
||||
|
||||
get paused() {
|
||||
get paused(): boolean {
|
||||
return !this.clock.running;
|
||||
}
|
||||
|
||||
set paused(value) {
|
||||
set paused(value: boolean) {
|
||||
if (value) {
|
||||
this.clock.stop();
|
||||
} else {
|
||||
|
@ -128,7 +128,7 @@ export class RootAnimation extends CompositeAnimation implements AnimationHandle
|
|||
this.play(player, this.progress);
|
||||
}
|
||||
|
||||
reset() {
|
||||
reset(): void {
|
||||
this.progress = 0;
|
||||
}
|
||||
}
|
||||
|
|
16
src/model.ts
16
src/model.ts
|
@ -1,6 +1,6 @@
|
|||
import { BoxGeometry, DoubleSide, FrontSide, Group, Mesh, MeshBasicMaterial, Object3D, Texture, Vector2 } from "three";
|
||||
|
||||
function toFaceVertices(x1: number, y1: number, x2: number, y2: number, w: number, h: number) {
|
||||
function toFaceVertices(x1: number, y1: number, x2: number, y2: number, w: number, h: number): Array<Vector2> {
|
||||
return [
|
||||
new Vector2(x1 / w, 1.0 - y2 / h),
|
||||
new Vector2(x2 / w, 1.0 - y2 / h),
|
||||
|
@ -9,15 +9,15 @@ function toFaceVertices(x1: number, y1: number, x2: number, y2: number, w: numbe
|
|||
];
|
||||
}
|
||||
|
||||
function toSkinVertices(x1: number, y1: number, x2: number, y2: number) {
|
||||
function toSkinVertices(x1: number, y1: number, x2: number, y2: number): Array<Vector2> {
|
||||
return toFaceVertices(x1, y1, x2, y2, 64.0, 64.0);
|
||||
}
|
||||
|
||||
function toCapeVertices(x1: number, y1: number, x2: number, y2: number) {
|
||||
function toCapeVertices(x1: number, y1: number, x2: number, y2: number): Array<Vector2> {
|
||||
return toFaceVertices(x1, y1, x2, y2, 64.0, 32.0);
|
||||
}
|
||||
|
||||
function setVertices(box: BoxGeometry, top: Array<Vector2>, bottom: Array<Vector2>, left: Array<Vector2>, front: Array<Vector2>, right: Array<Vector2>, back: Array<Vector2>) {
|
||||
function setVertices(box: BoxGeometry, top: Array<Vector2>, bottom: Array<Vector2>, left: Array<Vector2>, front: Array<Vector2>, right: Array<Vector2>, back: Array<Vector2>): void {
|
||||
|
||||
box.faceVertexUvs[0] = [];
|
||||
box.faceVertexUvs[0][0] = [right[3], right[0], right[2]];
|
||||
|
@ -367,7 +367,7 @@ export class SkinObject extends Group {
|
|||
this.slim = false;
|
||||
}
|
||||
|
||||
get slim() {
|
||||
get slim(): boolean {
|
||||
return this._slim;
|
||||
}
|
||||
|
||||
|
@ -376,15 +376,15 @@ export class SkinObject extends Group {
|
|||
this.modelListeners.forEach(listener => listener());
|
||||
}
|
||||
|
||||
private getBodyParts() {
|
||||
private getBodyParts(): Array<BodyPart> {
|
||||
return this.children.filter(it => it instanceof BodyPart) as Array<BodyPart>;
|
||||
}
|
||||
|
||||
setInnerLayerVisible(value: boolean) {
|
||||
setInnerLayerVisible(value: boolean): void {
|
||||
this.getBodyParts().forEach(part => part.innerLayer.visible = value);
|
||||
}
|
||||
|
||||
setOuterLayerVisible(value: boolean) {
|
||||
setOuterLayerVisible(value: boolean): void {
|
||||
this.getBodyParts().forEach(part => part.outerLayer.visible = value);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ import { SkinViewer } from "./viewer.js";
|
|||
import { Vector3 } from "three";
|
||||
import { OrbitControls } from "three/examples/jsm/controls/OrbitControls.js";
|
||||
|
||||
export function createOrbitControls(skinViewer: SkinViewer) {
|
||||
export function createOrbitControls(skinViewer: SkinViewer): OrbitControls {
|
||||
const control = new OrbitControls(skinViewer.camera, skinViewer.renderer.domElement);
|
||||
|
||||
// default configuration
|
||||
|
|
|
@ -73,8 +73,8 @@ export class SkinViewer {
|
|||
|
||||
// texture loading
|
||||
this.skinImg.crossOrigin = "anonymous";
|
||||
this.skinImg.onerror = () => console.error("Failed loading " + this.skinImg.src);
|
||||
this.skinImg.onload = () => {
|
||||
this.skinImg.onerror = (): void => console.error("Failed loading " + this.skinImg.src);
|
||||
this.skinImg.onload = (): void => {
|
||||
loadSkinToCanvas(this.skinCanvas, this.skinImg);
|
||||
|
||||
if (this.detectModel) {
|
||||
|
@ -86,8 +86,8 @@ export class SkinViewer {
|
|||
};
|
||||
|
||||
this.capeImg.crossOrigin = "anonymous";
|
||||
this.capeImg.onerror = () => console.error("Failed loading " + this.capeImg.src);
|
||||
this.capeImg.onload = () => {
|
||||
this.capeImg.onerror = (): void => console.error("Failed loading " + this.capeImg.src);
|
||||
this.capeImg.onload = (): void => {
|
||||
loadCapeToCanvas(this.capeCanvas, this.capeImg);
|
||||
|
||||
this.capeTexture.needsUpdate = true;
|
||||
|
@ -106,7 +106,7 @@ export class SkinViewer {
|
|||
window.requestAnimationFrame(() => this.draw());
|
||||
}
|
||||
|
||||
private draw() {
|
||||
private draw(): void {
|
||||
if (this.disposed || this._renderPaused) {
|
||||
return;
|
||||
}
|
||||
|
@ -115,17 +115,17 @@ export class SkinViewer {
|
|||
window.requestAnimationFrame(() => this.draw());
|
||||
}
|
||||
|
||||
protected doRender() {
|
||||
protected doRender(): void {
|
||||
this.renderer.render(this.scene, this.camera);
|
||||
}
|
||||
|
||||
setSize(width: number, height: number) {
|
||||
setSize(width: number, height: number): void {
|
||||
this.camera.aspect = width / height;
|
||||
this.camera.updateProjectionMatrix();
|
||||
this.renderer.setSize(width, height);
|
||||
}
|
||||
|
||||
dispose() {
|
||||
dispose(): void {
|
||||
this.disposed = true;
|
||||
this.domElement.removeChild(this.renderer.domElement);
|
||||
this.renderer.dispose();
|
||||
|
@ -133,7 +133,7 @@ export class SkinViewer {
|
|||
this.capeTexture.dispose();
|
||||
}
|
||||
|
||||
get renderPaused() {
|
||||
get renderPaused(): boolean {
|
||||
return this._renderPaused;
|
||||
}
|
||||
|
||||
|
@ -145,37 +145,37 @@ export class SkinViewer {
|
|||
}
|
||||
}
|
||||
|
||||
get skinUrl() {
|
||||
get skinUrl(): string {
|
||||
return this.skinImg.src;
|
||||
}
|
||||
|
||||
set skinUrl(url) {
|
||||
set skinUrl(url: string) {
|
||||
this.skinImg.src = url;
|
||||
}
|
||||
|
||||
get capeUrl() {
|
||||
get capeUrl(): string {
|
||||
return this.capeImg.src;
|
||||
}
|
||||
|
||||
set capeUrl(url) {
|
||||
set capeUrl(url: string) {
|
||||
this.capeImg.src = url;
|
||||
}
|
||||
|
||||
get width() {
|
||||
get width(): number {
|
||||
const target = new Vector2();
|
||||
return this.renderer.getSize(target).width;
|
||||
}
|
||||
|
||||
set width(newWidth) {
|
||||
set width(newWidth: number) {
|
||||
this.setSize(newWidth, this.height);
|
||||
}
|
||||
|
||||
get height() {
|
||||
get height(): number {
|
||||
const target = new Vector2();
|
||||
return this.renderer.getSize(target).height;
|
||||
}
|
||||
|
||||
set height(newHeight) {
|
||||
set height(newHeight: number) {
|
||||
this.setSize(this.width, newHeight);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,8 +8,6 @@
|
|||
],
|
||||
"target": "es2015",
|
||||
"strict": true,
|
||||
"noImplicitAny": false,
|
||||
"strictFunctionTypes": false,
|
||||
"declaration": true,
|
||||
"sourceMap": true,
|
||||
"outDir": "libs",
|
||||
|
|
Loading…
Reference in New Issue