From 97b9f18f8239423accccebfbb071c535b945e098 Mon Sep 17 00:00:00 2001 From: Luke <39926192+LukeWasTakenn@users.noreply.github.com> Date: Fri, 22 Sep 2023 14:03:48 +0200 Subject: [PATCH] feat(web/skillcheck): fail skill check only on keys that aren't passed --- web/src/features/skillcheck/index.tsx | 10 ++++++---- web/src/features/skillcheck/indicator.tsx | 4 +++- web/src/typings/skillcheck.ts | 1 + 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/web/src/features/skillcheck/index.tsx b/web/src/features/skillcheck/index.tsx index 1452360..dac4d51 100644 --- a/web/src/features/skillcheck/index.tsx +++ b/web/src/features/skillcheck/index.tsx @@ -74,7 +74,8 @@ const SkillCheck: React.FC = () => { angle: -90 + getRandomAngle(120, 360 - offset), difficultyOffset: offset, difficulty: gameData, - key: randomKey, + keys: data.inputs?.map((input) => input.toLowerCase()), + key: randomKey.toLowerCase(), }); setVisible(true); @@ -103,12 +104,13 @@ const SkillCheck: React.FC = () => { ? dataRef.current.inputs[Math.floor(Math.random() * dataRef.current.inputs.length)] : 'e'; const offset = typeof data === 'object' ? data.areaSize : difficultyOffsets[data]; - setSkillCheck({ + setSkillCheck((prev) => ({ + ...prev, angle: -90 + getRandomAngle(120, 360 - offset), difficultyOffset: offset, difficulty: data, - key, - }); + key: key.toLowerCase(), + })); }; return ( diff --git a/web/src/features/skillcheck/indicator.tsx b/web/src/features/skillcheck/indicator.tsx index 674f644..2385736 100644 --- a/web/src/features/skillcheck/indicator.tsx +++ b/web/src/features/skillcheck/indicator.tsx @@ -46,11 +46,13 @@ const Indicator: React.FC = ({ angle, offset, multiplier, handleComplete, useEffect(() => { if (!keyPressed) return; + if (skillCheck.keys && !skillCheck.keys?.includes(keyPressed)) return; + interval.stop(); window.removeEventListener('keydown', keyHandler); - if (keyPressed !== skillCheck.key.toLowerCase() || indicatorAngle < angle || indicatorAngle > angle + offset) + if (keyPressed !== skillCheck.key || indicatorAngle < angle || indicatorAngle > angle + offset) handleComplete(false); else handleComplete(true); diff --git a/web/src/typings/skillcheck.ts b/web/src/typings/skillcheck.ts index 8b52ad2..372a4d8 100644 --- a/web/src/typings/skillcheck.ts +++ b/web/src/typings/skillcheck.ts @@ -9,5 +9,6 @@ export interface SkillCheckProps { angle: number; difficultyOffset: number; difficulty: GameDifficulty; + keys?: string[]; key: string; }