Skip to content

Commit

Permalink
docs: add docs for the screenshot method
Browse files Browse the repository at this point in the history
  • Loading branch information
arianrhodsandlot committed Jan 5, 2024
1 parent 9f8a1cd commit b6b18c6
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 1 deletion.
3 changes: 2 additions & 1 deletion docs/src/content/docs/apis/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ title: API reference
+ [`resume`](/apis/resume)
+ [`exit`](/apis/exit)
+ [`resize`](/apis/resize)
+ [`press`](/apis/press)
+ [`screenshot`](/apis/screenshot)
+ [`getCanvas`](/apis/get-canvas) (advanced)
+ [`launchEmulator`](/apis/launch-emulator) (advanced)
+ [`getEmscriptenModule`](/apis/get-emscripten-module) (advanced)
+ [`getEmscriptenFS`](/apis/get-emscripten-fs) (advanced)
+ [`press`](/apis/press) (advanced)
+ [`pressDown`](/apis/press-down) (advanced)
+ [`pressUp`](/apis/press-up) (advanced)
15 changes: 15 additions & 0 deletions docs/src/content/docs/apis/screenshot.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
title: screenshot
---

Take a screenshot for the current running game.

## Usage
```js
const nostalgist = await Nostalgist.nes('flappybird.nes')

const blob = await nostalgist.screenshot()
```

## Returns
A `Promise` of the `Blob` of the screenshot.
48 changes: 48 additions & 0 deletions src/nostalgist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,18 @@ export class Nostalgist {
return this.getEmulator().resize(size)
}

/**
* Press a button programmatically. Analog Joysticks are not supported by now.
*
* @see {@link https://nostalgist.js.org/apis/press-down}
*
* @example
* ```js
* const nostalgist = await Nostalgist.nes('flappybird.nes')
*
* const blob = await nostalgist.pressDown('start')
* ```
*/
pressDown(options: string | { button: string; player?: number }) {
const emulator = this.getEmulator()
if (typeof options === 'string') {
Expand All @@ -332,6 +344,18 @@ export class Nostalgist {
return emulator.pressDown(options.button, options.player)
}

/**
* Release it programmatically. Analog Joysticks are not supported by now.
*
* @see {@link https://nostalgist.js.org/apis/press-up}
*
* @example
* ```js
* const nostalgist = await Nostalgist.nes('flappybird.nes')
*
* const blob = await nostalgist.pressUp('start')
* ```
*/
pressUp(options: string | { button: string; player?: number }) {
const emulator = this.getEmulator()
if (typeof options === 'string') {
Expand All @@ -340,6 +364,18 @@ export class Nostalgist {
return emulator.pressUp(options.button, options.player)
}

/**
* Press a button and then release it programmatically. Analog Joysticks are not supported by now.
*
* @see {@link https://nostalgist.js.org/apis/press}
*
* @example
* ```js
* const nostalgist = await Nostalgist.nes('flappybird.nes')
*
* const blob = await nostalgist.press('start')
* ```
*/
press(options: string | { button: string; player?: number; time?: number }) {
const emulator = this.getEmulator()
if (typeof options === 'string') {
Expand All @@ -348,6 +384,18 @@ export class Nostalgist {
return emulator.press(options.button, options.player, options.time)
}

/**
* Take a screenshot for the current running game.
*
* @see {@link https://nostalgist.js.org/apis/screenshot}
*
* @example
* ```js
* const nostalgist = await Nostalgist.nes('flappybird.nes')
*
* const blob = await nostalgist.screenshot()
* ```
*/
screenshot() {
const emulator = this.getEmulator()
return emulator.screenshot()
Expand Down

0 comments on commit b6b18c6

Please sign in to comment.