From f56d94bffc693677c3d85485b584b25a18939ffe Mon Sep 17 00:00:00 2001 From: not-nullptr Date: Sun, 10 Mar 2024 04:37:12 +0000 Subject: [PATCH] blarghh --- src/hooks.server.ts | 3 ++- src/lib/server/class/Room.ts | 37 ++++++++++++++++++++++++++++++++++++ src/routes/lobby/+server.ts | 9 +++++++++ src/types/rooms.d.ts | 21 ++++++++++++++++++++ 4 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 src/lib/server/class/Room.ts create mode 100644 src/routes/lobby/+server.ts create mode 100644 src/types/rooms.d.ts diff --git a/src/hooks.server.ts b/src/hooks.server.ts index 780214d..d7cbce9 100644 --- a/src/hooks.server.ts +++ b/src/hooks.server.ts @@ -1,9 +1,10 @@ import { db } from "$lib/server/db"; import "reflect-metadata"; import { building } from "$app/environment"; +import type { Handle } from "@sveltejs/kit"; const runAllTheInitFunctions = async () => { - await db.initialize(); + if (!db.isInitialized) await db.initialize(); }; if (!building) { diff --git a/src/lib/server/class/Room.ts b/src/lib/server/class/Room.ts new file mode 100644 index 0000000..a7d0665 --- /dev/null +++ b/src/lib/server/class/Room.ts @@ -0,0 +1,37 @@ +import type { IRoom } from "$types/rooms"; +import type { SuyuUser } from "../schema"; + +export class Room { + public roomInfo: IRoom; + constructor( + name: string, + description: string, + game: string, + players: SuyuUser[], + maxPlayers: number, + ) { + this.roomInfo = { + name, + description, + preferredGameName: game, + players, + maxPlayers, + address: "localhost", + externalGuid: "1234", + hasPassword: false, + id: "1234", + netVersion: 1, + owner: "1234", + port: 1234, + preferredGameId: 1234, + }; + } + + async addPlayer(user: SuyuUser) { + this.roomInfo.players.push(user); + } + + toJSON() { + return this.roomInfo; + } +} diff --git a/src/routes/lobby/+server.ts b/src/routes/lobby/+server.ts new file mode 100644 index 0000000..5c80518 --- /dev/null +++ b/src/routes/lobby/+server.ts @@ -0,0 +1,9 @@ +import { Room } from "$lib/server/class/Room"; +import { json } from "$lib/server/util"; +import type { LobbyResponse } from "$types/rooms"; + +export async function GET({ request }) { + return json({ + rooms: [new Room("suyu Testing Room 1", "A testing room for suyu", "suyu", [], 4).toJSON()], + }); +} diff --git a/src/types/rooms.d.ts b/src/types/rooms.d.ts new file mode 100644 index 0000000..b0a2e66 --- /dev/null +++ b/src/types/rooms.d.ts @@ -0,0 +1,21 @@ +import type { SuyuUser } from "$lib/server/schema"; + +export interface IRoom { + address: string; + description: string; + externalGuid: string; + hasPassword: boolean; + id: string; + maxPlayers: number; + name: string; + netVersion: number; + owner: string; + players: SuyuUser[]; + port: number; + preferredGameId: number; + preferredGameName: string; +} + +export interface LobbyResponse { + rooms: IRoom[]; +}