Skip to content

Commit

Permalink
Add types for exported module
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Goldstein authored and darthgoldstein committed Nov 24, 2021
1 parent c6cceb2 commit 964e5ce
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
2 changes: 2 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./src/nes";
export * from "./src/controller";
18 changes: 18 additions & 0 deletions src/controller.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export type ControllerKey = 1 | 2;

export type ButtonKey = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7;

export class Controller {
state: number[];
buttonDown: (key: ControllerKey) => void;
buttonUp: (key: ControllerKey) => void;

static readonly BUTTON_A = 0;
static readonly BUTTON_B = 1;
static readonly BUTTON_SELECT = 2;
static readonly BUTTON_START = 3;
static readonly BUTTON_UP = 4;
static readonly BUTTON_DOWN = 5;
static readonly BUTTON_LEFT = 6;
static readonly BUTTON_RIGHT = 7;
}
36 changes: 36 additions & 0 deletions src/nes.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { ControllerKey, ButtonKey } from "./controller";

export interface EmulatorData {
cpu: string;
mmap: string;
ppu: string;
papu: string;
}

export interface NESOptions {
onFrame?: (buffer: Buffer) => void;
onAudioSample?: (left: number, right: number) => void;
onStatusUpdate?: (status: string) => void;
onBatteryRamWrite?: (address: number, value: number) => void;
preferredFrameRate?: number;
emulateSound?: boolean;
sampleRate?: number;
}

export class NES {
constructor(opts: NESOptions);
stop: () => void;
reset: () => void;
frame: () => void;
buttonDown: (controller: ControllerKey, button: ButtonKey) => void;
buttonUp: (controller: ControllerKey, button: ButtonKey) => void;
zapperMove: (x: number, y: number) => void;
zapperFireDown: () => void;
zapperFireUp: () => void;
getFPS: () => number;
reloadROM: () => void;
loadROM: (data: string | Buffer) => void;
setFramerate: (rate: number) => void;
toJSON: () => EmulatorData;
fromJSON: (data: EmulatorData) => void;
}

0 comments on commit 964e5ce

Please sign in to comment.