Skip to content

Instantly share code, notes, and snippets.

@felladrin
Created August 21, 2022 16:52
Show Gist options
  • Save felladrin/cf6ff590fd17cbe7e3b21aa0775d01bb to your computer and use it in GitHub Desktop.
Save felladrin/cf6ff590fd17cbe7e3b21aa0775d01bb to your computer and use it in GitHub Desktop.
TypeScript declarations for "js13k-2d" (https://www.npmjs.com/package/js13k-2d)
declare module "js13k-2d" {
declare interface Point {
x: number;
y: number;
set(xy: number): void;
set(x: number, y: number): void;
}
declare interface Sprite {
position: Point;
alpha: number;
remove(): void;
}
declare interface Layer {
add(sprite: Sprite): void;
}
declare interface Camera {
at: Point;
to: Point;
angle: number;
}
declare interface Frame {
size: Point;
anchor: Point;
uvs: number[];
}
declare type Texture = Frame & {
frame(origin: Point, size: Point, anchor?: Point): Frame;
};
declare const Renderer: {
(canvas: HTMLCanvasElement, options?: any): {
gl: WebGLRenderingContext;
camera: Camera;
background(r: number, g: number, b: number, a: number): void;
layer(z: number): Layer;
add(sprite: Sprite): void;
texture(
source: HTMLImageElement | HTMLCanvasElement,
alphaTest?: number,
smooth?: boolean,
mipmap?: boolean
): Texture;
resize: () => boolean;
render(): void;
};
Point: {
(x?: number, y?: number): Point;
(xy?: number): Point;
};
Sprite: {
(frame: Frame, props?: Partial<Sprite>): Sprite;
};
Layer: {
(z: number): Layer;
};
};
export default Renderer;
}
declare module "js13k-2d/*" {
import Renderer from "js13k-2d";
export default Renderer;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment