Skip to content

Commit

Permalink
rewrite 1
Browse files Browse the repository at this point in the history
  • Loading branch information
flogross89 committed Dec 15, 2024
1 parent f51f65a commit 05b0fc7
Show file tree
Hide file tree
Showing 10 changed files with 688 additions and 651 deletions.
Original file line number Diff line number Diff line change
@@ -1,192 +1,28 @@
import { ConsumerSubject, FSComponent, VNode } from '@microsoft/msfs-sdk';
import { ConsumerSubject, FSComponent, Subject, VNode } from '@microsoft/msfs-sdk';
import {
ChecklistLineStyle,
EcamAbnormalSensedProcedures,
EcamDeferredProcedures,
isAbnormalSensedProcedure,
isChecklistAction,
isChecklistCondition,
WdLineData,
WdSpecialLine,
} from 'instruments/src/MsfsAvionicsCommon/EcamMessages';
ProcedureLinesGenerator,
ProcedureType,
} from 'instruments/src/MsfsAvionicsCommon/EcamMessages/ProcedureLinesGenerator';

import { WdAbstractChecklistComponent } from 'instruments/src/EWD/elements/WdAbstractChecklistComponent';
import { FwsEwdAbnormalSensedEntry } from 'instruments/src/MsfsAvionicsCommon/providers/FwsEwdPublisher';

export class WdAbnormalSensedProcedures extends WdAbstractChecklistComponent {
private readonly procedures = ConsumerSubject.create(this.sub.on('fws_abn_sensed_procedures'), []);

public updateChecklists() {
this.lineData.length = 0;

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

public static generateProcedureLineData(
procedures: FwsEwdAbnormalSensedEntry[],
lineData: WdLineData[],
showOnlyFirst = true,
deferredProcedure = false,
) {
procedures.forEach((procState, procIndex, array) => {
if (
procState &&
((!deferredProcedure && EcamAbnormalSensedProcedures[procState.id]) ||
(deferredProcedure && EcamDeferredProcedures[procState.id]))
) {
const cl = deferredProcedure
? EcamDeferredProcedures[procState.id]
: EcamAbnormalSensedProcedures[procState.id];

lineData.push({
abnormalProcedure: true,
activeProcedure: procIndex === 0 || deferredProcedure,
sensed: true,
checked: false,
text: cl.title,
style: ChecklistLineStyle.Headline,
firstLine: !deferredProcedure,
lastLine: procIndex !== 0 ? true : false,
});

if (!showOnlyFirst || procIndex === 0) {
if (isAbnormalSensedProcedure(cl) && cl.recommendation) {
lineData.push({
abnormalProcedure: true,
activeProcedure: procIndex === 0,
sensed: true,
checked: false,
text: cl.recommendation,
style: cl.recommendation === 'LAND ASAP' ? ChecklistLineStyle.LandAsap : ChecklistLineStyle.LandAnsa,
firstLine: false,
lastLine: false,
});
}

if (deferredProcedure) {
lineData.push({
abnormalProcedure: true,
activeProcedure: procIndex === 0 || deferredProcedure,
sensed: false,
checked: procState.procedureCompleted ?? false,
text: `${'\xa0'.repeat(31)}ACTIVATE`,
style: ChecklistLineStyle.ChecklistItem,
firstLine: procIndex !== 0 ? true : false,
lastLine: procIndex !== 0 ? true : false,
originalItemIndex: -1,
});
}

// If first and most important procedure: Display in full
cl.items.forEach((item, itemIndex) => {
if (!procState.itemsToShow[itemIndex]) {
return;
}

let clStyle: ChecklistLineStyle = item.style ? item.style : ChecklistLineStyle.ChecklistItem;
let text = item.level ? '\xa0'.repeat(item.level) : '';
if (isChecklistAction(item)) {
text += clStyle !== ChecklistLineStyle.SubHeadline ? '-' : '';
text += item.name;
if (!procState.itemsActive[itemIndex] && clStyle === ChecklistLineStyle.ChecklistItem) {
clStyle = ChecklistLineStyle.ChecklistItemInactive;
}
if (procState.itemsChecked[itemIndex] && item.labelCompleted) {
text += `${item.colonIfCompleted === false ? ' ' : ' : '}${item.labelCompleted}`;
} else if (procState.itemsChecked[itemIndex] && item.labelNotCompleted) {
text += `${item.colonIfCompleted === false ? ' ' : ' : '}${item.labelNotCompleted}`;
} else if (!procState.itemsChecked[itemIndex] && item.labelNotCompleted) {
// Pad to 39 characters max
const paddingNeeded = Math.max(
0,
39 - (item.labelNotCompleted.length + item.name.length + (item.level ?? 0) * 1 + 2),
);

text += ` ${'.'.repeat(paddingNeeded)}${item.labelNotCompleted}`;
}
} else if (isChecklistCondition(item)) {
clStyle = ChecklistLineStyle.ChecklistCondition;
if (item.name.substring(0, 4) === 'WHEN') {
text += `.${item.name}`;
} else {
text += procState.itemsChecked[itemIndex]
? `.AS ${item.name.substring(0, 2) === 'IF' ? item.name.substring(2) : item.name}`
: `.IF ${item.name.substring(0, 2) === 'IF' ? item.name.substring(2) : item.name}`;
}
} else {
text += item.name;
}

lineData.push({
abnormalProcedure: true,
activeProcedure: procIndex === 0 || deferredProcedure,
sensed: isChecklistCondition(item) ? true : item.sensed,
checked: procState.itemsChecked[itemIndex],
text: text,
style: clStyle,
firstLine: procIndex !== 0 ? true : false,
lastLine: procIndex !== 0 ? true : false,
originalItemIndex: isChecklistCondition(item) ? undefined : itemIndex,
});

if (isChecklistCondition(item) && !item.sensed) {
// Insert CONFIRM <condition>
const confirmText = `${item.level ? '\xa0'.repeat(item.level) : ''}CONFIRM ${item.name}`;
lineData.push({
abnormalProcedure: true,
activeProcedure: procIndex === 0 || deferredProcedure,
sensed: item.sensed,
checked: procState.itemsChecked[itemIndex],
text: confirmText,
style: clStyle,
firstLine: procIndex !== 0 ? true : false,
lastLine: procIndex !== 0 ? true : false,
originalItemIndex: itemIndex,
});
}
});

lineData.push({
abnormalProcedure: true,
activeProcedure: true,
sensed: false,
checked: false,
text: `${'\xa0'.repeat(34)}CLEAR`,
style: ChecklistLineStyle.ChecklistItem,
firstLine: false,
lastLine: true,
originalItemIndex: cl.items.length,
});
} else {
// Only three dots for following procedures
lineData.push({
abnormalProcedure: true,
activeProcedure: false,
sensed: true,
checked: false,
text: '...',
style: ChecklistLineStyle.OmissionDots,
firstLine: true,
lastLine: true,
});
}

// Empty line after procedure
if (procIndex < array.length - 1) {
lineData.push({
abnormalProcedure: true,
activeProcedure: procIndex === 0 || deferredProcedure,
sensed: true,
checked: false,
text: '',
style: ChecklistLineStyle.ChecklistItem,
firstLine: true,
lastLine: true,
specialLine: WdSpecialLine.Empty,
});
}
}
this.procedures.get().forEach((procState, procIndex) => {
const procGen = new ProcedureLinesGenerator(
procState.id,
Subject.create(procIndex === 0),
ProcedureType.Abnormal,
procState,
);
this.lineData.push(...procGen.toLineData());
});

super.updateChecklists();
}

public onAfterRender(node: VNode): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class WdAbstractChecklistComponent extends DisplayComponent<WdAbstractChe

protected readonly lineData: WdLineData[] = [];

protected readonly activeLine = ConsumerSubject.create(this.sub.on('fws_active_line'), 0);
protected readonly activeLine = ConsumerSubject.create(this.sub.on('fws_active_item'), 0);

protected readonly showFromLine = ConsumerSubject.create(this.sub.on('fws_show_from_line'), 0);
protected readonly totalLines = Subject.create(0);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ConsumerSubject, FSComponent, VNode } from '@microsoft/msfs-sdk';
import { ConsumerSubject, FSComponent, Subject, VNode } from '@microsoft/msfs-sdk';
import {
deferredProcedureIds,
EcamNormalProcedures,
Expand All @@ -9,7 +9,10 @@ import {
EcamDeferredProcedures,
} from 'instruments/src/MsfsAvionicsCommon/EcamMessages';
import { WdAbstractChecklistComponent } from 'instruments/src/EWD/elements/WdAbstractChecklistComponent';
import { WdAbnormalSensedProcedures } from 'instruments/src/EWD/elements/WdAbnormalSensedProcedures';
import {
ProcedureLinesGenerator,
ProcedureType,
} from 'instruments/src/MsfsAvionicsCommon/EcamMessages/ProcedureLinesGenerator';

export class WdNormalChecklists extends WdAbstractChecklistComponent {
private readonly checklists = ConsumerSubject.create(this.sub.on('fws_normal_checklists'), []);
Expand All @@ -29,9 +32,9 @@ export class WdNormalChecklists extends WdAbstractChecklistComponent {

const sorted = this.checklists
.get()
.filter((v) => v.id !== 0)
.sort((a, b) => a.id - b.id);
const clState = sorted.find((v) => v.id === this.checklistId.get());
.filter((v) => v.id !== '0')
.sort((a, b) => parseInt(a.id) - parseInt(b.id));
const clState = sorted.find((v) => parseInt(v.id) === this.checklistId.get());

if (this.deferred.get().length > 0) {
// Status of deferred procedures
Expand Down Expand Up @@ -79,31 +82,31 @@ export class WdNormalChecklists extends WdAbstractChecklistComponent {
});

sorted.forEach((state, index) => {
if (EcamNormalProcedures[state.id]) {
if (EcamNormalProcedures[parseInt(state.id)]) {
let lineStyle: ChecklistLineStyle;
let checked = false;
let display = true;
if (deferredProcedureIds.includes(state.id)) {
lineStyle = state.checklistCompleted
if (deferredProcedureIds.includes(parseInt(state.id))) {
lineStyle = state.procedureCompleted
? ChecklistLineStyle.CompletedDeferredProcedure
: ChecklistLineStyle.DeferredProcedure;
if (deferredProcedureIds.findIndex((p) => p === state.id) >= 0) {
checked = this.deferredIsCompleted[deferredProcedureIds.findIndex((p) => p === state.id)];
display = this.hasDeferred[deferredProcedureIds.findIndex((p) => p === state.id)];
if (deferredProcedureIds.findIndex((p) => p === parseInt(state.id)) >= 0) {
checked = this.deferredIsCompleted[deferredProcedureIds.findIndex((p) => p === parseInt(state.id))];
display = this.hasDeferred[deferredProcedureIds.findIndex((p) => p === parseInt(state.id))];
}
} else {
lineStyle = state.checklistCompleted
lineStyle = state.procedureCompleted
? ChecklistLineStyle.CompletedChecklist
: ChecklistLineStyle.ChecklistItem;
checked = state.checklistCompleted;
checked = state.procedureCompleted ?? false;
}

if (display) {
this.lineData.push({
activeProcedure: true,
sensed: true,
checked: checked,
text: EcamNormalProcedures[state.id].title,
text: EcamNormalProcedures[parseInt(state.id)].title,
style: lineStyle,
firstLine: false,
lastLine: index === sorted.length - 1,
Expand All @@ -113,74 +116,21 @@ export class WdNormalChecklists extends WdAbstractChecklistComponent {
}
});
this.totalLines.set(sorted.length + this.hasDeferred.reduce((acc, val) => acc + (val ? 1 : 0), 0) + 1);
} else if (clState && EcamNormalProcedures[clState.id] && !deferredProcedureIds.includes(clState.id)) {
const cl = EcamNormalProcedures[clState.id];

this.lineData.push({
activeProcedure: true,
sensed: true,
checked: false,
text: cl.title,
style: ChecklistLineStyle.Headline,
firstLine: true,
lastLine: false,
});

cl.items.forEach((item, index) => {
let text = item.level ? '\xa0'.repeat(item.level * 2) : '';
text += item.style !== ChecklistLineStyle.SubHeadline ? '-' : '';
text += item.name;
if (clState.itemsChecked[index] && item.labelCompleted) {
text += `${item.colonIfCompleted === false ? ' ' : ' : '}${item.labelCompleted}`;
} else if (clState.itemsChecked[index] && item.labelNotCompleted) {
text += `${item.colonIfCompleted === false ? ' ' : ' : '}${item.labelNotCompleted}`;
} else if (!clState.itemsChecked[index] && item.labelNotCompleted) {
// Pad to 39 characters max
const paddingNeeded = 39 - (item.labelNotCompleted.length + item.name.length + (item.level ?? 0) * 2 + 2);
text += ` ${'.'.repeat(paddingNeeded)}${item.labelNotCompleted}`;
}

this.lineData.push({
activeProcedure: true,
sensed: item.sensed,
checked: clState.itemsChecked[index],
text: text.substring(0, 39),
style: item.style ? item.style : ChecklistLineStyle.ChecklistItem,
firstLine: false,
lastLine: false,
originalItemIndex: index,
});
});

this.lineData.push({
activeProcedure: true,
sensed: false,
checked: clState.checklistCompleted,
text: `${'\xa0'.repeat(27)}C/L COMPLETE`,
style: ChecklistLineStyle.ChecklistItem,
firstLine: false,
lastLine: false,
originalItemIndex: cl.items.length,
});

this.lineData.push({
activeProcedure: true,
sensed: false,
checked: false,
text: `${'\xa0'.repeat(34)}RESET`,
style: ChecklistLineStyle.ChecklistItem,
firstLine: false,
lastLine: true,
originalItemIndex: cl.items.length + 1,
});
} else if (clState && deferredProcedureIds.includes(clState.id)) {
} else if (
clState &&
EcamNormalProcedures[parseInt(clState.id)] &&
!deferredProcedureIds.includes(parseInt(clState.id))
) {
const procGen = new ProcedureLinesGenerator(clState.id, Subject.create(true), ProcedureType.Normal, clState);
this.lineData.push(...procGen.toLineData());
} else if (clState && deferredProcedureIds.includes(parseInt(clState.id))) {
// Deferred procedures
this.lineData.push({
activeProcedure: true,
abnormalProcedure: true,
sensed: true,
checked: false,
text: `\x1b4m${clState.checklistCompleted ? '\x1b<4m' : ''}${EcamNormalProcedures[clState.id].title} \x1bm`,
text: `\x1b4m${clState.procedureCompleted ? '\x1b<4m' : ''}${EcamNormalProcedures[parseInt(clState.id)].title} \x1bm`,
style: ChecklistLineStyle.Headline,
firstLine: true,
lastLine: false,
Expand All @@ -195,7 +145,11 @@ export class WdNormalChecklists extends WdAbstractChecklistComponent {
firstLine: false,
lastLine: false,
});
WdAbnormalSensedProcedures.generateProcedureLineData(this.deferred.get(), this.lineData, false, true);

this.deferred.get().forEach((proc, index) => {
const procGen = new ProcedureLinesGenerator(proc.id, Subject.create(index === 0), ProcedureType.Deferred, proc);
this.lineData.push(...procGen.toLineData());
});
}
super.updateChecklists();
}
Expand Down
Loading

0 comments on commit 05b0fc7

Please sign in to comment.