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 {TSocket} from "../../../utilities/Types";
|
||||||
import ZoneRepository from "../../../repositories/ZoneRepository";
|
import ZoneRepository from "../../../repositories/ZoneRepository";
|
||||||
import ZoneManager from "../../../ZoneManager";
|
import ZoneManager from "../../../ZoneManager";
|
||||||
import {Character, Zone} from "@prisma/client";
|
import { Character, Zone, ZoneObject } from '@prisma/client'
|
||||||
|
|
||||||
interface IPayload {
|
interface IPayload {
|
||||||
zoneId: number;
|
zoneId: number;
|
||||||
@ -10,6 +10,7 @@ interface IPayload {
|
|||||||
width: number;
|
width: number;
|
||||||
height: number;
|
height: number;
|
||||||
tiles: string[][];
|
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(`---GM ${socket.character?.id} has updated zone via zone editor.`);
|
||||||
|
|
||||||
console.log(data);
|
|
||||||
|
|
||||||
if (!data.zoneId) {
|
if (!data.zoneId) {
|
||||||
console.log(`---Zone id not provided.`);
|
console.log(`---Zone id not provided.`);
|
||||||
return;
|
return;
|
||||||
@ -43,10 +42,11 @@ export default function (socket: TSocket, io: Server) {
|
|||||||
|
|
||||||
await ZoneRepository.update(
|
await ZoneRepository.update(
|
||||||
data.zoneId,
|
data.zoneId,
|
||||||
data.name,
|
zone.name,
|
||||||
data.width,
|
zone.width,
|
||||||
data.height,
|
zone.height,
|
||||||
data.tiles,
|
data.tiles,
|
||||||
|
data.objects
|
||||||
);
|
);
|
||||||
|
|
||||||
zone = await ZoneRepository.getById(data.zoneId);
|
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
|
import prisma from '../utilities/Prisma'; // Import the global Prisma instance
|
||||||
|
|
||||||
class ZoneRepository {
|
class ZoneRepository {
|
||||||
@ -27,7 +27,11 @@ class ZoneRepository {
|
|||||||
id: id
|
id: id
|
||||||
},
|
},
|
||||||
include: {
|
include: {
|
||||||
zoneObjects: true
|
zoneObjects: {
|
||||||
|
include: {
|
||||||
|
object: true
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (error: any) {
|
} 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 {
|
try {
|
||||||
|
console.log(tiles);
|
||||||
return await prisma.zone.update({
|
return await prisma.zone.update({
|
||||||
where: {
|
where: {
|
||||||
id: id
|
id: id
|
||||||
},
|
},
|
||||||
data: {
|
data: {
|
||||||
name: name,
|
name,
|
||||||
width: width,
|
width,
|
||||||
height: height,
|
height,
|
||||||
tiles: tiles
|
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) {
|
} catch (error: any) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user