throttle 'tilts' from the server

This commit is contained in:
Gavin McDonald
2025-06-28 20:16:52 -04:00
parent 2ae4c6a77b
commit 1dbe6b7ec0
8 changed files with 66 additions and 28 deletions

View File

@@ -2,6 +2,7 @@ import { useEffect } from 'react';
import { socket } from '@/socket';
import throttle from '@/tools/throttle';
import { thirtyFPS } from '@/constants/time';
import type { GameUpdate, Tilt } from '@/types';
interface UseSocketProps {
@@ -38,28 +39,28 @@ export default function useSocket({ gameID, setGameData, setNoGame }: UseSocketP
};
}, [gameID]);
const flipCard = (cardIndex: number) => {
const emitFlip = (cardIndex: number) => {
socket.emit('flip-card', {
gameID,
cardIndex,
});
};
const handleSettings = (gameData: GameUpdate) => {
const emitSettings = (gameData: GameUpdate) => {
socket.emit('settings', {
gameID,
gameData,
});
};
const redraw = (cardIndex: number) => {
const emitRedraw = (cardIndex: number) => {
socket.emit('redraw', {
gameID,
cardIndex,
});
};
const select = (cardIndex: number, cardID: string) => {
const emitSelect = (cardIndex: number, cardID: string) => {
socket.emit('select', {
gameID,
cardIndex,
@@ -72,13 +73,13 @@ export default function useSocket({ gameID, setGameData, setNoGame }: UseSocketP
cardIndex,
tilt,
});
}, 33.3);
}, thirtyFPS);
return {
flipCard,
handleSettings,
redraw,
select,
emitFlip,
emitSettings,
emitRedraw,
emitSelect,
emitTilt,
};
}