# JsPlanet

JsPlanet is a Javascript controller written in TypeScript for Trackmania 2020 dedicated server.

## Usage

```js
// Import the controller
import { JsPlanet } from "jsplanet";

// Instantiate the controller
const jsPlanet = new JsPlanet("localhost", 5000, "SuperAdmin", "SuperAdmin");

jsPlanet.on("ready", () => {
  console.log("JsPlanet is ready to use.");

  // Send a message to all players
  jsPlanet.chatManager.send("Controller has started.");
});

jsPlanet.on("race", (checkpoint) =>
  console.log(
    `${checkpoint.player.nickname} has finished in ${checkpoint.time} ms.`,
  ),
);

// Connect JsPlanet to the Trackmania Xml-RPC server
await jsPlanet.connect();
```

## Contributing

Ensure a supported [NodeJS](https://nodejs.org/en/download/) version is installed with [Yarn](https://yarnpkg.com/getting-started/install) and install dependencies with Yarn.

### Trackmania dev server

Ensure [Docker](https://docs.docker.com/get-docker/) is installed, copy `.env.example` to `.env` and fulfill it. Start a Trackmania development server with docker compose by running

```sh
docker compose -f compose.dev.yml up --build
```

## License

[MIT](https://choosealicense.com/licenses/mit/)
