Files
uconsole_asw_game/data/commander/js/app/bindings.js
T
db9979andClaude Opus 5.5 f7e6d05e2a Web: overlap-free status bar, h:mm:ss clocks, overlays inside the viewport
- Status bar stays one row at every desktop width: short clock labels (full
  names as tooltips), mission remaining/elapsed as h:mm:ss, connection text
  truncated with the full text as tooltip; badge, mission name and UTC give
  way on narrower windows instead of overlapping.
- Guide, lookout and contact library overlays no longer inherit the panel's
  100 % size, so they fit the viewport and the close button is visible.
- Regression tests for status-bar overlap and overlay bounds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-26 14:09:13 +02:00

122 lines
5.0 KiB
JavaScript

import { S } from "../state/store.js";
import { playAlert } from "../audio/alerts.js";
import { openSonarAudioSocket, scheduleSonarAudioPoll, sonarAudioAuthorized, stopSonarAudio, syncGameAudio } from "../audio/audio.js";
import { $ } from "../core/base.js";
import { on } from "../core/events.js";
import { t } from "../core/format.js";
import { syncPlotAnimation } from "../plot/clock.js";
import { renderBridgeOrders } from "../views/bridge-orders.js";
import { canvas, lookoutCanvas } from "../views/canvases.js";
import { fitChart, releaseCanvas } from "../views/chart.js";
import { renderActionState, renderSonarControlPage } from "../views/controls.js";
import { clearFireDrafts } from "../views/dom.js";
import { renderEvents, renderProposals } from "../views/feeds.js";
import { renderHost } from "../views/host.js";
import { acceptSession, activateTab, renderLobby } from "../views/lobby.js";
import { renderSnapshot } from "../views/render.js";
import { updateOpzSweepSample } from "../views/role-map.js";
import { queueVisualDraw, renderRoleVisuals } from "../views/role-visuals.js";
import { applySimlogView, loadSimlog } from "../views/simlog.js";
import { clearRoleState } from "../views/station-view.js";
import { renderConnection } from "../views/status.js";
// The transport (net/*) never touches the page. It updates the store and emits
// a topic; this module maps every topic to the views, audio and plot loops.
function revalidateAudio() {
if (S.sonarAudioEnabled && !sonarAudioAuthorized()) stopSonarAudio("sonar_live_unavailable");
}
function forgetPage() {
$("operations").hidden = true;
$("lobby").hidden = true;
$("role-rail").hidden = true;
$("mobile-role").hidden = true;
$("simlog-view").hidden = true;
$("simlog-list").replaceChildren();
$("simlog-current").replaceChildren();
$("simlog-count").textContent = "";
renderEvents();
$("pairing").hidden = false;
$("disconnect").hidden = true;
$("pair-error").textContent = "";
$("code").value = "";
$("navigation-form").reset();
$("navigation-status").textContent = "";
document.body.dataset.remoteRole = "";
$("host-screen").hidden = true;
$("host-bar").hidden = true;
activateTab("operations", false);
for (const id of ["track-list", "detail-label", "detail-badges", "detail-metrics", "mission-name", "objective", "mission-metrics", "proposal-status", "command-status", "snapshot-meta", "lookout-sea", "lookout-light", "lookout-own", "lookout-observations"]) $(id).replaceChildren();
$("lookout-scope").dataset.light = "unknown";
releaseCanvas(canvas);
releaseCanvas(lookoutCanvas);
}
function resetContextForms(worldChanged) {
clearFireDrafts();
if (!worldChanged) return;
$("navigation-form").reset();
$("bridge-course-form").reset();
$("bridge-speed-form").reset();
$("opz-manage").checked = false;
for (const id of ["sonar-bearing-form", "sonar-depth-form", "sonar-gain-form", "sonar-harmonic-form",
"engine-course-form", "engine-speed-form", "helicopter-waypoint-form",
"uboot-course-form", "uboot-speed-form", "uboot-depth-form"]) $(id).reset();
$("sonar-control-page").value = "listen";
renderSonarControlPage();
}
function followState(state) {
updateOpzSweepSample(state);
syncGameAudio();
// A new world epoch (the host's local input advances it) closes the live
// audio socket; resume it once the state for the new epoch has arrived.
const audioWorld = `${state.session}:${state.epoch}`;
if (audioWorld !== S.sonarAudioWorld) {
S.sonarAudioWorld = audioWorld;
if (S.sonarAudioEnabled && !S.sonarAudioSocket && sonarAudioAuthorized()) {
if (S.sonarAudioWorklet) openSonarAudioSocket();
else if (!S.sonarAudioController) scheduleSonarAudioPoll(0);
}
}
}
export function init() {
on("session:metadata", acceptSession);
on("session:forgetting", () => stopSonarAudio());
on("session:forgotten", forgetPage);
on("connection", (message) => {
renderConnection();
if (message) $("connection").textContent = $("connection").title = t(message);
renderActionState();
renderHost();
if (S.v2State?.role) renderRoleVisuals(S.v2State.role);
revalidateAudio();
syncGameAudio();
syncPlotAnimation();
});
on("lobby", renderLobby);
on("role:clear", clearRoleState);
on("role:fresh", () => document.body.removeAttribute("data-role-stale"));
on("chart:blank", () => { $("operations").hidden = true; });
on("chart:fit", fitChart);
on("context:changed", resetContextForms);
on("state:accepted", followState);
on("plots:sync", syncPlotAnimation);
on("sonar:frame", queueVisualDraw);
on("snapshot", (epochChanged) => {
$("pairing").hidden = true;
renderLobby();
applySimlogView();
renderSnapshot(epochChanged);
loadSimlog();
});
on("proposals", renderProposals);
on("events", (warning) => { if (warning) playAlert(); renderEvents(); });
on("command", (bridge) => (bridge ? renderBridgeOrders() : renderActionState()));
on("command:settled", clearFireDrafts);
on("audio:stop", (reason) => stopSonarAudio(reason));
on("audio:revalidate", revalidateAudio);
on("host", renderHost);
}