skin3d
Version:
Skin3d is a lightweight JS library that renders any Minecraft skin as a smooth, interactive 3D model you can drop straight into a webpage.
140 lines (139 loc) • 4.11 kB
TypeScript
/**
* @file Animation.ts
* @description This file defines the PlayerAnimation class and its subclasses for animating PlayerObject instances.
* @author Cosmic-fi
* @license MIT
*/
import { PlayerObject } from "./Model.js";
/**
* Abstract base class for animations that can be played on a PlayerObject.
*/
export declare abstract class PlayerAnimation {
/**
* Animation speed multiplier.
* @defaultValue 1.0
*/
speed: number;
/**
* Whether the animation is paused.
* @defaultValue false
*/
paused: boolean;
/** Current animation progress. */
progress: number;
/** Internal id counter for animations. */
private currentId;
private progress0;
private animationObjects;
/**
* Update the animation state.
* @param player - The player object.
* @param deltaTime - Time elapsed since last call.
*/
update(player: PlayerObject, deltaTime: number): void;
/**
* Add a new animation function and return its id.
* @param fn - Animation function (player, progress, id).
* @returns The id of the newly added animation.
*/
addAnimation(fn: (player: PlayerObject, progress: number, currentId: number) => void): number;
/**
* Remove an animation by its id.
* @param id - The id of the animation to remove.
*/
removeAnimation(id: number | undefined): void;
/**
* Subclasses must implement this to update the player state.
* @param player - The player object.
* @param delta - Progress difference since last call.
*/
protected abstract animate(player: PlayerObject, delta: number): void;
}
/**
* Animation from a function.
*/
export declare class FunctionAnimation extends PlayerAnimation {
fn: (player: PlayerObject, progress: number, delta: number) => void;
constructor(fn: (player: PlayerObject, progress: number, delta: number) => void);
/** @inheritdoc */
protected animate(player: PlayerObject, delta: number): void;
}
/**
* Idle animation (arms and cape sway gently).
*/
export declare class IdleAnimation extends PlayerAnimation {
/** @inheritdoc */
protected animate(player: PlayerObject): void;
}
/**
* Walking animation (arms and legs swing, head bobs).
*/
export declare class WalkingAnimation extends PlayerAnimation {
/**
* Whether to shake head when walking.
* @defaultValue true
*/
headBobbing: boolean;
/** @inheritdoc */
protected animate(player: PlayerObject): void;
}
/**
* Running animation (faster, more exaggerated swing).
*/
export declare class RunningAnimation extends PlayerAnimation {
/** @inheritdoc */
protected animate(player: PlayerObject): void;
}
/**
* Flying animation (body rotates, elytra wings expand).
*/
export declare class FlyingAnimation extends PlayerAnimation {
/** @inheritdoc */
protected animate(player: PlayerObject): void;
}
/**
* Waving animation (one arm waves).
*/
export declare class WaveAnimation extends PlayerAnimation {
/**
* Which arm to wave.
* defaultValue "left"
*/
whichArm: "left" | "right";
constructor(whichArm?: "left" | "right");
/** @inheritdoc */
protected animate(player: PlayerObject): void;
}
/**
* Crouch animation (body and limbs move to crouch pose).
*/
export declare class CrouchAnimation extends PlayerAnimation {
/**
* Show progress of animation.
* @defaultValue false
*/
showProgress: boolean;
/**
* Run this animation once.
* @defaultValue false
*/
runOnce: boolean;
private isRunningHitAnimation;
private hitAnimationSpeed;
private erp;
private isCrouched;
/**
* Add the hit animation.
* @param speed - Speed of hit animation (default: same as crouch speed).
*/
addHitAnimation(speed?: number): void;
/** @inheritdoc */
protected animate(player: PlayerObject): void;
}
/**
* Hit animation (right arm swings).
*/
export declare class HitAnimation extends PlayerAnimation {
/** @inheritdoc */
protected animate(player: PlayerObject): void;
}