diff --git a/src/instruments/src/EFB/Ground/Pages/Payload/Seating/Constants.ts b/src/instruments/src/EFB/Ground/Pages/Payload/Seating/Constants.ts
index 645c6bd5bec..57879b9a140 100644
--- a/src/instruments/src/EFB/Ground/Pages/Payload/Seating/Constants.ts
+++ b/src/instruments/src/EFB/Ground/Pages/Payload/Seating/Constants.ts
@@ -23,6 +23,7 @@ export interface RowInfo {
export interface PaxStationInfo {
name: string,
+ capacity: number,
rows: RowInfo[],
simVar: string,
index: number,
diff --git a/src/instruments/src/EFB/Ground/Pages/Payload/Seating/SeatMapWidget.tsx b/src/instruments/src/EFB/Ground/Pages/Payload/Seating/SeatMapWidget.tsx
index 46c6e05f3d5..e5aee999430 100644
--- a/src/instruments/src/EFB/Ground/Pages/Payload/Seating/SeatMapWidget.tsx
+++ b/src/instruments/src/EFB/Ground/Pages/Payload/Seating/SeatMapWidget.tsx
@@ -2,7 +2,7 @@ import React, { useEffect, useRef, useState } from 'react';
import { BitFlags } from '@shared/bitFlags';
import * as ReactDOMServer from 'react-dom/server';
import { usePersistentProperty } from '@instruments/common/persistence';
-import { CanvasConst, RowInfo, SeatConstants, SeatInfo, PaxStationInfo, TYPE } from './Constants';
+import { CanvasConst, SeatConstants, SeatInfo, PaxStationInfo, TYPE, RowInfo } from './Constants';
import { Seat } from '../../../../Assets/Seat';
import { SeatOutlineBg } from '../../../../Assets/SeatOutlineBg';
@@ -64,7 +64,7 @@ export const SeatMapWidget: React.FC = ({ seatMap, desiredFlags, a
const [xYMap, setXYMap] = useState([]);
const addXOffset = (xOff: number, station: number, row: number) => {
- let seatType = TYPE.NB_ECO;
+ let seatType: number = TYPE.NB_ECO;
xOff += seatMap[station].rows[row].xOffset;
for (let seat = 0; seat < seatMap[station].rows[row].seats.length; seat++) {
if (seatType < seatMap[station].rows[row].seats[seat].type) {
diff --git a/src/shared/src/bitFlags.ts b/src/shared/src/bitFlags.ts
index cbb4f5cc531..df38872e4c1 100644
--- a/src/shared/src/bitFlags.ts
+++ b/src/shared/src/bitFlags.ts
@@ -5,13 +5,23 @@ export class BitFlags {
static u32View = new Uint32Array(BitFlags.f64View.buffer);
- constructor(float: number) {
- this.setFlags(float);
+ constructor(number: number) {
+ this.setFlags(number);
}
- setFlags(float: number): void {
- BitFlags.f64View[0] = float;
+ setFlags(number: number): void {
this.flags = Array.from(BitFlags.u32View);
+ const bigNumberAsBinaryStr = number.toString(2); // '100000000000000000000000000000000000000000000000000000'
+
+ let bigNumberAsBinaryStr2 = '';
+ for (let i = 0; i < 64 - bigNumberAsBinaryStr.length; i++) {
+ bigNumberAsBinaryStr2 += '0';
+ }
+
+ bigNumberAsBinaryStr2 += bigNumberAsBinaryStr;
+
+ this.flags[1] = parseInt(bigNumberAsBinaryStr2.substring(0, 32), 2);
+ this.flags[0] = parseInt(bigNumberAsBinaryStr2.substring(32), 2);
}
getBitIndex(bit: number): boolean {
@@ -34,7 +44,110 @@ export class BitFlags {
return (new Float64Array(Uint32Array.from(this.flags).buffer))[0];
}
+ toDebug(): string {
+ const debug: string[] = [];
+ this.flags.forEach((flag, index) => {
+ debug.push(flag.toString(2));
+ const fL = 32 - flag.toString(2).length;
+ for (let i = 0; i < fL; i++) {
+ debug[index] = '0'.concat(debug[index]);
+ }
+ });
+ return (`HIGH [ ${debug[1]} | ${debug[0]} ] LOW`);
+ }
+
+ toNumber(): number {
+ return this.flags[1] * 2 ** 32 + this.flags[0];
+ }
+
toString(): string {
- return (`[ ${this.flags[0].toString(2)} | ${this.flags[1].toString(2)} ]`);
+ return this.toNumber().toString();
+ }
+
+ getTotalBits(): number {
+ let total = 0;
+ this.flags.forEach((flag) => {
+ const n = 32;
+ let i = 0;
+ while (i++ < n) {
+ if ((1 << i & flag) === (1 << i)) {
+ total++;
+ }
+ }
+ });
+ return total;
+ }
+}
+
+export class SeatFlags extends BitFlags {
+ // Limit bits utilisation to < totalSeats
+ totalSeats: number;
+
+ constructor(number: number, totalSeats: number) {
+ super(number);
+ this.totalSeats = totalSeats;
+ }
+
+ getEmptySeatIds(): number[] {
+ const emptySeats: number[] = [];
+ for (let seatId = 0; seatId < this.totalSeats; seatId++) {
+ if (!this.getBitIndex(seatId)) {
+ emptySeats.push(seatId);
+ }
+ }
+ return emptySeats;
+ }
+
+ getFilledSeatIds(): number[] {
+ const filledSeats: number[] = [];
+ for (let seatId = 0; seatId < this.totalSeats; seatId++) {
+ if (this.getBitIndex(seatId)) {
+ filledSeats.push(seatId);
+ }
+ }
+ return filledSeats;
+ }
+
+ isSeatFilled(seatId: number): boolean {
+ if (seatId > this.totalSeats) return false;
+ return this.getBitIndex(seatId);
+ }
+
+ toggleSeatId(seatId: number): void {
+ if (seatId > this.totalSeats) return;
+ this.toggleBitIndex(seatId);
+ }
+
+ fillEmptySeats(numFill: number) {
+ this.fillSeats(numFill, this.getEmptySeatIds());
+ }
+
+ fillSeats(numFill: number, choices: number[]) {
+ for (let i = 0; i < numFill; i++) {
+ if (choices.length > 0) {
+ const chosen = ~~(Math.random() * choices.length);
+ this.toggleSeatId(choices[chosen]);
+ choices.splice(chosen, 1);
+ }
+ }
+ }
+
+ emptyFilledSeats(numEmpty: number) {
+ const choices = this.getFilledSeatIds();
+ for (let i = 0; i < numEmpty; i++) {
+ if (choices.length > 0) {
+ const chosen = ~~(Math.random() * choices.length);
+ this.toggleSeatId(choices[chosen]);
+ choices.splice(chosen, 1);
+ }
+ }
+ }
+
+ getTotalFilledSeats(): number {
+ return this.getTotalBits();
+ }
+
+ getTotalEmptySeats(): number {
+ return this.totalSeats - this.getTotalBits();
}
}