Skip to content

Commit

Permalink
fix(a380x/mfd): ils duplicate names error (flybywiresim#9024)
Browse files Browse the repository at this point in the history
* feat(fms): add ndb type predicate

* feat(fms): add isfix type predicate

* fix(a380x/mfd): duplicate names error on ils
  • Loading branch information
tracernz authored Oct 5, 2024
1 parent 71e167a commit 0f6a08b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ import {
VNode,
} from '@microsoft/msfs-sdk';

import './MfdFmsFpln.scss';
import { IconButton } from 'instruments/src/MFD/pages/common/IconButton';
import { Button } from 'instruments/src/MFD/pages/common/Button';
import { ActivePageTitleBar } from 'instruments/src/MFD/pages/common/ActivePageTitleBar';
import { Coordinates, distanceTo } from 'msfs-geo';
import { FmcServiceInterface } from 'instruments/src/MFD/FMC/FmcServiceInterface';
import { DatabaseItem, NdbNavaid, VhfNavaid, Waypoint } from '@flybywiresim/fbw-sdk';
import { DatabaseItem, isFix, isIlsNavaid, isNdbNavaid, isVhfNavaid } from '@flybywiresim/fbw-sdk';

import './MfdFmsFpln.scss';

interface MfdFmsFplnDuplicateNamesProps extends ComponentProps {
visible: Subject<boolean>;
Expand All @@ -31,14 +32,6 @@ type DuplicateWaypointData = {
fixData: DatabaseItem<any>;
};

function isNavaid(fix: DatabaseItem<any>): fix is VhfNavaid | NdbNavaid {
return 'frequency' in fix;
}

function isNavaidOrWaypoint(fix: DatabaseItem<any>): fix is VhfNavaid | NdbNavaid | Waypoint {
return 'location' in fix;
}

export class MfdFmsFplnDuplicateNames extends DisplayComponent<MfdFmsFplnDuplicateNamesProps> {
// Make sure to collect all subscriptions here, otherwise page navigation doesn't work.
private subs = [] as Subscription[];
Expand Down Expand Up @@ -89,16 +82,17 @@ export class MfdFmsFplnDuplicateNames extends DisplayComponent<MfdFmsFplnDuplica
const result: DuplicateWaypointData[] = [];
items.forEach((fx) => {
const ppos = this.props.fmcService?.master?.navigation.getPpos();
if (isNavaid(fx)) {
if (isVhfNavaid(fx) || isNdbNavaid(fx) || isIlsNavaid(fx)) {
const location = isIlsNavaid(fx) ? fx.locLocation : fx.location;
const dwd: DuplicateWaypointData = {
ident: fx.ident,
distance: ppos ? distanceTo(fx.location, ppos) : null,
location: fx.location,
distance: ppos ? distanceTo(location, ppos) : null,
location,
freqChan: fx.frequency,
fixData: fx,
};
result.push(dwd);
} else if (isNavaidOrWaypoint(fx)) {
} else if (isFix(fx)) {
const dwd: DuplicateWaypointData = {
ident: fx.ident,
distance: ppos ? distanceTo(fx.location, ppos) : null,
Expand Down
4 changes: 4 additions & 0 deletions fbw-common/src/systems/navdata/shared/types/BaseFix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ export interface BaseFix<T extends SectionCode> extends DatabaseItem<T> {
* Union of all possible fix interfaces
*/
export type Fix = VhfNavaid | NdbNavaid | Waypoint;

export function isFix(o: any): o is Fix {
return typeof o === 'object' && 'location' in o && 'databaseId' in o;
}
10 changes: 9 additions & 1 deletion fbw-common/src/systems/navdata/shared/types/NdbNavaid.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { NauticalMiles } from 'msfs-geo';
import { BaseFix } from '..';
import { KiloHertz } from './Common';
import { NavaidSubsectionCode, SectionCode } from './SectionCode';
import { AirportSubsectionCode, NavaidSubsectionCode, SectionCode } from './SectionCode';

export interface NdbNavaid extends BaseFix<SectionCode.Navaid> {
subSectionCode: NavaidSubsectionCode.NdbNavaid;
Expand All @@ -20,6 +20,14 @@ export interface NdbNavaid extends BaseFix<SectionCode.Navaid> {
distance?: NauticalMiles;
}

export function isNdbNavaid(o: any): o is NdbNavaid {
return (
typeof o === 'object' &&
((o.sectionCode === SectionCode.Navaid && o.subSectionCode === NavaidSubsectionCode.NdbNavaid) ||
(o.sectionCode === SectionCode.Airport && o.subSectionCode === AirportSubsectionCode.TerminalNdb))
);
}

export enum NdbClass {
Unknown = 1 << 0,
/**
Expand Down

0 comments on commit 0f6a08b

Please sign in to comment.