Blueprints declare constructionDurationMinutes instead of tick counts. Delivering the last material starts construction at delivery time via maybeStartConstruction, setting constructionStartedAt/CompletesAt on the site; the game tick only sweeps completed sites. Structure detail page extracts server data helpers and shows a ConstructionPanel with a literal ETA countdown. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
33 lines
1 KiB
TypeScript
33 lines
1 KiB
TypeScript
"use client";
|
|
|
|
import { useEffect, useState } from "react";
|
|
|
|
interface ConstructionEtaProps {
|
|
completesAt: string | Date | null;
|
|
}
|
|
|
|
function formatDuration(ms: number): string {
|
|
const totalSeconds = Math.max(0, Math.round(ms / 1000));
|
|
const hours = Math.floor(totalSeconds / 3600);
|
|
const minutes = Math.floor((totalSeconds % 3600) / 60);
|
|
const seconds = totalSeconds % 60;
|
|
if (hours > 0) return `${hours}h ${minutes}m ${seconds}s`;
|
|
return `${minutes}m ${seconds}s`;
|
|
}
|
|
|
|
/**
|
|
* Live countdown to the site's exact constructionCompletesAt deadline.
|
|
*/
|
|
export function ConstructionEta({ completesAt }: ConstructionEtaProps) {
|
|
const [nowMs, setNowMs] = useState(() => Date.now());
|
|
|
|
useEffect(() => {
|
|
const timer = setInterval(() => setNowMs(Date.now()), 1000);
|
|
return () => clearInterval(timer);
|
|
}, []);
|
|
|
|
const deadline = completesAt ? new Date(completesAt).getTime() : NaN;
|
|
const remaining = Number.isFinite(deadline) ? deadline - nowMs : 0;
|
|
|
|
return <span>ETA {remaining <= 0 ? "any moment" : formatDuration(remaining)}</span>;
|
|
}
|