Converted socketEvents to new format

Still need to rework 'any' type Promises
This commit is contained in:
2024-09-22 18:35:07 +02:00
parent 81428ea0c2
commit a729371741
13 changed files with 279 additions and 202 deletions

View File

@ -10,14 +10,18 @@ type Payload = {
tags: string[]
}
/**
* Handle game master tile update event
* @param socket
* @param io
*/
export default function (io: Server, socket: TSocket) {
socket.on('gm:tile:update', async (data: Payload, callback: (success: boolean) => void) => {
const character = await characterRepository.getById(socket.characterId as number)
export default class TileUpdateEvent {
constructor(
private readonly io: Server,
private readonly socket: TSocket
) {}
public listen(): void {
this.socket.on('gm:tile:update', this.handleTileUpdate.bind(this))
}
private async handleTileUpdate(data: Payload, callback: (success: boolean) => void): Promise<void> {
const character = await characterRepository.getById(this.socket.characterId as number)
if (!character) return callback(false)
if (character.role !== 'gm') {
@ -40,5 +44,5 @@ export default function (io: Server, socket: TSocket) {
console.error(error)
callback(false)
}
})
}
}
}