From 355a02ef50ed6af23f635ca724adef6972b586c0 Mon Sep 17 00:00:00 2001 From: Vladimir-Urik Date: Tue, 2 Apr 2024 16:27:11 +0200 Subject: [PATCH] Fix duplicate issue --- src/components/Game.tsx | 13 +++++++++++-- src/components/Guidelines.tsx | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/components/Game.tsx b/src/components/Game.tsx index e6c2a33..3cd28c4 100644 --- a/src/components/Game.tsx +++ b/src/components/Game.tsx @@ -24,7 +24,16 @@ export function Game({ setGradient }: GameProps) { truth = true ) => { const texts = data[category][truth ? 'truth' : 'dare'] - return texts[Math.floor(Math.random() * texts.length)] + if (texts.length === 1) { + return texts[0] + } + + const randomText = texts[Math.floor(Math.random() * texts.length)] + while (randomText === text) { + return texts[Math.floor(Math.random() * texts.length)] + } + + return randomText } const getRandomText = () => { @@ -44,7 +53,7 @@ export function Game({ setGradient }: GameProps) { audio.click.playbackRate = 1.5 audio.click.play() const truth = Math.random() < 0.3 - const group = Math.random() < 0.15 + const group = Math.random() < 0.1 setTruth(truth) if (group) { diff --git a/src/components/Guidelines.tsx b/src/components/Guidelines.tsx index dd52550..2bd6fc1 100644 --- a/src/components/Guidelines.tsx +++ b/src/components/Guidelines.tsx @@ -47,7 +47,7 @@ export const Guidelines = () => { Šance na úkol: 70%
  • - Šance na skupinový úkol: 15% + Šance na skupinový úkol: 10%