import { defaultSonarPage } from "./shared.js"; // Mutable client state shared by several modules. Transient: never sent to // the host, stored or placed in the DOM. // Pages open in the host's saved language (the server names it in a meta // tag); without one, in the browser's. export function initialLanguage() { const host = document.querySelector('meta[name="u-jagd-host-language"]')?.getAttribute("content"); if (host === "en" || host === "de") return host; return (navigator.language || "en").toLowerCase().startsWith("de") ? "de" : "en"; } export const S = { language: initialLanguage(), catalog: {}, // Session metadata stays closure-local: no URL, DOM or persistence. session: null, pairingAvailable: false, generation: 0, snapshot: null, chart: null, chartSession: null, chartEpoch: null, chartRole: null, selected: null, connected: false, linkState: "unpaired", lastSuccess: 0, lastSessionFetch: 0, failures: 0, pollTimer: null, polling: false, pending: null, v2State: null, roleStale: false, // Solo host surface: the published host view and the one host command in flight. hostView: null, hostPending: null, hostMessage: null, hostMessageTimer: null, // Own-mission library of the solo host (net/missions.js, views/missions.js). missionLibrary: null, missionCatalog: null, stationRenderSignature: null, nextCommandSeq: 0, stationMutation: false, activatingStation: null, queuedSonarFocus: null, // Focus this client last sent, until the state shows it or it is rejected. requestedSonarFocus: null, stationPickerOpen: false, lobbyMessage: null, lobbyRoomMessage: null, // Unit chosen in the lobby ("frigate" | "opfor"); held stations decide otherwise. lobbySide: "frigate", commandMessage: null, lastToastedMessage: null, opzMarked: new Set(), opzSuppressed: new Set(), opzManage: false, stationDrafts: new Set(), // Snapshot seq after which a settled command's drafts are dropped. clearDraftsAfter: null, // Emitter the mast station has selected in the boat's ESM list (by number). ubootEsmSelected: null, // Bridge route mode: a chart click adds an autopilot waypoint. bridgeRouteMode: false, ubootRouteMode: false, requestQueue: Promise.resolve(), activeRequest: null, languageRequest: 0, audio: null, soundEnabled: false, speechEnabled: false, speechQueued: 0, calloutContext: null, calloutHighWater: 0, sonarAudioEnabled: false, sonarAudioController: null, sonarAudioTimer: null, sonarAudioSequence: null, sonarAudioNextTime: 0, helicopterAudioSource: null, sonarAudioSources: [], sonarAudioGain: null, sonarAudioHighpass: null, sonarAudioLowpass: null, sonarAudioWorklet: null, sonarAudioSocket: null, sonarAudioReconnect: null, sonarAudioMetrics: {buffered: 0, gaps: 0, concealed: 0, rate: 1, stale: false}, gameSoundContext: null, gameSoundHighWater: 0, chartHits: [], drag: null, activeTab: "operations", contactAnalysis: null, analysisSelected: null, analysisImageKey: null, lastSimlogFetch: 0, proposals: null, eventContext: null, eventBaselinePending: false, eventHighWater: 0, eventHistory: [], analysisError: false, latestSimlogState: null, simlogMapData: null, simlogMapSeq: null, simlogMapLatest: false, simlogMapFit: "world", roleMapHits: [], // Hover information for the maps (tracks, own ship, assets, chart items); // separate from the click hit lists so selection semantics are unchanged. roleMapInfo: [], chartInfo: [], damageHits: [], sonarVisualPage: defaultSonarPage(), helicopterVisualPage: "acoustic", helicopterPlot: "lofar", weatherFrame: null, weatherTimer: null, weatherLastDraw: 0, roleMapDrag: null, plotAnchor: null, plotListKey: "", sonarBroadbandDrag: null, opzSweepFrame: null, opzSweepSample: null, fireConfirmation: null, fireConfirmationTimer: null, sonarAudioGeneration: 0, // World session/epoch the live audio last saw; a change resumes the stream. sonarAudioWorld: null, // Pointer position over the weather profile (CSS px), or null. weatherCursor: null, webHostAvailable: false, };