setting to disable tilt
This commit is contained in:
@@ -1,41 +1,34 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { createContext, useContext, useEffect, useState, ReactNode } from 'react';
|
import { createContext, useContext, useEffect, useState } from 'react';
|
||||||
import useSocket from '@/hooks/useSocket';
|
import useSocket from '@/hooks/useSocket';
|
||||||
import type { GameUpdate, Tilt } from '@/types';
|
|
||||||
|
import { GAME_START, LOCAL_DEFAULTS } from '@/constants';
|
||||||
|
import type { Dispatch, ReactNode, SetStateAction } from 'react';
|
||||||
|
import type { GameUpdate, LocalSettings, Settings, Tilt } from '@/types';
|
||||||
|
|
||||||
const AppContext = createContext<AppContext | undefined>(undefined);
|
const AppContext = createContext<AppContext | undefined>(undefined);
|
||||||
|
|
||||||
const gameStart: GameUpdate = {
|
|
||||||
dmID: '',
|
|
||||||
spectatorID: '',
|
|
||||||
cards: [],
|
|
||||||
settings: {
|
|
||||||
positionBack: false,
|
|
||||||
positionFront: false,
|
|
||||||
prophecy: false,
|
|
||||||
notes: false,
|
|
||||||
cardStyle: 'color',
|
|
||||||
},
|
|
||||||
tilts: Array.from({ length: 5 }, () => []),
|
|
||||||
};
|
|
||||||
|
|
||||||
export interface AppContext {
|
export interface AppContext {
|
||||||
gameData: GameUpdate;
|
gameData: GameUpdate;
|
||||||
|
isDM: boolean;
|
||||||
noGame: boolean;
|
noGame: boolean;
|
||||||
tilt: Tilt[];
|
|
||||||
selectCardIndex: number;
|
selectCardIndex: number;
|
||||||
|
settings: Settings;
|
||||||
|
tilt: Tilt[];
|
||||||
emitFlip: (cardIndex: number) => void;
|
emitFlip: (cardIndex: number) => void;
|
||||||
emitSettings: (gameData: GameUpdate) => void;
|
emitSettings: (gameData: GameUpdate) => void;
|
||||||
emitRedraw: (cardIndex: number) => void;
|
emitRedraw: (cardIndex: number) => void;
|
||||||
emitSelect: (cardID: string) => void;
|
emitSelect: (cardID: string) => void;
|
||||||
setGameID: (gameID: string) => void;
|
setGameID: (gameID: string) => void;
|
||||||
|
setLocalSettings: Dispatch<SetStateAction<LocalSettings>>;
|
||||||
setSelectCardIndex: (cardIndex: number) => void;
|
setSelectCardIndex: (cardIndex: number) => void;
|
||||||
setTilt: (tilt: Tilt[]) => void;
|
setTilt: (tilt: Tilt[]) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function AppProvider({ children }: { children: ReactNode }) {
|
export function AppProvider({ children }: { children: ReactNode }) {
|
||||||
const [gameData, setGameData] = useState<GameUpdate>(gameStart);
|
const [gameData, setGameData] = useState<GameUpdate>({ ...GAME_START });
|
||||||
|
const [localSettings, setLocalSettings] = useState<LocalSettings>(() => ({ ...LOCAL_DEFAULTS }));
|
||||||
const [gameID, setGameID] = useState('');
|
const [gameID, setGameID] = useState('');
|
||||||
const [noGame, setNoGame] = useState(false);
|
const [noGame, setNoGame] = useState(false);
|
||||||
const [selectCardIndex, setSelectCardIndex] = useState(-1);
|
const [selectCardIndex, setSelectCardIndex] = useState(-1);
|
||||||
@@ -61,16 +54,22 @@ export function AppProvider({ children }: { children: ReactNode }) {
|
|||||||
emitSelect(selectCardIndex, cardID);
|
emitSelect(selectCardIndex, cardID);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const { dmID } = gameData;
|
||||||
|
const isDM = !!dmID;
|
||||||
|
|
||||||
const appInterface = {
|
const appInterface = {
|
||||||
gameData,
|
gameData,
|
||||||
|
isDM,
|
||||||
noGame,
|
noGame,
|
||||||
tilt,
|
|
||||||
selectCardIndex,
|
selectCardIndex,
|
||||||
|
settings: { ...gameData.settings, ...localSettings },
|
||||||
|
tilt,
|
||||||
emitFlip,
|
emitFlip,
|
||||||
emitSettings,
|
emitSettings,
|
||||||
emitRedraw,
|
emitRedraw,
|
||||||
emitSelect: handleSelect,
|
emitSelect: handleSelect,
|
||||||
setGameID,
|
setGameID,
|
||||||
|
setLocalSettings,
|
||||||
setSelectCardIndex,
|
setSelectCardIndex,
|
||||||
setTilt,
|
setTilt,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -10,7 +10,9 @@ import CopyButton from '@/components/CopyButton';
|
|||||||
import GitHubButton from '@/components/GitHubButton';
|
import GitHubButton from '@/components/GitHubButton';
|
||||||
import Scrim from '@/components/Scrim';
|
import Scrim from '@/components/Scrim';
|
||||||
import Switch from '@/components/Switch';
|
import Switch from '@/components/Switch';
|
||||||
import { CardStyle } from '@/types';
|
|
||||||
|
import { LOCAL_SETTINGS, SPECTATOR_SETTINGS } from '@/constants';
|
||||||
|
import type { CardStyle, LocalSettings } from '@/types';
|
||||||
|
|
||||||
const cinzel = Cinzel_Decorative({
|
const cinzel = Cinzel_Decorative({
|
||||||
variable: '--font-cinzel',
|
variable: '--font-cinzel',
|
||||||
@@ -22,12 +24,12 @@ const cardStyleOptions: CardStyle[] = ['standard', 'color', 'grayscale'];
|
|||||||
|
|
||||||
export default function Settings() {
|
export default function Settings() {
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
const { gameData, emitSettings } = useAppContext();
|
const { gameData, isDM, settings, emitSettings, setLocalSettings } = useAppContext();
|
||||||
|
|
||||||
const { dmID } = gameData;
|
const togglePermission = (key: keyof LocalSettings) => {
|
||||||
const isDM = !!dmID;
|
if (LOCAL_SETTINGS.includes(key)) {
|
||||||
|
setLocalSettings((prev) => ({ ...prev, [key]: !prev[key] }));
|
||||||
const togglePermission = (key: string) => {
|
} else if (isDM) {
|
||||||
emitSettings({
|
emitSettings({
|
||||||
...gameData,
|
...gameData,
|
||||||
settings: {
|
settings: {
|
||||||
@@ -35,6 +37,7 @@ export default function Settings() {
|
|||||||
[key]: !gameData.settings[key],
|
[key]: !gameData.settings[key],
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const tuneRadio = (cardStyle: CardStyle) => {
|
const tuneRadio = (cardStyle: CardStyle) => {
|
||||||
@@ -47,14 +50,25 @@ export default function Settings() {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const Icon = () => (
|
||||||
|
<button
|
||||||
|
className={`p-2 transition-all duration-250 text-yellow-400 hover:text-yellow-300 hover:drop-shadow-[0_0_3px_#ffd700] cursor-pointer ${open ? 'pointer-events-none opacity-0' : 'pointer-events-auto opacity-100'}`}
|
||||||
|
onClick={() => setOpen((prev) => !prev)}
|
||||||
|
>
|
||||||
|
<Gear className="w-5 h-5" />
|
||||||
|
</button>
|
||||||
|
);
|
||||||
|
|
||||||
const Links = () => (
|
const Links = () => (
|
||||||
<>
|
<>
|
||||||
|
{isDM && (
|
||||||
<CopyButton
|
<CopyButton
|
||||||
title="Copy DM link"
|
title="Copy DM link"
|
||||||
copy={`${location.origin}/${gameData.dmID}`}
|
copy={`${location.origin}/${gameData.dmID}`}
|
||||||
tooltip={`${location.origin}/${gameData.dmID}`}
|
tooltip={`${location.origin}/${gameData.dmID}`}
|
||||||
className="flex flex-row content-between w-full py-1 px-2 transition-all duration-250 bg-slate-700 hover:bg-slate-600 hover:text-yellow-300 rounded-lg shadow"
|
className="flex flex-row content-between w-full py-1 px-2 transition-all duration-250 bg-slate-700 hover:bg-slate-600 hover:text-yellow-300 rounded-lg shadow"
|
||||||
/>
|
/>
|
||||||
|
)}
|
||||||
<CopyButton
|
<CopyButton
|
||||||
title="Copy Spectator link"
|
title="Copy Spectator link"
|
||||||
copy={`${location.origin}/${gameData.spectatorID}`}
|
copy={`${location.origin}/${gameData.spectatorID}`}
|
||||||
@@ -66,15 +80,17 @@ export default function Settings() {
|
|||||||
|
|
||||||
const Permissions = () => (
|
const Permissions = () => (
|
||||||
<>
|
<>
|
||||||
{Object.entries(gameData.settings)
|
{Object.entries(settings)
|
||||||
.filter(([_key, value]) => typeof value === 'boolean')
|
.filter(([_key, value]) => typeof value === 'boolean')
|
||||||
|
.filter(([key]) => isDM || SPECTATOR_SETTINGS.includes(key))
|
||||||
.map(([key, value]) => (
|
.map(([key, value]) => (
|
||||||
<Switch key={key} label={key} value={value} toggleAction={() => togglePermission(key)} />
|
<Switch key={key} label={key} value={value} toggleAction={() => togglePermission(key)} />
|
||||||
))}
|
))}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|
||||||
const CardStyle = () => (
|
const CardStyle = () =>
|
||||||
|
isDM ? (
|
||||||
<fieldset className="flex flex-col w-full">
|
<fieldset className="flex flex-col w-full">
|
||||||
<div className="text-xs my-1">Card style:</div>
|
<div className="text-xs my-1">Card style:</div>
|
||||||
<div className="inline-flex overflow-hidden rounded-md w-full">
|
<div className="inline-flex overflow-hidden rounded-md w-full">
|
||||||
@@ -82,7 +98,7 @@ export default function Settings() {
|
|||||||
<label
|
<label
|
||||||
key={option}
|
key={option}
|
||||||
className={`flex justify-center items-center cursor-pointer w-full px-4 py-2 text-sm font-medium transition
|
className={`flex justify-center items-center cursor-pointer w-full px-4 py-2 text-sm font-medium transition
|
||||||
${gameData.settings.cardStyle === option ? 'bg-slate-700 text-yellow-300 font-extrabold' : 'bg-slate-800 hover:bg-slate-700'}
|
${settings.cardStyle === option ? 'bg-slate-700 text-yellow-300 font-extrabold' : 'bg-slate-800 hover:bg-slate-700'}
|
||||||
${index === 0 ? 'rounded-l-md' : ''}
|
${index === 0 ? 'rounded-l-md' : ''}
|
||||||
${index === cardStyleOptions.length - 1 ? 'rounded-r-md' : ''}
|
${index === cardStyleOptions.length - 1 ? 'rounded-r-md' : ''}
|
||||||
${index !== 0 && 'border-l border-gray-600'}
|
${index !== 0 && 'border-l border-gray-600'}
|
||||||
@@ -93,7 +109,7 @@ export default function Settings() {
|
|||||||
type="radio"
|
type="radio"
|
||||||
name="cardStyle"
|
name="cardStyle"
|
||||||
value={option}
|
value={option}
|
||||||
checked={gameData.settings.cardStyle === option}
|
checked={settings.cardStyle === option}
|
||||||
onChange={() => tuneRadio(option)}
|
onChange={() => tuneRadio(option)}
|
||||||
className="sr-only"
|
className="sr-only"
|
||||||
/>
|
/>
|
||||||
@@ -102,9 +118,9 @@ export default function Settings() {
|
|||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
);
|
) : null;
|
||||||
|
|
||||||
return isDM ? (
|
return (
|
||||||
<div className={`fixed top-4 right-4 z-25 ${cinzel.className}`}>
|
<div className={`fixed top-4 right-4 z-25 ${cinzel.className}`}>
|
||||||
<Scrim
|
<Scrim
|
||||||
clickAction={() => setOpen((prev) => !prev)}
|
clickAction={() => setOpen((prev) => !prev)}
|
||||||
@@ -122,12 +138,7 @@ export default function Settings() {
|
|||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</Scrim>
|
</Scrim>
|
||||||
<button
|
<Icon />
|
||||||
className={`p-2 transition-all duration-250 text-yellow-400 hover:text-yellow-300 hover:drop-shadow-[0_0_3px_#ffd700] cursor-pointer ${open ? 'pointer-events-none opacity-0' : 'pointer-events-auto opacity-100'}`}
|
|
||||||
onClick={() => setOpen((prev) => !prev)}
|
|
||||||
>
|
|
||||||
<Gear className="w-5 h-5" />
|
|
||||||
</button>
|
|
||||||
</div>
|
</div>
|
||||||
) : null;
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,12 +12,17 @@ export default function TiltCard({
|
|||||||
className?: string;
|
className?: string;
|
||||||
}) {
|
}) {
|
||||||
const cardRef = useRef<HTMLDivElement>(null);
|
const cardRef = useRef<HTMLDivElement>(null);
|
||||||
const { gameData, setTilt } = useAppContext();
|
const {
|
||||||
|
gameData,
|
||||||
|
settings: { tilt },
|
||||||
|
setTilt,
|
||||||
|
} = useAppContext();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const card = cardRef.current;
|
const card = cardRef.current;
|
||||||
if (!card) return;
|
if (!card) return;
|
||||||
|
|
||||||
|
if (tilt) {
|
||||||
const tilt = gameData.tilts[cardIndex];
|
const tilt = gameData.tilts[cardIndex];
|
||||||
if (!tilt) {
|
if (!tilt) {
|
||||||
card.style.transform = `rotateX(0deg) rotateY(0deg)`;
|
card.style.transform = `rotateX(0deg) rotateY(0deg)`;
|
||||||
@@ -42,7 +47,10 @@ export default function TiltCard({
|
|||||||
} else {
|
} else {
|
||||||
card.style.transform = `rotateX(0deg) rotateY(0deg)`;
|
card.style.transform = `rotateX(0deg) rotateY(0deg)`;
|
||||||
}
|
}
|
||||||
}, [gameData]);
|
} else if (card.style.transform !== 'rotateX(0deg) rotateY(0deg)') {
|
||||||
|
card.style.transform = 'rotateX(0deg) rotateY(0deg)';
|
||||||
|
}
|
||||||
|
}, [tilt, gameData]);
|
||||||
|
|
||||||
const handleMouseMove = (e: React.MouseEvent) => {
|
const handleMouseMove = (e: React.MouseEvent) => {
|
||||||
const card = cardRef.current;
|
const card = cardRef.current;
|
||||||
@@ -68,7 +76,11 @@ export default function TiltCard({
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={`${className}`} onMouseMove={handleMouseMove} onMouseLeave={handleMouseLeave}>
|
<div
|
||||||
|
className={`${className}`}
|
||||||
|
onMouseMove={tilt ? handleMouseMove : undefined}
|
||||||
|
onMouseLeave={handleMouseLeave}
|
||||||
|
>
|
||||||
<div ref={cardRef} className={`h-full w-full transition-transform duration-0`}>
|
<div ref={cardRef} className={`h-full w-full transition-transform duration-0`}>
|
||||||
{children}
|
{children}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
33
constants/index.ts
Normal file
33
constants/index.ts
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
export * from '@/constants/standardCards';
|
||||||
|
export * from '@/constants/tarokka';
|
||||||
|
export * from '@/constants/tarokkaCards';
|
||||||
|
export * from '@/constants/time';
|
||||||
|
|
||||||
|
import type { GameUpdate, LocalSettings, Settings } from '@/types';
|
||||||
|
|
||||||
|
export const SETTINGS: Settings = {
|
||||||
|
cardStyle: 'color',
|
||||||
|
notes: false,
|
||||||
|
positionBack: false,
|
||||||
|
positionFront: false,
|
||||||
|
prophecy: false,
|
||||||
|
tilt: true,
|
||||||
|
remoteTilt: false,
|
||||||
|
};
|
||||||
|
|
||||||
|
export const GAME_START: GameUpdate = {
|
||||||
|
dmID: '',
|
||||||
|
spectatorID: '',
|
||||||
|
cards: [],
|
||||||
|
settings: SETTINGS,
|
||||||
|
tilts: Array.from({ length: 5 }, () => []),
|
||||||
|
};
|
||||||
|
|
||||||
|
export const LOCAL_DEFAULTS: LocalSettings = {
|
||||||
|
tilt: true,
|
||||||
|
remoteTilt: true,
|
||||||
|
};
|
||||||
|
|
||||||
|
export const LOCAL_SETTINGS = ['tilt', 'remoteTilt'];
|
||||||
|
|
||||||
|
export const SPECTATOR_SETTINGS = ['tilt', 'remoteTilt'];
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
import Deck from '@/lib/TarokkaDeck';
|
import Deck from '@/lib/TarokkaDeck';
|
||||||
import generateID from '@/tools/simpleID';
|
import generateID from '@/tools/simpleID';
|
||||||
import parseMilliseconds from '@/tools/parseMilliseconds';
|
import parseMilliseconds from '@/tools/parseMilliseconds';
|
||||||
import { HOUR, DAY } from '@/constants/time';
|
|
||||||
|
import { HOUR, DAY, SETTINGS } from '@/constants';
|
||||||
import { GameState, GameUpdate, Settings, Tilt } from '@/types';
|
import { GameState, GameUpdate, Settings, Tilt } from '@/types';
|
||||||
|
|
||||||
const deck = new Deck();
|
const deck = new Deck();
|
||||||
@@ -84,13 +85,7 @@ export default class GameStore {
|
|||||||
players: new Set(),
|
players: new Set(),
|
||||||
cards: deck.getHand(),
|
cards: deck.getHand(),
|
||||||
lastUpdated: Date.now(),
|
lastUpdated: Date.now(),
|
||||||
settings: {
|
settings: SETTINGS,
|
||||||
positionBack: true,
|
|
||||||
positionFront: true,
|
|
||||||
prophecy: true,
|
|
||||||
notes: true,
|
|
||||||
cardStyle: 'color',
|
|
||||||
},
|
|
||||||
tilts: Array.from({ length: 5 }, () => []),
|
tilts: Array.from({ length: 5 }, () => []),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -4,11 +4,18 @@ export type CardStyle = 'standard' | 'color' | 'grayscale';
|
|||||||
export type Deck = 'high' | 'common' | 'both' | 'back' | 'all';
|
export type Deck = 'high' | 'common' | 'both' | 'back' | 'all';
|
||||||
|
|
||||||
export interface Settings {
|
export interface Settings {
|
||||||
|
cardStyle: CardStyle;
|
||||||
|
notes: boolean;
|
||||||
positionBack: boolean;
|
positionBack: boolean;
|
||||||
positionFront: boolean;
|
positionFront: boolean;
|
||||||
prophecy: boolean;
|
prophecy: boolean;
|
||||||
notes: boolean;
|
tilt: boolean;
|
||||||
cardStyle: CardStyle;
|
remoteTilt: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface LocalSettings {
|
||||||
|
tilt: boolean;
|
||||||
|
remoteTilt: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface StandardCard {
|
export interface StandardCard {
|
||||||
|
|||||||
Reference in New Issue
Block a user