# @rpgjs/interpreter

> ## Goal

Latest version **4.2.2** (published 2024-01-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install @rpgjs/interpreter
pnpm add @rpgjs/interpreter
yarn add @rpgjs/interpreter
bun add @rpgjs/interpreter
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.2.2 |
| Published | 2024-01-15 |
| First published | 2023-07-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 3 |
| Unpacked size | 35.3 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Author | Samuel Ronce |
| Maintainers | webcreative5 |

## Links

- npm: https://www.npmjs.com/package/@rpgjs/interpreter
- npm.io page: https://npm.io/package/@rpgjs/interpreter

## Dependencies (3)

- [zod](https://npm.io/package/zod.md) ^3.21.4
- [rxjs](https://npm.io/package/rxjs.md) ^7.8.1
- [@rpgjs/server](https://npm.io/package/@rpgjs/server.md) ^4.2.2

## Recent versions

- 4.2.2 (latest) — 2024-01-15
- 4.2.1 — 2024-01-12
- 4.2.0 — 2023-12-09
- 4.1.3 — 2023-11-17
- 4.1.2 — 2023-10-30
- 4.1.1 — 2023-10-27
- 4.1.0 — 2023-10-20
- 4.0.5 — 2023-10-18
- 4.0.4 — 2023-10-13
- 4.0.3 — 2023-10-10
- 4.0.2 — 2023-10-03
- 4.0.0 — 2023-09-15
- 4.0.0-rc.13 — 2023-09-09
- 4.0.0-rc.12 — 2023-09-08
- 4.0.0-rc.11 — 2023-08-30
- … 11 more at https://npm.io/package/@rpgjs/interpreter/versions

## README

# RPGJS Interpreter

## Goal

The aim is to interpret JSON to trigger server-side commands.
What's the point? This allows you to launch commands on the fly, via an HTTP request for example, without having to write them in hard code.
It gives you greater flexibility. What's more, we can imagine a graphical game editor mode that constructs the events

## Installation

`npm install @rpgjs/interpreter`

## Usage

Example:

```ts
// in player.ts
import { RpgInterpreter} from '@rpgjs/interpreter'
import { RpgPlayer, RpgPlayerHooks } from '@rpgjs/server'


const blocks = {
    block1: {
        id: 'text',
        text: 'Hello World'
    },
    block2: {
        id: 'change_gold',
        value: 10
    },
    block3: {
        id: 'choice',
        text: 'Please ?',
        choices: 1
    },
    block4: {
        id: 'text',
        text: 'Thanks'
    },
    block5: {
        id: 'text',
        text: 'Ok...'
    }
}

const edges = {
    'block1': 'block2',
    'block2': 'block3',
    'block3': {
        blocks: [{
            blockId: 'block5',
            handle: 'choices.0'
        }]
    }
}

const interpreter = new Interpreter(blocks, edges)

const player: RpgPlayerHooks = {
    onConnected(player: RpgPlayer) {
        interpreter
            .start({
                block: 'block1',
                player
            })
            .subscribe()
    }
}

export default player
```

---
_Source: https://npm.io/package/@rpgjs/interpreter · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
