diff --git a/CHANGELOG.md b/CHANGELOG.md index 8452db0..804f283 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ Änderungen an TIDEFRONT, neueste zuerst. Die Version steht im Handbuch unten und auf dem Anmeldebildschirm. +## 0.37.0 – 27.11.2026 +- **Alle Zeiten und Bestände laufen live:** Countdowns, Ankunftszeiten, „in ca.“-Angaben, Rohstoffstände, rot markierte Kosten und „Was hilft?“-Hinweise rechnen sich ständig neu – ohne erneutes Öffnen. Reichen die Rohstoffe, verschwindet der Hinweis und der Ausbau-Knopf wird von selbst aktiv. Ist ein Bau fertig oder eine Mission angekommen, holt die App die neuen Daten selbst. +- **Lesbare Zeiten überall gleich:** „45 s“, „56 min“, „1 h 05 min“, „2 T 3 h“, „vor 12 min“, „morgen 06:00 Uhr“ – nie mehr „55:59 min“. +- **Lagezentrum:** Lieferungen ohne Konvoi (ältere Börsenkäufe) stehen jetzt unter „Unterwegs“. Neue Einträge seit deinem letzten Blick tragen „neu“. Die Zahl an „Meldungen“ verschwindet nach dem Öffnen der Lage und kommt erst bei neuem Dringendem wieder – laufende Angriffe bleiben immer markiert. + ## 0.36.0 – 27.11.2026 - **Lagezentrum (Meldungen → „Lage“):** Alles, was gerade läuft, auf einer Seite und nach Zeit sortiert – „Gleich / heute“ (Angriffe rot ganz oben, Ankünfte, Konvois und Lieferungen, Bau, Ausbildung, Forschung, fällige Verträge, Nachtschild, Satelliten, Weltereignisse), „Unterwegs“ mit Fortschrittsbalken, „Wartet auf dich“ (abholbare Belohnungen, leere Bauschlange, freie Plätze, volles Lager, veraltende Lagebilder) und „Zuletzt passiert“. Jede Zeile führt per Tippen direkt dorthin; die Zahl an „Meldungen“ zeigt nur Dringendes. - **Börsenlieferung in 4 Stunden – für alle gleich (Balance v1.34):** Jeder Börsenkauf kommt nach genau 4 Stunden an, egal wie weit dein Hafen vom Handelshafen liegt; das Kartell-Risiko ist für alle gleich (im Schnitt rund 1 % Warenverlust ohne Geleit). diff --git a/apps/web/e2e/24-lage.spec.ts b/apps/web/e2e/24-lage.spec.ts index 29ab7b5..ff73cf2 100644 --- a/apps/web/e2e/24-lage.spec.ts +++ b/apps/web/e2e/24-lage.spec.ts @@ -47,6 +47,9 @@ test("Lage: Konvoi und Bau, Antippen springt, Zahl am Navigationszeichen bei abh await expect(badge).toHaveText(String(before + 1)); await nav.click(); await expect(page.getByTestId("lage-waiting").locator('[data-lage-key="belohnung:erfolge"]')).toContainText("abholbereit"); + // Neu seit dem letzten Öffnen markiert; nach dem Öffnen der Lage verschwindet die Zahl. + await expect(page.getByTestId("lage-waiting").locator('[data-lage-key="belohnung:erfolge"]').getByLabel("neu")).toBeVisible(); + await expect(badge).toHaveCount(0); expect((await readState(seed.sql, player.baseId)).buildQueue).toHaveLength(1); await seed.sql`delete from convoy where id = ${cv.id}`; }); diff --git a/apps/web/e2e/24-live-zeit.spec.ts b/apps/web/e2e/24-live-zeit.spec.ts new file mode 100644 index 0000000..f4ccb65 --- /dev/null +++ b/apps/web/e2e/24-live-zeit.spec.ts @@ -0,0 +1,74 @@ +// Live-Zeiten: Bestände, Fehlmengen, Wartezeiten und Countdowns laufen ohne Neuöffnen mit (gemeinsame Uhr, +// Hochrechnung aus dem Stand der letzten Abfrage). Die Seite bekommt eine Playwright-Uhr; damit der Server die +// vorgespulte Zeit nicht zurückstellt, bleiben Abrufe (GET) und Live-Verbindung währenddessen angehalten. +import type { Page, Route } from "@playwright/test"; +import { expect, test } from "./fixtures.ts"; +import { setBuildings, setResources } from "./game.ts"; + +/** Abrufe anhalten (nie beantworten) – die Oberfläche rechnet nur mit der Uhr weiter. */ +async function holdFetches(page: Page): Promise<() => Promise> { + const hold = (route: Route) => (route.request().method() === "GET" ? new Promise(() => {}) : route.fallback()); + await page.route("**/trpc/**", hold); + return () => page.unroute("**/trpc/**", hold); +} + +const num = (s: string) => Number(s.replace(/\./g, "")); + +test("Gebäudeblatt offen: Bestand steigt, Wartezeit sinkt, Blocker verschwindet, Ausbau wird aktiv; Bau-Countdown läuft", async ({ page, player, seed }) => { + test.slow(); + await setBuildings(seed.sql, player.baseId, { stahlwerk: 4, kraftwerk: 4, kommandozentrale: 4 }); + await setResources(seed.sql, player.baseId, { stahl: 0, treibstoff: 4000, elektronik: 4000, proviant: 4000 }); + // Live-Meldungen (WebSocket) stumm: ihr Zeitstempel würde die Uhr auf Serverzeit zurückstellen. + await page.routeWebSocket(/\/ws$/, () => {}); + await page.clock.install({ time: new Date() }); + + await page.goto("/"); + await page.getByRole("button", { name: /^Stahlwerk 4/ }).click(); + const sheet = page.getByRole("dialog"); + await expect(sheet.getByText("Noch nicht genug Ressourcen.")).toBeVisible(); + const up = sheet.getByRole("button", { name: "Ausbau auf 5" }); + await expect(up).toHaveAttribute("aria-disabled", "true"); + + const release = await holdFetches(page); + // Blocker aufklappen: Fortschrittszeile Stahl „Bestand / Bedarf“ und „in ca. …“. + const hint = sheet.locator("[data-remedy]"); + await hint.getByRole("button", { name: /Noch nicht genug Ressourcen/ }).click(); + const row = hint.getByRole("listitem").filter({ hasText: "Stahl" }); + const read = async () => { + const t = (await row.textContent()) ?? ""; + const m = /([\d.]+)\s*\/\s*([\d.]+)/.exec(t); + return { have: num(m![1]), need: num(m![2]), text: t, summary: (await hint.textContent()) ?? "" }; + }; + const a = await read(); + expect(a.text).toMatch(/in ca\. \d/); + expect(a.summary).toMatch(/Fehlt: [\d.]+ Stahl · ca\. /); + expect(a.summary).not.toMatch(/\d:\d\d min/); // einheitliches Format, nie „55:59 min“ + + // 20 Minuten vorspulen: Bestand steigt, Wartezeit sinkt – ohne Neuöffnen. + await page.clock.fastForward("00:20:00"); + await expect.poll(async () => (await read()).have).toBeGreaterThan(a.have); + const b = await read(); + expect(b.need).toBe(a.need); + expect(b.summary).not.toBe(a.summary); + + // Bis der Stahl reicht: Blocker weg, Knopf aktiv. + await page.clock.fastForward("24:00:00"); + await expect(sheet.getByText("Noch nicht genug Ressourcen.")).toHaveCount(0); + await expect(up).not.toHaveAttribute("aria-disabled", "true"); + + // Auch der Server hat jetzt genug; Ausbau starten (Abrufe wieder frei), dann läuft der Countdown im Bauhof. + await setResources(seed.sql, player.baseId, { stahl: 4000 }); + await release(); + await up.click(); + await expect(sheet).toHaveCount(0); + const yard = page.getByRole("listitem").filter({ hasText: "Stahlwerk · Ausbau auf Stufe 5" }); + const left = yard.getByText(/^noch /); + await expect(left).toBeVisible(); + await holdFetches(page); + const before = (await left.textContent()) ?? ""; + expect(before).toMatch(/^noch \d+ (s|min)$|^noch \d+ h/); // einheitlich, nie „1:59 min“ + // Gut eine Minute weiter: aus „noch 2 min“ werden Sekunden (oder der Abschluss) – ohne Neuladen. + await page.clock.fastForward("00:01:05"); + await expect(yard).not.toContainText(before); + await expect(yard).toContainText(/noch \d+ (s|min)|wird abgeschlossen/); +}); diff --git a/apps/web/src/App.tsx b/apps/web/src/App.tsx index 2bb5018..27454b3 100644 --- a/apps/web/src/App.tsx +++ b/apps/web/src/App.tsx @@ -3,7 +3,7 @@ import { useViewScroll } from "./lib/view-scroll.ts"; import { keepPreviousData, useQuery } from "@tanstack/react-query"; import { trpc, trpcClient, queryClient } from "./lib/trpc.ts"; import { useLive } from "./lib/live.ts"; -import { useNow } from "./lib/time.ts"; +import { useDueRefresh } from "./lib/due.ts"; // Bau fertig, Mission angekommen: Daten nachholen import { ActionBarHost, Loading, openCard } from "./ui.tsx"; import { Icon } from "./icons.tsx"; // Anmeldung und Hafenwahl nur bei Bedarf laden: angemeldete Spieler mit Hafen brauchen sie nicht. @@ -110,7 +110,7 @@ function Game({ playerId, playerName, onLoggedOut }: { playerId: number; playerN const claimable = (daily.data?.claimable ?? 0) + (guide.data?.claimable ?? 0); const lageBadge = useLageBadge(hasBase, claimable); useLive(loggedIn); - const now = useNow(); + useDueRefresh(base.data?.base ?? null); // Ziel aus einer Benachrichtigung (?tab=…, ?view=…) beim Start und per Nachricht vom Service Worker. const [opened] = useState(() => parseOpenUrl(location.href)); const [tab, setTab] = useState(opened.tab ?? "basis"); @@ -306,7 +306,7 @@ function Game({ playerId, playerName, onLoggedOut }: { playerId: number; playerN {/* Desktop ab 1024 px: breiter (max-w-3xl), die Karte volle Breite; mobil bleibt alles wie gehabt. */}
- go("karte")} onPower={() => { setSheet(null); go("basis"); openCard("basis-versorgung", "versorgung"); }} onMenu={(i) => { + go("karte")} onPower={() => { setSheet(null); go("basis"); openCard("basis-versorgung", "versorgung"); }} onMenu={(i) => { if (i === "logout") { void logout(); return; } setPlan(null); setResearch(false); setHelpView(i === "handbuch" ? null : i); diff --git a/apps/web/src/components/AllianceOps.tsx b/apps/web/src/components/AllianceOps.tsx index d3171b8..6b5178f 100644 --- a/apps/web/src/components/AllianceOps.tsx +++ b/apps/web/src/components/AllianceOps.tsx @@ -5,7 +5,7 @@ import { useQuery } from "@tanstack/react-query"; import { trpc, trpcClient, type Balance, type BaseData } from "../lib/trpc.ts"; import { useCommand } from "../lib/command.ts"; import { fmtNum } from "../lib/names.ts"; -import { fmtDuration, fmtTime } from "../lib/time.ts"; +import { fmtDuration, fmtTime, useNow } from "../lib/time.ts"; import { Button, Card, ErrorLine, ResChips, UnitChips } from "../ui.tsx"; import { Icon } from "../icons.tsx"; import { invalidateOps } from "./AllianceRaids.tsx"; @@ -19,7 +19,7 @@ export function opsLimits(b: Balance | undefined): Limits { } function minutesText(m: number): string { - return m < 60 ? `${m} min` : m % 60 === 0 ? `${m / 60} h` : `${Math.floor(m / 60)} h ${m % 60} min`; + return fmtDuration(m * 60_000); // einheitlich: „30 min“, „2 h“, „1 T“ } /** Missionsplanung (Überfall): denselben Verband als Sammelangriff der Allianz eröffnen. */ @@ -31,13 +31,14 @@ export function RaidOpenCard({ balance, target, units, travelSeconds, ok, onDone const joinChoices = [15, 30, 60, 120, 240, 480, 720, 1440].filter((m) => m >= lim.minJoinMinutes && m <= lim.maxJoinHours * 60); const [join, setJoin] = useState(joinChoices[1] ?? joinChoices[0] ?? lim.minJoinMinutes); const [extra, setExtra] = useState(0); + const now = useNow(60_000); // „Ankunft frühestens“ läuft mit der Uhr mit const open = useCommand( (i: { key: string; col: number; row: number; eventId?: number; units: Counts; joinMinutes: number; arriveMinutes: number }) => trpcClient.allianceOps.open.mutate(i), invalidateOps, ); if (!al.data?.alliance) return null; const arriveMinutes = Math.min(lim.maxArriveHours * 60, join + extra); - const earliest = Date.now() + join * 60000 + (travelSeconds ?? 0) * 1000; + const earliest = now + join * 60000 + (travelSeconds ?? 0) * 1000; return ( Als Sammelangriff eröffnen}>

Deine Allianz kann bis zur Frist mit eigenen Verbänden beitreten. Alle laufen so aus, dass sie gleichzeitig ankommen; die Beute wird nach Kampfbeitrag geteilt.

@@ -51,7 +52,7 @@ export function RaidOpenCard({ balance, target, units, travelSeconds, ok, onDone {[0, 15, 30, 60, 120, 240].map((m) => )} -

Ankunft frühestens {fmtTime(Math.max(earliest, Date.now() + arriveMinutes * 60000))} – ein langsamerer Verband verschiebt sie.

+

Ankunft frühestens {fmtTime(Math.max(earliest, now + arriveMinutes * 60000))} – ein langsamerer Verband verschiebt sie.

Jede Einheit isst Proviant, auch unterwegs. Der Saldo steht oben in der Leiste bei Proviant. Ist er negativ, schrumpft der Vorrat; bei 0 droht Versorgungsmangel.

- {(base.rates.proviant ?? 0) < 0 && !base.versorgungsmangel &&

Deine Truppen essen mehr, als du erzeugst: Vorrat reicht noch {fmtNum(Math.floor((base.resources.proviant ?? 0) / -(base.rates.proviant ?? -1)))} h. Versorgungshof ausbauen oder Proviant kaufen.

} + {(base.rates.proviant ?? 0) < 0 && !base.versorgungsmangel &&

Deine Truppen essen mehr, als du erzeugst: Vorrat reicht noch . Versorgungshof ausbauen oder Proviant kaufen.

} {base.versorgungsmangel &&

Versorgungsmangel: keine Ausbildung, Angriff −20 %. Versorgungshof ausbauen oder Proviant kaufen.

} {base.deliveries.length > 0 && } @@ -42,6 +43,13 @@ export function Supply({ base }: { base: BaseData }) { ); } +/** Restdauer des Proviants bei negativem Saldo, aus dem hochgerechneten Bestand (live). */ +function ProvisionLeft({ base }: { base: BaseData }) { + const live = useLiveBase(base); + const rate = base.rates.proviant ?? 0; + return {rate < 0 ? fmtDuration(((live.resources.proviant ?? 0) / -rate) * 3_600_000) : "–"}; +} + /** Kleiner Forschungshinweis hinter einem Wert („+20 % durch Forschung“). */ function Note({ text }: { text: string | null }) { return text ? {text} : null; @@ -90,7 +98,7 @@ export function Protection({ base, now }: { base: BaseData; now: number }) { const win = p.nightWindow; const beginnerEnd = p.createdAtMs + (prot?.beginnerDays ?? 7) * 86400000; return ( - {p.status ? `${label(p.status)} aktiv` : "kein Schutz aktiv"}{win ? ` · Nachtschild ${fmtTime(win.startMs)}–${fmtTime(win.endMs)}` : ""}}> + {p.status ? `${label(p.status)} aktiv` : "kein Schutz aktiv"}{win ? ` · Nachtschild ${fmtRange(win.startMs, win.endMs)}` : ""}}>
@@ -99,7 +107,10 @@ export function Protection({ base, now }: { base: BaseData; now: number }) { {p.defeatShieldUntilMs > now &&
Schutz nach Niederlage bis {fmtTime(p.defeatShieldUntilMs)}
} {win && (
- {now >= win.startMs && now < win.endMs ? `Nachtschild bis ${fmtTime(win.endMs)}` : `Nächster Nachtschild ${fmtTime(win.startMs)}–${fmtTime(win.endMs)}`} + {now >= win.startMs && now < win.endMs + ? `Nachtschild bis ${fmtTime(win.endMs)} (noch ${fmtDuration(win.endMs - now)})` + : now >= win.endMs ? "Nachtschild vorbei – nächster Zeitraum wird geladen …" + : `Nächster Nachtschild ${fmtRange(win.startMs, win.endMs)} (beginnt in ${fmtDuration(win.startMs - now)})`} {p.nightShieldSuspendedUntilMs > now ? " (durch eigenen Angriff aufgehoben)" : ""}
)} diff --git a/apps/web/src/components/BattleSim.tsx b/apps/web/src/components/BattleSim.tsx index 9e12a0b..1870398 100644 --- a/apps/web/src/components/BattleSim.tsx +++ b/apps/web/src/components/BattleSim.tsx @@ -58,9 +58,9 @@ export function ProbeKampf({ balance, base, units, versorgungsmangel, modifiers, return (
{target.kind === "base" && scout.data && ( -

Lagebild vom {fmtTime(scout.data.atMs)}. Der Hafen kann sich seither verändert haben.

+

Lagebild mit Stand {fmtTime(scout.data.atMs)}. Der Hafen kann sich seither verändert haben.

)} - {target.kind === "nest" && target.lagebild &&

Genau gegen das Lagebild vom {fmtTime(target.lagebild.atMs)} (Erholung und Beute hochgerechnet).

} + {target.kind === "nest" && target.lagebild &&

Genau gegen das Lagebild mit Stand {fmtTime(target.lagebild.atMs)} (Erholung und Beute hochgerechnet).

} {target.kind === "nest" && !target.lagebild && } {weather &&

Wetter am Ziel zur Ankunft (Vorhersage, Mitte der Spanne): {weatherText(weather)}.

} diff --git a/apps/web/src/components/Fields.tsx b/apps/web/src/components/Fields.tsx index cd86ea8..07d1c9a 100644 --- a/apps/web/src/components/Fields.tsx +++ b/apps/web/src/components/Fields.tsx @@ -63,7 +63,7 @@ export function FieldSheet({ data, sel, onPlan }: { data: FieldsData | null | un {f.garrison &&
Besatzung:
} {f.guard && Object.keys(f.guard).length > 0 &&
Kartell-Wache:
} {f.guardAtMs &&
Unbewacht – das Kartell kehrt in {fmtDuration(f.guardAtMs - now)} zurück
} - {f.intel &&
Lagebild vom {fmtTime(f.intel.atMs)}:
} + {f.intel &&
Lagebild (Stand {fmtTime(f.intel.atMs)}):
} {!f.garrison && !f.guard && !f.intel && f.relation !== "frei" &&
Besatzung unbekannt – erst aufklären.
} {f.zone && f.zone.size >= 2 &&
Einflusszone: {f.zone.size} Felder{f.zone.bonus ? " – Ertragsbonus aktiv" : ""}
} diff --git a/apps/web/src/components/Guide.tsx b/apps/web/src/components/Guide.tsx index 692a642..5f38ac0 100644 --- a/apps/web/src/components/Guide.tsx +++ b/apps/web/src/components/Guide.tsx @@ -6,6 +6,7 @@ import { useEffect, useState } from "react"; import { useQuery } from "@tanstack/react-query"; import { queryClient, trpc, trpcClient, type BaseData, type Balance, type Outputs } from "../lib/trpc.ts"; import { serverNow } from "../lib/time.ts"; +import { useLiveBase } from "../lib/live-base.ts"; import { useCommand } from "../lib/command.ts"; import { countLabel, fmtNum } from "../lib/names.ts"; import { Icon } from "../icons.tsx"; @@ -108,7 +109,8 @@ export function overflowOf(base: BaseData, reward: Record | unde const invalidate = () => [trpc.guide.pathFilter().queryKey, trpc.base.pathFilter().queryKey, trpc.social.ranking.pathFilter().queryKey]; -export function Guide({ base, onAction }: { base: BaseData; onAction: (a: GuideAction) => void }) { +export function Guide({ base: snap, onAction }: { base: BaseData; onAction: (a: GuideAction) => void }) { + const base = useLiveBase(snap); // Lagerwarnung mit hochgerechnetem Bestand const meta = useQuery({ ...trpc.meta.queryOptions(), staleTime: Infinity }); const q = useGuide(); const [showAll, setShowAll] = useState(false); diff --git a/apps/web/src/components/IntelOpsPlan.tsx b/apps/web/src/components/IntelOpsPlan.tsx index f087b86..2a8cfd7 100644 --- a/apps/web/src/components/IntelOpsPlan.tsx +++ b/apps/web/src/components/IntelOpsPlan.tsx @@ -49,7 +49,7 @@ export function IntelOpsPlan({ op, base, map, initial, onSent }: { : op === "postenangriff" ? { op, units: chosen, postId: initial?.postId ?? 0 } : { op, units: chosen, col: points[0]?.col, row: points[0]?.row }; const ready = Object.keys(chosen).length > 0 && (op === "postenangriff" ? !!initial?.postId : points.length > 0); - const preview = useQuery({ ...trpc.intel.preview.queryOptions(input), enabled: ready, placeholderData: keepPreviousData }); + const preview = useQuery({ ...trpc.intel.preview.queryOptions(input), enabled: ready, placeholderData: keepPreviousData, refetchInterval: 60_000 }); // Ankunftszeit aktuell const launch = useCommand((i: typeof input & { key: string }) => trpcClient.intel.launch.mutate(i), () => [trpc.base.pathFilter().queryKey, trpc.world.map.pathFilter().queryKey]); if (!meta.data) return null; const balance = meta.data.balance; diff --git a/apps/web/src/components/IntelStand.tsx b/apps/web/src/components/IntelStand.tsx index b890d6c..df73af7 100644 --- a/apps/web/src/components/IntelStand.tsx +++ b/apps/web/src/components/IntelStand.tsx @@ -1,7 +1,7 @@ // Lagebild: Stand einer Angabe im Feld-Blatt („Stand: vor 5 h, Radar Hafen X“) und fremde Verbände auf einem Feld. // Live-Angaben (jetzt im Sensorbereich) brauchen keinen Stand; veraltete stehen in Klammern (docs/REGELN-LAGEBILD.md). import type { MapData } from "../lib/trpc.ts"; -import { fmtDuration } from "../lib/time.ts"; +import { fmtAgo } from "../lib/time.ts"; export type IntelTag = { age: "live" | "bekannt" | "veraltet"; atMs: number; source: string; level: string } | null | undefined; export type MapFleet = MapData["fleets"][number]; @@ -10,10 +10,9 @@ const LEVEL_TEXT: Record = { sichtung: "Sichtung", erkennung: "E const SIZE_TEXT: Record = { klein: "klein (bis 10 Einheiten)", mittel: "mittel (bis 40)", gross: "groß (über 40)" }; const REL_TEXT: Record = { allianz: "Allianz", pakt: "Paktpartner", krieg: "Kriegsgegner", neutral: "neutral", kartell: "Kartell" }; -/** „vor 5 h“ (unter einer Stunde in Minuten). */ +/** „vor 5 h“ (unter einer Stunde in Minuten) – einheitlich über fmtAgo (lib/time.ts). */ export function agoText(atMs: number, now: number): string { - const ms = Math.max(0, now - atMs); - return ms < 60000 ? "gerade eben" : `vor ${fmtDuration(ms)}`; + return fmtAgo(atMs, now); } /** Zeile „Stand: vor X (Quelle)“ für bekanntes oder veraltetes Wissen; live: kleine Quellenangabe. */ diff --git a/apps/web/src/components/LagebildTab.tsx b/apps/web/src/components/LagebildTab.tsx index f5fca20..eb6e541 100644 --- a/apps/web/src/components/LagebildTab.tsx +++ b/apps/web/src/components/LagebildTab.tsx @@ -6,7 +6,7 @@ import { useQuery } from "@tanstack/react-query"; import { queryClient, trpc, trpcClient } from "../lib/trpc.ts"; import { useCommand } from "../lib/command.ts"; import { fmtNum, label } from "../lib/names.ts"; -import { fmtTime } from "../lib/time.ts"; +import { fmtAgo, fmtTime, useNow } from "../lib/time.ts"; import type { Target } from "../App.tsx"; import { Icon } from "../icons.tsx"; import { Badge, Card, ErrorLine, Loading, SmallButton, UnitChips } from "../ui.tsx"; @@ -18,19 +18,16 @@ const SENSOR_TEXT: Record = { }; const LEVEL_TEXT: Record = { sichtung: "Sichtung", erkennung: "Erkennung", lagebild: "Lagebild" }; -function ago(ms: number, now: number): string { - const min = Math.max(0, Math.round((now - ms) / 60000)); - return min < 60 ? `vor ${min} min` : `vor ${Math.round(min / 60)} h`; -} +const ago = fmtAgo; // „vor 12 min“, „vor 2 h“ – live mit der gemeinsamen Uhr export function LagebildTab({ onShowOnMap }: { onShowOnMap: (t: Target) => void }) { const q = useQuery({ ...trpc.intel.overview.queryOptions(), refetchInterval: 60000 }); + const now = useNow(60000); const [confirm, setConfirm] = useState(null); const dismantle = useCommand((i: { key: string; postId: number }) => trpcClient.intel.dismantlePost.mutate(i), () => [trpc.intel.pathFilter().queryKey, trpc.base.pathFilter().queryKey, trpc.world.map.pathFilter().queryKey]); if (!q.data) return ; const d = q.data; if (!d.enabled) return

In dieser Saison gibt es keinen Kartennebel: Du siehst die ganze Welt.

; - const now = d.serverNow; const here = (col: number | null, row: number | null) => col !== null && row !== null ? onShowOnMap({ col, row })}>Karte : null; const sensors = Object.entries(d.sensors.reduce>((acc, s) => { @@ -114,7 +111,7 @@ export function LagebildTab({ onShowOnMap }: { onShowOnMap: (t: Target) => void )} -

Stand {fmtTime(now)}.

+

Stand {fmtTime(d.serverNow, now)}.

diff --git a/apps/web/src/components/MissionSheet.tsx b/apps/web/src/components/MissionSheet.tsx index 6b855d5..e3be5a4 100644 --- a/apps/web/src/components/MissionSheet.tsx +++ b/apps/web/src/components/MissionSheet.tsx @@ -113,7 +113,7 @@ export function MissionPanel({ mission, now, home, onClose, onShowTarget }: {
{ph.outbound ? `Ankunft in ${fmtDuration(ph.end - now)}` : `Daheim in ${fmtDuration(ph.end - now)}`} - · {fmtTime(ph.end)} Uhr + · {fmtTime(ph.end)}
@@ -123,9 +123,9 @@ export function MissionPanel({ mission, now, home, onClose, onShowTarget }: {
Ziel{name}{m.target.kind !== "kartell" ? ` (Feld ${m.target.col}/${m.target.row})` : ""} HeimathafenFeld {home.col}/{home.row} - Abfahrt{fmtTime(m.departAtMs)} Uhr - Ankunft am Ziel{fmtTime(m.arriveAtMs)} Uhr{!ph.outbound ? " (erreicht)" : ""} - Zurück daheim{m.recalled && ph.outbound ? "–" : `${fmtTime(m.returnAtMs)} Uhr`} + Abfahrt{fmtTime(m.departAtMs)} + Ankunft am Ziel{fmtTime(m.arriveAtMs)}{!ph.outbound ? " (erreicht)" : ""} + Zurück daheim{m.recalled && ph.outbound ? "–" : `${fmtTime(m.returnAtMs)}`} {m.reportId && Der Bericht liegt unter Meldungen.}
)} diff --git a/apps/web/src/components/Naval.tsx b/apps/web/src/components/Naval.tsx index ef4f098..a807b51 100644 --- a/apps/web/src/components/Naval.tsx +++ b/apps/web/src/components/Naval.tsx @@ -5,7 +5,7 @@ import { hexAtXY, hexDistanceKm } from "@tidefront/world"; import { trpc, trpcClient, type BaseData, type Outputs } from "../lib/trpc.ts"; import { useCommand } from "../lib/command.ts"; import { errorText, fmtNum, label } from "../lib/names.ts"; -import { fmtDuration, fmtTime, useNow } from "../lib/time.ts"; +import { fmtDuration, fmtTime, useCountdownNow, useNow } from "../lib/time.ts"; import { Button, Card, CountsLine, ErrorLine, Stepper, SmallButton } from "../ui.tsx"; import { Icon } from "../icons.tsx"; import type { Target } from "../App.tsx"; @@ -29,12 +29,13 @@ const resLine = (m: Counts | null | undefined) => { export function BlockadeBanner() { const q = useNaval(); const b = q.data?.ownBlockade; - if (!b) return null; + const now = useCountdownNow(b?.endsAtMs); + if (!b || b.endsAtMs <= now) return null; // abgelaufen: ausblenden, bis die nächste Abfrage kommt return (
-
Hafen blockiert bis {fmtTime(b.endsAtMs)}
+
Hafen blockiert bis {fmtTime(b.endsAtMs)} · noch {fmtDuration(b.endsAtMs - now)}

Produktion −{Math.round((1 - b.factor) * 100)} %, eingehende Lieferungen werden zurückgehalten, Börsenverkäufe gesperrt. Greife den Blockadeverband über die Karte an – Verbündete können helfen.

@@ -179,11 +180,12 @@ export function LiftBlockade({ missionId }: { missionId: number }) { const q = useNaval(); const lift = useCommand((i: { key: string; blockadeId: number }) => trpcClient.naval.liftBlockade.mutate(i), () => [trpc.base.pathFilter().queryKey, trpc.naval.pathFilter().queryKey]); const b = q.data?.blockades.find((x) => x.role === "own"); + const now = useNow(); void missionId; if (!b) return null; return (
- Hält die Blockade vor {b.targetName} noch {fmtDuration(b.endsAtMs - Date.now())}. + Hält die Blockade vor {b.targetName} noch {fmtDuration(b.endsAtMs - now)}.
diff --git a/apps/web/src/components/PlayerTrade.tsx b/apps/web/src/components/PlayerTrade.tsx index 1a3efea..72673a6 100644 --- a/apps/web/src/components/PlayerTrade.tsx +++ b/apps/web/src/components/PlayerTrade.tsx @@ -5,6 +5,7 @@ import { trpc, trpcClient, type BaseData, type Outputs } from "../lib/trpc.ts"; import { useCommand } from "../lib/command.ts"; import { fmtNum, label } from "../lib/names.ts"; import { fmtDuration } from "../lib/time.ts"; +import { useLiveBase } from "../lib/live-base.ts"; import { ActionBar, Badge, Button, Card, ErrorLine, Loading, UnitChips } from "../ui.tsx"; import { ActionRemedy, ReasonLine } from "./Remedy.tsx"; // „Was hilft?“ import { Icon } from "../icons.tsx"; @@ -23,6 +24,7 @@ function Asset({ id, qty }: { id: string; qty: number }) { export function PlayerTrade({ base }: { base: BaseData }) { const list = useQuery({ ...trpc.playerTrade.list.queryOptions(), refetchInterval: 60000 }); + const res = useLiveBase(base).resources; // Bestand live hochgerechnet const me = useQuery(trpc.alliance.get.queryOptions()); const prices = usePrices(); const [give, setGive] = useState("stahl"); @@ -42,7 +44,7 @@ export function PlayerTrade({ base }: { base: BaseData }) { const ownOpen = open.filter((o) => o.own).length; const g = Math.floor(Number(giveQty) || 0); const w = Math.floor(Number(wantQty) || 0); - const have = give === "credits" ? base.market.credits : base.resources[give] ?? 0; + const have = give === "credits" ? base.market.credits : res[give] ?? 0; const unlocked = base.market.unlocked; // Gesperrt mit bekanntem Grund: der graue Knopf klappt „Was hilft?“ über der Leiste auf. const blockCode = !unlocked ? "locked" : ownOpen >= maxOpen ? "too_many_offers" : g > have ? (give === "credits" ? "funds" : "insufficient_resources") : null; @@ -129,9 +131,10 @@ export function PlayerTrade({ base }: { base: BaseData }) { function OfferRow({ o, fee, base, prices, busy, onAccept, onWithdraw }: { o: Offer; fee: number; base: BaseData; prices: Prices | null; busy: boolean; onAccept: (escort?: Record) => void; onWithdraw: () => void }) { const [confirm, setConfirm] = useState(false); const [escort, setEscort] = useState>({}); // See: Konvoi – Geleitschutz + const res = useLiveBase(base).resources; // Aus Sicht des Lesers: beim eigenen Angebot gibt er give, sonst gibt er want und bekommt give. const v = o.own ? readerValue(prices, o.give, o.giveQty, o.want, o.wantQty) : readerValue(prices, o.want, o.wantQty, o.give, o.giveQty); - const have = o.want === "credits" ? base.market.credits : base.resources[o.want] ?? 0; + const have = o.want === "credits" ? base.market.credits : res[o.want] ?? 0; const net = o.give === "credits" ? Math.floor(o.giveQty * (1 - fee) * 100) / 100 : o.giveQty - Math.floor(o.giveQty * fee); return (
  • diff --git a/apps/web/src/components/PowerGrid.tsx b/apps/web/src/components/PowerGrid.tsx index 316a5ac..1c766ce 100644 --- a/apps/web/src/components/PowerGrid.tsx +++ b/apps/web/src/components/PowerGrid.tsx @@ -6,7 +6,8 @@ import type React from "react"; import { BEAUFORT_WORDS, beaufort } from "@tidefront/game-core"; import type { BaseData } from "../lib/trpc.ts"; import { fmtNum } from "../lib/names.ts"; -import { serverNow } from "../lib/time.ts"; +import { fmtAt, fmtDuration, serverNow, useNow } from "../lib/time.ts"; +import { liveStoredAt } from "../lib/live-base.ts"; import { Icon } from "../icons.tsx"; import { INK, MESSING, MOOS, SEE, SIEGEL } from "../icons-art.tsx"; import { Bar } from "../ui.tsx"; @@ -47,7 +48,7 @@ function hourOf(ms: number): number { /** Uhrzeit hh:mm in Ortszeit des Geräts. */ function clockOf(ms: number): string { - return new Date(ms - (serverNow() - Date.now())).toLocaleTimeString("de-DE", { hour: "2-digit", minute: "2-digit" }); + return fmtAt(ms); // einheitlich, mit „morgen“ } const sum = (o: Record) => Object.values(o).reduce((a, b) => a + b, 0); @@ -81,6 +82,7 @@ export function PowerGrid({ base }: { base: BaseData }) { const meta = useQuery({ ...trpc.meta.queryOptions(), staleTime: Infinity }); const windCut = (meta.data?.balance as { buildings?: { windpark?: { stormCutoff?: number } } } | undefined)?.buildings?.windpark?.stormCutoff; const g = base.grid; + const stored = liveStoredAt(base, useNow()); // Speicher live hochgerechnet const supply = sum(g.now.supply); const demand = sum(g.now.demand); const short = g.now.served.radar < 1 || g.now.served.production < 1; @@ -104,10 +106,10 @@ export function PowerGrid({ base }: { base: BaseData }) { {g.now.capacity > 0 && (
    - Speicher {fmtNum(g.now.stored)} / {fmtNum(g.now.capacity)} + Speicher {fmtNum(stored)} / {fmtNum(g.now.capacity)} {g.now.charge > 0.5 ? `lädt ${fmtNum(g.now.charge)}/h` : g.now.charge < -0.5 ? `liefert ${fmtNum(-g.now.charge)}/h` : "ruht"}
    - +
    )} @@ -130,7 +132,7 @@ export function PowerGrid({ base }: { base: BaseData }) {
  • {g.warning ? (

    - {g.warning.atMs - serverNow() < 60000 ? "Jetzt" : `Voraussichtlich ab ${hourOf(g.warning.atMs)} Uhr`} fehlen {fmtNum(g.warning.missing)} Strom – {g.warning.text} + {g.warning.atMs - serverNow() < 60000 ? "Jetzt" : `Voraussichtlich ab ${fmtAt(g.warning.atMs)} Uhr (in ${fmtDuration(g.warning.atMs - serverNow())})`} fehlen {fmtNum(g.warning.missing)} Strom – {g.warning.text}

    ) : (

    Die nächsten {g.curve.length} Stunden reicht der Strom voraussichtlich.

    diff --git a/apps/web/src/components/Remedy.tsx b/apps/web/src/components/Remedy.tsx index 113bf05..008dadc 100644 --- a/apps/web/src/components/Remedy.tsx +++ b/apps/web/src/components/Remedy.tsx @@ -9,19 +9,25 @@ import { Bar, SmallButton } from "../ui.tsx"; import { Icon } from "../icons.tsx"; import { errorText, fmtNum } from "../lib/names.ts"; import type { NavTarget } from "../lib/remedies/types.ts"; +import { useNow } from "../lib/time.ts"; +import { liveBaseAt } from "../lib/live-base.ts"; /** Gibt es zu diesem Code überhaupt einen Hinweis? */ export function hasRemedy(code: string | null | undefined): boolean { return !!code && Object.hasOwn(REMEDIES, code); } -/** Abhilfe zum Code mit aktivem Hafen und Balance (null: nichts zu tun). */ +/** + * Abhilfe zum Code mit aktivem Hafen und Balance (null: nichts zu tun). Live: Bestände werden sekündlich + * hochgerechnet, Fehlmengen und Wartezeiten passen sich ohne Neuöffnen an. + */ export function useRemedy(code: string | null | undefined, detail?: RemedyDetail): Remedy | null { const { base } = useNav(); const known = hasRemedy(code); const meta = useQuery({ ...trpc.meta.queryOptions(), staleTime: Infinity, enabled: known }); + const now = useNow(); if (!known) return null; - return remedy(code, { base, balance: (meta.data?.balance ?? null) as CoreBalance | null, detail: detail ?? {}, now: Date.now() }); + return remedy(code, { base: liveBaseAt(base, now), balance: (meta.data?.balance ?? null) as CoreBalance | null, detail: detail ?? {}, now }); } /** Klappzustand eines Hinweises, damit auch ein grauer Knopf ihn öffnen kann. */ diff --git a/apps/web/src/components/ResourceBar.tsx b/apps/web/src/components/ResourceBar.tsx index 5baba27..6c7e44f 100644 --- a/apps/web/src/components/ResourceBar.tsx +++ b/apps/web/src/components/ResourceBar.tsx @@ -2,6 +2,8 @@ import type { BaseData } from "../lib/trpc.ts"; import { fmtNum, label } from "../lib/names.ts"; import { RES_ORDER, liveAmount } from "../lib/live.res.ts"; import { useState } from "react"; +import { useNow } from "../lib/time.ts"; +import { liveStoredAt } from "../lib/live-base.ts"; import { Icon } from "../icons.tsx"; import { ResourceSheet } from "./ResourceSheet.tsx"; import { HarborSwitcher } from "./HarborSwitcher.tsx"; @@ -23,10 +25,10 @@ const sum = (o: Record) => Object.values(o).reduce((a, b) => a + * Ausgeglichen (Kraftwerk regelt nach, Bilanz 0) steht „gedeckt“; ohne Speicher zeigt die zweite Zeile die * Kraftwerk-Auslastung statt eines Strichs. */ -function PowerField({ base, onOpen }: { base: BaseData; onOpen: () => void }) { +function PowerField({ base, now, onOpen }: { base: BaseData; now: number; onOpen: () => void }) { const g = base.grid; const bal = Math.round(sum(g.now.supply) - sum(g.now.demand)); - const fill = g.now.capacity > 0 ? Math.min(1, g.now.stored / g.now.capacity) : 0; + const fill = g.now.capacity > 0 ? Math.min(1, liveStoredAt(base, now) / g.now.capacity) : 0; // Speicher live const warn = g.warning; const sign = bal > 0 ? "+" : bal < 0 ? "−" : "±"; const demand = Math.round(sum(g.now.demand)); @@ -58,9 +60,10 @@ function PowerField({ base, onOpen }: { base: BaseData; onOpen: () => void }) { } /** Kopfleiste: Hafenwahl (ab zwei Häfen), Papierstreifen mit vier Ressourcen (Stich, Bestand, Rate, Füllstand), Stromfeld und Menü. */ -export function ResourceBar({ base, asOf, now, onMenu, onSwitchBase, onPlanFounding, onPower }: { base: BaseData; asOf: number; now: number; onMenu: (item: MenuItem) => void; onSwitchBase: (id: number) => void; onPlanFounding: () => void; onPower: () => void }) { +export function ResourceBar({ base, asOf, onMenu, onSwitchBase, onPlanFounding, onPower }: { base: BaseData; asOf: number; onMenu: (item: MenuItem) => void; onSwitchBase: (id: number) => void; onPlanFounding: () => void; onPower: () => void }) { const [open, setOpen] = useState(null); const [menu, setMenu] = useState(false); + const now = useNow(); // gemeinsame Uhr: Bestände sekündlich hochgerechnet return (
    @@ -85,7 +88,7 @@ export function ResourceBar({ base, asOf, now, onMenu, onSwitchBase, onPlanFound ); })} - +