diff --git a/PackageSources/js-bundle/src/components/SBEntry/SBEntryF.tsx b/PackageSources/js-bundle/src/components/SBEntry/SBEntryF.tsx index c1ad670..9682fb1 100644 --- a/PackageSources/js-bundle/src/components/SBEntry/SBEntryF.tsx +++ b/PackageSources/js-bundle/src/components/SBEntry/SBEntryF.tsx @@ -1,14 +1,9 @@ import { FC, useEffect, useRef, useState } from 'react'; -import { - COHERENT_COMM_BUS_WASM_CALL, - COMM_BUS_UPDATE_TARGET_EVENT, - GSX_SERVICE_CALLED, - GSX_SERVICE_FINISHED, -} from '../../constants'; +import { GSX_SERVICE_CALLED, GSX_SERVICE_FINISHED } from '../../constants'; import { WASMDataF } from '../../types/WASMData'; -import { LoadingState } from '../../types/general'; +import { LoadingState, SimBrief } from '../../types/general'; import { ImportFlightPlan } from '../../utils/TFDISBImport'; -import { inRangeOf, loadAircraft, unloadAircraft } from '../../utils/utils'; +import { CoherentCallSBEntryF, inRangeOf, loadAircraft, unloadAircraft } from '../../utils/utils'; import CGSelect from '../CGSelect/CGSelect'; import ActionBar from '../actionbar/ActionBar'; @@ -23,8 +18,7 @@ const SBEntryF: FC = ({ WASMData, loadingState, username, setLoadi const [CGTarget, setCGTarget] = useState(WASMData.targetPayload.CGTarget); const [fuel, setFuel] = useState(Math.round(WASMData.livePayload.fuel)); const [fuelEnabled, setFuelEnabled] = useState(true); - //eslint-disable-next-line @typescript-eslint/no-explicit-any - const [SBPlan, setSBPlan] = useState(); + const [SBPlan, setSBPlan] = useState(); const [SBInFlight, setSBInFlight] = useState(false); const cargo = useRef(0); @@ -83,7 +77,7 @@ const SBEntryF: FC = ({ WASMData, loadingState, username, setLoadi cargo.current = parseFloat(SBResponse.message.cargo) ?? 0; - updateData(); + updateData(undefined, SBResponse.message); setSBPlan(SBResponse.message); setFuel(parseFloat(SBResponse.message.fuel) ?? 0); @@ -102,16 +96,8 @@ const SBEntryF: FC = ({ WASMData, loadingState, username, setLoadi setFuelEnabled(inRangeOf(Math.round(WASMData.livePayload.fuel), fuel)); }, [WASMData.livePayload.fuel]); - const updateData = (_CGTarget?: number) => { - Coherent.call( - COHERENT_COMM_BUS_WASM_CALL, - COMM_BUS_UPDATE_TARGET_EVENT, - JSON.stringify({ - mode: 0, - cargo: cargo.current ?? 0, - CGTarget: _CGTarget ?? CGTarget, - }) - ); + const updateData = (_CGTarget?: number, _SBPlan?: SimBrief) => { + CoherentCallSBEntryF(cargo.current ?? 0, _CGTarget ?? CGTarget, _SBPlan ?? SBPlan); }; return ( @@ -153,7 +139,7 @@ const SBEntryF: FC = ({ WASMData, loadingState, username, setLoadi type="text" placeholder="" className="w-1/2 rounded-lg border border-white bg-zinc-700 px-3 py-2 text-right focus:border-blue-600 focus:ring-blue-600" - value={SBPlan?.plannedZFW ?? 0} + value={SBPlan?.plannedZFW ?? WASMData.sbPlanned.ZFW} disabled /> @@ -163,7 +149,7 @@ const SBEntryF: FC = ({ WASMData, loadingState, username, setLoadi type="text" placeholder="" className="w-1/2 rounded-lg border border-white bg-zinc-700 px-3 py-2 text-right focus:border-blue-600 focus:ring-blue-600" - value={SBPlan?.plannedGW ?? 0} + value={SBPlan?.plannedGW ?? WASMData.sbPlanned.GW} disabled /> diff --git a/PackageSources/js-bundle/src/components/SBEntry/SBEntryPax.tsx b/PackageSources/js-bundle/src/components/SBEntry/SBEntryPax.tsx index 5d755df..1bd613d 100644 --- a/PackageSources/js-bundle/src/components/SBEntry/SBEntryPax.tsx +++ b/PackageSources/js-bundle/src/components/SBEntry/SBEntryPax.tsx @@ -1,14 +1,9 @@ import { FC, useEffect, useRef, useState } from 'react'; -import { - COHERENT_COMM_BUS_WASM_CALL, - COMM_BUS_UPDATE_TARGET_EVENT, - GSX_SERVICE_CALLED, - GSX_SERVICE_FINISHED, -} from '../../constants'; +import { GSX_SERVICE_CALLED, GSX_SERVICE_FINISHED } from '../../constants'; import { WASMDataPax } from '../../types/WASMData'; -import { LoadingState } from '../../types/general'; +import { LoadingState, SimBrief } from '../../types/general'; import { ImportFlightPlan } from '../../utils/TFDISBImport'; -import { inRangeOf, loadAircraft, unloadAircraft } from '../../utils/utils'; +import { CoherentCallSBEntryPax, inRangeOf, loadAircraft, unloadAircraft } from '../../utils/utils'; import CGSelect from '../CGSelect/CGSelect'; import ActionBar from '../actionbar/ActionBar'; @@ -23,8 +18,7 @@ const SBEntryPax: FC = ({ WASMData, loadingState, username, setLoa const [CGTarget, setCGTarget] = useState(WASMData.targetPayload.CGTarget); const [fuel, setFuel] = useState(Math.round(WASMData.livePayload.fuel)); const [fuelEnabled, setFuelEnabled] = useState(true); - //eslint-disable-next-line @typescript-eslint/no-explicit-any - const [SBPlan, setSBPlan] = useState(); + const [SBPlan, setSBPlan] = useState(); const [SBInFlight, setSBInFlight] = useState(false); const numPax = useRef(0); @@ -85,7 +79,7 @@ const SBEntryPax: FC = ({ WASMData, loadingState, username, setLoa cargo.current = parseFloat(SBResponse.message.cargo) ?? 0; numPax.current = parseInt(SBResponse.message.pax) ?? 0; - updateData(); + updateData(SBResponse.message); setSBPlan(SBResponse.message); setFuel(parseFloat(SBResponse.message.fuel) ?? 0); @@ -104,17 +98,8 @@ const SBEntryPax: FC = ({ WASMData, loadingState, username, setLoa setFuelEnabled(inRangeOf(Math.round(WASMData.livePayload.fuel), fuel)); }, [WASMData.livePayload.fuel]); - const updateData = (_CGTarget?: number) => { - Coherent.call( - COHERENT_COMM_BUS_WASM_CALL, - COMM_BUS_UPDATE_TARGET_EVENT, - JSON.stringify({ - mode: 0, - cargo: cargo.current ?? 0, - numPax: numPax.current ?? 0, - CGTarget: _CGTarget ?? CGTarget, - }) - ); + const updateData = (_CGTarget?: number, _SBPlan?: SimBrief) => { + CoherentCallSBEntryPax(cargo.current ?? 0, numPax.current ?? 0, _CGTarget ?? CGTarget, _SBPlan ?? SBPlan); }; return ( @@ -156,7 +141,7 @@ const SBEntryPax: FC = ({ WASMData, loadingState, username, setLoa type="text" placeholder="" className="w-1/2 rounded-lg border border-white bg-zinc-700 px-3 py-2 text-right focus:border-blue-600 focus:ring-blue-600" - value={SBPlan?.plannedZFW ?? 0} + value={SBPlan?.plannedZFW ?? WASMData.sbPlanned.ZFW} disabled /> @@ -166,7 +151,7 @@ const SBEntryPax: FC = ({ WASMData, loadingState, username, setLoa type="text" placeholder="" className="w-1/2 rounded-lg border border-white bg-zinc-700 px-3 py-2 text-right focus:border-blue-600 focus:ring-blue-600" - value={SBPlan?.plannedGW ?? 0} + value={SBPlan?.plannedGW ?? WASMData.sbPlanned.GW} disabled /> diff --git a/PackageSources/js-bundle/src/components/options/OptionsPax.tsx b/PackageSources/js-bundle/src/components/options/OptionsPax.tsx new file mode 100644 index 0000000..b1380ea --- /dev/null +++ b/PackageSources/js-bundle/src/components/options/OptionsPax.tsx @@ -0,0 +1,42 @@ +import { FC } from 'react'; +import { GSX_SERVICE_CALLED, GSX_SERVICE_FINISHED } from '../../constants'; +import { LoadingState } from '../../types/general'; +import { WASMDataPax } from '../../types/WASMData'; +import { CoherentCallOptionsSet } from '../../utils/utils'; +import ToggleComponent from '../toggleComponent/ToggleComponent'; + +interface OptionsPaxProps { + WASMData: WASMDataPax; + loadingState: LoadingState; +} + +const OptionsPax: FC = ({ WASMData, loadingState }) => { + const GSXActive = () => { + return ( + (WASMData.GSX.boardingState >= GSX_SERVICE_CALLED || WASMData.GSX.deboardingState >= GSX_SERVICE_CALLED) && + WASMData.GSX.deboardingState !== GSX_SERVICE_FINISHED + ); + }; + + return ( + <> +
+
+ { + CoherentCallOptionsSet(value); + }} + disabled={loadingState !== 'preview' || GSXActive()} + /> +
+
+ + ); +}; + +export default OptionsPax; diff --git a/PackageSources/js-bundle/src/components/pax/Pax.tsx b/PackageSources/js-bundle/src/components/pax/Pax.tsx index 38e0078..ee2c20e 100644 --- a/PackageSources/js-bundle/src/components/pax/Pax.tsx +++ b/PackageSources/js-bundle/src/components/pax/Pax.tsx @@ -2,6 +2,7 @@ import { FC, useState } from 'react'; import { GSX_SERVICE_CALLED, GSX_SERVICE_FINISHED } from '../../constants'; import { LoadingState } from '../../types/general'; import { WASMDataPax } from '../../types/WASMData'; +import OptionsPax from '../options/OptionsPax'; import Profile from '../profile/Profile'; import SBEntryPax from '../SBEntry/SBEntryPax'; import StationEntryPax from '../stationEntry/StationEntryPax'; @@ -125,6 +126,9 @@ const Pax: FC = ({ WASMData, username }) => { {((username && selectedTab === 2) || (!username && selectedTab === 1)) && ( )} + {((username && selectedTab === 3) || (!username && selectedTab === 2)) && ( + + )} ); }; diff --git a/PackageSources/js-bundle/src/components/stationEntry/StationEntryF.tsx b/PackageSources/js-bundle/src/components/stationEntry/StationEntryF.tsx index 8fbff4c..72da9fe 100644 --- a/PackageSources/js-bundle/src/components/stationEntry/StationEntryF.tsx +++ b/PackageSources/js-bundle/src/components/stationEntry/StationEntryF.tsx @@ -1,13 +1,8 @@ import { FC, useEffect, useState } from 'react'; -import { - COHERENT_COMM_BUS_WASM_CALL, - COMM_BUS_UPDATE_TARGET_EVENT, - GSX_SERVICE_CALLED, - GSX_SERVICE_FINISHED, -} from '../../constants'; +import { GSX_SERVICE_CALLED, GSX_SERVICE_FINISHED } from '../../constants'; import { LoadingState } from '../../types/general'; import { WASMDataF } from '../../types/WASMData'; -import { inRangeOf, loadAircraft, unloadAircraft } from '../../utils/utils'; +import { CoherentCallStationEntryF, inRangeOf, loadAircraft, unloadAircraft } from '../../utils/utils'; import ActionBar from '../actionbar/ActionBar'; interface StationEntryProps { @@ -76,19 +71,7 @@ const StationEntryF: FC = ({ WASMData, loadingState, setLoadi }, [WASMData.livePayload.fuel]); const updateData = () => { - Coherent.call( - COHERENT_COMM_BUS_WASM_CALL, - COMM_BUS_UPDATE_TARGET_EVENT, - JSON.stringify({ - mode: 2, - business1: upper1, - business2: upper2, - economy1: upper3, - economy2: upper4, - forwardCargo: lowerForward, - rearCargo: lowerRear, - }) - ); + CoherentCallStationEntryF(upper1, upper2, upper3, upper4, lowerForward, lowerRear); }; return ( diff --git a/PackageSources/js-bundle/src/components/stationEntry/StationEntryPax.tsx b/PackageSources/js-bundle/src/components/stationEntry/StationEntryPax.tsx index 7f9bcae..82f538c 100644 --- a/PackageSources/js-bundle/src/components/stationEntry/StationEntryPax.tsx +++ b/PackageSources/js-bundle/src/components/stationEntry/StationEntryPax.tsx @@ -1,13 +1,8 @@ import { FC, useEffect, useState } from 'react'; -import { - COHERENT_COMM_BUS_WASM_CALL, - COMM_BUS_UPDATE_TARGET_EVENT, - GSX_SERVICE_CALLED, - GSX_SERVICE_FINISHED, -} from '../../constants'; +import { GSX_SERVICE_CALLED, GSX_SERVICE_FINISHED } from '../../constants'; import { LoadingState } from '../../types/general'; import { WASMDataPax } from '../../types/WASMData'; -import { inRangeOf, loadAircraft, unloadAircraft } from '../../utils/utils'; +import { CoherentCallStationEntryPax, inRangeOf, loadAircraft, unloadAircraft } from '../../utils/utils'; import ActionBar from '../actionbar/ActionBar'; interface StationEntryProps { @@ -76,19 +71,7 @@ const StationEntryPax: FC = ({ WASMData, loadingState, setLoa }, [WASMData.livePayload.fuel]); const updateData = () => { - Coherent.call( - COHERENT_COMM_BUS_WASM_CALL, - COMM_BUS_UPDATE_TARGET_EVENT, - JSON.stringify({ - mode: 2, - business1, - business2, - economy1, - economy2, - forwardCargo, - rearCargo, - }) - ); + CoherentCallStationEntryPax(business1, business2, economy1, economy2, forwardCargo, rearCargo); }; return ( diff --git a/PackageSources/js-bundle/src/components/toggleComponent/ToggleComponent.tsx b/PackageSources/js-bundle/src/components/toggleComponent/ToggleComponent.tsx new file mode 100644 index 0000000..c2b961d --- /dev/null +++ b/PackageSources/js-bundle/src/components/toggleComponent/ToggleComponent.tsx @@ -0,0 +1,51 @@ +interface ToggleComponentProps { + optionName: string; + value: T; + leftLabel: { + value: T; + label?: string; + }; + rightLabel: { + value: T; + label?: string; + }; + backgroundColor: string; + disabled?: boolean; + setValue: (value: T) => void; +} + +const ToggleComponent = ({ + optionName, + value, + leftLabel, + rightLabel, + backgroundColor, + disabled, + setValue, +}: ToggleComponentProps) => { + return ( +
+ {optionName} +
+ + +
+
+ ); +}; + +export default ToggleComponent; diff --git a/PackageSources/js-bundle/src/components/zfwEntry/ZFWEntryF.tsx b/PackageSources/js-bundle/src/components/zfwEntry/ZFWEntryF.tsx index da2c435..16bdda7 100644 --- a/PackageSources/js-bundle/src/components/zfwEntry/ZFWEntryF.tsx +++ b/PackageSources/js-bundle/src/components/zfwEntry/ZFWEntryF.tsx @@ -1,13 +1,8 @@ import { FC, useEffect, useState } from 'react'; -import { - COHERENT_COMM_BUS_WASM_CALL, - COMM_BUS_UPDATE_TARGET_EVENT, - GSX_SERVICE_CALLED, - GSX_SERVICE_FINISHED, -} from '../../constants'; +import { GSX_SERVICE_CALLED, GSX_SERVICE_FINISHED } from '../../constants'; import { WASMDataF } from '../../types/WASMData'; import { LoadingState } from '../../types/general'; -import { inRangeOf, loadAircraft, unloadAircraft } from '../../utils/utils'; +import { CoherentCallZFWEntry, inRangeOf, loadAircraft, unloadAircraft } from '../../utils/utils'; import CGSelect from '../CGSelect/CGSelect'; import ActionBar from '../actionbar/ActionBar'; @@ -99,15 +94,7 @@ const ZFWEntryF: FC = ({ WASMData, loadingState, setLoadingState }, [WASMData.livePayload.fuel]); const updateData = (_ZFWTarget?: number, _CGTarget?: number) => { - Coherent.call( - COHERENT_COMM_BUS_WASM_CALL, - COMM_BUS_UPDATE_TARGET_EVENT, - JSON.stringify({ - mode: 1, - ZFWTarget: _ZFWTarget ?? ZFWTarget, - CGTarget: _CGTarget ?? CGTarget, - }) - ); + CoherentCallZFWEntry(_ZFWTarget ?? ZFWTarget, _CGTarget ?? CGTarget); }; return ( diff --git a/PackageSources/js-bundle/src/components/zfwEntry/ZFWEntryPax.tsx b/PackageSources/js-bundle/src/components/zfwEntry/ZFWEntryPax.tsx index e80e045..b261588 100644 --- a/PackageSources/js-bundle/src/components/zfwEntry/ZFWEntryPax.tsx +++ b/PackageSources/js-bundle/src/components/zfwEntry/ZFWEntryPax.tsx @@ -1,13 +1,8 @@ import { FC, useEffect, useState } from 'react'; -import { - COHERENT_COMM_BUS_WASM_CALL, - COMM_BUS_UPDATE_TARGET_EVENT, - GSX_SERVICE_CALLED, - GSX_SERVICE_FINISHED, -} from '../../constants'; +import { GSX_SERVICE_CALLED, GSX_SERVICE_FINISHED } from '../../constants'; import { WASMDataPax } from '../../types/WASMData'; import { LoadingState } from '../../types/general'; -import { inRangeOf, loadAircraft, unloadAircraft } from '../../utils/utils'; +import { CoherentCallZFWEntry, inRangeOf, loadAircraft, unloadAircraft } from '../../utils/utils'; import CGSelect from '../CGSelect/CGSelect'; import ActionBar from '../actionbar/ActionBar'; @@ -99,15 +94,7 @@ const ZFWEntryPax: FC = ({ WASMData, loadingState, setLoadingStat }, [WASMData.livePayload.fuel]); const updateData = (_ZFWTarget?: number, _CGTarget?: number) => { - Coherent.call( - COHERENT_COMM_BUS_WASM_CALL, - COMM_BUS_UPDATE_TARGET_EVENT, - JSON.stringify({ - mode: 1, - ZFWTarget: _ZFWTarget ?? ZFWTarget, - CGTarget: _CGTarget ?? CGTarget, - }) - ); + CoherentCallZFWEntry(_ZFWTarget ?? ZFWTarget, _CGTarget ?? CGTarget); }; return ( diff --git a/PackageSources/js-bundle/src/constants.ts b/PackageSources/js-bundle/src/constants.ts index ec273aa..04c5587 100644 --- a/PackageSources/js-bundle/src/constants.ts +++ b/PackageSources/js-bundle/src/constants.ts @@ -11,3 +11,10 @@ export const CG_ADJUST = 0.05; export const GSX_SERVICE_CALLED = 4; export const GSX_SERVICE_ACTIVE = 5; export const GSX_SERVICE_FINISHED = 6; + +export const MODE_SB_SET = 0; +export const MODE_ZFW_SET = 1; +export const MODE_STATION_SET = 2; +export const MODE_LOAD_SET = 3; +export const MODE_UNLOAD_SET = 4; +export const MODE_OPTIONS_SET = 5; diff --git a/PackageSources/js-bundle/src/types/WASMData.ts b/PackageSources/js-bundle/src/types/WASMData.ts index 6b3bba8..c9260b5 100644 --- a/PackageSources/js-bundle/src/types/WASMData.ts +++ b/PackageSources/js-bundle/src/types/WASMData.ts @@ -1,19 +1,23 @@ -export interface WASMDataPax { - livePayload: LivePayloadPax; - targetPayload: TargetPayloadPax; +interface WASMData { GSX: GSX; userData: UserData; - limits: LimitsPax; options: Options; + sbPlanned: { + ZFW: number; + GW: number; + }; } -export interface WASMDataF { +export interface WASMDataPax extends WASMData { + livePayload: LivePayloadPax; + targetPayload: TargetPayloadPax; + limits: LimitsPax; +} + +export interface WASMDataF extends WASMData { livePayload: LivePayloadF; targetPayload: TargetPayloadF; - GSX: GSX; - userData: UserData; limits: LimitsF; - options: Options; } interface TargetPayload { diff --git a/PackageSources/js-bundle/src/types/general.ts b/PackageSources/js-bundle/src/types/general.ts index 284dc5c..402bdd9 100644 --- a/PackageSources/js-bundle/src/types/general.ts +++ b/PackageSources/js-bundle/src/types/general.ts @@ -1 +1,9 @@ export type LoadingState = 'preview' | 'loaded'; + +export interface SimBrief { + plannedZFW: number; + plannedGW: number; + pax: number; + cargo: number; + fuel: number; +} diff --git a/PackageSources/js-bundle/src/utils/utils.ts b/PackageSources/js-bundle/src/utils/utils.ts index fd2d72c..17b8cdd 100644 --- a/PackageSources/js-bundle/src/utils/utils.ts +++ b/PackageSources/js-bundle/src/utils/utils.ts @@ -1,11 +1,21 @@ -import { COHERENT_COMM_BUS_WASM_CALL, COMM_BUS_UPDATE_TARGET_EVENT } from '../constants'; +import { + COHERENT_COMM_BUS_WASM_CALL, + COMM_BUS_UPDATE_TARGET_EVENT, + MODE_LOAD_SET, + MODE_OPTIONS_SET, + MODE_SB_SET, + MODE_STATION_SET, + MODE_UNLOAD_SET, + MODE_ZFW_SET, +} from '../constants'; +import { SimBrief } from '../types/general'; export const loadAircraft = () => { Coherent.call( COHERENT_COMM_BUS_WASM_CALL, COMM_BUS_UPDATE_TARGET_EVENT, JSON.stringify({ - mode: 3, + mode: MODE_LOAD_SET, }) ); }; @@ -15,7 +25,7 @@ export const unloadAircraft = () => { COHERENT_COMM_BUS_WASM_CALL, COMM_BUS_UPDATE_TARGET_EVENT, JSON.stringify({ - mode: 4, + mode: MODE_UNLOAD_SET, }) ); }; @@ -23,3 +33,103 @@ export const unloadAircraft = () => { export const inRangeOf = (value: number, target: number, tolerance: number = 10) => { return Math.abs(value - target) < tolerance; }; + +export const CoherentCallZFWEntry = (ZFWTarget: number, CGTarget: number) => { + Coherent.call( + COHERENT_COMM_BUS_WASM_CALL, + COMM_BUS_UPDATE_TARGET_EVENT, + JSON.stringify({ + mode: MODE_ZFW_SET, + ZFWTarget: ZFWTarget, + CGTarget: CGTarget, + }) + ); +}; + +export const CoherentCallStationEntryPax = ( + business1: number, + business2: number, + economy1: number, + economy2: number, + forwardCargo: number, + rearCargo: number +) => { + Coherent.call( + COHERENT_COMM_BUS_WASM_CALL, + COMM_BUS_UPDATE_TARGET_EVENT, + JSON.stringify({ + mode: MODE_STATION_SET, + business1, + business2, + economy1, + economy2, + forwardCargo, + rearCargo, + }) + ); +}; + +export const CoherentCallStationEntryF = ( + upper1: number, + upper2: number, + upper3: number, + upper4: number, + lowerForward: number, + lowerRear: number +) => { + Coherent.call( + COHERENT_COMM_BUS_WASM_CALL, + COMM_BUS_UPDATE_TARGET_EVENT, + JSON.stringify({ + mode: MODE_STATION_SET, + upper1, + upper2, + upper3, + upper4, + lowerForward, + lowerRear, + }) + ); +}; + +export const CoherentCallSBEntryPax = (cargo: number, numPax: number, CGTarget: number, SBPlan?: SimBrief) => { + Coherent.call( + COHERENT_COMM_BUS_WASM_CALL, + COMM_BUS_UPDATE_TARGET_EVENT, + JSON.stringify({ + mode: MODE_SB_SET, + cargo: cargo, + numPax: numPax, + CGTarget: CGTarget, + plannedZFW: SBPlan?.plannedZFW ?? 0, + plannedGW: SBPlan?.plannedGW ?? 0, + }) + ); +}; + +export const CoherentCallSBEntryF = (cargo: number, CGTarget: number, SBPlan?: SimBrief) => { + Coherent.call( + COHERENT_COMM_BUS_WASM_CALL, + COMM_BUS_UPDATE_TARGET_EVENT, + JSON.stringify({ + mode: MODE_SB_SET, + cargo: cargo, + CGTarget: CGTarget, + plannedZFW: SBPlan?.plannedZFW ?? 0, + plannedGW: SBPlan?.plannedGW ?? 0, + }) + ); +}; + +export const CoherentCallOptionsSet = (GSXSync?: boolean, paxWeight?: number, bagWeight?: number) => { + Coherent.call( + COHERENT_COMM_BUS_WASM_CALL, + COMM_BUS_UPDATE_TARGET_EVENT, + JSON.stringify({ + mode: MODE_OPTIONS_SET, + GSXSync, + paxWeight, + bagWeight, + }) + ); +}; diff --git a/PackageSources/wasm-module/load-manager.cpp b/PackageSources/wasm-module/load-manager.cpp index e63667f..9fbc0dd 100644 --- a/PackageSources/wasm-module/load-manager.cpp +++ b/PackageSources/wasm-module/load-manager.cpp @@ -502,12 +502,14 @@ int receiveData(const char* buf) { switch(mode) { // SB Entry case 0: { - if (!document.HasMember("cargo") || !document.HasMember("CGTarget")) return -1; + if (!document.HasMember("cargo") || !document.HasMember("CGTarget") || !document.HasMember("plannedZFW") || !document.HasMember("plannedGW")) return -1; unsigned int cargo = document["cargo"].GetInt(); double CGTarget = document["CGTarget"].GetDouble(); if (UserData->isCargo) { targetFPayloadData->CGTarget = CGTarget; + targetFPayloadData->sbPlanned.ZFW = document["plannedZFW"].GetDouble(); + targetFPayloadData->sbPlanned.GW = document["plannedGW"].GetDouble(); distribute(targetFPayloadData, liveFuelData, cargo, UserData->isImperial, UserData->isER); } @@ -516,6 +518,9 @@ int receiveData(const char* buf) { unsigned short numPax = document["numPax"].GetInt(); targetPaxPayloadData->CGTarget = CGTarget; + targetPaxPayloadData->sbPlanned.ZFW = document["plannedZFW"].GetDouble(); + targetPaxPayloadData->sbPlanned.GW = document["plannedGW"].GetDouble(); + distribute(targetPaxPayloadData, liveFuelData, numPax, cargo, UserData->isImperial, UserData->isER); } break; @@ -588,6 +593,32 @@ int receiveData(const char* buf) { break; } + // Option set + case 5: { + if (document.HasMember("GSXSync")) { + UserOptions->GSXSync = document["GSXSync"].GetBool(); + } + + rapidjson::Document optionsDoc; + rapidjson::Document::AllocatorType& allocator = optionsDoc.GetAllocator(); + optionsDoc.SetObject(); + optionsDoc.AddMember("GSXSync", UserOptions->GSXSync, allocator); + optionsDoc.AddMember("paxWeightKG", UserOptions->paxWeightKG, allocator); + optionsDoc.AddMember("bagWeightKG", UserOptions->bagWeightKG, allocator); + optionsDoc.AddMember("paxWeightLBS", UserOptions->paxWeightLBS, allocator); + optionsDoc.AddMember("bagWeightLBS", UserOptions->bagWeightLBS, allocator); + FILE* optionsFile = fopen("\\work\\options.json", "wb"); + if (optionsFile != NULL) { + char writeBuffer[256]; + rapidjson::FileWriteStream os(optionsFile, writeBuffer, sizeof(writeBuffer)); + rapidjson::Writer writer(os); + optionsDoc.Accept(writer); + fclose(optionsFile); + + log(stdout, MODULE_NAME"Options written.\n"); + } + break; + } default: break; } @@ -619,6 +650,8 @@ void sendData () { limits.SetObject(); rapidjson::Value options; options.SetObject(); + rapidjson::Value sbPlanned; + sbPlanned.SetObject(); rapidjson::StringBuffer strbuf; rapidjson::Writer writer(strbuf); @@ -773,6 +806,10 @@ void sendData () { options.AddMember("paxWeight", UserData->isImperial ? UserOptions->paxWeightLBS : UserOptions->paxWeightKG, allocator); options.AddMember("bagWeight", UserData->isImperial ? UserOptions->bagWeightLBS : UserOptions->bagWeightKG, allocator); + // SB Planned + sbPlanned.AddMember("ZFW", UserData->isCargo ? targetFPayloadData->sbPlanned.ZFW: targetPaxPayloadData->sbPlanned.ZFW, allocator); + sbPlanned.AddMember("GW", UserData->isCargo ? targetFPayloadData->sbPlanned.GW : targetPaxPayloadData->sbPlanned.GW, allocator); + // Construct document document.AddMember("livePayload", livePayload.Move(), allocator); document.AddMember("targetPayload", targetPayload.Move(), allocator); @@ -780,6 +817,7 @@ void sendData () { document.AddMember("userData", userData.Move(), allocator); document.AddMember("limits", limits.Move(), allocator); document.AddMember("options", options.Move(), allocator); + document.AddMember("sbPlanned", sbPlanned.Move(), allocator); // Write to CommBus document.Accept(writer); diff --git a/PackageSources/wasm-module/types.h b/PackageSources/wasm-module/types.h index 068e0d7..bafb0c1 100644 --- a/PackageSources/wasm-module/types.h +++ b/PackageSources/wasm-module/types.h @@ -18,7 +18,7 @@ //PMC pallet due to 104in door #define MAX_FRONT_CARGO(IS_IMPERIAL) ((IS_IMPERIAL) ? (6.0 * 15000.0) : (6.0 * 6804.0)) #define MAX_UPPER_CARGO(IS_IMPERIAL) ((IS_IMPERIAL) ? (6.5 * 15000.0) : (6.5 * 6804.0)) -//LD3s due to 70in door +//LD3s due to 70in door, ER option takes up two slots #define MAX_REAR_CARGO(IS_IMPERIAL, IS_ER) ((IS_IMPERIAL) ? ((IS_ER ? 12.0 : 14.0) * 3500.0) : ((IS_ER ? 12.0 : 14.0) * 1588.0)) // All actual Business seats @@ -187,6 +187,10 @@ typedef struct { unsigned char economy2; unsigned short total; } paxCount; + struct sbPlanned { + double ZFW; + double GW; + } sbPlanned; } paxPayloadData_t; typedef struct { double pilot; @@ -243,6 +247,10 @@ typedef struct { unsigned int upper4; unsigned int total; } stations; + struct sbPlanned { + double ZFW; + double GW; + } sbPlanned; } fPayloadData_t; typedef struct { // SimConnect mapped diff --git a/README.md b/README.md index 210ac73..c86edd0 100644 --- a/README.md +++ b/README.md @@ -18,8 +18,6 @@ TODO: - Add to EFB.js and EFB.html - Automate this? - JS - - Persist SB data across page changes - - Options (GSX sync, pax/bag weights) - - Types for SB plan (only what I need) + - Options (pax/bag weights) - WASM - Custom pax/bag weights