diff --git a/changelog.d/1833-hud-credits-sonar-links.md b/changelog.d/1833-hud-credits-sonar-links.md new file mode 100644 index 0000000000..c81dbc0590 --- /dev/null +++ b/changelog.d/1833-hud-credits-sonar-links.md @@ -0,0 +1,4 @@ +- Keep the HUD's bottom corners, the Omnibar dock and the corner row clear of + the map credits at every desktop width, also right to left and when the + credits wrap onto several lines; and carry Sonar with the Minimal HUD layout + in share links and scene shots (manjunath22466, samehkhamis, #1833). diff --git a/changelog.d/1835-icon-near-plane-flicker.md b/changelog.d/1835-icon-near-plane-flicker.md new file mode 100644 index 0000000000..b6cf5c620c --- /dev/null +++ b/changelog.d/1835-icon-near-plane-flicker.md @@ -0,0 +1,3 @@ +- Icons drawn over depth (aircraft, vessels) no longer vanish for a frame now + and then in dense far-away clusters: they sit just past the near plane instead + of exactly on it, where rounding could discard them (samehkhamis, #1835). diff --git a/changelog.d/1836-delayed-clock-test.md b/changelog.d/1836-delayed-clock-test.md new file mode 100644 index 0000000000..22456a2314 --- /dev/null +++ b/changelog.d/1836-delayed-clock-test.md @@ -0,0 +1,3 @@ +- The delayed-live aircraft icon test holds the clock still while it compares + drawn and read positions, so it no longer fails on a busy machine + (samehkhamis, #1836). diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index fe0a23d384..5803d88fbf 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -1136,8 +1136,12 @@ opt-in visual style over Tactical or Minimal: Display > HUD > Sonar is OFF by default, and ON reveals the Rings, Range, Power, Opacity and Sector sliders. Share links, scenes and saved views that name Cyber keep its enum code and open in Tactical with Sonar on. Links and scene shots record Tactical with -Sonar on under that same code, and a restored state that names another layout -turns Sonar off; Minimal has no such code, so its Sonar is not carried. +Sonar on under that same code, so older builds still read it. Minimal with +Sonar on is recorded as Minimal plus an explicit Sonar mark: flag bit 5 +(`hudSonar`) of a compact link, `hs=1` in the long form, and `hud.sonar: true` +in a scene shot. A restored state turns Sonar on when it names Cyber or carries +that mark, and off otherwise, so a link or shot made before the mark restores +as it always did. An explicit Sonar toggle or validated voice setting takes visual restore authority, so a delayed share-link restore cannot undo the newer choice. Choosing Reset Visual keeps the HUD layout and the Sonar setting. @@ -1181,12 +1185,19 @@ corners, so it keeps to the bottom edge, the attribution row sits above it and the coordinates clear the row's logo line. In the desktop Omnibar layout the Omnibar's own rules (`src/ui/styles/omnibar-dock.css`) place the dock, the World Timeline, the credits and the coordinates; its Tactical bottom-right -readout also keeps 8px above the Power Up row. The left rail treats the -centered World Timeline and voice control as obstacles only where they reach a -laid-out panel, not the stack's transparent gutter. Known limit, unchanged -from main: below 1200px with the World Timeline showing, the Tactical -bottom-right readout does not rise with the bar and can touch the dock, and a -credit line longer than the screen does not wrap. +readout also keeps 8px above the Power Up row. There the credit line wraps at +every width, right to left it takes the bottom right at every width, and +`src/ui/creditLineHeight.js` keeps its height in `--credit-line-height`: the +coordinates (and, right to left, the Tactical readout) stay 6px above it +however many lines it wraps onto, and the dock and World Timeline rise when +it is taller than their usual clearance. Narrower than 1120px the dock leaves +no room between the corners, so the coordinates and the readout sit above +the dock, and above the World Timeline while it shows. Outside that layout +Cesium's credit box wraps from 1200px, as before; the phone shell, clean +view, recording and scene playback lay the line out themselves. +The left rail treats the centered World Timeline and voice control as +obstacles only where they reach a laid-out panel, not the stack's +transparent gutter. Wind appears in the Weather group before Audio. The surface-weather prototype uses keyless NOAA GFS or ECMWF IFS forecasts on an approximately 1° display grid. diff --git a/docs/SCENE-DOCUMENT.md b/docs/SCENE-DOCUMENT.md index 6d4077d959..948062c8e0 100644 --- a/docs/SCENE-DOCUMENT.md +++ b/docs/SCENE-DOCUMENT.md @@ -54,8 +54,14 @@ fallback for zero; holds may be zero. Visual fields are `style`, `mapStack`, `styleParams`, `bloom`, `sharpen`, `hud`, and `detection`, and `scope`. Bloom has `enabled`, `intensity`, `version`; sharpen has `enabled`, -`intensity`; HUD has `visible`, `variant`; detection has `mode`, `density`, +`intensity`; HUD has `visible`, `variant` and an optional `sonar`; detection has `mode`, `density`, `allocation`, `fadePct` and `outsideOpacityPct`. Scope has `enabled`, `featherPct`. +HUD `sonar: true` is Sonar on beside a layout that cannot say it (Minimal); it +is written only then, so Tactical with Sonar stays the variant `cyber` and a +shot without Sonar has no `sonar`. A shot without it opens with Sonar on only +when its variant is `cyber`. A build from before `sonar` refuses a project +that has it, as it refuses any field it does not know; every other project +still opens there. The latter settings were written by Update Shot but previously lost during normalization; they now survive import and capture. Version-1/2 bloom without an explicit scale version uses the original inverted diff --git a/docs/SHARE-LINK-FORMAT.md b/docs/SHARE-LINK-FORMAT.md index 888c3a91e3..41e1b81abd 100644 --- a/docs/SHARE-LINK-FORMAT.md +++ b/docs/SHARE-LINK-FORMAT.md @@ -176,7 +176,11 @@ Opacity slider (the long form's `sco`). It is written only below 100, so a link made before it, which opens at full opacity, keeps its code. Flag bits (field 9): 0 `bloom`, 1 `sharpen`, 2 `hudVisible`, 3 -`celestialRing` (each defaulting by style), 4 `scopeEnabled` (default on). +`celestialRing` (each defaulting by style), 4 `scopeEnabled` (default on), 5 +`hudSonar` (default off). `hudSonar` is Sonar on beside a HUD layout whose code +cannot say so, Minimal (the long form's `hs=1`); Tactical with Sonar stays the +`cyber` layout code alone. A link made before the bit has it off, and opens +with Sonar on only when it names `cyber`, as before. ### Style defaults diff --git a/scripts/format-scope.json b/scripts/format-scope.json index b8ce23b532..d2f4f549a3 100644 --- a/scripts/format-scope.json +++ b/scripts/format-scope.json @@ -1565,6 +1565,8 @@ "dev/stub-app/main.js", "scripts/qa-stub-boot.mjs", "src/ui/creditsView.js", + "src/ui/creditLineHeight.js", + "src/ui/creditLineHeight.test.mjs", "src/ui/creditsView.test.mjs", "src/cockpitSubjectProviders.js", "src/cockpitSubjectProviders.test.mjs", diff --git a/scripts/package-boundaries.json b/scripts/package-boundaries.json index dffb890a48..2289a8318d 100644 --- a/scripts/package-boundaries.json +++ b/scripts/package-boundaries.json @@ -5477,6 +5477,7 @@ "src/render/applicationHooks.js", "src/maps/globeEngine.js", "src/render/cesium/viewers.js", + "src/ui/creditLineHeight.js", "src/ui/creditsView.js", "src/data/planespottersPhoto.js", "src/maps/keylessTerrain.js", diff --git a/src/app/scene.js b/src/app/scene.js index 63012fb663..9945fb2bbd 100644 --- a/src/app/scene.js +++ b/src/app/scene.js @@ -1,6 +1,7 @@ import { createApplicationOperations } from './operations.js'; import { registerDataCredits } from '../data/dataCredits.js'; import { mountCreditsView } from '../ui/creditsView.js'; +import { trackCreditLineHeight } from '../ui/creditLineHeight.js'; import { MapStackController } from '../mapStackController.js'; import { mapEngineFor } from '../maps/engine.js'; import { initLogoGaze } from '../logoGaze.js'; @@ -173,6 +174,8 @@ export async function createApplicationScene({ // The credits, in the application's own line, unless the renderer shows // them in a display of its own. if (!hooks.ownCreditDisplay) defer(mountCreditsView(viewer)); + // The HUD corners above the line clear it when it wraps. + defer(trackCreditLineHeight(document)); loaderStatus.textContent = googleApiKey || googleTokens || cesiumToken ? t('Loading Google 3D Tiles...') diff --git a/src/creditAttribution.test.mjs b/src/creditAttribution.test.mjs index 879f58d64e..958578689d 100644 --- a/src/creditAttribution.test.mjs +++ b/src/creditAttribution.test.mjs @@ -439,12 +439,21 @@ function resolve(candidates, prop, width, label) { /** Evaluate a length. Anything the model cannot resolve exactly fails loudly. */ function toPx(value, viewportHeight, where) { const trimmed = value.trim(); + // The larger of its lengths, each resolved the same way. + if (/^max\(.*\)$/.test(trimmed)) + return Math.max( + ...splitTopLevel(trimmed.slice(4, -1), ',').map((part) => + toPx(part, viewportHeight, where), + ), + ); const inner = /^calc\(/.test(trimmed) ? trimmed.slice(5, -1) : trimmed; - assert.doesNotMatch( - inner, - /\bcalc\(/, - `nested calc() in ${where}: "${value}"`, - ); + // A calc() is a whole term of its own, resolved below; nowhere else. + for (const term of splitTopLevel(inner, '+')) + assert.doesNotMatch( + term.trim().replace(/^calc\(.*\)$/, ''), + /\bcalc\(/, + `nested calc() in ${where}: "${value}"`, + ); assert.doesNotMatch( inner, /\b(min|max|clamp|env|attr|round|mod)\(/, @@ -465,6 +474,18 @@ function toPx(value, viewportHeight, where) { const term = raw.trim(); if (!term) continue; if (term === '100%') continue; // the tray's own panel height, added separately + // A calc() of its own, as a term ("calc(var(--omnibar-credits-clear) + + // 2px)" once substituted). + if (/^calc\(.*\)$/.test(term)) { + total += toPx(term, viewportHeight, where); + continue; + } + // The credit line's own height (src/ui/creditLineHeight.js), at the + // height this pin models it at. + if (/^var\(--credit-line-height\b/.test(term)) { + total += CREDIT_HEIGHT_PX; + continue; + } if (term.startsWith('var(')) { const name = term.slice(4, term.lastIndexOf(')')).split(',')[0].trim(); assert.ok( @@ -859,16 +880,28 @@ function omnibarVar(name) { const decls = RULES.filter((rule) => rule.parts.includes(OMNIBAR_SCOPE)) .flatMap((rule) => rule.decls) .filter((decl) => decl.prop === name); - assert.equal(decls.length, 1, `${name} is declared once in the Omnibar scope`); + assert.equal( + decls.length, + 1, + `${name} is declared once in the Omnibar scope`, + ); return decls[0].value; } /** A length in the Omnibar layout, with its scope's own custom properties. */ function omnibarPx(value, viewportHeight, where) { - const substituted = value.replace( - /var\((--omnibar-[\w-]+)\)/g, - (_, name) => omnibarVar(name), - ); + // The scope's properties may name each other ("--omnibar-dock-bottom" + // clears "--omnibar-credits-clear"): substitute until none is left. + let substituted = value; + for (let pass = 0; /var\(--omnibar-/.test(substituted); pass += 1) { + assert.ok( + pass < 8, + `Omnibar properties name each other in a loop: ${value}`, + ); + substituted = substituted.replace(/var\((--omnibar-[\w-]+)\)/g, (_, name) => + omnibarVar(name), + ); + } return toPx(substituted, viewportHeight, where); } @@ -893,7 +926,11 @@ test('Omnibar reserves a non-overlapping desktop footer at native credit sizing' width, 'Omnibar dock', ); - assert.equal(dock.part, OMNIBAR.dock, `the Omnibar owns the dock at ${width}px`); + assert.equal( + dock.part, + OMNIBAR.dock, + `the Omnibar owns the dock at ${width}px`, + ); // Its top and height too: a legacy top or height winning here would // move or stretch the dock the clearance below is measured from. for (const [prop, value] of [ @@ -906,8 +943,16 @@ test('Omnibar reserves a non-overlapping desktop footer at native credit sizing' width, `Omnibar dock ${prop}`, ); - assert.equal(own.part, OMNIBAR.dock, `the Omnibar owns the dock ${prop} at ${width}px`); - assert.equal(own.decl.value, value, `Omnibar dock ${prop} at ${width}px`); + assert.equal( + own.part, + OMNIBAR.dock, + `the Omnibar owns the dock ${prop} at ${width}px`, + ); + assert.equal( + own.decl.value, + value, + `Omnibar dock ${prop} at ${width}px`, + ); } const credit = resolve( [ @@ -923,7 +968,11 @@ test('Omnibar reserves a non-overlapping desktop footer at native credit sizing' credit.part.startsWith(OMNIBAR_SCOPE), `the Omnibar owns the credit row at ${width}px`, ); - const dockBottom = omnibarPx(dock.decl.value, height, 'Omnibar dock bottom'); + const dockBottom = omnibarPx( + dock.decl.value, + height, + 'Omnibar dock bottom', + ); const creditTop = omnibarPx(credit.decl.value, height, 'Omnibar credit bottom') + CREDIT_HEIGHT_PX; @@ -938,7 +987,10 @@ test('Omnibar reserves a non-overlapping desktop footer at native credit sizing' // and no rule elsewhere forces them back. const trays = RULES.find((rule) => rule.parts.includes(OMNIBAR.trays)); assert.ok(trays, 'the Omnibar layout hides the legacy trays'); - assert.equal(trays.decls.find((decl) => decl.prop === 'display')?.value, 'none'); + assert.equal( + trays.decls.find((decl) => decl.prop === 'display')?.value, + 'none', + ); for (const rule of RULES) { for (const part of rule.parts) { if (!/#(location-bar|control-panel)$/.test(lastCompound(part))) continue; @@ -951,8 +1003,13 @@ test('Omnibar reserves a non-overlapping desktop footer at native credit sizing' // The minimal-HUD rail cap only shortens the rail, which is anchored at // its top, so it can only add room above the credit. const rail = RULES.find((rule) => rule.parts.includes(OMNIBAR.minimalRail)); - const cap = rail.decls.find((decl) => decl.prop === '--omnibar-minimal-rail-height'); - assert.match(cap?.value || '', /^min\(\s*var\(--right-stack-max-height, 70vh\),/); + const cap = rail.decls.find( + (decl) => decl.prop === '--omnibar-minimal-rail-height', + ); + assert.match( + cap?.value || '', + /^min\(\s*var\(--right-stack-max-height, 70vh\),/, + ); assert.equal( rail.decls.find((decl) => decl.prop === 'max-height')?.value, 'var(--omnibar-minimal-rail-height)', diff --git a/src/director/document.js b/src/director/document.js index 2ab0e6ec32..a682605a00 100644 --- a/src/director/document.js +++ b/src/director/document.js @@ -36,7 +36,7 @@ function visual(value, path, legacy) { const specs = { bloom: { enabled: 'boolean', intensity: [-100, 10000], version: [1, 100] }, sharpen: { enabled: 'boolean', intensity: [0, 100] }, - hud: { visible: 'boolean', variant: 'string' }, + hud: { visible: 'boolean', variant: 'string', sonar: 'boolean' }, detection: { mode: 'string', density: [0, 100], diff --git a/src/director/document.test.mjs b/src/director/document.test.mjs index 0a73f98edb..4e7e1112a5 100644 --- a/src/director/document.test.mjs +++ b/src/director/document.test.mjs @@ -168,3 +168,30 @@ test('captured scope and extended detection edits survive migration', () => { project.scenes[0].shots[0].visual.detection, ); }); + +test('a shot keeps Sonar beside its HUD layout; one without it reads as before', () => { + const project = fixture(); + const shot = project.scenes[0].shots[0]; + shot.visual = { hud: { visible: true, variant: 'minimal', sonar: true } }; + const read = (p) => + normalizeProject(parseSceneDocument(JSON.stringify(p))).scenes[0].shots[0] + .visual.hud; + assert.deepEqual(read(project), { + visible: true, + variant: 'minimal', + sonar: true, + }); + // Older shots name no Sonar: the layout alone, Cyber included, as before. + for (const variant of ['minimal', 'cyber']) { + shot.visual = { hud: { visible: true, variant } }; + assert.deepEqual(read(project), { visible: true, variant }); + } + // Off is the meaning of an absent field, so it is not kept. + shot.visual = { hud: { variant: 'minimal', sonar: false } }; + assert.equal(Object.hasOwn(read(project), 'sonar'), false); + shot.visual = { hud: { variant: 'minimal', sonar: 'on' } }; + assert.throws( + () => validateSceneDocument(project), + /\$\.scenes\[0\]\.shots\[0\]\.visual\.hud\.sonar/, + ); +}); diff --git a/src/render/cesium/draw.test.mjs b/src/render/cesium/draw.test.mjs index 63f42ad4ab..e524925b09 100644 --- a/src/render/cesium/draw.test.mjs +++ b/src/render/cesium/draw.test.mjs @@ -4452,19 +4452,28 @@ test('an aircraft layer draws its contacts as one GPU icon set moving on the del } assert.equal(host._recedeParams().scaleFloor, 0.45); - // Drawn where the layer reads it, between its two fixes. - const t = Date.now() - delayMs; - const tau = set.seconds(julianAt(t)); - const drawn = set.position(row, tau); - const read = icons._iconPosition('abc123'); - assert.ok(Cesium.Cartesian3.distance(drawn, read) < 0.5, 'same place'); - const lon = Cesium.Math.toDegrees( - Cesium.Cartographic.fromCartesian(drawn).longitude, - ); - assert.ok(lon > -97 && lon < -96.9, 'interpolating the fixes'); - assert.ok( - Math.abs(set.course(row, tau) - icons._iconCourse('abc123')) < 0.01, - ); + // Drawn where the layer reads it, between its two fixes. The clock + // holds still while both are read: the contact covers half a metre in + // about a millisecond, so two readings of a moving clock may not agree. + const realNow = Date.now; + const frozen = realNow(); + Date.now = () => frozen; + try { + const t = frozen - delayMs; + const tau = set.seconds(julianAt(t)); + const drawn = set.position(row, tau); + const read = icons._iconPosition('abc123'); + assert.ok(Cesium.Cartesian3.distance(drawn, read) < 0.5, 'same place'); + const lon = Cesium.Math.toDegrees( + Cesium.Cartographic.fromCartesian(drawn).longitude, + ); + assert.ok(lon > -97 && lon < -96.9, 'interpolating the fixes'); + assert.ok( + Math.abs(set.course(row, tau) - icons._iconCourse('abc123')) < 0.01, + ); + } finally { + Date.now = realNow; + } assert.equal(state._icons.expires('abc123'), now - 20_000); assert.deepEqual( drawHitOf(host._pickObject('abc123', null, { show: true })), diff --git a/src/render/cesium/iconSetPrimitive.js b/src/render/cesium/iconSetPrimitive.js index f1559019d3..432f78ffd1 100644 --- a/src/render/cesium/iconSetPrimitive.js +++ b/src/render/cesium/iconSetPrimitive.js @@ -261,7 +261,12 @@ void main() { if (overDepth && zclip >= -1.0 && zclip <= 1.0) { gl_Position.z = -gl_Position.w; #ifdef LOG_DEPTH - v_depthFromNearPlusOne = 1.0; + // Just past the near plane, not on it: czm_writeLogDepth discards a + // fragment at or below 0.9999999, and 1.0 interpolated across the quad + // can arrive a rounding step or two under that, dropping the icon for a + // frame as it moves (flicker). 1e-4 m past the near plane is still in + // front of everything the scene draws. + v_depthFromNearPlusOne = 1.0001; #endif } diff --git a/src/scenes/project.js b/src/scenes/project.js index 95397183c7..b4cdf33571 100644 --- a/src/scenes/project.js +++ b/src/scenes/project.js @@ -287,6 +287,9 @@ export function normalizeShot( hud: { visible: typeof hud.visible === 'boolean' ? hud.visible : true, variant: typeof hud.variant === 'string' ? hud.variant : 'tactical', + // Sonar on beside a layout whose code cannot say so; absent is off + // unless the variant names the retired Cyber layout. + ...(hud.sonar === true ? { sonar: true } : {}), }, detection: { ...(typeof detection.allocation === 'string' diff --git a/src/share/legacyShareState.js b/src/share/legacyShareState.js index e941faeee8..98fae4a75f 100644 --- a/src/share/legacyShareState.js +++ b/src/share/legacyShareState.js @@ -34,6 +34,7 @@ export const LEGACY_SHARE_STATE_KEYS = Object.freeze([ 'bloomVersion', 'sharpenIntensity', 'hudVariant', + 'hudSonar', 'hudVisible', 'detectionMode', 'detectionDensity', diff --git a/src/share/legacyShareState.test.mjs b/src/share/legacyShareState.test.mjs index 7f3bac84ab..a511ca1f7d 100644 --- a/src/share/legacyShareState.test.mjs +++ b/src/share/legacyShareState.test.mjs @@ -146,6 +146,23 @@ test('links from earlier long-form versions keep their historical meaning', () = assert.equal(off.layerState.options.flights.models3d, false); }); +test('Sonar beside the Minimal layout survives the compact form; older links do not name it', () => { + const { parsed, state } = assertLegacyRoundTrip( + 'v=2&lat=10&lon=20&hud=minimal&hs=1', + ); + assert.equal(parsed.hudSonar, true); + assert.equal(state.hudVariant, 'minimal'); + assert.equal(state.hudSonar, true); + // Links made before `hs`: Minimal carries no Sonar, Cyber carries it in + // its own code. + for (const hud of ['minimal', 'cyber']) { + const old = assertLegacyRoundTrip(`v=2&lat=10&lon=20&hud=${hud}`); + assert.equal(old.parsed.hudSonar, false); + assert.equal(old.state.hudVariant, hud); + assert.equal(old.state.hudSonar, false); + } +}); + test('a tracking selection becomes a thing view and back', () => { const flights = assertLegacyRoundTrip('v=2&lat=1&lon=2&l=f&lo=f.t.a1b2c3'); assert.deepEqual(flights.state.view.entity, { @@ -232,6 +249,7 @@ function generatedLegacyHash(random) { bloomVersion: pick(random, [1, 2]), sharpenIntensity: int(0, 100), hudVariant: pick(random, HUD_LAYOUTS), + hudSonar: random() < 0.5, hudVisible: random() < 0.5, detectionMode: pick(random, ['OFF', 'SPARSE', 'BALANCED', 'DENSE']), detectionDensity: density, diff --git a/src/share/viewCodec.js b/src/share/viewCodec.js index 518156fb67..9a5015964d 100644 --- a/src/share/viewCodec.js +++ b/src/share/viewCodec.js @@ -255,6 +255,9 @@ export const SHARE_VIEW_FLAGS = freezeAll([ { bit: 2, key: 'hudVisible', default: BY_STYLE }, { bit: 3, key: 'celestialRing', default: BY_STYLE }, { bit: 4, key: 'scopeEnabled', default: true }, + // Sonar on beside a HUD layout whose code cannot say so (Minimal). Tactical + // with Sonar stays the `cyber` layout code alone. + { bit: 5, key: 'hudSonar', default: false }, ]); /** diff --git a/src/share/viewCodec.test.mjs b/src/share/viewCodec.test.mjs index aafa5083b2..1a2c87e0c0 100644 --- a/src/share/viewCodec.test.mjs +++ b/src/share/viewCodec.test.mjs @@ -348,6 +348,7 @@ test('every registered field round-trips at once', () => { bloomVersion: 1, sharpenIntensity: 65, hudVariant: 'operator', + hudSonar: true, hudVisible: false, detectionMode: 'SPARSE', detectionDensity: 100, @@ -449,6 +450,28 @@ test('links made with a retired HUD layout still decode to its name', () => { } }); +test('Sonar beside the Minimal layout is flag bit 5; links made before it keep their meaning', () => { + const minimal = { ...createDefaultShareViewState(), hudVariant: 'minimal' }; + const plain = encodeShareView(minimal); + // Off is the default, so a view without Sonar costs nothing for it. + assert.equal(encodeShareView({ ...minimal, hudSonar: false }), plain); + const withSonar = assertRoundTrip({ ...minimal, hudSonar: true }); + assert.notEqual(withSonar, plain); + const decoded = decodeOk(withSonar).state; + assert.equal(decoded.hudVariant, 'minimal'); + assert.equal(decoded.hudSonar, true); + assert.equal(decodeOk(plain).state.hudSonar, false); + // Tactical with Sonar is still the Cyber code alone. + const cyber = { ...createDefaultShareViewState(), hudVariant: 'cyber' }; + assert.equal(decodeOk(encodeShareView(cyber)).state.hudSonar, false); + // A link made before the bit (thermal, Cyber, Scope off) decodes as it did: + // Cyber without the bit, which the app opens as Tactical with Sonar on. + const before = decodeOk('ARD-7j4YuxMguBcoUEgQcAOAAQPIASPQAWGa').state; + assert.equal(before.hudVariant, 'cyber'); + assert.equal(before.hudSonar, false); + assert.equal(encodeShareView(before), 'ARD-7j4YuxMguBcoUEgQcAOAAQPIASPQAWGa'); +}); + test('defaults travel as frozen meanings that match today’s app defaults', () => { const defaults = createDefaultShareViewState(); // When an app default moves, these tests should be updated to document the @@ -535,6 +558,7 @@ test('the field registry is well formed and permanent', () => { [2, 'hudVisible', BY_STYLE], [3, 'celestialRing', BY_STYLE], [4, 'scopeEnabled', true], + [5, 'hudSonar', false], ], ); // The style-applied defaults are frozen meanings too. If the app's style @@ -921,7 +945,7 @@ test('unknown fields inside a thing view, codes and bits are skipped too', () => thing.textField(20, 'cockpit'); // a future thing field const writer = new WireWriter(); writer.bytes.push(1); - writer.sintField(2, 100000).uintField(9, 0b100001); // flag bit 5 unknown + writer.sintField(2, 100000).uintField(9, 0b1000001); // flag bit 6 unknown writer.bytesField( 10, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], @@ -944,7 +968,7 @@ test('unknown fields inside a thing view, codes and bits are skipped too', () => result.unknownFields.map((u) => [u.scope, u.field ?? u.code]), [ ['enum:style', 99], - ['flags', 32], + ['flags', 64], ['layer', 160], ['panel', 12], ['thing', 20], diff --git a/src/sharelink.celestial.test.mjs b/src/sharelink.celestial.test.mjs index 6e2cd935c0..aa679c105e 100644 --- a/src/sharelink.celestial.test.mjs +++ b/src/sharelink.celestial.test.mjs @@ -158,6 +158,37 @@ test('share-link serialization emits the current celestial state', () => { assert.equal(new URLSearchParams(window.location.hash.slice(1)).get('cr'), '1'); }); +test('Sonar beside the HUD layout rides as hs only when on, and through the compact link', async () => { + // Links made before `hs` name no Sonar. + assert.equal(makeManager('#v=2&lat=10&lon=20&hud=minimal').parseInitialHash().hudSonar, false); + assert.equal(makeManager('#v=2&lat=10&lon=20&hud=minimal&hs=1').parseInitialHash().hudSonar, true); + + const manager = makeManager(); + manager.onToggleChange(false, false, { hudVariant: 'minimal', hudSonar: false }); + assert.equal(manager._buildHashParams().has('hs'), false, 'off writes nothing'); + assert.equal(sharedState(manager.buildLink()).hudSonar, false); + manager.onToggleChange(false, false, { hudVariant: 'minimal', hudSonar: true }); + assert.equal(manager._buildHashParams().get('hs'), '1'); + const shared = sharedState(manager.buildLink()); + assert.equal(shared.hudVariant, 'minimal'); + assert.equal(shared.hudSonar, true); + // Tactical with Sonar is written as the Cyber layout code alone. + manager.onToggleChange(false, false, { hudVariant: 'cyber', hudSonar: false }); + assert.equal(manager._buildHashParams().get('hud'), 'cyber'); + assert.equal(manager._buildHashParams().has('hs'), false); + assert.equal(sharedState(manager.buildLink()).hudVariant, 'cyber'); + clearTimeout(manager._debounceTimer); + + // The restore hands it to the visual settings beside the layout. + const opened = makeManager('#v=2&lat=40&lon=-74&hud=minimal&hs=1'); + let restored = null; + opened._onRestore = (state) => { restored = state; }; + opened._isNavigationCurrent = () => false; + await opened.applyState(opened.parseInitialHash(), { navigationToken: 1 }); + assert.equal(restored.hudVariant, 'minimal'); + assert.equal(restored.hudSonar, true); +}); + test('generated links are v2 and include deterministic layers, options, style params, and panels', () => { const manager = makeManager(); const layers = createDefaultLayerState(); diff --git a/src/sharelink.js b/src/sharelink.js index 063a2792b2..1ddfeeb326 100644 --- a/src/sharelink.js +++ b/src/sharelink.js @@ -94,6 +94,8 @@ export class ShareLinkManager { this._bloomVersion = BLOOM_SCALE_VERSION; this._sharpenIntensity = 49; this._hudVariant = 'tactical'; + // Sonar on beside a layout whose code cannot say so (Minimal); `hs`. + this._hudSonar = false; this._hudVisible = false; this._detectionMode = 'OFF'; this._detectionDensity = 50; @@ -260,6 +262,9 @@ export class ShareLinkManager { bloomVersion: parseOr(params.get('bv'), 1), sharpenIntensity: parseOr(params.get('si'), 49), hudVariant: params.get('hud') || 'tactical', + // Absent in links made before it, which restore Sonar from `hud=cyber` + // alone. + hudSonar: params.get('hs') === '1', hudVisible: params.get('hv') === '1', detectionMode: restoredDetection.enabled ? restoredDetection.profile @@ -477,6 +482,7 @@ export class ShareLinkManager { bloomVersion: visualCurrent ? state.bloomVersion : undefined, sharpenIntensity: visualCurrent ? state.sharpenIntensity : undefined, hudVariant: visualCurrent ? state.hudVariant : undefined, + hudSonar: visualCurrent ? state.hudSonar : undefined, hudVisible: visualCurrent ? state.hudVisible : undefined, detectionMode: visualCurrent ? state.detectionMode : undefined, detectionDensity: visualCurrent ? state.detectionDensity : undefined, @@ -627,6 +633,7 @@ export class ShareLinkManager { this._sharpenIntensity = extras.sharpenIntensity; if (typeof extras.hudVariant === 'string') this._hudVariant = extras.hudVariant; + if (typeof extras.hudSonar === 'boolean') this._hudSonar = extras.hudSonar; if (typeof extras.hudVisible === 'boolean') this._hudVisible = extras.hudVisible; if (typeof extras.detectionMode === 'string') @@ -786,6 +793,8 @@ export class ShareLinkManager { params.set('bv', Math.round(this._bloomVersion).toString()); params.set('si', Math.round(this._sharpenIntensity).toString()); params.set('hud', this._hudVariant); + // Only written when on, so a link without Sonar keeps its old form. + if (this._hudSonar) params.set('hs', '1'); params.set('hv', this._hudVisible ? '1' : '0'); params.set('dm', this._detectionMode); params.set('dd', Math.round(this._detectionDensity).toString()); diff --git a/src/ui/creditLineHeight.js b/src/ui/creditLineHeight.js new file mode 100644 index 0000000000..700f6c8789 --- /dev/null +++ b/src/ui/creditLineHeight.js @@ -0,0 +1,41 @@ +/** + * @module ui/creditLineHeight + * @description Keeps `--credit-line-height` on the page's root at the + * height of the attribution line at the bottom of the screen, so what sits + * above it (the HUD's bottom corners) clears it when it wraps onto more + * lines. The line is the application's own (`#gev-credits`) or the one a + * renderer draws inside `#cesium-credits`. + */ + +const LINES = ['#gev-credits', '#cesium-credits .cesium-widget-credits']; + +/** + * Follow the attribution line's height in `--credit-line-height`. + * @param {Document} [doc] + * @returns {() => void} Stops following it and clears the property. + */ +export function trackCreditLineHeight(doc = globalThis.document) { + const Observer = doc?.defaultView?.ResizeObserver; + if (!doc?.documentElement || typeof Observer !== 'function') return () => {}; + const root = doc.documentElement; + const lines = LINES.map((selector) => doc.querySelector(selector)).filter( + Boolean, + ); + if (!lines.length) return () => {}; + const update = () => { + const height = Math.max( + 0, + ...lines.map((line) => line.getBoundingClientRect().height), + ); + if (height > 0) + root.style.setProperty('--credit-line-height', `${Math.ceil(height)}px`); + else root.style.removeProperty('--credit-line-height'); + }; + const observer = new Observer(update); + for (const line of lines) observer.observe(line); + update(); + return () => { + observer.disconnect(); + root.style.removeProperty('--credit-line-height'); + }; +} diff --git a/src/ui/creditLineHeight.test.mjs b/src/ui/creditLineHeight.test.mjs new file mode 100644 index 0000000000..6b3def9ba8 --- /dev/null +++ b/src/ui/creditLineHeight.test.mjs @@ -0,0 +1,79 @@ +import '../testSupport/registerDom.mjs'; +import test from 'node:test'; +import assert from 'node:assert/strict'; +import { trackCreditLineHeight } from './creditLineHeight.js'; + +/** A ResizeObserver the test drives, with each line's height set by hand. */ +function fakeResizing() { + const observers = []; + const window = document.defaultView; + const original = window.ResizeObserver; + window.ResizeObserver = class { + constructor(callback) { + this.callback = callback; + this.targets = new Set(); + observers.push(this); + } + observe(target) { + this.targets.add(target); + } + disconnect() { + this.targets.clear(); + } + }; + return { + resize(element, height) { + element.getBoundingClientRect = () => ({ height }); + for (const observer of observers) + if (observer.targets.has(element)) observer.callback([]); + }, + restore() { + window.ResizeObserver = original; + }, + }; +} + +test("the credit line's height follows it as it wraps, for either renderer's line", () => { + const resizing = fakeResizing(); + try { + for (const markup of [ + '
', + '