teletilt #3

Merged
gavin merged 20 commits from teletilt into trunk 2025-07-03 14:40:35 -04:00
2 changed files with 42 additions and 27 deletions
Showing only changes of commit 4ec4ac0242 - Show all commits

View File

@@ -41,6 +41,7 @@ export function AppProvider({ children }: { children: ReactNode }) {
}); });
useEffect(() => { useEffect(() => {
if (localSettings.remoteTilt) {
const cardIndex = tilt.findIndex((tilt) => !!tilt); const cardIndex = tilt.findIndex((tilt) => !!tilt);
if (tilt[cardIndex]) { if (tilt[cardIndex]) {
@@ -50,7 +51,8 @@ export function AppProvider({ children }: { children: ReactNode }) {
// all tilts for this user will be cleared // all tilts for this user will be cleared
emitTilt(0, { rotateX: 0, rotateY: 0 }); emitTilt(0, { rotateX: 0, rotateY: 0 });
} }
}, [tilt]); }
}, [tilt, localSettings]);
const handleSelect = (cardID: string) => { const handleSelect = (cardID: string) => {
setSelectCardIndex(-1); setSelectCardIndex(-1);

View File

@@ -14,8 +14,9 @@ export default function TiltCard({
const cardRef = useRef<HTMLDivElement>(null); const cardRef = useRef<HTMLDivElement>(null);
const { const {
gameData, gameData,
settings: { tilt }, settings: { tilt, remoteTilt },
setTilt, setTilt,
tilt: localTilts,
} = useAppContext(); } = useAppContext();
useEffect(() => { useEffect(() => {
@@ -23,6 +24,7 @@ export default function TiltCard({
if (!card) return; if (!card) return;
if (tilt) { if (tilt) {
if (remoteTilt) {
const tilts = gameData.tilts[cardIndex]; const tilts = gameData.tilts[cardIndex];
if (!tilts.length) { if (!tilts.length) {
card.style.transform = `rotateX(0deg) rotateY(0deg)`; card.style.transform = `rotateX(0deg) rotateY(0deg)`;
@@ -45,10 +47,21 @@ export default function TiltCard({
} else { } else {
card.style.transform = `rotateX(0deg) rotateY(0deg)`; card.style.transform = `rotateX(0deg) rotateY(0deg)`;
} }
} else {
console.log(localTilts);
const rotateX = localTilts[cardIndex]?.rotateX || 0;
const rotateY = localTilts[cardIndex]?.rotateY || 0;
if (rotateX || rotateY) {
card.style.transform = `rotateX(${rotateX}deg) rotateY(${rotateY}deg)`;
} else {
card.style.transform = `rotateX(0deg) rotateY(0deg)`;
}
}
} else if (card.style.transform !== 'rotateX(0deg) rotateY(0deg)') { } else if (card.style.transform !== 'rotateX(0deg) rotateY(0deg)') {
card.style.transform = 'rotateX(0deg) rotateY(0deg)'; card.style.transform = 'rotateX(0deg) rotateY(0deg)';
} }
}, [tilt, gameData]); }, [tilt, localTilts, gameData]);
const handleMouseMove = (e: React.MouseEvent) => { const handleMouseMove = (e: React.MouseEvent) => {
const card = cardRef.current; const card = cardRef.current;