Skip to content

Commit

Permalink
before refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
flogross89 committed Dec 15, 2024
1 parent b57c098 commit f51f65a
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class WdAbnormalSensedProcedures extends WdAbstractChecklistComponent {
public updateChecklists() {
this.lineData.length = 0;

WdAbnormalSensedProcedures.generateProcedureLineData(this.procedures.get(), this.lineData);
WdAbnormalSensedProcedures.generateProcedureLineData(this.procedures.get(), this.lineData, true, false);
super.updateChecklists();
}

Expand Down Expand Up @@ -49,7 +49,7 @@ export class WdAbnormalSensedProcedures extends WdAbstractChecklistComponent {
lastLine: procIndex !== 0 ? true : false,
});

if (showOnlyFirst || procIndex === 0) {
if (!showOnlyFirst || procIndex === 0) {
if (isAbnormalSensedProcedure(cl) && cl.recommendation) {
lineData.push({
abnormalProcedure: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -605,15 +605,15 @@ interface ChecklistCondition extends AbstractChecklistItem {
interface ChecklistSpecialItem extends AbstractChecklistItem {}

export function isChecklistAction(c: AbstractChecklistItem): c is ChecklistAction {
return (c as ChecklistAction).labelNotCompleted !== undefined;
return (c as ChecklistAction)?.labelNotCompleted !== undefined;
}

export function isChecklistCondition(c: AbstractChecklistItem): c is ChecklistCondition {
return (c as ChecklistCondition).condition !== undefined;
return (c as ChecklistCondition)?.condition !== undefined;
}

export function isAbnormalSensedProcedure(c: AbnormalProcedure | DeferredProcedure): c is AbnormalProcedure {
return (c as AbnormalProcedure).recommendation !== undefined;
return (c as AbnormalProcedure)?.recommendation !== undefined;
}

export interface AbnormalProcedure {
Expand Down Expand Up @@ -678,6 +678,8 @@ export const EcamAbnormalSensedProcedures: { [n: string]: AbnormalProcedure } =
/** All abnormal non-sensed procedures (via ECL) should be here. Don't start for now, format needs to be defined. */
export const EcamAbnormalNonSensedProcedures = AbnormalNonSensedProcedures;

export const EcamAbnormalProcedures = { ...EcamAbnormalSensedProcedures, ...EcamAbnormalNonSensedProcedures };

export const EcamAbNormalSensedSubMenuVector: AbnormalNonSensedCategory[] = [
'ENG',
'F/CTL',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import { MapSubject, SimVarValueType, Subject } from '@microsoft/msfs-sdk';
import { NormalChecklistState, FwsEwdEvents } from 'instruments/src/MsfsAvionicsCommon/providers/FwsEwdPublisher';
import { FwsCore } from 'systems-host/systems/FlightWarningSystem/FwsCore';
import { FwcAuralWarning, FwsCore } from 'systems-host/systems/FlightWarningSystem/FwsCore';
import {
EcamAbnormalNonSensedProcedures,
EcamAbNormalSensedSubMenuVector,
Expand Down Expand Up @@ -96,7 +96,7 @@ export class FwsAbnormalNonSensed {
} else if (this.selectedItem.get() < skipProcsFromTopMenu) {
// Preview non-sensed procedure
this.checklistId.set(EcamAbnormalNonSensedProcedures[this.selectedItem.get()]?.id ?? 0);
this.selectedItem.set(0);
this.selectedItem.set(-1);
}
} else if (this.checklistId.get() > 0 && this.checklistId.get() <= 10) {
// Sub menu
Expand All @@ -105,8 +105,9 @@ export class FwsAbnormalNonSensed {
);
// Preview non-sensed procedure
this.checklistId.set(EcamAbnormalNonSensedProcedures[subMenuProcsStartAt + this.selectedItem.get()].id);
this.selectedItem.set(0);
this.selectedItem.set(-1);
} else {
console.log('---');
// Activate non-sensed procedure (add to ECAM faults) and close dialog, i.e. return to abnormal procs
this.fws.activeAbnormalNonSensedKeys.push(this.checklistId.get());
this.selectedItem.set(0);
Expand All @@ -130,7 +131,8 @@ export class FwsAbnormalNonSensed {
false,
false,
],
failure: 1,
failure: 3,
auralWarning: Subject.create(FwcAuralWarning.None),
sysPage: SdPages.None,
redundLoss: () => [],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,9 @@ export class FwsAbnormalSensed {
}),
);
// Sort by decreasing importance
console.log(flattened);
const sortedAbnormalsFlattened = flattened.sort(
(a, b) => this.ewdAbnormalSensed[b.id].failure - this.ewdAbnormalSensed[a.id].failure,
(a, b) => this.fws.ewdAbnormal[b.id].failure - this.fws.ewdAbnormal[a.id].failure,
);
this.activeProcedureId.set(sortedAbnormalsFlattened.length > 0 ? sortedAbnormalsFlattened[0].id : null);
this.pub.pub('fws_abn_sensed_procedures', sortedAbnormalsFlattened, true);
Expand Down Expand Up @@ -248,9 +249,21 @@ export class FwsAbnormalSensed {
}
}

private clearActiveProcedure() {
public clearActiveProcedure() {
console.log(
this.fws.presentedFailures,
parseInt(this.activeProcedureId.get()),
this.fws.activeAbnormalNonSensedKeys.includes(parseInt(this.activeProcedureId.get())),
);
this.fws.presentedFailures.splice(0, 1);
this.fws.recallFailures = this.fws.allCurrentFailures.filter((item) => !this.fws.presentedFailures.includes(item));

if (this.fws.activeAbnormalNonSensedKeys.includes(parseInt(this.activeProcedureId.get()))) {
this.fws.activeAbnormalNonSensedKeys.splice(
this.fws.activeAbnormalNonSensedKeys.indexOf(parseInt(this.activeProcedureId.get())),
1,
);
}
}

private scrollToSelectedLine() {
Expand Down Expand Up @@ -300,7 +313,7 @@ export class FwsAbnormalSensed {
for (let id = 0; id < ids.length; id++) {
const procId = ids[id];

if (!this.ewdAbnormalSensed[procId] || !this.fws.abnormalUpdatedItems.has(procId)) {
if (!this.fws.ewdAbnormal[procId] || !this.fws.abnormalUpdatedItems.has(procId)) {
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import { FuelSystemEvents } from 'instruments/src/MsfsAvionicsCommon/providers/F
import {
AbnormalProcedure,
DeferredProcedure,
EcamAbnormalSensedProcedures,
EcamAbnormalProcedures,
EcamDeferredProcedures,
EcamMemos,
isChecklistCondition,
Expand All @@ -51,7 +51,11 @@ import {
} from '../../../instruments/src/MsfsAvionicsCommon/providers/FwsEwdPublisher';
import { FwsMemos } from 'systems-host/systems/FlightWarningSystem/FwsMemos';
import { FwsNormalChecklists } from 'systems-host/systems/FlightWarningSystem/FwsNormalChecklists';
import { EwdAbnormalItem, FwsAbnormalSensed } from 'systems-host/systems/FlightWarningSystem/FwsAbnormalSensed';
import {
EwdAbnormalDict,
EwdAbnormalItem,
FwsAbnormalSensed,
} from 'systems-host/systems/FlightWarningSystem/FwsAbnormalSensed';
import { FwsAbnormalNonSensed } from 'systems-host/systems/FlightWarningSystem/FwsAbnormalNonSensed';
import { MfdSurvEvents } from 'instruments/src/MsfsAvionicsCommon/providers/MfdSurvPublisher';
import { Mle, Mmo, VfeF1, VfeF1F, VfeF2, VfeF3, VfeFF, Vle, Vmo } from '@shared/PerformanceConstants';
Expand Down Expand Up @@ -1502,13 +1506,20 @@ export class FwsCore {

public readonly memos = new FwsMemos(this);
public readonly normalChecklists = new FwsNormalChecklists(this);
public readonly abnormalSensed = new FwsAbnormalSensed(this);
public readonly abnormalNonSensed = new FwsAbnormalNonSensed(this);
public readonly abnormalSensed = new FwsAbnormalSensed(this);
public ewdAbnormal: EwdAbnormalDict;

constructor(
public readonly fwsNumber: 1 | 2,
public readonly bus: EventBus,
) {
this.ewdAbnormal = Object.assign(
{},
this.abnormalSensed.ewdAbnormalSensed,
this.abnormalNonSensed.ewdAbnormalNonSensed,
);

this.ewdMessageLinesLeft.forEach((ls, i) =>
ls.sub((l) => {
SimVar.SetSimVarValue(FwsCore.ewdMessageSimVarsLeft[i], 'string', l ?? '');
Expand Down Expand Up @@ -3773,8 +3784,7 @@ export class FwsCore {
/* CLEAR AND RECALL */
if (this.clrPulseNode.read()) {
// delete the first failure
this.presentedFailures.splice(0, 1);
this.recallFailures = this.allCurrentFailures.filter((item) => !this.presentedFailures.includes(item));
this.abnormalSensed.clearActiveProcedure();
}

if (this.rclUpPulseNode.read()) {
Expand Down Expand Up @@ -3815,7 +3825,7 @@ export class FwsCore {
const auralScKeys: string[] = [];

// Update memos and failures list in case failure has been resolved
for (const [key, value] of Object.entries(this.abnormalSensed.ewdAbnormalSensed)) {
for (const [key, value] of Object.entries(this.ewdAbnormal)) {
if (!value.simVarIsActive.get() || value.flightPhaseInhib.some((e) => e === flightPhase)) {
failureKeys = failureKeys.filter((e) => e !== key);
recallFailureKeys = recallFailureKeys.filter((e) => e !== key);
Expand All @@ -3827,9 +3837,7 @@ export class FwsCore {
this.nonCancellableWarningCount = 0;

// Abnormal sensed procedures
const ewdAbnormalEntries: [string, EwdAbnormalItem][] = Object.entries(
this.abnormalSensed.ewdAbnormalSensed,
).concat(Object.entries(this.abnormalNonSensed.ewdAbnormalNonSensed));
const ewdAbnormalEntries: [string, EwdAbnormalItem][] = Object.entries(this.ewdAbnormal);
const ewdDeferredEntries = Object.entries(this.abnormalSensed.ewdDeferredProcs);
this.abnormalUpdatedItems.clear();
this.deferredUpdatedItems.clear();
Expand All @@ -3840,14 +3848,14 @@ export class FwsCore {

// new warning?
const newWarning = !this.presentedFailures.includes(key) && !recallFailureKeys.includes(key);
const proc = EcamAbnormalSensedProcedures[key] as AbnormalProcedure;
const proc = EcamAbnormalProcedures[key];

if (value.simVarIsActive.get() || this.activeAbnormalNonSensedKeys.includes(parseInt(key))) {
// Skip if other fault overrides this one
let overridden = false;
value.notActiveWhenFaults.forEach((val) => {
if (val && this.abnormalSensed.ewdAbnormalSensed[val]) {
const otherFault = this.abnormalSensed.ewdAbnormalSensed[val] as EwdAbnormalItem;
if (val && this.ewdAbnormal[val]) {
const otherFault = this.ewdAbnormal[val] as EwdAbnormalItem;
if (otherFault.simVarIsActive.get()) {
overridden = true;
}
Expand Down Expand Up @@ -3927,6 +3935,9 @@ export class FwsCore {
} else if (this.activeAbnormalProceduresList.has(key)) {
// Update internal map
const prevEl = this.activeAbnormalProceduresList.getValue(key);
if (!proc.items) {
console.log(proc, prevEl);
}
const fusedChecked = [...prevEl.itemsChecked].map((val, index) =>
proc.items[index].sensed ? itemsChecked[index] : !!val,
);
Expand Down Expand Up @@ -4074,7 +4085,7 @@ export class FwsCore {

const failOrder: string[] = [];

for (const [key] of Object.entries(this.abnormalSensed.ewdAbnormalSensed)) {
for (const [key] of Object.entries(this.ewdAbnormal)) {
failOrder.push(...key);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,17 @@ export class FwsNormalChecklists {
}
});
this.selectedLine.set(firstIncompleteChecklist - 1);
} else {
} else if (!deferredProcedureIds.includes(this.checklistId.get())) {
const clState = this.checklistState.getValue(this.checklistId.get());
const selectableAndNotChecked = EcamNormalProcedures[this.checklistId.get()].items
.map((_, index) => (clState.itemsChecked[index] === false ? index : null))
.filter((v) => v !== null);
this.selectedLine.set(
selectableAndNotChecked[0] !== undefined ? selectableAndNotChecked[0] - 1 : clState.itemsChecked.length - 1,
);
} else {
// Deferred procedure
this.selectedLine.set(-2);
}
this.moveDown(false);
}
Expand Down Expand Up @@ -237,7 +240,7 @@ export class FwsNormalChecklists {
this.getNormalProceduresKeysSorted(true).length,
),
);
} else {
} else if (!deferredProcedureIds.includes(this.checklistId.get())) {
const numItems = EcamNormalProcedures[this.checklistId.get()].items.length;
const selectable = this.selectableItems(skipCompletedSensed);
if (this.selectedLine.get() >= selectable[selectable.length - 1] || selectable.length == 0) {
Expand All @@ -251,6 +254,8 @@ export class FwsNormalChecklists {
),
);
}
} else {
//...
}
}

Expand Down

0 comments on commit f51f65a

Please sign in to comment.