33 lines
857 B
TypeScript
33 lines
857 B
TypeScript
import { Tile } from '@prisma/client'
|
|
import { Server } from 'socket.io'
|
|
|
|
import { TSocket } from '#application/types'
|
|
import characterRepository from '#repositories/characterRepository'
|
|
import TileRepository from '#repositories/tileRepository'
|
|
|
|
interface IPayload {}
|
|
|
|
export default class TileListEvent {
|
|
constructor(
|
|
private readonly io: Server,
|
|
private readonly socket: TSocket
|
|
) {}
|
|
|
|
public listen(): void {
|
|
this.socket.on('gm:tile:list', this.handleEvent.bind(this))
|
|
}
|
|
|
|
private async handleEvent(data: any, callback: (response: Tile[]) => void): Promise<void> {
|
|
const character = await characterRepository.getById(this.socket.characterId as number)
|
|
if (!character) return
|
|
|
|
if (character.role !== 'gm') {
|
|
return
|
|
}
|
|
|
|
// get all tiles
|
|
const tiles = await TileRepository.getAll()
|
|
callback(tiles)
|
|
}
|
|
}
|