Skip to content

Commit 5fd5199

Browse files
bgdfendbfirsh
authored andcommitted
Add types for exported module
1 parent 606e76e commit 5fd5199

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from "./src/nes";
2+
export * from "./src/controller";

src/controller.d.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
export type ControllerKey = 1 | 2;
2+
3+
export type ButtonKey = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7;
4+
5+
export class Controller {
6+
state: number[];
7+
buttonDown: (key: ControllerKey) => void;
8+
buttonUp: (key: ControllerKey) => void;
9+
10+
static readonly BUTTON_A = 0;
11+
static readonly BUTTON_B = 1;
12+
static readonly BUTTON_SELECT = 2;
13+
static readonly BUTTON_START = 3;
14+
static readonly BUTTON_UP = 4;
15+
static readonly BUTTON_DOWN = 5;
16+
static readonly BUTTON_LEFT = 6;
17+
static readonly BUTTON_RIGHT = 7;
18+
}

src/nes.d.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { ControllerKey, ButtonKey } from "./controller";
2+
3+
export interface EmulatorData {
4+
cpu: string;
5+
mmap: string;
6+
ppu: string;
7+
papu: string;
8+
}
9+
10+
export interface NESOptions {
11+
onFrame?: (buffer: Buffer) => void;
12+
onAudioSample?: (left: number, right: number) => void;
13+
onStatusUpdate?: (status: string) => void;
14+
onBatteryRamWrite?: (address: number, value: number) => void;
15+
preferredFrameRate?: number;
16+
emulateSound?: boolean;
17+
sampleRate?: number;
18+
}
19+
20+
export class NES {
21+
constructor(opts: NESOptions);
22+
stop: () => void;
23+
reset: () => void;
24+
frame: () => void;
25+
buttonDown: (controller: ControllerKey, button: ButtonKey) => void;
26+
buttonUp: (controller: ControllerKey, button: ButtonKey) => void;
27+
zapperMove: (x: number, y: number) => void;
28+
zapperFireDown: () => void;
29+
zapperFireUp: () => void;
30+
getFPS: () => number;
31+
reloadROM: () => void;
32+
loadROM: (data: string | Buffer) => void;
33+
setFramerate: (rate: number) => void;
34+
toJSON: () => EmulatorData;
35+
fromJSON: (data: EmulatorData) => void;
36+
}

0 commit comments

Comments
 (0)