fix(selection): selecting or tracking a contact never recolours it

A tracked aircraft's icon and 3D model keep the colours they have
untracked in Flights and Military Flights (no cyan, no lighter amber);
only the icon's alpha changes (stale fade, clear while its model draws).
A selected vessel or aid keeps its type colour instead of white, and a
tracked satellite's dot keeps its class colour instead of yellow. An
emergency stays red while tracked.
This commit is contained in:
Sameh Khamis committed 2026-11-17 17:49:33 -08:00
1 parent 2f0c01eaa7
commit f49352d228
23 files changed
+192 -108

No files matched your search

+5 -6
View File
@@ -1,5 +1,3 @@
import { TRACKED_ICON_COLOR } from '../layers/military/policy.js';
import { TRACKED_CYAN } from '../layers/flights/policy.js';
import { createRendering as civilRendering } from '../layers/flights/rendering.js';
import { createRendering as militaryRendering } from '../layers/military/rendering.js';
import { createMilitarySnapshotRenderer } from '../layers/military/snapshotRenderer.js';
@@ -463,15 +461,16 @@ test('tint priorities cover normal, priority, emergency, tracking and Cockpit do
assert.equal(rendering._modelColor('civil'), red);
if (rendering._cockpitContactColor)
assert.equal(rendering._cockpitContactColor('civil'), red);
// Tracking never recolours: a tracked emergency stays red.
flightState._trackedIcao = 'civil';
assert.equal(
rendering._modelColor('civil'),
factory === civilRendering ? TRACKED_CYAN : TRACKED_ICON_COLOR,
);
assert.equal(rendering._modelColor('civil'), red);
flightState._trackedIcao = null;
flightState.records.data.set('civil', { emergency: null });
// An ordinary model draws its mesh's own colours, whatever the billboard's.
assert.deepEqual([...rendering._modelColor('civil')], [1, 1, 1, 1]);
flightState._trackedIcao = 'civil';
assert.deepEqual([...rendering._modelColor('civil')], [1, 1, 1, 1]);
flightState._trackedIcao = null;
}
});
+4 -5
View File
@@ -400,7 +400,7 @@ export function createAircraftModels({
minPixelSize: record.minPixelSize,
shading: _shadingOf(),
tint: record.tint ?? WHITE,
// The mesh's own colours, tinted while tracked or in an emergency;
// The mesh's own colours, tinted red in an emergency;
// the IR boost draws it flat white.
colorBlend: aircraftModelBlend(state._irBoost === true, record.tint),
environmentMap: AIRCRAFT_ENVIRONMENT_MAP_OPTIONS.enabled,
@@ -828,10 +828,9 @@ export function createAircraftModels({
* in, can never stall or freeze the centering (the old model-graphic-on-entity failure mode).
*
* The model draws exactly as the fleet would draw this contact: the same
* asset at the same scale (its true size), only its
* tint the tracked colour; whether it draws at all is the fleet's rule too
* (`_trackedModelRegimeActive`). Selecting a contact changes its colour,
* never its size or form. */
* asset at the same scale (its true size) in the same colours; whether it
* draws at all is the fleet's rule too (`_trackedModelRegimeActive`).
* Selecting a contact changes neither its colour nor its size or form. */
function _updateTrackedModel() {
// A failed load is let go (the icon carries the contact); the budget
+5 -6
View File
@@ -18,11 +18,10 @@ const HIGHLIGHT = Object.freeze({ mode: 'highlight' });
const FLAT = Object.freeze({ mode: 'mix', amount: 1 });
/**
* How much of a tracked or emergency colour a model takes over its paint.
* Multiplying by a saturated tint zeroes every channel the tint lacks: the
* tracked cyan (no red) draws a red helicopter black and a white Cessna flat
* cyan. Mixed in at this share, the paint stays readable and the colour still
* marks the model.
* How much of an emergency colour a model takes over its paint. Multiplying
* by a saturated tint zeroes every channel the tint lacks: a cyan tint (no
* red) draws a red helicopter black and a white Cessna flat cyan. Mixed in at
* this share, the paint stays readable and the colour still marks the model.
*/
export const AIRCRAFT_MODEL_TINT_MIX = 0.3;
@@ -31,7 +30,7 @@ const TINTED = Object.freeze({ mode: 'mix', amount: AIRCRAFT_MODEL_TINT_MIX });
/**
* How an aircraft model's colour meets its mesh, as a draw item's
* `colorBlend`. White (no tint) multiplies (`highlight`), which draws the
* mesh's own colours as built. A tracked or emergency colour is mixed in at
* mesh's own colours as built. An emergency colour is mixed in at
* `AIRCRAFT_MODEL_TINT_MIX`, so it tints the mesh without hiding its paint.
* The IR boost draws the model flat white instead (`mix` at 1, unlit).
* @param {boolean} irBoost
+5 -5
View File
@@ -81,12 +81,12 @@ test('an untinted model draws its mesh in its own colours', () => {
}
});
test('the tracked and emergency tints keep every paint, never black or one flat colour', () => {
test('the emergency tints keep every paint, never black or one flat colour', () => {
const tints = {
'tracked cyan': flightsPolicy.TRACKED_CYAN,
emergency: flightsPolicy.EMERGENCY_TINT,
'military tracked': militaryPolicy.TRACKED_ICON_COLOR,
'military emergency': militaryPolicy.EMERGENCY_ICON_COLOR,
// Any saturated tint: one with no red once drew a red helicopter black.
cyan: [0, 1, 1, 1],
};
for (const [tintName, tint] of Object.entries(tints)) {
const blend = aircraftModelBlend(false, tint);
@@ -94,7 +94,7 @@ test('the tracked and emergency tints keep every paint, never black or one flat
for (const [paintName, paint] of Object.entries(PAINTS)) {
const out = blended(paint, tint, blend);
drawn[paintName] = out;
// Multiplying by the tracked cyan (no red) drew a red helicopter black.
// Multiplying by a tint with no red drew a red helicopter black.
paint.forEach((c, i) =>
assert.ok(
out[i] >= c * 0.6,
@@ -110,6 +110,6 @@ test('the tracked and emergency tints keep every paint, never black or one flat
});
test('the IR boost draws every model flat white whatever its tint', () => {
for (const tint of [null, flightsPolicy.TRACKED_CYAN])
for (const tint of [null, flightsPolicy.EMERGENCY_TINT])
assert.deepEqual(aircraftModelBlend(true, tint), { mode: 'mix', amount: 1 });
});
+27
View File
@@ -28,6 +28,33 @@ const sameColor = (a, b) =>
a.length === b.length &&
a.every((value, i) => value === b[i]));
/** `trackedIconColor`'s answers, by base colour then alpha. */
const tintsAtAlpha = new Map();
/**
* The tracked icon's colour: the contact's own colour (the one its fleet
* icon draws in), at `alpha`. Tracking never recolours a contact; only the
* alpha changes (faded while stale, clear while its model draws it). One
* frozen array per colour and alpha, so a frame allocates nothing.
* @param {ArrayLike<number>} color The contact's RGBA colour, 0..1.
* @param {number} alpha
* @returns {readonly number[]}
*/
export function trackedIconColor(color, alpha) {
if (color[3] === alpha && Object.isFrozen(color)) return color;
let byAlpha = tintsAtAlpha.get(color);
if (!byAlpha) {
byAlpha = new Map();
tintsAtAlpha.set(color, byAlpha);
}
let tint = byAlpha.get(alpha);
if (!tint) {
tint = Object.freeze([color[0], color[1], color[2], alpha]);
byAlpha.set(alpha, tint);
}
return tint;
}
/**
* Whether `setId` names another layer's tracked icon set: a layer must not
* take a pick of that icon for one of its own contacts.
+11
View File
@@ -5,6 +5,7 @@ import {
createTrackedAircraftIcon,
isOtherTrackedIconSet,
trackedContactHolder,
trackedIconColor,
} from './trackedAircraftIcon.js';
/** A viewer double with a fake draw port and a frame port whose preRender the test runs. */
@@ -188,3 +189,13 @@ test("a layer tells another layer's tracked icon set from its own sets", () => {
);
assert.equal(isOtherTrackedIconSet(undefined, 'military'), false);
});
test('the tracked icon keeps its contact\'s colour; only the alpha changes', () => {
const amber = Object.freeze([1, 0.72, 0, 1]);
assert.equal(trackedIconColor(amber, 1), amber, 'unchanged at its own alpha');
const stale = trackedIconColor(amber, 0.45);
assert.deepEqual(stale, [1, 0.72, 0, 0.45]);
assert.equal(trackedIconColor(amber, 0.45), stale, 'one array per alpha');
assert.ok(Object.isFrozen(stale));
assert.deepEqual(trackedIconColor(amber, 0), [1, 0.72, 0, 0]);
});
+6 -4
View File
@@ -1321,10 +1321,11 @@ for (const fixture of LAYERS) {
fleetItem.minPixelSize,
'the same minimum pixel size',
);
assert.notDeepEqual(
trackedItem.tint,
fleetItem.tint,
'only the colour differs',
assert.deepEqual(trackedItem.tint, fleetItem.tint, 'the same colour');
assert.deepEqual(
trackedItem.colorBlend,
fleetItem.colorBlend,
'the same colour blend',
);
} finally {
fixture.layer.setParams({ models3d: false });
@@ -1355,6 +1356,7 @@ for (const fixture of LAYERS) {
fleet.scaleByDistance,
'the same scale by distance',
);
assert.deepEqual(tracked.color, fleet.color, 'the same colour');
// A landing changes the fleet icon's scale, and the tracked one's with it.
fixture.seed({ viewer, onGround: true });
const grounded = fixture.trackedIconLook(ICAO);