Zone loading stuffs
This commit is contained in:
parent
c7069c9e98
commit
76207e3bc3
@ -3,8 +3,7 @@ import {TSocket} from '../../../utilities/Types'
|
||||
import { Zone } from '@prisma/client'
|
||||
import ZoneRepository from '../../../repositories/ZoneRepository'
|
||||
|
||||
interface IPayload {
|
||||
}
|
||||
interface IPayload {}
|
||||
|
||||
/**
|
||||
* Handle game master list zones event
|
||||
@ -12,7 +11,7 @@ interface IPayload {
|
||||
* @param io
|
||||
*/
|
||||
export default function (socket: TSocket, io: Server) {
|
||||
socket.on('gm:zone_editor:zone:list', async (data: any, callback: (response: Zone[]) => void) => {
|
||||
socket.on('gm:zone_editor:zone:list', async (data: IPayload, callback: (response: Zone[]) => void) => {
|
||||
|
||||
if (socket.character?.role !== 'gm') {
|
||||
console.log(`---Character #${socket.character?.id} is not a game master.`);
|
||||
|
@ -1,8 +1,7 @@
|
||||
import { Server } from "socket.io";
|
||||
import {TSocket} from "../../../utilities/Types";
|
||||
import ZoneRepository from "../../../repositories/ZoneRepository";
|
||||
import ZoneManager from "../../../ZoneManager";
|
||||
import {Character, Zone} from "@prisma/client";
|
||||
import {Zone} from "@prisma/client";
|
||||
|
||||
interface IPayload {
|
||||
zoneId: number;
|
||||
@ -14,7 +13,7 @@ interface IPayload {
|
||||
* @param io
|
||||
*/
|
||||
export default function (socket: TSocket, io: Server) {
|
||||
socket.on('gm:zone_editor:zone:request', async (data: IPayload) => {
|
||||
socket.on('gm:zone_editor:zone:request', async (data: IPayload, callback: (response: Zone) => void) => {
|
||||
|
||||
if (socket.character?.role !== 'gm') {
|
||||
return;
|
||||
@ -27,14 +26,17 @@ export default function (socket: TSocket, io: Server) {
|
||||
return;
|
||||
}
|
||||
|
||||
const zone = await ZoneRepository.getById(data.zoneId);
|
||||
try {
|
||||
const zone = await ZoneRepository.getById(data.zoneId);
|
||||
|
||||
if (!zone) {
|
||||
console.log(`---Zone not found.`);
|
||||
return;
|
||||
if (!zone) {
|
||||
console.log(`---Zone not found.`);
|
||||
return;
|
||||
}
|
||||
|
||||
callback(zone);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
|
||||
// send over zone to game master
|
||||
socket.emit('gm:zone_editor:zone:load', zone);
|
||||
});
|
||||
}
|
@ -25,6 +25,9 @@ class ZoneRepository {
|
||||
return await prisma.zone.findUnique({
|
||||
where: {
|
||||
id: id
|
||||
},
|
||||
include: {
|
||||
zoneObjects: true
|
||||
}
|
||||
});
|
||||
} catch (error: any) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user