Skip to content

Commit

Permalink
clean up more subscriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
flogross89 committed Jan 26, 2025
1 parent 816ca4c commit e820f45
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export class AtcMailbox extends DisplayComponent<AtcMailboxProps> {

destroy(): void {
this.topRef.getOrDefault()?.removeEventListener('mousemove', this.onMouseMoveHandler);
this.mouseCursorRef.getOrDefault()?.destroy();

super.destroy();
}
Expand Down
2 changes: 2 additions & 0 deletions fbw-a380x/src/systems/instruments/src/MFD/MFD.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,8 @@ export class MfdComponent extends DisplayComponent<MfdComponentProps> implements

destroy(): void {
this.topRef.getOrDefault()?.removeEventListener('mousemove', this.onMouseMoveHandler);
this.mouseCursorRef.getOrDefault()?.destroy();
this.duplicateNamesRef.getOrDefault()?.destroy();

super.destroy();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ interface MouseCursorProps extends ComponentProps {
}

export class MouseCursor extends DisplayComponent<MouseCursorProps> {
private subs: Subscription[] = [];
private readonly subs: Subscription[] = [];

private readonly divRef = FSComponent.createRef<HTMLSpanElement>();

Expand All @@ -36,6 +36,8 @@ export class MouseCursor extends DisplayComponent<MouseCursorProps> {

private readonly fillColor = this.color.map((c) => (c === MouseCursorColor.Magenta ? '#ff94ff' : '#ffff00'));

private readonly rotation = this.props.side.map((side) => `rotate(${side === 'FO' ? 90 : 0} 40 40)`);

private hideTimer: ReturnType<typeof setTimeout> | undefined = undefined;

updatePosition(x: number, y: number) {
Expand Down Expand Up @@ -72,13 +74,21 @@ export class MouseCursor extends DisplayComponent<MouseCursorProps> {
if (this.props.visible) {
this.subs.push(this.props.visible.sub((vis) => (vis ? this.show() : this.hide()), true));
}

this.subs.push(this.fillColor, this.rotation);
}

destroy(): void {
for (const s of this.subs) {
s.destroy();
}
}

render(): VNode {
return (
<div ref={this.divRef} class="mfd-mouse-cursor">
<svg width="80" height="80" xmlns="http://www.w3.org/2000/svg">
<g transform={this.props.side.map((side) => `rotate(${side === 'FO' ? 90 : 0} 40 40)`)}>
<g transform={this.rotation}>
<polyline points="0,0 40,35 80,0" style={{ fill: 'none', stroke: this.fillColor, 'stroke-width': '3' }} />
<line x1="40" y1="39" x2="40" y2="41" style={{ stroke: this.fillColor, 'stroke-width': '2' }} />
<line x1="39" y1="40" x2="41" y2="40" style={{ stroke: this.fillColor, 'stroke-width': '2' }} />
Expand Down
132 changes: 80 additions & 52 deletions fbw-a380x/src/systems/instruments/src/ND/OansControlPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,23 +163,22 @@ export class OansControlPanel extends DisplayComponent<OansProps> {

private readonly pposLongWord = Arinc429LocalVarConsumerSubject.create(this.sub.on('longitude'));

private presentPos = MappedSubject.create(
private readonly presentPos = MappedSubject.create(
([lat, lon]) => {
return { lat: lat.value, long: lon.value } as Coordinates;
},
this.pposLatWord,
this.pposLongWord,
);

private presentPosNotAvailable = MappedSubject.create(
private readonly presentPosNotAvailable = MappedSubject.create(
([lat, long]) => !lat.isNormalOperation() || !long.isNormalOperation(),
this.pposLatWord,
this.pposLongWord,
);

private readonly setPlanModeDisplay = ConsumerSubject.create(this.sub.on('oans_show_set_plan_mode'), false).map(
(it) => (it ? 'inherit' : 'none'),
);
private readonly setPlanModeConsumer = ConsumerSubject.create(this.sub.on('oans_show_set_plan_mode'), false);
private readonly setPlanModeDisplay = this.setPlanModeConsumer.map((it) => (it ? 'inherit' : 'none'));

private readonly fmsDataStore = new FmsDataStore(this.props.bus);

Expand Down Expand Up @@ -304,16 +303,18 @@ export class OansControlPanel extends DisplayComponent<OansProps> {
}, true),
);

this.fmsDataStore.landingRunway.sub(async (it) => {
// Set control panel display
if (it) {
// Load runway data
const destination = this.fmsDataStore.destination.get();
if (destination && this.navigraphAvailable.get() === false) {
this.setBtvRunwayFromFmsRunway();
this.subs.push(
this.fmsDataStore.landingRunway.sub(async (it) => {
// Set control panel display
if (it) {
// Load runway data
const destination = this.fmsDataStore.destination.get();
if (destination && this.navigraphAvailable.get() === false) {
this.setBtvRunwayFromFmsRunway();
}
}
}
});
}),
);

this.subs.push(
this.sub
Expand All @@ -336,47 +337,74 @@ export class OansControlPanel extends DisplayComponent<OansProps> {

this.subs.push(this.sub.on('oans_display_airport').handle((arpt) => this.handleSelectAirport(arpt)));

this.selectedEntityIndex.sub((val) => {
const searchMode = this.selectedEntityType.get();
if (searchMode !== null && this.mapDataFeatures && val !== null) {
const prop = ControlPanelUtils.getMapDataSearchModeProp(searchMode);
const idx = this.mapDataFeatures.findIndex((f) => f.properties[prop] === this.availableEntityList.get(val));
this.selectedEntityString.set(idx !== -1 ? this.mapDataFeatures[idx]?.properties[prop]?.toString() ?? '' : '');

if (
(idx !== -1 && searchMode === ControlPanelMapDataSearchMode.Runway) ||
searchMode === ControlPanelMapDataSearchMode.Stand
) {
const feature = this.mapDataFeatures[idx] as Feature<Point>;
this.selectedEntityPosition = feature.geometry.coordinates;
this.selectedFeatureId.set(feature.properties?.id);
this.selectedFeatureType.set(feature.properties?.feattype);
} else if (
idx !== -1 &&
(searchMode === ControlPanelMapDataSearchMode.Taxiway || searchMode === ControlPanelMapDataSearchMode.Other)
) {
const taxiway = this.mapDataFeatures[idx] as Feature<LineString, AmdbProperties>;
this.selectedEntityPosition = taxiway.properties.midpoint?.coordinates ?? [0, 0];
this.selectedFeatureId.set(taxiway.properties?.id);
this.selectedFeatureType.set(taxiway.properties?.feattype);
}
this.subs.push(
this.selectedEntityIndex.sub((val) => {
const searchMode = this.selectedEntityType.get();
if (searchMode !== null && this.mapDataFeatures && val !== null) {
const prop = ControlPanelUtils.getMapDataSearchModeProp(searchMode);
const idx = this.mapDataFeatures.findIndex((f) => f.properties[prop] === this.availableEntityList.get(val));
this.selectedEntityString.set(
idx !== -1 ? this.mapDataFeatures[idx]?.properties[prop]?.toString() ?? '' : '',
);

if (idx !== -1 && this.selectedEntityType.get() === ControlPanelMapDataSearchMode.Runway) {
this.runwayLda.set(this.mapDataFeatures[idx].properties.lda?.toFixed(0) ?? '');
this.runwayTora.set(this.mapDataFeatures[idx].properties.tora?.toFixed(0) ?? '');
if (
(idx !== -1 && searchMode === ControlPanelMapDataSearchMode.Runway) ||
searchMode === ControlPanelMapDataSearchMode.Stand
) {
const feature = this.mapDataFeatures[idx] as Feature<Point>;
this.selectedEntityPosition = feature.geometry.coordinates;
this.selectedFeatureId.set(feature.properties?.id);
this.selectedFeatureType.set(feature.properties?.feattype);
} else if (
idx !== -1 &&
(searchMode === ControlPanelMapDataSearchMode.Taxiway || searchMode === ControlPanelMapDataSearchMode.Other)
) {
const taxiway = this.mapDataFeatures[idx] as Feature<LineString, AmdbProperties>;
this.selectedEntityPosition = taxiway.properties.midpoint?.coordinates ?? [0, 0];
this.selectedFeatureId.set(taxiway.properties?.id);
this.selectedFeatureType.set(taxiway.properties?.feattype);
}

if (idx !== -1 && this.selectedEntityType.get() === ControlPanelMapDataSearchMode.Runway) {
this.runwayLda.set(this.mapDataFeatures[idx].properties.lda?.toFixed(0) ?? '');
this.runwayTora.set(this.mapDataFeatures[idx].properties.tora?.toFixed(0) ?? '');
}
} else {
this.selectedEntityString.set('');
this.runwayLda.set('');
this.runwayTora.set('');
}
} else {
this.selectedEntityString.set('');
this.runwayLda.set('');
this.runwayTora.set('');
}
}, true);
this.selectedEntityType.sub((v) => this.handleSelectMapDataSearchMode(v ?? ControlPanelMapDataSearchMode.Runway));
}, true),
);
this.subs.push(
this.selectedEntityType.sub((v) => this.handleSelectMapDataSearchMode(v ?? ControlPanelMapDataSearchMode.Runway)),
);

this.sub
.on(this.props.side === 'L' ? 'kccuOnL' : 'kccuOnR')
.whenChanged()
.handle((it) => this.interactionMode.set(it ? InteractionMode.Kccu : InteractionMode.Touchscreen));
this.subs.push(
this.sub
.on(this.props.side === 'L' ? 'kccuOnL' : 'kccuOnR')
.whenChanged()
.handle((it) => this.interactionMode.set(it ? InteractionMode.Kccu : InteractionMode.Touchscreen)),
);

this.subs.push(
this.setPlanModeConsumer,
this.setPlanModeDisplay,
this.oansResetPulled,
this.oansAvailable,
this.entityIsNotSelected,
this.symbolsForFeatureIds,
this.flagExistsForEntity,
this.crossExistsForEntity,
this.pposLatWord,
this.pposLongWord,
this.presentPos,
this.presentPosNotAvailable,
this.oansRequestedStoppingDistance,
this.reqStoppingDistance,
this.fmsLandingRunwayVisibility,
this.airportDatabase,
);
}

public updateAirportSearchData() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ export class OancMovingModeOverlay extends DisplayComponent<OancMapOverlayProps>
this.rotationArinc429Word.setValueSsm(r, Arinc429SignStatusMatrix.NormalOperation);
}),
);

this.subs.push(this.arcModeVisible, this.roseModeVisible);
}

destroy(): void {
Expand Down

0 comments on commit e820f45

Please sign in to comment.