mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 12:20:46 +00:00
unify time logic
This commit is contained in:
@@ -158,6 +158,17 @@ export function getModifierLabels(
|
||||
return getActiveModifiers(modifiers).map((m) => translateText(m.badgeKey));
|
||||
}
|
||||
|
||||
export function secondsToHms(d: number): string {
|
||||
const pad = (n: number) => (n < 10 ? `0${n}` : n);
|
||||
const h = Math.floor(d / 3600);
|
||||
const m = Math.floor((d % 3600) / 60);
|
||||
const s = Math.floor((d % 3600) % 60);
|
||||
if (h !== 0) {
|
||||
return `${pad(h)}:${pad(m)}:${pad(s)}`;
|
||||
}
|
||||
return `${pad(m)}:${pad(s)}`;
|
||||
}
|
||||
|
||||
export function renderDuration(totalSeconds: number): string {
|
||||
if (totalSeconds <= 0) return "0s";
|
||||
const minutes = Math.floor(totalSeconds / 60);
|
||||
|
||||
@@ -5,7 +5,7 @@ import { GameType } from "../../../core/game/Game";
|
||||
import { GameView } from "../../../core/game/GameView";
|
||||
import { crazyGamesSDK } from "../../CrazyGamesSDK";
|
||||
import { PauseGameIntentEvent, SendWinnerEvent } from "../../Transport";
|
||||
import { translateText } from "../../Utils";
|
||||
import { secondsToHms, translateText } from "../../Utils";
|
||||
import { ImmunityBarVisibleEvent } from "./ImmunityTimer";
|
||||
import { Layer } from "./Layer";
|
||||
import { ShowReplayPanelEvent } from "./ReplayPanel";
|
||||
@@ -111,20 +111,6 @@ export class GameRightSidebar extends LitElement implements Layer {
|
||||
}
|
||||
}
|
||||
|
||||
private secondsToHms = (d: number): string => {
|
||||
const pad = (n: number) => (n < 10 ? `0${n}` : n);
|
||||
|
||||
const h = Math.floor(d / 3600);
|
||||
const m = Math.floor((d % 3600) / 60);
|
||||
const s = Math.floor((d % 3600) % 60);
|
||||
|
||||
if (h !== 0) {
|
||||
return `${pad(h)}:${pad(m)}:${pad(s)}`;
|
||||
} else {
|
||||
return `${pad(m)}:${pad(s)}`;
|
||||
}
|
||||
};
|
||||
|
||||
private toggleReplayPanel(): void {
|
||||
this._isReplayVisible = !this._isReplayVisible;
|
||||
this.eventBus.emit(
|
||||
@@ -179,7 +165,7 @@ export class GameRightSidebar extends LitElement implements Layer {
|
||||
@contextmenu=${(e: Event) => e.preventDefault()}
|
||||
>
|
||||
<!-- In-game time -->
|
||||
<div class=${timerColor}>${this.secondsToHms(this.timer)}</div>
|
||||
<div class=${timerColor}>${secondsToHms(this.timer)}</div>
|
||||
|
||||
<!-- Buttons -->
|
||||
${this.maybeRenderReplayButtons()}
|
||||
|
||||
@@ -13,18 +13,11 @@ import {
|
||||
formatPercentage,
|
||||
renderNumber,
|
||||
renderTroops,
|
||||
secondsToHms,
|
||||
translateText,
|
||||
} from "../../Utils";
|
||||
import { Layer } from "./Layer";
|
||||
|
||||
function formatCrownTime(ticks: number): string {
|
||||
const seconds = Math.floor(ticks / 10);
|
||||
if (seconds <= 0) return "0:00";
|
||||
const m = Math.floor(seconds / 60);
|
||||
const s = seconds % 60;
|
||||
return `${m}:${String(s).padStart(2, "0")}`;
|
||||
}
|
||||
|
||||
type ViewMode = "control" | "units" | "competitive";
|
||||
|
||||
interface TeamEntry {
|
||||
@@ -342,7 +335,8 @@ export class TeamStats extends LitElement implements Layer {
|
||||
return html`
|
||||
<div class="${rowClass}">
|
||||
${td(team.teamName)} ${td(team.totalScoreStr)}
|
||||
${td(team.peakScoreStr)} ${td(formatCrownTime(team.crownTicks))}
|
||||
${td(team.peakScoreStr)}
|
||||
${td(secondsToHms(Math.floor(team.crownTicks / 10)))}
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import { customElement, state } from "lit/decorators.js";
|
||||
import {
|
||||
getGamesPlayed,
|
||||
isInIframe,
|
||||
secondsToHms,
|
||||
translateText,
|
||||
TUTORIAL_VIDEO_URL,
|
||||
} from "../../../client/Utils";
|
||||
@@ -108,12 +109,6 @@ export class WinModal extends LitElement implements Layer {
|
||||
`;
|
||||
}
|
||||
|
||||
private formatTime(seconds: number): string {
|
||||
const m = Math.floor(seconds / 60);
|
||||
const s = seconds % 60;
|
||||
return `${m}m${String(s).padStart(2, "0")}s`;
|
||||
}
|
||||
|
||||
private _tooltip: HTMLDivElement | null = null;
|
||||
|
||||
private _showTooltip(e: MouseEvent, text: string) {
|
||||
@@ -197,7 +192,7 @@ export class WinModal extends LitElement implements Layer {
|
||||
<td class="py-1.5 px-1">
|
||||
${s.crownTimePoints}
|
||||
${this.renderInfoIcon(
|
||||
`${s.team} ranked #${s.crownTimeRank} in crown time (${this.formatTime(s.crownTimeSeconds)})`,
|
||||
`${s.team} ranked #${s.crownTimeRank} in crown time (${secondsToHms(s.crownTimeSeconds)})`,
|
||||
)}
|
||||
</td>
|
||||
<td class="py-1.5 px-1">
|
||||
|
||||
Reference in New Issue
Block a user