Skip to content

Commit

Permalink
Send updated field options to realtime server
Browse files Browse the repository at this point in the history
  • Loading branch information
jfabellera committed Sep 13, 2024
1 parent d90df57 commit 5bd8bd3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
9 changes: 9 additions & 0 deletions back-end/realtime/src/rooms/FCS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any>) => {
// this.broadcastFcsUpdate(this.fcsPackets.???);
// });
}

public initializeEvents(socket: Socket): void {
Expand All @@ -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);
}

Expand Down
7 changes: 6 additions & 1 deletion front-end/src/seasons/fgc-2024/field-control.tsx
Original file line number Diff line number Diff line change
@@ -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<FeedingTheFuture.MatchDetails> => {
const [socket] = useSocket();
const fieldOptions: FieldOptions = useRecoilValue(fieldOptionsSelector);

const prestartField = () => {
socket?.emit('fcs:test', { test: 'test' });
Expand All @@ -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');
};
Expand Down
12 changes: 10 additions & 2 deletions front-end/src/seasons/fgc-2024/settings.tsx
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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);
Expand All @@ -33,6 +35,12 @@ export const Settings: FC = () => {
matchEndRampColorAtom
);

const fieldOptions: FieldOptions = useRecoilValue(fieldOptionsSelector);

useEffect(() => {
socket?.emit('fcs:settings', fieldOptions);
}, [fieldOptions]);

return (
<Box>
<NumberSetting
Expand Down

0 comments on commit 5bd8bd3

Please sign in to comment.