diff --git a/back-end/realtime/src/rooms/FCS.ts b/back-end/realtime/src/rooms/FCS.ts index eea9199f..e8d20e68 100644 --- a/back-end/realtime/src/rooms/FCS.ts +++ b/back-end/realtime/src/rooms/FCS.ts @@ -51,6 +51,11 @@ export default class FCS extends Room { matchRoom.localEmitter.on(MatchSocketEvent.ABORT, () => { this.broadcastFcsUpdate(this.fcsPackets.fieldFault); }); + + // TODO(jan): Callback to process match details + // matchRoom.localEmitter.on(MatchSocketEvent.UPDATE, (match: Match) => { + // this.broadcastFcsUpdate(this.fcsPackets.???); + // }); } public initializeEvents(socket: Socket): void { @@ -72,6 +77,10 @@ export default class FCS extends Room { this.broadcastFcsUpdate(this.fcsPackets.allClear); }); + socket.on('fcs:settings', (fieldOptions: FieldOptions) => { + this.fcsPackets = getFcsPackets(fieldOptions); + }); + socket.emit('fcs:update', this.latestFcsStatus); } diff --git a/front-end/src/seasons/fgc-2024/field-control.tsx b/front-end/src/seasons/fgc-2024/field-control.tsx index b8a81839..1c33198e 100644 --- a/front-end/src/seasons/fgc-2024/field-control.tsx +++ b/front-end/src/seasons/fgc-2024/field-control.tsx @@ -1,10 +1,13 @@ -import { FeedingTheFuture } from '@toa-lib/models'; +import { FeedingTheFuture, FieldOptions } from '@toa-lib/models'; import { FieldControlCallbacks } from '..'; import { useSocket } from 'src/api/use-socket'; +import { useRecoilValue } from 'recoil'; +import { fieldOptionsSelector } from './stores/settings-store'; export const useFieldControl = (): FieldControlCallbacks => { const [socket] = useSocket(); + const fieldOptions: FieldOptions = useRecoilValue(fieldOptionsSelector); const prestartField = () => { socket?.emit('fcs:test', { test: 'test' }); @@ -16,6 +19,8 @@ export const useFieldControl = }; const prepareField = () => { + // Keep field options up to date + socket?.emit('fcs:settings', fieldOptions); socket?.emit('fcs:prepareField'); console.log('prepareField'); }; diff --git a/front-end/src/seasons/fgc-2024/settings.tsx b/front-end/src/seasons/fgc-2024/settings.tsx index f599f02b..1760b36e 100644 --- a/front-end/src/seasons/fgc-2024/settings.tsx +++ b/front-end/src/seasons/fgc-2024/settings.tsx @@ -1,5 +1,5 @@ import { Box } from '@mui/material'; -import { FC } from 'react'; +import { FC, useEffect } from 'react'; import { useRecoilState, useRecoilValue } from 'recoil'; import { allClearColorAtom, @@ -13,10 +13,12 @@ import { rampLedLengthAtom } from './stores/settings-store'; import { NumberSetting } from 'src/apps/settings/components/number-setting'; +import { useSocket } from 'src/api/use-socket'; +import { FieldOptions } from '@toa-lib/models'; import { TextSetting } from 'src/apps/settings/components/text-setting'; export const Settings: FC = () => { - const [test, setTest] = useRecoilState(testAtom); + const [socket] = useSocket(); const [goalLedLength, setGoalLedLength] = useRecoilState(goalLedLengthAtom); const [rampLedLength, setRampLedLength] = useRecoilState(rampLedLengthAtom); const [allClearColor, setAllClearColor] = useRecoilState(allClearColorAtom); @@ -33,6 +35,12 @@ export const Settings: FC = () => { matchEndRampColorAtom ); + const fieldOptions: FieldOptions = useRecoilValue(fieldOptionsSelector); + + useEffect(() => { + socket?.emit('fcs:settings', fieldOptions); + }, [fieldOptions]); + return (