Fixed creating objects when updating map
This commit is contained in:
parent
4fcb9693b6
commit
37764847a9
@ -2,7 +2,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 { Character, Zone, ZoneObject } from '@prisma/client'
|
||||
|
||||
interface IPayload {
|
||||
zoneId: number;
|
||||
@ -10,6 +10,7 @@ interface IPayload {
|
||||
width: number;
|
||||
height: number;
|
||||
tiles: string[][];
|
||||
objects: ZoneObject[];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -27,8 +28,6 @@ export default function (socket: TSocket, io: Server) {
|
||||
|
||||
console.log(`---GM ${socket.character?.id} has updated zone via zone editor.`);
|
||||
|
||||
console.log(data);
|
||||
|
||||
if (!data.zoneId) {
|
||||
console.log(`---Zone id not provided.`);
|
||||
return;
|
||||
@ -43,10 +42,11 @@ export default function (socket: TSocket, io: Server) {
|
||||
|
||||
await ZoneRepository.update(
|
||||
data.zoneId,
|
||||
data.name,
|
||||
data.width,
|
||||
data.height,
|
||||
zone.name,
|
||||
zone.width,
|
||||
zone.height,
|
||||
data.tiles,
|
||||
data.objects
|
||||
);
|
||||
|
||||
zone = await ZoneRepository.getById(data.zoneId);
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Zone } from '@prisma/client';
|
||||
import { Zone, ZoneObject } from '@prisma/client'
|
||||
import prisma from '../utilities/Prisma'; // Import the global Prisma instance
|
||||
|
||||
class ZoneRepository {
|
||||
@ -27,7 +27,11 @@ class ZoneRepository {
|
||||
id: id
|
||||
},
|
||||
include: {
|
||||
zoneObjects: true
|
||||
zoneObjects: {
|
||||
include: {
|
||||
object: true
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (error: any) {
|
||||
@ -52,17 +56,28 @@ class ZoneRepository {
|
||||
}
|
||||
}
|
||||
|
||||
async update(id: number, name: string, width: number, height: number, tiles: string[][]): Promise<Zone> {
|
||||
async update(id: number, name: string, width: number, height: number, tiles: string[][], objects: ZoneObject[]): Promise<Zone> {
|
||||
try {
|
||||
console.log(tiles);
|
||||
return await prisma.zone.update({
|
||||
where: {
|
||||
id: id
|
||||
},
|
||||
data: {
|
||||
name: name,
|
||||
width: width,
|
||||
height: height,
|
||||
tiles: tiles
|
||||
name,
|
||||
width,
|
||||
height,
|
||||
tiles,
|
||||
zoneObjects: {
|
||||
deleteMany: {
|
||||
zoneId: id // Ensure only objects related to the zone are deleted
|
||||
},
|
||||
create: objects.map(obj => ({
|
||||
objectId: obj.objectId,
|
||||
position_x: obj.position_x,
|
||||
position_y: obj.position_y
|
||||
}))
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (error: any) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user