mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-18 15:36:02 +01:00
feat(web): skillcheck minigame
This commit is contained in:
93
web/src/features/skillcheck/index.tsx
Normal file
93
web/src/features/skillcheck/index.tsx
Normal file
@@ -0,0 +1,93 @@
|
||||
import { Box, Center } from '@chakra-ui/react';
|
||||
import { useEffect, useMemo, useState } from 'react';
|
||||
import { useNuiEvent } from '../../hooks/useNuiEvent';
|
||||
import { debugData } from '../../utils/debugData';
|
||||
import Indicator from './indicator';
|
||||
|
||||
export interface SkillCheckProps {
|
||||
visible: boolean;
|
||||
angle: number;
|
||||
difficultyOffset: number;
|
||||
difficulty: 'easy' | 'medium' | 'hard';
|
||||
}
|
||||
|
||||
const getRandomAngle = (min: number, max: number) => Math.floor(Math.random() * (max - min)) + min;
|
||||
|
||||
const difficultyOffsets = {
|
||||
easy: 275,
|
||||
medium: 290,
|
||||
hard: 300,
|
||||
};
|
||||
|
||||
debugData([
|
||||
{
|
||||
action: 'startSkillCheck',
|
||||
data: 'easy',
|
||||
},
|
||||
]);
|
||||
|
||||
const SkillCheck: React.FC = () => {
|
||||
const [skillCheck, setSkillCheck] = useState<SkillCheckProps>({
|
||||
visible: false,
|
||||
angle: 0,
|
||||
difficultyOffset: 315,
|
||||
difficulty: 'easy',
|
||||
});
|
||||
|
||||
useNuiEvent('startSkillCheck', (data: 'easy' | 'medium' | 'hard') => {
|
||||
setSkillCheck({
|
||||
visible: true,
|
||||
angle: -90 + getRandomAngle(0, 360),
|
||||
difficultyOffset: difficultyOffsets[data],
|
||||
difficulty: data,
|
||||
});
|
||||
});
|
||||
|
||||
return (
|
||||
<Center height="100%" width="100%">
|
||||
{skillCheck.visible && (
|
||||
<>
|
||||
<svg width={500} height={500}>
|
||||
{/*Circle track*/}
|
||||
<circle r={50} cx={250} cy={250} fill="transparent" stroke="#a3a8a5" strokeDasharray={360} />
|
||||
{/*SkillCheck area*/}
|
||||
<circle
|
||||
r={50}
|
||||
cx={250}
|
||||
cy={250}
|
||||
fill="transparent"
|
||||
stroke="white"
|
||||
strokeDasharray={315}
|
||||
strokeDashoffset={skillCheck.difficultyOffset}
|
||||
strokeWidth={5}
|
||||
transform={`rotate(${skillCheck.angle}, 250, 250)`}
|
||||
/>
|
||||
<Indicator
|
||||
angle={skillCheck.angle}
|
||||
offset={skillCheck.difficultyOffset}
|
||||
multiplier={skillCheck.difficulty === 'easy' ? 1 : skillCheck.difficulty === 'medium' ? 1.5 : 2}
|
||||
setSkillCheck={setSkillCheck}
|
||||
/>
|
||||
</svg>
|
||||
<Box
|
||||
position="absolute"
|
||||
left="50%"
|
||||
top="50%"
|
||||
transform="translate(-50%, -50%)"
|
||||
backgroundColor="rgba(0, 0, 0, 0.4)"
|
||||
w={25}
|
||||
h={25}
|
||||
textAlign="center"
|
||||
borderRadius={5}
|
||||
fontFamily="Inter"
|
||||
fontSize={16}
|
||||
>
|
||||
E
|
||||
</Box>
|
||||
</>
|
||||
)}
|
||||
</Center>
|
||||
);
|
||||
};
|
||||
|
||||
export default SkillCheck;
|
||||
Reference in New Issue
Block a user