mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-17 00:32:21 +00:00
fix(cockpit): an application subject's wait for the floor is bounded, a late asynchronous hold is released, and a hold never counts as the user's selection
- A subject with no height at all waits at most COCKPIT_GROUND_WAIT_TIMEOUT_MS for the floor, its HUD updating and reading ACQUIRING SURFACE; then the view ends and the provider gets its subject back (there is no height of its own to fall back to). - A hold that returns a promise is refused as before and released again once it settles, unless that subject is being ridden by then; release must tolerate a second call. - Rail and Transit stamp selectedAtMs only for a user's selection (a click, focusTrain or focusVehicle); a deselection clears it, and a train or vehicle selected only by a hold reads null.
This commit is contained in:
1 parent
1e4060f6ba
commit
4c33552105
13 files changed
+239
-28
No files matched your search
@@ -17,8 +17,9 @@ import { displayMotion } from '../transit/movement.js';
|
||||
* view that waits for it holds it again if the feed lists it again.
|
||||
* `focusTrain(key)` selects a train and hands it the camera, as a click does.
|
||||
* A snapshot's `selectedAtMs` is when the user last selected the selected
|
||||
* train, even again (null for any other), for a view's entry to tell a
|
||||
* re-selection.
|
||||
* train (a click, or `focusTrain`), even again, for a view's entry to tell a
|
||||
* re-selection. It is null for any other train, after a deselection, and for
|
||||
* a train selected only by a hold: a hold is not a user's selection.
|
||||
*
|
||||
* @param {object} context The layer's state, parts, services and timetable.
|
||||
* @returns {{methods: object}}
|
||||
@@ -181,7 +182,11 @@ export function createRailCockpitSubject({
|
||||
}
|
||||
const entry = state._trains.get(key);
|
||||
if (!entry) return false;
|
||||
if (state._selectedKey !== key) parts.selection.selectTrain(key);
|
||||
if (state._selectedKey !== key) {
|
||||
parts.selection.selectTrain(key);
|
||||
// A hold is not a selection the user made (selectedAtMs).
|
||||
state._selectedAtMs = null;
|
||||
}
|
||||
state._cockpitSubjectKey = key;
|
||||
state._cockpitLostFeedId = null;
|
||||
if (previous && previous !== entry) parts.rendering.paint(previous);
|
||||
|
||||
@@ -196,6 +196,36 @@ test('a held train its feed drops leaves the feed polled until the view lets go'
|
||||
assert.equal(app.state()._trains.size, 0);
|
||||
});
|
||||
|
||||
test('selectedAtMs is the user’s selection time, never a hold’s or another train’s', async (t) => {
|
||||
const app = await onTheLine(t);
|
||||
assert.equal(app.layer.focusTrain(T1), true);
|
||||
const first = app.layer.getSelectedTrain().selectedAtMs;
|
||||
assert.ok(Number.isFinite(first), 'a click or focusTrain stamps it');
|
||||
// Selected again: a later stamp.
|
||||
app.run(1000);
|
||||
app.layer.focusTrain(T1);
|
||||
assert.ok(app.layer.getSelectedTrain().selectedAtMs > first);
|
||||
// A hold of another train is not the user's selection.
|
||||
app.layer.setCockpitSubject(T2);
|
||||
assert.equal(app.layer.getCockpitSubject().key, T2);
|
||||
assert.equal(app.layer.getCockpitSubject().selectedAtMs, null);
|
||||
app.layer.setCockpitSubject(null);
|
||||
// Nor after a deselection (Escape), then a hold.
|
||||
app.layer.focusTrain(T1);
|
||||
globalThis.document.dispatchEvent(
|
||||
Object.assign(new Event('keydown'), { key: 'Escape' }),
|
||||
);
|
||||
assert.equal(app.state()._selectedKey, null);
|
||||
assert.equal(app.state()._selectedAtMs, null, 'deselection clears it');
|
||||
app.layer.setCockpitSubject(T2);
|
||||
assert.equal(app.layer.getCockpitSubject().selectedAtMs, null);
|
||||
// Releasing twice is harmless: the selection stays.
|
||||
assert.equal(app.layer.setCockpitSubject(null), true);
|
||||
assert.equal(app.layer.setCockpitSubject(null), true);
|
||||
assert.equal(app.state()._selectedKey, T2);
|
||||
assert.equal(app.layer.getCockpitSubject(), null);
|
||||
});
|
||||
|
||||
test('turning the layer off ends the hold', async (t) => {
|
||||
const app = await onTheLine(t);
|
||||
app.layer.setCockpitSubject(T1);
|
||||
|
||||
@@ -127,6 +127,7 @@ export function createSelection({ state, services, parts }) {
|
||||
const hadSelection = state._selectedKey !== null;
|
||||
parts.follow.release({ untrack });
|
||||
state._selectedKey = null;
|
||||
state._selectedAtMs = null;
|
||||
state._selectedCardText = null;
|
||||
if (hadSelection) {
|
||||
parts.rendering.paintAll();
|
||||
|
||||
@@ -17,8 +17,10 @@ import { displayMotion } from './movement.js';
|
||||
* change the selection. The hold ends with `setCockpitSubject(null)`, and on
|
||||
* its own when the vehicle is removed or the layer is turned off.
|
||||
* `focusVehicle(key)` selects a vehicle, as a click does. A snapshot's
|
||||
* `selectedAtMs` is when the user last selected the selected vehicle, even
|
||||
* again (null for any other).
|
||||
* `selectedAtMs` is when the user last selected the selected vehicle (a
|
||||
* click, or `focusVehicle`), even again. It is null for any other vehicle,
|
||||
* after a deselection, and for a vehicle selected only by a hold: a hold is
|
||||
* not a user's selection.
|
||||
*
|
||||
* @param {object} context The layer's state, parts and services.
|
||||
* @returns {{methods: object}}
|
||||
@@ -165,7 +167,7 @@ export function createTransitCockpitSubject({ state, parts, services }) {
|
||||
*/
|
||||
focusVehicle(key) {
|
||||
if (!state._vehicles.get(key)?.marker) return false;
|
||||
parts.selection.selectVehicle(key);
|
||||
parts.selection.selectVehicle(key, { byUser: true });
|
||||
return true;
|
||||
},
|
||||
};
|
||||
|
||||
@@ -4196,6 +4196,32 @@ test('the selected vehicle reads as a snapshot of its place, motion and source',
|
||||
assert.ok(Number.isFinite(view.position.latitude));
|
||||
});
|
||||
|
||||
test('selectedAtMs is the user’s selection time; a hold and a deselection leave none', async (t) => {
|
||||
const app = harness(t);
|
||||
const key = await busRunningNorth(app);
|
||||
// A vehicle only a hold selected reports none.
|
||||
assert.equal(app.layer.setCockpitSubject(key), true);
|
||||
assert.equal(app.layer.getCockpitSubject().selectedAtMs, null);
|
||||
app.layer.setCockpitSubject(null);
|
||||
assert.equal(app.layer.setCockpitSubject(null), true, 'twice is harmless');
|
||||
assert.equal(app.state()._selectedKey, key);
|
||||
// The user's selection stamps it, again on a re-selection.
|
||||
assert.equal(app.layer.focusVehicle(key), true);
|
||||
const first = app.layer.getSelectedVehicle().selectedAtMs;
|
||||
assert.ok(Number.isFinite(first));
|
||||
app.run(1000);
|
||||
app.layer.focusVehicle(key);
|
||||
assert.ok(app.layer.getSelectedVehicle().selectedAtMs > first);
|
||||
// Deselected, then held: none.
|
||||
globalThis.document.dispatchEvent(
|
||||
Object.assign(new Event('keydown'), { key: 'Escape' }),
|
||||
);
|
||||
assert.equal(app.state()._selectedKey, null);
|
||||
assert.equal(app.state()._selectedAtMs, null);
|
||||
app.layer.setCockpitSubject(key);
|
||||
assert.equal(app.layer.getCockpitSubject().selectedAtMs, null);
|
||||
});
|
||||
|
||||
test('a held vehicle hides, keeps moving out of view, and lets go when it goes', async (t) => {
|
||||
const app = harness(t);
|
||||
const key = await busRunningNorth(app);
|
||||
|
||||
@@ -97,6 +97,7 @@ export function createSelection({ state, services, parts }) {
|
||||
: null;
|
||||
parts.trails.clear();
|
||||
state._selectedKey = null;
|
||||
state._selectedAtMs = null;
|
||||
state._selectedCardText = null;
|
||||
state._detectRevision += 1;
|
||||
// Cleared first: the styling path reads the selection from state.
|
||||
@@ -104,12 +105,18 @@ export function createSelection({ state, services, parts }) {
|
||||
state._overlayHost.clearSource(TRANSIT_SELECTED_OVERLAY_SOURCE_ID);
|
||||
}
|
||||
|
||||
function selectVehicle(key) {
|
||||
/**
|
||||
* Select a vehicle. `byUser` marks a selection the user made (a click, or
|
||||
* focusVehicle), even of the selected vehicle again: its time is the
|
||||
* snapshot's `selectedAtMs` (cockpitSubject.js). A first-person view's hold
|
||||
* selects without it.
|
||||
*/
|
||||
function selectVehicle(key, { byUser = false } = {}) {
|
||||
clearSelection();
|
||||
const entry = state._vehicles.get(key);
|
||||
if (!entry?.marker) return;
|
||||
state._selectedKey = key;
|
||||
state._selectedAtMs = Date.now();
|
||||
if (byUser) state._selectedAtMs = Date.now();
|
||||
state._detectRevision += 1;
|
||||
parts.rendering.paintSelected(entry, true);
|
||||
parts.trails.select(entry);
|
||||
@@ -190,11 +197,11 @@ export function createSelection({ state, services, parts }) {
|
||||
typeof primitiveId === 'string' &&
|
||||
state._vehicles.has(primitiveId)
|
||||
) {
|
||||
selectVehicle(primitiveId);
|
||||
selectVehicle(primitiveId, { byUser: true });
|
||||
return;
|
||||
}
|
||||
if (typeof picked.id === 'string' && state._vehicles.has(picked.id)) {
|
||||
selectVehicle(picked.id);
|
||||
selectVehicle(picked.id, { byUser: true });
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user