fix the embedded url times

This commit is contained in:
Ryan Barlow
2026-01-25 19:51:11 +00:00
parent de3794313d
commit 1a9ccc6415
3 changed files with 30 additions and 3 deletions
+2 -2
View File
@@ -4,7 +4,6 @@ import {
Difficulty,
Game,
GameMode,
GameType,
Gold,
Player,
PlayerInfo,
@@ -25,6 +24,7 @@ import { Config, GameEnv, NukeMagnitude, ServerConfig, Theme } from "./Config";
import { Env } from "./Env";
import { PastelTheme } from "./PastelTheme";
import { PastelThemeDark } from "./PastelThemeDark";
import { spawnPhaseTurns } from "./Timing";
const DEFENSE_DEBUFF_MIDPOINT = 150_000;
const DEFENSE_DEBUFF_DECAY_RATE = Math.LN2 / 50000;
@@ -542,7 +542,7 @@ export class DefaultConfig implements Config {
return 3;
}
numSpawnPhaseTurns(): number {
return this._gameConfig.gameType === GameType.Singleplayer ? 100 : 300;
return spawnPhaseTurns(this._gameConfig.gameType);
}
numBots(): number {
return this.bots();
+19
View File
@@ -0,0 +1,19 @@
import { GameType } from "../game/Game";
export const TICKS_PER_SECOND = 10;
export const SPAWN_PHASE_TICKS = {
singleplayer: 100,
multiplayer: 300,
} as const;
export type GameTypeLike = GameType | string | undefined;
export function spawnPhaseTurns(gameType: GameTypeLike): number {
return gameType === GameType.Singleplayer
? SPAWN_PHASE_TICKS.singleplayer
: SPAWN_PHASE_TICKS.multiplayer;
}
export function spawnPhaseSeconds(gameType: GameTypeLike): number {
return spawnPhaseTurns(gameType) / TICKS_PER_SECOND;
}
+9 -1
View File
@@ -1,5 +1,6 @@
import { z } from "zod";
import { GameInfo } from "../core/Schemas";
import { spawnPhaseSeconds } from "../core/configuration/Timing";
import { GameMode } from "../core/game/Game";
export const PlayerInfoSchema = z.object({
@@ -179,6 +180,11 @@ export function buildPreview(
const winner = parseWinner(publicInfo?.info?.winner, players);
const duration = publicInfo?.info?.duration;
const gameType = lobby?.gameConfig?.gameType ?? config.gameType;
const adjustedDuration =
typeof duration === "number"
? Math.max(0, duration - spawnPhaseSeconds(gameType))
: undefined;
// Normalize map name to match filesystem (lowercase, no spaces or special chars)
const normalizedMap = map ? map.toLowerCase().replace(/[\s.()]+/g, "") : null;
@@ -211,7 +217,9 @@ export function buildPreview(
const detailParts: string[] = [];
const playerCountLabel = `${activePlayers} ${activePlayers === 1 ? "player" : "players"}`;
detailParts.push(playerCountLabel);
if (duration !== undefined) detailParts.push(`${formatDuration(duration)}`);
if (adjustedDuration !== undefined) {
detailParts.push(`${formatDuration(adjustedDuration)}`);
}
if (matchTimestamp !== undefined) {
const dateTime = formatDateTimeParts(matchTimestamp);
detailParts.push(`${dateTime.date}`);