This commit is contained in:
not-nullptr 2024-03-10 04:37:12 +00:00
parent 5351c54d8d
commit f56d94bffc
4 changed files with 69 additions and 1 deletions

View file

@ -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) {

View file

@ -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;
}
}

View file

@ -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<LobbyResponse>({
rooms: [new Room("suyu Testing Room 1", "A testing room for suyu", "suyu", [], 4).toJSON()],
});
}

21
src/types/rooms.d.ts vendored Normal file
View file

@ -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[];
}