Spaces:
Sleeping
Sleeping
File size: 2,211 Bytes
6bb08c4 ba7c9fe 6bb08c4 6371c28 6bb08c4 ba7c9fe 6bb08c4 970c966 6bb08c4 f9cbedb 6371c28 6bb08c4 ba7c9fe 6bb08c4 970c966 f9cbedb 6bb08c4 ba7c9fe 6bb08c4 6371c28 6bb08c4 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
'use client';
import { PresetsType } from '@react-three/drei/helpers/environment-assets';
import { RefObject, createContext, useContext, useState } from 'react';
import { RubiksCubeRef } from '@/components/rubiks-cube';
type ControlContextType = {
showRotationIndicators: boolean;
setShowRotationIndicators: (showRotationIndicators: boolean) => void;
cubeRoughness: number;
setCubeRoughness: (cubeRoughness: number) => void;
cubeSpeed: number;
setCubeSpeed: (cubeSpeed: number) => void;
scrambleLength: number;
setScrambleLength: (scrambleLength: number) => void;
background: PresetsType;
setBackground: (background: PresetsType) => void;
rubiksCubeRef?: RefObject<RubiksCubeRef | null>;
setRubiksCubeRef: (rubiksCubeRef: RefObject<RubiksCubeRef | null>) => void;
};
export const ControlContext = createContext<ControlContextType>({
showRotationIndicators: false,
setShowRotationIndicators: () => {},
cubeRoughness: 0.5,
setCubeRoughness: () => {},
cubeSpeed: 8,
setCubeSpeed: () => {},
scrambleLength: 6,
setScrambleLength: () => {},
background: 'sunset',
setBackground: () => {},
rubiksCubeRef: undefined,
setRubiksCubeRef: () => {},
});
export const useControlContext = () => {
return useContext(ControlContext);
};
export const ControlProvider = ({ children }: { children: React.ReactNode }) => {
const [showRotationIndicators, setShowRotationIndicators] = useState(false);
const [cubeRoughness, setCubeRoughness] = useState(0.5);
const [cubeSpeed, setCubeSpeed] = useState(8);
const [scrambleLength, setScrambleLength] = useState(6);
const [background, setBackground] = useState<PresetsType>('sunset');
const [rubiksCubeRef, setRubiksCubeRef] = useState<RefObject<RubiksCubeRef | null> | undefined>(undefined);
return (
<ControlContext.Provider
value={{
showRotationIndicators,
setShowRotationIndicators,
cubeRoughness,
setCubeRoughness,
cubeSpeed,
setCubeSpeed,
scrambleLength,
setScrambleLength,
background,
setBackground,
rubiksCubeRef,
setRubiksCubeRef,
}}
>
{children}
</ControlContext.Provider>
);
};
|