From 9000d516ae611664bea439f55a309d6d80ce6897 Mon Sep 17 00:00:00 2001 From: Kilian Hofmann Date: Mon, 8 Sep 2025 03:06:48 +0200 Subject: [PATCH] Allow GSX state reset Fix KG rounding of pax --- PackageSources/js-bundle/package.json | 2 +- PackageSources/js-bundle/rollup.config.js | 5 +- .../src/components/freighter/Freighter.tsx | 6 +- .../src/components/options/OptionsF.tsx | 13 +---- .../src/components/options/OptionsPax.tsx | 17 ++---- .../js-bundle/src/components/pax/Pax.tsx | 58 ++++++++++--------- .../src/components/zfwEntry/ZFWEntryF.tsx | 1 - PackageSources/wasm-module/load-manager.cpp | 16 ++--- 8 files changed, 52 insertions(+), 66 deletions(-) diff --git a/PackageSources/js-bundle/package.json b/PackageSources/js-bundle/package.json index 25ec1a3..f916fec 100644 --- a/PackageSources/js-bundle/package.json +++ b/PackageSources/js-bundle/package.json @@ -1,6 +1,6 @@ { "name": "tfdidesign-md11-load-manager", - "version": "0.1.116", + "version": "0.1.122", "description": "", "main": "index.js", "type": "module", diff --git a/PackageSources/js-bundle/rollup.config.js b/PackageSources/js-bundle/rollup.config.js index 6c9dce2..f823634 100644 --- a/PackageSources/js-bundle/rollup.config.js +++ b/PackageSources/js-bundle/rollup.config.js @@ -31,6 +31,7 @@ export default { plugins: [ replace({ 'process.env.NODE_ENV': `"${targetEnv}"`, + preventAssignment: true, }), versionInjector(), postcss({ @@ -43,7 +44,9 @@ export default { reactSvg(), resolve(), json(), - typescript(), + typescript({ + outputToFilesystem: false, + }), commonjs({ requireReturnsDefault: 'auto', }), diff --git a/PackageSources/js-bundle/src/components/freighter/Freighter.tsx b/PackageSources/js-bundle/src/components/freighter/Freighter.tsx index 5d2cbfc..d9dc91c 100644 --- a/PackageSources/js-bundle/src/components/freighter/Freighter.tsx +++ b/PackageSources/js-bundle/src/components/freighter/Freighter.tsx @@ -21,16 +21,12 @@ const Freighter: FC = ({ WASMData, username }) => { const [deboardingState, setDeboardingState] = useState(1); useEffect(() => { - console.log('GSX boarding state changed', boardingState, WASMData.GSX.boardingState); - if (WASMData.GSX.boardingState < GSX_SERVICE_CALLED) return; setBoardingState(WASMData.GSX.boardingState); setDeboardingState(1); }, [WASMData.GSX.boardingState]); useEffect(() => { - console.log('GSX deboarding state changed', deboardingState, WASMData.GSX.deboardingState); - if (WASMData.GSX.deboardingState < GSX_SERVICE_CALLED) return; setBoardingState(1); @@ -178,7 +174,7 @@ const Freighter: FC = ({ WASMData, username }) => { /> )} {((username && selectedTab === 3) || (!username && selectedTab === 2)) && ( - + )} ); diff --git a/PackageSources/js-bundle/src/components/options/OptionsF.tsx b/PackageSources/js-bundle/src/components/options/OptionsF.tsx index 187559a..e5e30b8 100644 --- a/PackageSources/js-bundle/src/components/options/OptionsF.tsx +++ b/PackageSources/js-bundle/src/components/options/OptionsF.tsx @@ -1,5 +1,4 @@ import { FC } from 'react'; -import { GSX_SERVICE_CALLED, GSX_SERVICE_FINISHED } from '../../constants'; import { LoadingState } from '../../types/general'; import { WASMDataF } from '../../types/WASMData'; import { CoherentCallOptionsSet } from '../../utils/utils'; @@ -8,16 +7,10 @@ import ToggleComponentKH from '../toggleComponent/ToggleComponent'; interface OptionsFProps { WASMData: WASMDataF; loadingState: LoadingState; + gsxActive: boolean; } -const OptionsF: FC = ({ WASMData, loadingState }) => { - const GSXActive = () => { - return ( - (WASMData.GSX.boardingState >= GSX_SERVICE_CALLED || WASMData.GSX.deboardingState >= GSX_SERVICE_CALLED) && - WASMData.GSX.deboardingState !== GSX_SERVICE_FINISHED - ); - }; - +const OptionsF: FC = ({ WASMData, loadingState, gsxActive }) => { return ( <>
@@ -31,7 +24,7 @@ const OptionsF: FC = ({ WASMData, loadingState }) => { setValue={(value) => { CoherentCallOptionsSet(value); }} - disabled={loadingState !== 'preview' || GSXActive()} + disabled={loadingState !== 'preview' || gsxActive} />
diff --git a/PackageSources/js-bundle/src/components/options/OptionsPax.tsx b/PackageSources/js-bundle/src/components/options/OptionsPax.tsx index 113c1ed..1156282 100644 --- a/PackageSources/js-bundle/src/components/options/OptionsPax.tsx +++ b/PackageSources/js-bundle/src/components/options/OptionsPax.tsx @@ -1,5 +1,4 @@ import { FC, useEffect, useState } 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'; @@ -8,19 +7,13 @@ import ToggleComponentKH from '../toggleComponent/ToggleComponent'; interface OptionsPaxProps { WASMData: WASMDataPax; loadingState: LoadingState; + gsxActive: boolean; } -const OptionsPax: FC = ({ WASMData, loadingState }) => { +const OptionsPax: FC = ({ WASMData, loadingState, gsxActive }) => { const [paxWeight, setPaxWeight] = useState(WASMData.options.paxWeight); const [bagWeight, setBagWeight] = useState(WASMData.options.bagWeight); - const GSXActive = () => { - return ( - (WASMData.GSX.boardingState >= GSX_SERVICE_CALLED || WASMData.GSX.deboardingState >= GSX_SERVICE_CALLED) && - WASMData.GSX.deboardingState !== GSX_SERVICE_FINISHED - ); - }; - const updateData = () => { CoherentCallOptionsSet(undefined, paxWeight, bagWeight); }; @@ -54,7 +47,7 @@ const OptionsPax: FC = ({ WASMData, loadingState }) => { setValue={(value) => { CoherentCallOptionsSet(value); }} - disabled={loadingState !== 'preview' || GSXActive()} + disabled={loadingState !== 'preview' || gsxActive} /> @@ -69,7 +62,7 @@ const OptionsPax: FC = ({ WASMData, loadingState }) => { 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={paxWeight} onChange={(e) => handleInput(e.target.value, Number.MAX_VALUE, setPaxWeight)} - disabled={loadingState !== 'preview' || GSXActive()} + disabled={loadingState !== 'preview' || gsxActive} /> @@ -82,7 +75,7 @@ const OptionsPax: FC = ({ WASMData, loadingState }) => { 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={bagWeight} onChange={(e) => handleInput(e.target.value, Number.MAX_VALUE, setBagWeight)} - disabled={loadingState !== 'preview' || GSXActive()} + disabled={loadingState !== 'preview' || gsxActive} /> diff --git a/PackageSources/js-bundle/src/components/pax/Pax.tsx b/PackageSources/js-bundle/src/components/pax/Pax.tsx index 4708843..833dcad 100644 --- a/PackageSources/js-bundle/src/components/pax/Pax.tsx +++ b/PackageSources/js-bundle/src/components/pax/Pax.tsx @@ -1,4 +1,4 @@ -import { FC, useEffect, useState } from 'react'; +import { FC, useEffect, useMemo, useState } from 'react'; import { GSX_SERVICE_CALLED, GSX_SERVICE_FINISHED } from '../../constants'; import { LoadingState } from '../../types/general'; import { WASMDataPax } from '../../types/WASMData'; @@ -21,17 +21,13 @@ const Pax: FC = ({ WASMData, username }) => { const [deboardingState, setDeboardingState] = useState(1); useEffect(() => { - console.log('GSX boarding state changed', boardingState, WASMData.GSX.boardingState); - - if (WASMData.GSX.boardingState < GSX_SERVICE_CALLED) return; + if (WASMData.GSX.boardingState > 1 && WASMData.GSX.boardingState < GSX_SERVICE_CALLED) return; setBoardingState(WASMData.GSX.boardingState); setDeboardingState(1); }, [WASMData.GSX.boardingState]); useEffect(() => { - console.log('GSX deboarding state changed', deboardingState, WASMData.GSX.deboardingState); - - if (WASMData.GSX.deboardingState < GSX_SERVICE_CALLED) return; + if (WASMData.GSX.deboardingState > 1 && WASMData.GSX.deboardingState < GSX_SERVICE_CALLED) return; setBoardingState(1); setDeboardingState(WASMData.GSX.deboardingState); @@ -58,27 +54,27 @@ const Pax: FC = ({ WASMData, username }) => { return WASMData.livePayload.economy2; }; const lower1 = () => { - if (loadingState !== 'loaded' && !GSXActive()) return Math.round(WASMData.targetPayload.forwardCargo); + if (loadingState !== 'loaded' && !GSXActive) return Math.round(WASMData.targetPayload.forwardCargo); return Math.round(WASMData.livePayload.forwardCargo); }; const lower2 = () => { - if (loadingState !== 'loaded' && !GSXActive()) return Math.round(WASMData.targetPayload.rearCargo); + if (loadingState !== 'loaded' && !GSXActive) return Math.round(WASMData.targetPayload.rearCargo); return Math.round(WASMData.livePayload.rearCargo); }; const OEW = () => { - if (loadingState !== 'loaded' && !GSXActive()) return Math.round(WASMData.targetPayload.empty); + if (loadingState !== 'loaded' && !GSXActive) return Math.round(WASMData.targetPayload.empty); return Math.round(WASMData.livePayload.empty); }; const crew = () => { - if (loadingState !== 'loaded' && !GSXActive()) return Math.round(WASMData.targetPayload.crew); + if (loadingState !== 'loaded' && !GSXActive) return Math.round(WASMData.targetPayload.crew); return Math.round(WASMData.livePayload.crew); }; - const GSXActive = () => { + const GSXActive = useMemo(() => { // Cases when active: // BOARDING called, running or done // DEBOARDING called, running or done @@ -87,14 +83,20 @@ const Pax: FC = ({ WASMData, username }) => { // DEBOARDING not called, disabled // BOTH done + console.log( + 'GSXActive', + (boardingState >= GSX_SERVICE_CALLED || deboardingState >= GSX_SERVICE_CALLED) && + deboardingState !== GSX_SERVICE_FINISHED + ); + return ( (boardingState >= GSX_SERVICE_CALLED || deboardingState >= GSX_SERVICE_CALLED) && deboardingState !== GSX_SERVICE_FINISHED ); - }; + }, [boardingState, deboardingState]); const CGs = (): [string, boolean, string, boolean] => { - if (loadingState !== 'loaded' && !GSXActive()) { + if (loadingState !== 'loaded' && !GSXActive) { return [ WASMData.targetPayload.ZFWCG.toFixed(1), WASMData.targetPayload.ZFWCG < WASMData.limits.minCG || WASMData.targetPayload.ZFWCG > WASMData.limits.maxCG, @@ -103,7 +105,7 @@ const Pax: FC = ({ WASMData, username }) => { ]; } - if (WASMData.options.GSXSync && GSXActive() && boardingState !== GSX_SERVICE_FINISHED) { + if (WASMData.options.GSXSync && GSXActive && boardingState !== GSX_SERVICE_FINISHED) { return [ WASMData.targetPayload.ZFWCG.toFixed(1), WASMData.targetPayload.ZFWCG < WASMData.limits.minCG || WASMData.targetPayload.ZFWCG > WASMData.limits.maxCG, @@ -129,20 +131,20 @@ const Pax: FC = ({ WASMData, username }) => { = ({ WASMData, username }) => { WASMData={WASMData} loadingState={loadingState} setLoadingState={setLoadingState} - gsxActive={GSXActive()} + gsxActive={GSXActive} /> )} {((username && selectedTab === 1) || (!username && selectedTab === 0)) && ( @@ -170,7 +172,7 @@ const Pax: FC = ({ WASMData, username }) => { WASMData={WASMData} loadingState={loadingState} setLoadingState={setLoadingState} - gsxActive={GSXActive()} + gsxActive={GSXActive} /> )} {((username && selectedTab === 2) || (!username && selectedTab === 1)) && ( @@ -178,11 +180,11 @@ const Pax: FC = ({ WASMData, username }) => { WASMData={WASMData} loadingState={loadingState} setLoadingState={setLoadingState} - gsxActive={GSXActive()} + gsxActive={GSXActive} /> )} {((username && selectedTab === 3) || (!username && selectedTab === 2)) && ( - + )} ); diff --git a/PackageSources/js-bundle/src/components/zfwEntry/ZFWEntryF.tsx b/PackageSources/js-bundle/src/components/zfwEntry/ZFWEntryF.tsx index 2700e55..cf44869 100644 --- a/PackageSources/js-bundle/src/components/zfwEntry/ZFWEntryF.tsx +++ b/PackageSources/js-bundle/src/components/zfwEntry/ZFWEntryF.tsx @@ -1,5 +1,4 @@ import { FC, useEffect, useState } from 'react'; -import { GSX_SERVICE_CALLED, GSX_SERVICE_FINISHED } from '../../constants'; import { WASMDataF } from '../../types/WASMData'; import { LoadingState } from '../../types/general'; import { CoherentCallZFWEntry, inRangeOf, loadAircraft, unloadAircraft } from '../../utils/utils'; diff --git a/PackageSources/wasm-module/load-manager.cpp b/PackageSources/wasm-module/load-manager.cpp index d9c807c..54bca84 100644 --- a/PackageSources/wasm-module/load-manager.cpp +++ b/PackageSources/wasm-module/load-manager.cpp @@ -721,20 +721,20 @@ void sendData () { FROM_POUNDS(UserData->isImperial, livePaxPayloadData->cabinCrewRear), allocator); livePayload.AddMember("business1", - (short)(FROM_POUNDS(UserData->isImperial, livePaxPayloadData->business1Left + livePaxPayloadData->business1Center + - livePaxPayloadData->business1Right) / PAX_WEIGHT(UserData->isImperial, UserOptions)), + (short)round((livePaxPayloadData->business1Left + livePaxPayloadData->business1Center + + livePaxPayloadData->business1Right) / PAX_WEIGHT(true, UserOptions)), allocator); livePayload.AddMember("business2", - (short)(FROM_POUNDS(UserData->isImperial, livePaxPayloadData->business2Left + livePaxPayloadData->business2Center + - livePaxPayloadData->business2Right) / PAX_WEIGHT(UserData->isImperial, UserOptions)), + (short)round((livePaxPayloadData->business2Left + livePaxPayloadData->business2Center + + livePaxPayloadData->business2Right) / PAX_WEIGHT(true, UserOptions)), allocator); livePayload.AddMember("economy1", - (short)(FROM_POUNDS(UserData->isImperial, livePaxPayloadData->economy1Left + livePaxPayloadData->economy1Center + - livePaxPayloadData->economy1Right) / PAX_WEIGHT(UserData->isImperial, UserOptions)), + (short)round((livePaxPayloadData->economy1Left + livePaxPayloadData->economy1Center + + livePaxPayloadData->economy1Right) / PAX_WEIGHT(true, UserOptions)), allocator); livePayload.AddMember("economy2", - (short)(FROM_POUNDS(UserData->isImperial, livePaxPayloadData->economy2Left + livePaxPayloadData->economy2Center + - livePaxPayloadData->economy2Right) / PAX_WEIGHT(UserData->isImperial, UserOptions)), + (short)round((livePaxPayloadData->economy2Left + livePaxPayloadData->economy2Center + + livePaxPayloadData->economy2Right) / PAX_WEIGHT(true, UserOptions)), allocator); livePayload.AddMember("forwardCargo", FROM_POUNDS(UserData->isImperial, livePaxPayloadData->forwardCargo), allocator); livePayload.AddMember("rearCargo", FROM_POUNDS(UserData->isImperial, livePaxPayloadData->rearCargo), allocator);