This commit is contained in:
2025-08-30 16:01:43 -04:00
parent 391bf3d1f8
commit 2fbd09e43f
17 changed files with 382 additions and 36 deletions

View File

@@ -2,6 +2,14 @@ import { CloudRegionCode } from "../../util/photon.ts";
import type Profile from "../profiles/profile.ts";
import { RoomInstance, RoomLocation } from "./base.ts";
export interface InstanceCreationOptions {
roomId: number,
subRoomId: number,
name: string,
maxCapacity: number,
private?: boolean
}
export class Instance {
#createdAt = new Date();
@@ -9,40 +17,42 @@ export class Instance {
#players: Set<Profile> = new Set();
#instanceId: number;
//#roomId: number;
//#subRoomId: number;
#roomId: number;
#subRoomId: number;
#location: RoomLocation;
//#name: string;
//#maxCapacity: number;
#name: string;
#maxCapacity: number;
#isFull: boolean = false;
//#isPrivate: boolean;
#isPrivate: boolean;
#isInProgress: boolean = false;
#photonRegionId: string = CloudRegionCode.us;
//#photonRoomId: string;
#photonRoomId: string;
#dataBlob?: string;
#eventId?: string
#eventId?: number
constructor(options: {
id: number,
location: RoomLocation,
}
) {
this.#instanceId = options.id;
this.#location = options.location;
constructor(id: number, location: RoomLocation, options: InstanceCreationOptions) {
this.#instanceId = id;
this.#location = location;
this.#roomId = options.roomId;
this.#subRoomId = options.subRoomId;
this.#isPrivate = typeof options.private == 'boolean' ? options.private : false;
this.#name = options.name;
this.#maxCapacity = options.maxCapacity;
this.#photonRoomId = `GCR-${this.#instanceId}`;
}
getPlayers() {
return this.#players.values().toArray();
}
playerIsHere(profile: Profile) {
return this.getPlayers().find(prof => prof.same(profile)) ? true : false;
return Boolean(this.getPlayers().find(prof => prof.same(profile)));
}
removePlayer(profile: Profile) {
this.#players.delete(profile);
}
addPlayer(profile: Profile) {
this.#players.add(profile);
}
getCreatedAt() {
@@ -50,10 +60,22 @@ export class Instance {
}
export() {
/*const inst: RoomInstance = {
const inst: RoomInstance = {
roomInstanceId: this.#instanceId,
}*/
roomId: this.#roomId,
subRoomId: this.#subRoomId,
location: this.#location,
name: this.#name,
maxCapacity: this.#maxCapacity,
isFull: this.#isFull,
isPrivate: this.#isPrivate,
isInProgress: this.#isInProgress,
photonRegionId: this.#photonRegionId,
photonRoomId: this.#photonRoomId,
dataBlob: this.#dataBlob,
eventId: this.#eventId
};
return inst;
}
}

View File

@@ -58,6 +58,6 @@ export interface RoomInstance {
export class InstanceManager extends ServerContentBase {
}