mirror of
https://github.com/db9979/uconsole_asw_game.git
synced 2026-12-05 20:34:16 +01:00
- Remote Crew browser client rebuilt as a dark combat-information-centre layout for large desktop monitors: slim status bar (stations, mission, clocks, UTC, link state), pulsing alert band, the instrument as centrepiece and collapsible docks (contacts, station, contact detail, log drawer; keys , . L). Four columns from 2400 px, fluid type up to 4K; guide, lookout and contact library open as overlays (Esc closes). - app.js split into native ES modules under data/commander/js; the transport (net/*) no longer touches the DOM and talks to the views through synchronous topics (core/events.js, app/bindings.js); redraws share one frame scheduler. - style.css replaced by a token-based design system in data/commander/css. - Inter 4.1 and JetBrains Mono 2.304 bundled unmodified (OFL-1.1) with provenance in THIRD_PARTY_NOTICES.md; CSP allows font-src 'self'. - Server serves the css/js/fonts trees from one asset manifest (src/commander/assets.py); packaging, capture tool, help, manual and docs updated; tests share tests/commander_web.py and import modules directly. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
38 lines
2.0 KiB
JavaScript
38 lines
2.0 KiB
JavaScript
import { S } from "./store.js";
|
|
import { finite } from "../core/format.js";
|
|
|
|
// The host publishes at most every 0.5 s, so drawing the acoustic plots only
|
|
// when data arrived made the waterfalls jump in steps. They are instead drawn
|
|
// against a smoothed display clock. The game always runs in real time and
|
|
// never pauses, so the clock simply advances 1:1 with wall time from the last
|
|
// publication while the world is live, runs a fixed jitter delay behind it
|
|
// (rows scroll in over the top edge instead of popping in) and only slews
|
|
// gently. Purely presentational: nothing here is sent to the host.
|
|
export const DISPLAY_CLOCK_LAG_S = .75;
|
|
const displayClock = {context: null, sim: 0, wall: 0, live: false, shown: null, shownWall: 0};
|
|
export function sampleDisplayClock(state, sim = state?.clock?.sim) {
|
|
if (!state || !finite(sim)) return;
|
|
const context = `${state.session}:${state.epoch}`;
|
|
const live = state.phase === "live";
|
|
const reset = displayClock.context !== context;
|
|
if (reset) { displayClock.context = context; displayClock.shown = null; }
|
|
// One publication reaches the page twice (stream frame and state poll);
|
|
// its earliest arrival is the better anchor for extrapolation.
|
|
if (reset || sim > displayClock.sim || live !== displayClock.live)
|
|
Object.assign(displayClock, {sim, wall: performance.now(), live});
|
|
}
|
|
export function displaySimNow(wallNow = performance.now()) {
|
|
if (displayClock.context === null) return S.v2State?.clock?.sim ?? 0;
|
|
const rate = displayClock.live ? 1 : 0;
|
|
const elapsed = Math.min(1.5, Math.max(0, (wallNow - displayClock.wall) / 1000));
|
|
const target = displayClock.sim + elapsed * rate - DISPLAY_CLOCK_LAG_S;
|
|
if (displayClock.shown === null || Math.abs(target - displayClock.shown) > 3) {
|
|
displayClock.shown = target;
|
|
} else {
|
|
const dt = Math.min(.25, Math.max(0, (wallNow - displayClock.shownWall) / 1000));
|
|
displayClock.shown += Math.max(0, dt * (rate + Math.max(-.1, Math.min(.1, target - displayClock.shown))));
|
|
}
|
|
displayClock.shownWall = wallNow;
|
|
return displayClock.shown;
|
|
}
|