Add explicit function return types

This commit is contained in:
yushijinhun 2020-02-01 19:13:46 +08:00
parent 9baa4d9989
commit 8a474cbc8c
No known key found for this signature in database
GPG Key ID: 5BC167F73EA558E4
6 changed files with 37 additions and 40 deletions

View File

@ -8,5 +8,4 @@ extends:
- 'plugin:@typescript-eslint/recommended' - 'plugin:@typescript-eslint/recommended'
rules: rules:
'@typescript-eslint/no-inferrable-types': off '@typescript-eslint/no-inferrable-types': off
'@typescript-eslint/explicit-function-return-type': off
'@typescript-eslint/interface-name-prefix': off '@typescript-eslint/interface-name-prefix': off

View File

@ -9,7 +9,7 @@ export type AnimationFn = (player: PlayerObject, time: number) => void;
export type Animation = AnimationFn | IAnimation; 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) { if (animation instanceof Function) {
animation(player, time); animation(player, time);
} else { } else {
@ -47,7 +47,7 @@ class AnimationWrapper implements SubAnimationHandle, IAnimation {
this.animation = animation; this.animation = animation;
} }
play(player: PlayerObject, time: number) { play(player: PlayerObject, time: number): void {
if (this.toResetAndRemove) { if (this.toResetAndRemove) {
invokeAnimation(this.animation, player, 0); invokeAnimation(this.animation, player, 0);
this.remove(); this.remove();
@ -68,15 +68,15 @@ class AnimationWrapper implements SubAnimationHandle, IAnimation {
invokeAnimation(this.animation, player, this.progress); invokeAnimation(this.animation, player, this.progress);
} }
reset() { reset(): void {
this.progress = 0; this.progress = 0;
} }
remove() { remove(): void {
// stub get's overriden // stub get's overriden
} }
resetAndRemove() { resetAndRemove(): void {
this.toResetAndRemove = true; this.toResetAndRemove = true;
} }
} }
@ -87,14 +87,14 @@ export class CompositeAnimation implements IAnimation {
add(animation: Animation): AnimationHandle { add(animation: Animation): AnimationHandle {
const handle = new AnimationWrapper(animation); const handle = new AnimationWrapper(animation);
handle.remove = () => { handle.remove = (): void => {
this.handles.delete(handle); this.handles.delete(handle);
}; };
this.handles.add(handle); this.handles.add(handle);
return handle; return handle;
} }
play(player: PlayerObject, time: number) { play(player: PlayerObject, time: number): void {
this.handles.forEach(handle => handle.play(player, time)); this.handles.forEach(handle => handle.play(player, time));
} }
} }
@ -104,15 +104,15 @@ export class RootAnimation extends CompositeAnimation implements AnimationHandle
progress: number = 0.0; progress: number = 0.0;
readonly clock: Clock = new Clock(true); readonly clock: Clock = new Clock(true);
get animation() { get animation(): RootAnimation {
return this; return this;
} }
get paused() { get paused(): boolean {
return !this.clock.running; return !this.clock.running;
} }
set paused(value) { set paused(value: boolean) {
if (value) { if (value) {
this.clock.stop(); this.clock.stop();
} else { } else {
@ -128,7 +128,7 @@ export class RootAnimation extends CompositeAnimation implements AnimationHandle
this.play(player, this.progress); this.play(player, this.progress);
} }
reset() { reset(): void {
this.progress = 0; this.progress = 0;
} }
} }

View File

@ -1,6 +1,6 @@
import { BoxGeometry, DoubleSide, FrontSide, Group, Mesh, MeshBasicMaterial, Object3D, Texture, Vector2 } from "three"; 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 [ return [
new Vector2(x1 / w, 1.0 - y2 / h), new Vector2(x1 / w, 1.0 - y2 / h),
new Vector2(x2 / 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); 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); 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] = [];
box.faceVertexUvs[0][0] = [right[3], right[0], right[2]]; box.faceVertexUvs[0][0] = [right[3], right[0], right[2]];
@ -367,7 +367,7 @@ export class SkinObject extends Group {
this.slim = false; this.slim = false;
} }
get slim() { get slim(): boolean {
return this._slim; return this._slim;
} }
@ -376,15 +376,15 @@ export class SkinObject extends Group {
this.modelListeners.forEach(listener => listener()); this.modelListeners.forEach(listener => listener());
} }
private getBodyParts() { private getBodyParts(): Array<BodyPart> {
return this.children.filter(it => it instanceof BodyPart) as 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); this.getBodyParts().forEach(part => part.innerLayer.visible = value);
} }
setOuterLayerVisible(value: boolean) { setOuterLayerVisible(value: boolean): void {
this.getBodyParts().forEach(part => part.outerLayer.visible = value); this.getBodyParts().forEach(part => part.outerLayer.visible = value);
} }
} }

View File

@ -2,7 +2,7 @@ import { SkinViewer } from "./viewer.js";
import { Vector3 } from "three"; import { Vector3 } from "three";
import { OrbitControls } from "three/examples/jsm/controls/OrbitControls.js"; 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); const control = new OrbitControls(skinViewer.camera, skinViewer.renderer.domElement);
// default configuration // default configuration

View File

@ -73,8 +73,8 @@ export class SkinViewer {
// texture loading // texture loading
this.skinImg.crossOrigin = "anonymous"; this.skinImg.crossOrigin = "anonymous";
this.skinImg.onerror = () => console.error("Failed loading " + this.skinImg.src); this.skinImg.onerror = (): void => console.error("Failed loading " + this.skinImg.src);
this.skinImg.onload = () => { this.skinImg.onload = (): void => {
loadSkinToCanvas(this.skinCanvas, this.skinImg); loadSkinToCanvas(this.skinCanvas, this.skinImg);
if (this.detectModel) { if (this.detectModel) {
@ -86,8 +86,8 @@ export class SkinViewer {
}; };
this.capeImg.crossOrigin = "anonymous"; this.capeImg.crossOrigin = "anonymous";
this.capeImg.onerror = () => console.error("Failed loading " + this.capeImg.src); this.capeImg.onerror = (): void => console.error("Failed loading " + this.capeImg.src);
this.capeImg.onload = () => { this.capeImg.onload = (): void => {
loadCapeToCanvas(this.capeCanvas, this.capeImg); loadCapeToCanvas(this.capeCanvas, this.capeImg);
this.capeTexture.needsUpdate = true; this.capeTexture.needsUpdate = true;
@ -106,7 +106,7 @@ export class SkinViewer {
window.requestAnimationFrame(() => this.draw()); window.requestAnimationFrame(() => this.draw());
} }
private draw() { private draw(): void {
if (this.disposed || this._renderPaused) { if (this.disposed || this._renderPaused) {
return; return;
} }
@ -115,17 +115,17 @@ export class SkinViewer {
window.requestAnimationFrame(() => this.draw()); window.requestAnimationFrame(() => this.draw());
} }
protected doRender() { protected doRender(): void {
this.renderer.render(this.scene, this.camera); 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.aspect = width / height;
this.camera.updateProjectionMatrix(); this.camera.updateProjectionMatrix();
this.renderer.setSize(width, height); this.renderer.setSize(width, height);
} }
dispose() { dispose(): void {
this.disposed = true; this.disposed = true;
this.domElement.removeChild(this.renderer.domElement); this.domElement.removeChild(this.renderer.domElement);
this.renderer.dispose(); this.renderer.dispose();
@ -133,7 +133,7 @@ export class SkinViewer {
this.capeTexture.dispose(); this.capeTexture.dispose();
} }
get renderPaused() { get renderPaused(): boolean {
return this._renderPaused; return this._renderPaused;
} }
@ -145,37 +145,37 @@ export class SkinViewer {
} }
} }
get skinUrl() { get skinUrl(): string {
return this.skinImg.src; return this.skinImg.src;
} }
set skinUrl(url) { set skinUrl(url: string) {
this.skinImg.src = url; this.skinImg.src = url;
} }
get capeUrl() { get capeUrl(): string {
return this.capeImg.src; return this.capeImg.src;
} }
set capeUrl(url) { set capeUrl(url: string) {
this.capeImg.src = url; this.capeImg.src = url;
} }
get width() { get width(): number {
const target = new Vector2(); const target = new Vector2();
return this.renderer.getSize(target).width; return this.renderer.getSize(target).width;
} }
set width(newWidth) { set width(newWidth: number) {
this.setSize(newWidth, this.height); this.setSize(newWidth, this.height);
} }
get height() { get height(): number {
const target = new Vector2(); const target = new Vector2();
return this.renderer.getSize(target).height; return this.renderer.getSize(target).height;
} }
set height(newHeight) { set height(newHeight: number) {
this.setSize(this.width, newHeight); this.setSize(this.width, newHeight);
} }
} }

View File

@ -8,8 +8,6 @@
], ],
"target": "es2015", "target": "es2015",
"strict": true, "strict": true,
"noImplicitAny": false,
"strictFunctionTypes": false,
"declaration": true, "declaration": true,
"sourceMap": true, "sourceMap": true,
"outDir": "libs", "outDir": "libs",