Converted socketEvents to new format
Still need to rework 'any' type Promises
This commit is contained in:
@ -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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user