From c483ae33eef5466c102d3fd48d1817671b02adc2 Mon Sep 17 00:00:00 2001 From: Pig Fang Date: Mon, 5 Feb 2018 09:14:43 +0800 Subject: [PATCH] fix some types defs --- types/animation.d.ts | 22 ++++++++++++++++------ types/model.d.ts | 34 ++++++++++++++++------------------ types/skinview3d.d.ts | 2 +- 3 files changed, 33 insertions(+), 25 deletions(-) diff --git a/types/animation.d.ts b/types/animation.d.ts index b52038e..5e01acf 100644 --- a/types/animation.d.ts +++ b/types/animation.d.ts @@ -1,6 +1,16 @@ import { PlayerObject } from './model' -export type Animation = CompositeAnimation | typeof WalkAnimation +type AnimationFn = (player: PlayerObject, time: number) => void +interface IAnimation { + play(player: PlayerObject, time: number): void +} +export type Animation = + | AnimationFn + | IAnimation + | { + play(player: PlayerObject, time: number): void + [x: string]: any + } declare function invokeAnimation( animation: Animation, @@ -8,8 +18,8 @@ declare function invokeAnimation( time: number ): void -declare class AnimationHandle { - animation: Animation +declare class AnimationHandle implements IAnimation { + readonly animation: Animation paused: boolean speed: number @@ -20,8 +30,8 @@ declare class AnimationHandle { reset(): void } -export class CompositeAnimation { - handles: Set +export class CompositeAnimation implements IAnimation { + readonly handles: Set constructor() @@ -30,4 +40,4 @@ export class CompositeAnimation { play(player: PlayerObject, time: number): void } -export function WalkAnimation(player: PlayerObject, time: number): void +export const WalkAnimation: AnimationFn diff --git a/types/model.d.ts b/types/model.d.ts index 2d08d9e..5a48b3c 100644 --- a/types/model.d.ts +++ b/types/model.d.ts @@ -1,37 +1,35 @@ import * as THREE from 'three' -type Material = THREE.Material | THREE.Material[] - export class SkinObject extends THREE.Group { - head: THREE.Group - body: THREE.Group - rightArm: THREE.Group - leftArm: THREE.Group - rightLeg: THREE.Group - leftLeg: THREE.Group + readonly head: THREE.Group + readonly body: THREE.Group + readonly rightArm: THREE.Group + readonly leftArm: THREE.Group + readonly rightLeg: THREE.Group + readonly leftLeg: THREE.Group constructor( isSlim: boolean, - layer1Material: Material, - layer2Material: Material + layer1Material: THREE.Material, + layer2Material: THREE.Material ) } export class CapeObject extends THREE.Group { - cape: THREE.Mesh + readonly cape: THREE.Mesh - constructor(capeMaterial: Material) + constructor(capeMaterial: THREE.Material) } export class PlayerObject extends THREE.Group { - slim: boolean - skin: SkinObject - cape: CapeObject + readonly slim: boolean + readonly skin: SkinObject + readonly cape: CapeObject constructor( isSlim: boolean, - layer1Material: Material, - layer2Material: Material, - capeMaterial: Material + layer1Material: THREE.Material, + layer2Material: THREE.Material, + capeMaterial: THREE.Material ) } diff --git a/types/skinview3d.d.ts b/types/skinview3d.d.ts index 3c38e53..2836014 100644 --- a/types/skinview3d.d.ts +++ b/types/skinview3d.d.ts @@ -1,3 +1,3 @@ -export { CompositeAnimation, WalkAnimation } from './animation' +export { CompositeAnimation, WalkAnimation, Animation } from './animation' export { SkinViewer, SkinControl } from './viewer' export { SkinObject, CapeObject, PlayerObject } from './model'