mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-30 12:42:12 +00:00
visibleAt (#3497)
## Description: needs prereq of https://github.com/openfrontio/infra/pull/272 ## Please complete the following: - [x] I have added screenshots for all UI updates - [x] I process any text displayed to the user through translateText() and I've added it to the en.json file - [x] I have added relevant tests to the test directory - [x] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced ## Please put your Discord username so you can be contacted if a bug or regression is found: w.o.n
This commit is contained in:
@@ -331,6 +331,7 @@ export class ClientGameRunner {
|
||||
Date.now(),
|
||||
update.winner,
|
||||
this.lobby.gameStartInfo.lobbyCreatedAt,
|
||||
this.lobby.gameStartInfo.visibleAt,
|
||||
);
|
||||
endGame(record);
|
||||
}
|
||||
|
||||
@@ -526,6 +526,7 @@ export const PlayerSchema = z.object({
|
||||
export const GameStartInfoSchema = z.object({
|
||||
gameID: ID,
|
||||
lobbyCreatedAt: z.number(),
|
||||
visibleAt: z.number().optional(),
|
||||
config: GameConfigSchema,
|
||||
players: PlayerSchema.array(),
|
||||
});
|
||||
|
||||
+4
-1
@@ -251,6 +251,8 @@ export function createPartialGameRecord(
|
||||
winner: Winner,
|
||||
// lobby creation time (ms). Defaults to start time for singleplayer.
|
||||
lobbyCreatedAt?: number,
|
||||
// Time the lobby became visible to players (ms).
|
||||
visibleAt?: number,
|
||||
): PartialGameRecord {
|
||||
const duration = Math.floor((end - start) / 1000);
|
||||
const num_turns = allTurns.length;
|
||||
@@ -262,13 +264,14 @@ export function createPartialGameRecord(
|
||||
const actualLobbyCreatedAt = lobbyCreatedAt ?? start;
|
||||
const lobbyFillTime = Math.max(
|
||||
0,
|
||||
start - Math.min(actualLobbyCreatedAt, start),
|
||||
start - (visibleAt ?? actualLobbyCreatedAt),
|
||||
);
|
||||
|
||||
const record: PartialGameRecord = {
|
||||
info: {
|
||||
gameID,
|
||||
lobbyCreatedAt: actualLobbyCreatedAt,
|
||||
visibleAt,
|
||||
lobbyFillTime,
|
||||
config,
|
||||
players,
|
||||
|
||||
@@ -87,6 +87,8 @@ export class GameServer {
|
||||
|
||||
private lobbyInfoIntervalId: ReturnType<typeof setInterval> | null = null;
|
||||
|
||||
private visibleAt?: number;
|
||||
|
||||
constructor(
|
||||
public readonly id: string,
|
||||
readonly log_: Logger,
|
||||
@@ -98,6 +100,9 @@ export class GameServer {
|
||||
private publicGameType?: PublicGameType,
|
||||
) {
|
||||
this.log = log_.child({ gameID: id });
|
||||
if (startsAt !== undefined) {
|
||||
this.visibleAt = Date.now();
|
||||
}
|
||||
}
|
||||
|
||||
private get lobbyCreatorID(): ClientID | undefined {
|
||||
@@ -558,6 +563,8 @@ export class GameServer {
|
||||
|
||||
public setStartsAt(startsAt: number) {
|
||||
this.startsAt = startsAt;
|
||||
// Record when the lobby first became visible to players, used to measure lobby fill time.
|
||||
this.visibleAt ??= Date.now();
|
||||
}
|
||||
|
||||
public numClients(): number {
|
||||
@@ -656,6 +663,7 @@ export class GameServer {
|
||||
const result = GameStartInfoSchema.safeParse({
|
||||
gameID: this.id,
|
||||
lobbyCreatedAt: this.createdAt,
|
||||
visibleAt: this.visibleAt,
|
||||
config: this.gameConfig,
|
||||
players: this.activeClients.map((c) => ({
|
||||
username: c.username,
|
||||
@@ -1001,6 +1009,7 @@ export class GameServer {
|
||||
Date.now(),
|
||||
this.winner?.winner,
|
||||
this.createdAt,
|
||||
this.visibleAt,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user