From a713d10fac59b8a6495388b71c9de9e087d71fb4 Mon Sep 17 00:00:00 2001 From: Saurabh Bhagat Date: Tue, 2 Apr 2024 19:08:35 +0530 Subject: [PATCH] bugfixes --- src/game/main.ts | 3 ++- src/game/models/ground.ts | 3 ++- src/index.ts | 3 +++ src/rooms/GameRoom.ts | 4 ++-- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/game/main.ts b/src/game/main.ts index 68204fb..806dab8 100644 --- a/src/game/main.ts +++ b/src/game/main.ts @@ -14,6 +14,7 @@ import { GameRoom } from '@/rooms/GameRoom'; import { physicsEngine } from '@/app.config'; import { Player } from '@/rooms/schema/RoomState'; import { IMessageInput } from '@/types/interfaces'; +import { port } from '@/index'; export class World { private static timeStep = 1 / 60; @@ -58,7 +59,7 @@ export class World { private static async importPlayerMesh(instance: World) { const { meshes } = await SceneLoader.ImportMeshAsync( null, - 'http://localhost:2567/assets/models/', + `http://localhost:${port}/assets/models/`, 'Panzer_I.glb', instance.scene ); diff --git a/src/game/models/ground.ts b/src/game/models/ground.ts index 47f6eee..9b813bc 100644 --- a/src/game/models/ground.ts +++ b/src/game/models/ground.ts @@ -1,3 +1,4 @@ +import { port } from '@/index'; import { Scene } from '@babylonjs/core'; import { MeshBuilder, type GroundMesh } from '@babylonjs/core/Meshes'; import { PhysicsAggregate, PhysicsShapeType } from '@babylonjs/core/Physics'; @@ -15,7 +16,7 @@ export class Ground { private static createMesh(scene: Scene) { const ground = new Ground(); return new Promise((resolve, reject) => { - loadImage('http://localhost:2567/assets/map/desert/height.png').then((image) => { + loadImage(`http://localhost:${port}/assets/map/desert/height.png`).then((image) => { const canvas = createCanvas(2048, 2048); const ctx = canvas.getContext('2d'); ctx.drawImage(image, 0, 0, 2048, 2048); diff --git a/src/index.ts b/src/index.ts index eb750ac..ec0edf8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -8,4 +8,7 @@ let port = 2567; if (['string', 'number'].includes(typeof process.env.PORT)) { port = typeof process.env.PORT === 'number' ? process.env.PORT : parseInt(process.env.PORT); } + +export { port }; + listen(app, port); diff --git a/src/rooms/GameRoom.ts b/src/rooms/GameRoom.ts index e0f4c9b..6236740 100644 --- a/src/rooms/GameRoom.ts +++ b/src/rooms/GameRoom.ts @@ -77,8 +77,8 @@ export class GameRoom extends Room { } } onDispose() { - this.monitor.stop(); - this.world.destroy(); + this.monitor?.stop(); + this.world?.destroy(); console.log('Room', this.roomId, 'disposed'); }