mirror of
https://git.suyu.dev/suyu/website.git
synced 2025-12-31 03:37:37 +01:00
remove concepts, finish lobbies/rooms
This commit is contained in:
parent
e498d512b4
commit
6bd72d56de
29 changed files with 235 additions and 822 deletions
|
|
@ -1,37 +1,73 @@
|
|||
import type { IRoom } from "$types/rooms";
|
||||
import type { IRoom, IRoomConfig, RoomPlayer } from "$types/rooms";
|
||||
import type { SuyuUser } from "../schema";
|
||||
import { v4 } from "uuid";
|
||||
|
||||
export class RoomManager {
|
||||
private static rooms: Room[] = [];
|
||||
static createRoom(room: IRoomConfig) {
|
||||
const newRoom = new Room(room);
|
||||
this.rooms.push(newRoom);
|
||||
return newRoom;
|
||||
}
|
||||
|
||||
static getRooms() {
|
||||
return this.rooms;
|
||||
}
|
||||
|
||||
static getRoom(id: string) {
|
||||
return this.rooms.find((room) => room.roomInfo.id === id);
|
||||
}
|
||||
|
||||
static removeRoom(id: string) {
|
||||
const index = this.rooms.findIndex((room) => room.roomInfo.id === id);
|
||||
this.rooms.splice(index, 1);
|
||||
}
|
||||
}
|
||||
|
||||
export class Room {
|
||||
public roomInfo: IRoom;
|
||||
public host: SuyuUser;
|
||||
constructor(
|
||||
name: string,
|
||||
description: string,
|
||||
game: string,
|
||||
players: SuyuUser[],
|
||||
maxPlayers: number,
|
||||
// name: string,
|
||||
// description: string,
|
||||
// game: string,
|
||||
// players: SuyuUser[],
|
||||
// maxPlayers: number,
|
||||
// ip: string,
|
||||
config: IRoomConfig,
|
||||
) {
|
||||
const parsed = config.ip.split(":");
|
||||
this.host = config.host;
|
||||
this.roomInfo = {
|
||||
name,
|
||||
description,
|
||||
preferredGameName: game,
|
||||
players,
|
||||
maxPlayers,
|
||||
address: "localhost",
|
||||
externalGuid: "1234",
|
||||
hasPassword: false,
|
||||
id: "1234",
|
||||
name: config.name,
|
||||
description: config.description,
|
||||
preferredGameName: config.gameName,
|
||||
preferredGameId: config.gameId,
|
||||
players: config.players,
|
||||
maxPlayers: config.maxPlayers,
|
||||
address: parsed[0],
|
||||
externalGuid: v4(),
|
||||
hasPassword: config.hasPassword,
|
||||
id: v4(),
|
||||
netVersion: 1,
|
||||
owner: "1234",
|
||||
port: 1234,
|
||||
preferredGameId: 1234,
|
||||
owner: this.host.username,
|
||||
port: parseInt(parsed[1]),
|
||||
};
|
||||
}
|
||||
|
||||
async addPlayer(user: SuyuUser) {
|
||||
addPlayer(user: RoomPlayer) {
|
||||
this.roomInfo.players.push(user);
|
||||
}
|
||||
|
||||
setPlayerList(players: RoomPlayer[]) {
|
||||
this.roomInfo.players = players;
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
return this.roomInfo;
|
||||
}
|
||||
|
||||
delete() {
|
||||
RoomManager.removeRoom(this.roomInfo.id);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue