From 9ca34540e8700a515442c281b2c5b3f39322448d Mon Sep 17 00:00:00 2001 From: Gavin McDonald Date: Tue, 8 Jul 2025 16:04:30 -0400 Subject: [PATCH] fix tilt settings --- app/AppContext.tsx | 5 +++-- components/TiltCard.tsx | 2 -- tools/reduceTilts.ts | 16 +++++++++------- tools/validTilt.ts | 9 +++++++-- 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/app/AppContext.tsx b/app/AppContext.tsx index f530a13..58d28c4 100644 --- a/app/AppContext.tsx +++ b/app/AppContext.tsx @@ -63,14 +63,15 @@ export function AppProvider({ children }: { children: ReactNode }) { const { dmID } = gameData; const isDM = !!dmID; + const settings = { ...gameData.settings, ...localSettings }; const appInterface = { gameData, isDM, noGame, selectCardIndex, - settings: { ...gameData.settings, ...localSettings }, - tilts: reduceTilts(gameData, localTilt), + settings, + tilts: reduceTilts(gameData, localTilt, settings), emitFlip, emitSettings, emitRedraw, diff --git a/components/TiltCard.tsx b/components/TiltCard.tsx index d357fa3..aaba5e1 100644 --- a/components/TiltCard.tsx +++ b/components/TiltCard.tsx @@ -73,8 +73,6 @@ export default function TiltCard({ }, thirtyFPS); const handleTouchMove = throttle((e: React.TouchEvent) => { - e.stopPropagation(); - const card = cardRef.current; const touch = e.touches[0]; diff --git a/tools/reduceTilts.ts b/tools/reduceTilts.ts index 1167997..2289625 100644 --- a/tools/reduceTilts.ts +++ b/tools/reduceTilts.ts @@ -1,5 +1,5 @@ -import { log, validTilt } from '@/tools'; -import { GameUpdate, Tilt } from '@/types'; +import { validTilt } from '@/tools'; +import { GameUpdate, Settings, Tilt } from '@/types'; const combineTilts = (tilts: Tilt[]) => tilts.reduce( @@ -13,13 +13,15 @@ const combineTilts = (tilts: Tilt[]) => { pX: 0, pY: 0, rX: 0, rY: 0, count: 0 }, ); -export function reduceTilts(gameData: GameUpdate, localTilt: Tilt[]): Tilt[] { +export function reduceTilts( + gameData: GameUpdate, + localTilt: Tilt[], + { tilt, remoteTilt }: Settings, +): Tilt[] { const remoteTilts = gameData.tilts; - const tiltEnabled = gameData.settings.tilt; - const remoteTiltEnabled = gameData.settings.remoteTilt; - if (!tiltEnabled) return []; - if (!remoteTiltEnabled) return Array.from({ length: 5 }, (_, i) => localTilt[i]); + if (!tilt) return []; + if (!remoteTilt) return localTilt; return Array.from({ length: 5 }, (_, i) => (localTilt[i] ? [localTilt[i]] : [])) .map((cardTilts, cardIndex) => [...remoteTilts[cardIndex], ...cardTilts]) diff --git a/tools/validTilt.ts b/tools/validTilt.ts index cae0758..806d0f0 100644 --- a/tools/validTilt.ts +++ b/tools/validTilt.ts @@ -1,4 +1,9 @@ import { Tilt } from '@/types'; -export const validTilt = ({ percentX, percentY, rotateX, rotateY }: Tilt) => - percentX >= 0 && percentY >= 0 && !!rotateX && !!rotateY; +export const validTilt = (tilt: Tilt) => { + if (!tilt) return false; + + const { percentX, percentY, rotateX, rotateY } = tilt; + + return percentX >= 0 && percentY >= 0 && !!rotateX && !!rotateY; +};