teletilt #3
@@ -41,6 +41,7 @@ export function AppProvider({ children }: { children: ReactNode }) {
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
if (localSettings.remoteTilt) {
|
||||
const cardIndex = tilt.findIndex((tilt) => !!tilt);
|
||||
|
||||
if (tilt[cardIndex]) {
|
||||
@@ -50,7 +51,8 @@ export function AppProvider({ children }: { children: ReactNode }) {
|
||||
// all tilts for this user will be cleared
|
||||
emitTilt(0, { rotateX: 0, rotateY: 0 });
|
||||
}
|
||||
}, [tilt]);
|
||||
}
|
||||
}, [tilt, localSettings]);
|
||||
|
||||
const handleSelect = (cardID: string) => {
|
||||
setSelectCardIndex(-1);
|
||||
|
||||
@@ -14,8 +14,9 @@ export default function TiltCard({
|
||||
const cardRef = useRef<HTMLDivElement>(null);
|
||||
const {
|
||||
gameData,
|
||||
settings: { tilt },
|
||||
settings: { tilt, remoteTilt },
|
||||
setTilt,
|
||||
tilt: localTilts,
|
||||
} = useAppContext();
|
||||
|
||||
useEffect(() => {
|
||||
@@ -23,6 +24,7 @@ export default function TiltCard({
|
||||
if (!card) return;
|
||||
|
||||
if (tilt) {
|
||||
if (remoteTilt) {
|
||||
const tilts = gameData.tilts[cardIndex];
|
||||
if (!tilts.length) {
|
||||
card.style.transform = `rotateX(0deg) rotateY(0deg)`;
|
||||
@@ -45,10 +47,21 @@ export default function TiltCard({
|
||||
} else {
|
||||
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)') {
|
||||
card.style.transform = 'rotateX(0deg) rotateY(0deg)';
|
||||
}
|
||||
}, [tilt, gameData]);
|
||||
}, [tilt, localTilts, gameData]);
|
||||
|
||||
const handleMouseMove = (e: React.MouseEvent) => {
|
||||
const card = cardRef.current;
|
||||
|
||||
Reference in New Issue
Block a user