added animation toggle

This commit is contained in:
MasterGordon 2024-10-27 19:13:41 +01:00
parent 195ac8039a
commit 6bd39ccd2d
3 changed files with 17 additions and 1 deletions

View File

@ -3,6 +3,7 @@ import { z } from "zod";
export const userSettings = z.object({ export const userSettings = z.object({
placeQuestionMark: z.boolean().default(false), placeQuestionMark: z.boolean().default(false),
longPressOnDesktop: z.boolean().default(false), longPressOnDesktop: z.boolean().default(false),
showRevealAnimation: z.boolean().default(true),
}); });
export type UserSettings = z.infer<typeof userSettings>; export type UserSettings = z.infer<typeof userSettings>;

View File

@ -44,6 +44,7 @@ import "@pixi/canvas-text";
import { themes } from "../themes"; import { themes } from "../themes";
import { weightedPickRandom } from "../../shared/utils"; import { weightedPickRandom } from "../../shared/utils";
import gen from "random-seed"; import gen from "random-seed";
import type { UserSettings } from "../../shared/user-settings";
interface BoardProps { interface BoardProps {
className?: string; className?: string;
@ -74,6 +75,7 @@ const toViewportInfo = (viewport: PixiViewport) => {
const Board: React.FC<BoardProps> = (props) => { const Board: React.FC<BoardProps> = (props) => {
const { game, restartGame } = props; const { game, restartGame } = props;
const { data: user } = useWSQuery("user.getSelf", null); const { data: user } = useWSQuery("user.getSelf", null);
const { data: settings } = useWSQuery("user.getSettings", null);
const ref = useRef<HTMLDivElement>(null); const ref = useRef<HTMLDivElement>(null);
const [width, setWidth] = useState(0); const [width, setWidth] = useState(0);
const [height, setHeight] = useState(0); const [height, setHeight] = useState(0);
@ -246,6 +248,7 @@ const Board: React.FC<BoardProps> = (props) => {
showLastPos={showLastPos} showLastPos={showLastPos}
onLeftClick={props.onLeftClick} onLeftClick={props.onLeftClick}
onRightClick={props.onRightClick} onRightClick={props.onRightClick}
userSettings={settings}
/> />
); );
}); });
@ -267,6 +270,7 @@ interface TileProps {
showLastPos: boolean; showLastPos: boolean;
onLeftClick: (x: number, y: number) => void; onLeftClick: (x: number, y: number) => void;
onRightClick: (x: number, y: number) => void; onRightClick: (x: number, y: number) => void;
userSettings?: UserSettings | undefined;
} }
const Tile = ({ const Tile = ({
@ -277,6 +281,7 @@ const Tile = ({
showLastPos, showLastPos,
onRightClick, onRightClick,
onLeftClick, onLeftClick,
userSettings,
}: TileProps) => { }: TileProps) => {
const resolveSprite = useCallback( const resolveSprite = useCallback(
(lt: LoadedTexture) => { (lt: LoadedTexture) => {
@ -322,12 +327,13 @@ const Tile = ({
const [doTick, setDoTick] = useState(true); const [doTick, setDoTick] = useState(true);
const frame = useRef<number>(0); const frame = useRef<number>(0);
useEffect(() => { useEffect(() => {
if (userSettings?.showRevealAnimation === false) return;
if (oldState.current !== `${isRevealed},${isMine},${value}`) { if (oldState.current !== `${isRevealed},${isMine},${value}`) {
oldState.current = `${isRevealed},${isMine},${value}`; oldState.current = `${isRevealed},${isMine},${value}`;
frame.current = 0; frame.current = 0;
setDoTick(true); setDoTick(true);
} }
}, [isMine, isRevealed, value]); }, [isMine, isRevealed, userSettings?.showRevealAnimation, value]);
useTick((delta) => { useTick((delta) => {
frame.current += delta * 0.1; frame.current += delta * 0.1;
if (frame.current > 3) { if (frame.current > 3) {

View File

@ -62,6 +62,15 @@ const Settings = () => {
refetch(); refetch();
}} }}
/> />
<BoolSetting
label="Show Reveal Animation"
description={<>Show an animation when a tile is revealed.</>}
value={settings?.showRevealAnimation ?? true}
onChange={async (value) => {
updateSettings.mutateAsync({ showRevealAnimation: value });
refetch();
}}
/>
</div> </div>
</div> </div>
</div> </div>