From 893e69244ddfa7cddb5c2f105e936bb4fb4a96cf Mon Sep 17 00:00:00 2001 From: Dennis Postma Date: Sat, 15 Jun 2024 03:15:03 +0200 Subject: [PATCH] worked on wall logics --- package-lock.json | 15 ++++---- .../migration.sql | 25 ++++++++++--- prisma/schema.prisma | 35 +++++++++++++------ src/app/events/GmZoneEditorZoneSave.ts | 6 +++- src/app/repositories/ZoneRepository.ts | 10 +++--- src/app/services/ZoneService.ts | 11 ++++++ 6 files changed, 76 insertions(+), 26 deletions(-) rename prisma/migrations/{20240602200800_init => 20240614234637_init}/migration.sql (66%) diff --git a/package-lock.json b/package-lock.json index a17b5e3..7aebaf2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -320,9 +320,9 @@ } }, "node_modules/acorn": { - "version": "8.11.3", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.11.3.tgz", - "integrity": "sha512-Y9rRfJG5jcKOE0CLisYbojUjIrIEE7AGMzA/Sm4BslANhbS+cDMpgBdcPT91oJ7OuJ9hYJBx59RjbhxVnrF8Xg==", + "version": "8.12.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.12.0.tgz", + "integrity": "sha512-RTvkC4w+KNXrM39/lWCUaG0IbRkWdCv7W/IOW9oU6SawyxulvkQy5HQPVTKxEjczcUvapcrw3cFx/60VN/NRNw==", "license": "MIT", "bin": { "acorn": "bin/acorn" @@ -332,10 +332,13 @@ } }, "node_modules/acorn-walk": { - "version": "8.3.2", - "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.3.2.tgz", - "integrity": "sha512-cjkyv4OtNCIeqhHrfS81QWXoCBPExR/J62oyEqepVw8WaQeSqpW2uhuLPh1m9eWhDuOo/jUXVTlifvesOWp/4A==", + "version": "8.3.3", + "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.3.3.tgz", + "integrity": "sha512-MxXdReSRhGO7VlFe1bRG/oI7/mdLV9B9JJT0N8vZOhF7gFRR5l3M8W9G8JxmKV+JC5mGqJ0QvqfSOLsCPa4nUw==", "license": "MIT", + "dependencies": { + "acorn": "^8.11.0" + }, "engines": { "node": ">=0.4.0" } diff --git a/prisma/migrations/20240602200800_init/migration.sql b/prisma/migrations/20240614234637_init/migration.sql similarity index 66% rename from prisma/migrations/20240602200800_init/migration.sql rename to prisma/migrations/20240614234637_init/migration.sql index a6f9516..ade3ac0 100644 --- a/prisma/migrations/20240602200800_init/migration.sql +++ b/prisma/migrations/20240614234637_init/migration.sql @@ -34,6 +34,20 @@ CREATE TABLE `Zone` ( `width` INTEGER NOT NULL, `height` INTEGER NOT NULL, `tiles` JSON NOT NULL, + `walls` JSON NOT NULL, + `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3), + `updatedAt` DATETIME(3) NOT NULL, + + PRIMARY KEY (`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `ZoneDecoration` ( + `id` INTEGER NOT NULL AUTO_INCREMENT, + `zoneId` INTEGER NOT NULL, + `type` INTEGER NOT NULL, + `position_x` INTEGER NOT NULL, + `position_y` INTEGER NOT NULL, PRIMARY KEY (`id`) ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; @@ -50,13 +64,16 @@ CREATE TABLE `Chat` ( ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; -- AddForeignKey -ALTER TABLE `Character` ADD CONSTRAINT `Character_userId_fkey` FOREIGN KEY (`userId`) REFERENCES `User`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE `Character` ADD CONSTRAINT `Character_userId_fkey` FOREIGN KEY (`userId`) REFERENCES `User`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey -ALTER TABLE `Character` ADD CONSTRAINT `Character_zoneId_fkey` FOREIGN KEY (`zoneId`) REFERENCES `Zone`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE `Character` ADD CONSTRAINT `Character_zoneId_fkey` FOREIGN KEY (`zoneId`) REFERENCES `Zone`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey -ALTER TABLE `Chat` ADD CONSTRAINT `Chat_characterId_fkey` FOREIGN KEY (`characterId`) REFERENCES `Character`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE `ZoneDecoration` ADD CONSTRAINT `ZoneDecoration_zoneId_fkey` FOREIGN KEY (`zoneId`) REFERENCES `Zone`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey -ALTER TABLE `Chat` ADD CONSTRAINT `Chat_zoneId_fkey` FOREIGN KEY (`zoneId`) REFERENCES `Zone`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE `Chat` ADD CONSTRAINT `Chat_characterId_fkey` FOREIGN KEY (`characterId`) REFERENCES `Character`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `Chat` ADD CONSTRAINT `Chat_zoneId_fkey` FOREIGN KEY (`zoneId`) REFERENCES `Zone`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 233efe4..fbbf7a9 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -29,7 +29,7 @@ model User { model Character { id Int @id @default(autoincrement()) userId Int - user User @relation(fields: [userId], references: [id]) + user User @relation(fields: [userId], references: [id], onDelete: Cascade) name String @unique hitpoints Int @default(100) mana Int @default(100) @@ -40,26 +40,39 @@ model Character { position_y Int rotation Int zoneId Int - zone Zone @relation(fields: [zoneId], references: [id]) + zone Zone @relation(fields: [zoneId], references: [id], onDelete: Cascade) chats Chat[] } model Zone { - id Int @id @default(autoincrement()) - name String - width Int - height Int - tiles Json - characters Character[] - chats Chat[] + id Int @id @default(autoincrement()) + name String + width Int + height Int + tiles Json + walls Json + decorations ZoneDecoration[] + characters Character[] + chats Chat[] + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt +} + +model ZoneDecoration { + id Int @id @default(autoincrement()) + zoneId Int + zone Zone @relation(fields: [zoneId], references: [id], onDelete: Cascade) + type Int + position_x Int + position_y Int } model Chat { id Int @id @default(autoincrement()) characterId Int - character Character @relation(fields: [characterId], references: [id]) + character Character @relation(fields: [characterId], references: [id], onDelete: Cascade) zoneId Int - zone Zone @relation(fields: [zoneId], references: [id]) + zone Zone @relation(fields: [zoneId], references: [id], onDelete: Cascade) message String createdAt DateTime } diff --git a/src/app/events/GmZoneEditorZoneSave.ts b/src/app/events/GmZoneEditorZoneSave.ts index 05e1b9c..d8b41e5 100644 --- a/src/app/events/GmZoneEditorZoneSave.ts +++ b/src/app/events/GmZoneEditorZoneSave.ts @@ -10,6 +10,7 @@ interface IZoneLoad { width: number; height: number; tiles: number[][]; + walls: number[][]; } /** @@ -21,6 +22,8 @@ export default function (socket: TSocket, io: Server) { socket.on('gm:zone_editor:zone:save', async (data: IZoneLoad) => { console.log(`---GM ${socket.character?.id} has saved zone via zone editor.`); + console.log(data); + if (!data.zoneId) { console.log(`---Zone id not provided.`); return; @@ -38,7 +41,8 @@ export default function (socket: TSocket, io: Server) { data.name, data.width, data.height, - data.tiles + data.tiles, + data.walls ); zone = await ZoneRepository.getById(data.zoneId); diff --git a/src/app/repositories/ZoneRepository.ts b/src/app/repositories/ZoneRepository.ts index b906f4d..35857db 100644 --- a/src/app/repositories/ZoneRepository.ts +++ b/src/app/repositories/ZoneRepository.ts @@ -33,14 +33,15 @@ class ZoneRepository { } } - async create(name: string, width: number, height: number, tiles: any): Promise { + async create(name: string, width: number, height: number, tiles: number[][], walls: number[][]): Promise { try { return await prisma.zone.create({ data: { name: name, width: width, height: height, - tiles: tiles + tiles: tiles, + walls: walls, } }); } catch (error: any) { @@ -49,7 +50,7 @@ class ZoneRepository { } } - async update(id: number, name: string, width: number, height: number, tiles: any): Promise { + async update(id: number, name: string, width: number, height: number, tiles: number[][], walls: number[][]): Promise { try { return await prisma.zone.update({ where: { @@ -59,7 +60,8 @@ class ZoneRepository { name: name, width: width, height: height, - tiles: tiles + tiles: tiles, + walls: walls, } }); } catch (error: any) { diff --git a/src/app/services/ZoneService.ts b/src/app/services/ZoneService.ts index 0860cca..f036041 100644 --- a/src/app/services/ZoneService.ts +++ b/src/app/services/ZoneService.ts @@ -16,6 +16,17 @@ class ZoneService [0, 1, 1, 1, 1, 1, 1, 1, 1, 0], [0, 1, 1, 1, 1, 1, 1, 1, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + ], [ + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 1, 1, 1, 1, 1, 1, 1, 1, 0], + [0, 1, 1, 1, 1, 1, 1, 1, 1, 0], + [0, 1, 1, 1, 1, 1, 1, 1, 1, 0], + [0, 1, 1, 1, 1, 1, 1, 1, 1, 0], + [0, 1, 1, 1, 1, 1, 1, 1, 1, 0], + [0, 1, 1, 1, 1, 1, 1, 1, 1, 0], + [0, 1, 1, 1, 1, 1, 1, 1, 1, 0], + [0, 1, 1, 1, 1, 1, 1, 1, 1, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], ]) console.log("Demo zone created."); return true;