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