Added game events

2025-08-10 16:26:56 +02:00
parent 8403670a98
commit 3f68594a11
2 changed files with 71 additions and 1 deletions

@@ -15,7 +15,7 @@ Controller.call(action, mode, intensity?);
| Argument | Type | Description | | Argument | Type | Description |
| -------------------- | ----------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------- | | -------------------- | ----------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------- |
| action | "left" / "right" / "up" / "down" / "upleft" / "upright" / "downleft" / "downright" / "start" / "select" / "back" / "identify" | The action to send. | | action | "left" / "right" / "up" / "down" / "upleft" / "upright" / "downleft" / "downright" / "start" / "select" / "back" / "identify" | The action to send. |
| mode | "on" / "off" | The ID of the controller. | | mode | "on" / "off" | The mode of the action. |
| (Optional) intensity | number | The intensity of the button press (between 0 and 1). | | (Optional) intensity | number | The intensity of the button press (between 0 and 1). |
### callCustom ### callCustom

@@ -112,3 +112,73 @@ Game.getPlayers();
**Return** [GamePlayer](./ModuleServerAPIGameLibGamePlayer)[] _GamePlayer instances._ **Return** [GamePlayer](./ModuleServerAPIGameLibGamePlayer)[] _GamePlayer instances._
## Events ## Events
### on: playerJoinGame
Triggers when a player joins the game.
```javascript
Game.on('playerJoinGame', (player) => {});
```
| Argument | Type | Description |
| -------- | ------------------------------------------------ | -------------------------------- |
| player | [GamePlayer](./ModuleServerAPIGameLibGamePlayer) | The player that joined the game. |
### on: playerLeaveGame
Triggers when a player leaves the game.
```javascript
Game.on('playerLeaveGame', (player) => {});
```
| Argument | Type | Description |
| -------- | ------------------------------------------------ | -------------------------------- |
| player | [GamePlayer](./ModuleServerAPIGameLibGamePlayer) | The player that leaved the game. |
### on: gameStart
Triggers when the game starts.
```javascript
Game.on('gameStart', () => {});
```
### on: gameStop
Triggers when the game stops.
```javascript
Game.on('gameStop', () => {});
```
### on: action
Receive actions from a players controller.
```javascript
Game.on('action', (player, action, mode, intensity?) => {});
```
| Argument | Type | Description |
| -------------------- | ----------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------- |
| player | [GamePlayer](./ModuleServerAPIGameLibGamePlayer) | The player that leaved the game. |
| action | "left" / "right" / "up" / "down" / "upleft" / "upright" / "downleft" / "downright" / "start" / "select" / "back" / "identify" | The received action. |
| mode | "on" / "off" | The mode of the action. |
| (Optional) intensity | number | \*_Only when control is analog._ The intensity of the action. |
### on: customAction
Receive custom from for a players controller.
```javascript
Game.on('customAction', (player, action, mode, intensity?) => {});
```
| Argument | Type | Description |
| -------------------- | ------------------------------------------------ | ------------------------------------------------------------- |
| player | [GamePlayer](./ModuleServerAPIGameLibGamePlayer) | The player that leaved the game. |
| action | string | The received action. |
| mode | "on" / "off" | The mode of the action. |
| (Optional) intensity | number | \*_Only when control is analog._ The intensity of the action. |