Eustia/project/types/plugin.d.ts

192 lines
4.0 KiB
TypeScript
Raw Normal View History

// 这里包含所有插件导出的函数及变量声明声明的函数会在类型标注中标注到core上
interface PluginDeclaration {
/**
* 使core.addPop或core.plugin.addPop调用
* @param px
* @param py
* @param value
*/
addPop(px: number, py: number, value: string): void;
/**
* 使core.plugin.pop获取
*/
pop: any[];
}
type Forward<T> = {
[K in keyof T as T[K] extends Function
? K extends `_${string}`
? never
: K
: never]: T[K];
};
type ForwardKeys<T> = keyof Forward<T>;
type SpriteMouseEvent = (px: number, py: number) => void;
type SpritKeyEvent = (
key: string,
keyCode: number,
altKey: boolean,
ctrlKey: boolean,
shiftKey: boolean
) => void;
type SpriteWheelEvent = (
deltaY: number,
deltaX: number,
deltaZ: number
) => void;
type SpriteTouchEvent = (...locs: [number, number][]) => void;
interface SpriteEvent {
click: SpriteMouseEvent;
mousedown: SpriteMouseEvent;
mouseup: SpriteMouseEvent;
mouseenter: SpriteMouseEvent;
mouseleave: SpriteMouseEvent;
mousemove: SpriteMouseEvent;
keydown: SpritKeyEvent;
keyup: SpritKeyEvent;
keypress: SpritKeyEvent;
wheel: SpriteWheelEvent;
touchstart: SpriteTouchEvent;
touchend: SpriteTouchEvent;
touchmove: SpriteTouchEvent;
touchcancel: SpriteTouchEvent;
}
declare class Sprite {
/**
* sprite标识符
*/
static count: number;
/**
* sprite的左上角横坐标
*/
x: number;
/**
* sprite的左上角纵坐标
*/
y: number;
/**
* sprite的宽度
*/
width: number;
/**
* sprite的高度
*/
height: number;
/**
* sprite的纵深
*/
zIndex: number;
/**
* sprite的相对模式
*/
reference: 'game' | 'window';
/**
* sprite的canvas元素
*/
canvas: HTMLCanvasElement;
/**
* sprite的context
*/
context: CanvasRenderingContext2D;
/**
* sprite的名称
*/
name: string;
/**
* spirte的唯一标识符
*/
readonly count: number;
/**
* sprite画布
* @param reference
* @param name sprite的名称便core.dymCanvas获取
*/
constructor(
x: number,
y: number,
w: number,
h: number,
z: number,
reference?: 'game' | 'window',
name?: string
);
/**
*
*/
init(): void;
/**
* @deprecated
* css特效使css()
*/
setCss(css: string): Sprite;
/**
* css特效
*/
css(css: string): Sprite;
/**
* sprite
* @param isDelta sprite会相对于原先的位置进行移动
*/
move(x: number, y: number, isDelta?: boolean): Sprite;
/**
* sprite的大小
* @param {boolean} styleOnly css效果
*/
resize(w: number, h: number, styleOnly?: boolean): Sprite;
/**
*
*/
rotate(angle: number, cx?: number, cy?: number): Sprite;
/**
*
*/
clear(x?: number, y?: number, w?: number, h?: number): Sprite;
/**
*
*/
destroy(): void;
/**
* registerAction类似
*/
on<K extends keyof SpriteEvent>(type: K, handler: SpriteEvent[K]): void;
/**
*
*/
addEventListener: HTMLCanvasElement['addEventListener'];
/**
*
*/
removeEventListenr: HTMLCanvasElement['removeEventListener'];
}