зеркало из
https://github.com/kodackx/disinformation-quest.git
synced 2025-10-29 12:46:03 +02:00
soundtrack trigger fix
Этот коммит содержится в:
родитель
70e47928ae
Коммит
81ba0e8385
@ -1,24 +1,21 @@
|
|||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
|
|
||||||
export const GameBackground = () => {
|
interface GameBackgroundProps {
|
||||||
|
shouldStartAudio?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const GameBackground = ({ shouldStartAudio = false }: GameBackgroundProps) => {
|
||||||
const [audioStarted, setAudioStarted] = useState(false);
|
const [audioStarted, setAudioStarted] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Only start audio after user interaction
|
if (shouldStartAudio && !audioStarted) {
|
||||||
const handleFirstInteraction = () => {
|
const audio = new Audio("/tension-background.mp3");
|
||||||
if (!audioStarted) {
|
audio.loop = true;
|
||||||
const audio = new Audio("/tension-background.mp3");
|
audio.volume = 0.3;
|
||||||
audio.loop = true;
|
audio.play().catch(console.error);
|
||||||
audio.volume = 0.3;
|
setAudioStarted(true);
|
||||||
audio.play().catch(console.error);
|
}
|
||||||
setAudioStarted(true);
|
}, [shouldStartAudio, audioStarted]);
|
||||||
document.removeEventListener("click", handleFirstInteraction);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
document.addEventListener("click", handleFirstInteraction);
|
|
||||||
return () => document.removeEventListener("click", handleFirstInteraction);
|
|
||||||
}, [audioStarted]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="fixed inset-0 -z-10 overflow-hidden">
|
<div className="fixed inset-0 -z-10 overflow-hidden">
|
||||||
|
|||||||
@ -11,10 +11,19 @@ import { useState } from "react";
|
|||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { LanguageSwitcher } from "@/components/LanguageSwitcher";
|
import { LanguageSwitcher } from "@/components/LanguageSwitcher";
|
||||||
|
|
||||||
export const IntroDialog = () => {
|
interface IntroDialogProps {
|
||||||
|
onStartAudio?: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const IntroDialog = ({ onStartAudio }: IntroDialogProps) => {
|
||||||
const [open, setOpen] = useState(true);
|
const [open, setOpen] = useState(true);
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
const handleBeginSimulation = () => {
|
||||||
|
setOpen(false);
|
||||||
|
onStartAudio?.();
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog open={open} onOpenChange={setOpen}>
|
<Dialog open={open} onOpenChange={setOpen}>
|
||||||
<DialogContent className="bg-black/90 text-white border-gray-700 max-w-2xl max-h-[90vh] overflow-y-auto">
|
<DialogContent className="bg-black/90 text-white border-gray-700 max-w-2xl max-h-[90vh] overflow-y-auto">
|
||||||
@ -57,7 +66,7 @@ export const IntroDialog = () => {
|
|||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<Button
|
<Button
|
||||||
onClick={() => setOpen(false)}
|
onClick={handleBeginSimulation}
|
||||||
className="bg-yellow-500 hover:bg-yellow-600 text-black font-semibold sm:w-auto"
|
className="bg-yellow-500 hover:bg-yellow-600 text-black font-semibold sm:w-auto"
|
||||||
>
|
>
|
||||||
{t('buttons.beginSimulation')}
|
{t('buttons.beginSimulation')}
|
||||||
|
|||||||
@ -63,6 +63,7 @@ const Index = () => {
|
|||||||
const [playerChoices, setPlayerChoices] = useState<string[]>([]);
|
const [playerChoices, setPlayerChoices] = useState<string[]>([]);
|
||||||
const [gameKey, setGameKey] = useState(0);
|
const [gameKey, setGameKey] = useState(0);
|
||||||
const loadingMessages = useLoadingMessages();
|
const loadingMessages = useLoadingMessages();
|
||||||
|
const [shouldStartAudio, setShouldStartAudio] = useState(false);
|
||||||
|
|
||||||
const handleStartGame = () => {
|
const handleStartGame = () => {
|
||||||
playAcceptMissionSound();
|
playAcceptMissionSound();
|
||||||
@ -197,7 +198,7 @@ const Index = () => {
|
|||||||
if (showingInitialTransition) {
|
if (showingInitialTransition) {
|
||||||
return (
|
return (
|
||||||
<div className="relative min-h-screen overflow-hidden">
|
<div className="relative min-h-screen overflow-hidden">
|
||||||
<GameBackground />
|
<GameBackground shouldStartAudio={shouldStartAudio} />
|
||||||
<div className="relative min-h-screen bg-transparent p-4 flex items-center justify-center">
|
<div className="relative min-h-screen bg-transparent p-4 flex items-center justify-center">
|
||||||
<div className="max-w-4xl mx-auto w-full relative">
|
<div className="max-w-4xl mx-auto w-full relative">
|
||||||
<MonthTransition
|
<MonthTransition
|
||||||
@ -212,9 +213,9 @@ const Index = () => {
|
|||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<div className="relative min-h-screen overflow-hidden">
|
<div className="relative min-h-screen overflow-hidden">
|
||||||
<GameBackground />
|
<GameBackground shouldStartAudio={shouldStartAudio} />
|
||||||
<div className="relative min-h-screen bg-transparent flex items-center justify-center p-4">
|
<div className="relative min-h-screen bg-transparent flex items-center justify-center p-4">
|
||||||
{showIntroDialog && <IntroDialog />}
|
{showIntroDialog && <IntroDialog onStartAudio={() => setShouldStartAudio(true)} />}
|
||||||
<Card className="w-full md:max-w-2xl bg-black/50 text-white border-gray-700 transition-all duration-1000 animate-fade-in backdrop-blur-sm">
|
<Card className="w-full md:max-w-2xl bg-black/50 text-white border-gray-700 transition-all duration-1000 animate-fade-in backdrop-blur-sm">
|
||||||
<CardHeader className="text-center space-y-4 p-4 md:p-6">
|
<CardHeader className="text-center space-y-4 p-4 md:p-6">
|
||||||
<div className="flex justify-between items-center px-4">
|
<div className="flex justify-between items-center px-4">
|
||||||
@ -311,7 +312,7 @@ const Index = () => {
|
|||||||
if (!currentStageData) {
|
if (!currentStageData) {
|
||||||
return (
|
return (
|
||||||
<div className="relative min-h-screen overflow-hidden">
|
<div className="relative min-h-screen overflow-hidden">
|
||||||
<GameBackground />
|
<GameBackground shouldStartAudio={shouldStartAudio} />
|
||||||
<div className="relative min-h-screen bg-transparent p-4">
|
<div className="relative min-h-screen bg-transparent p-4">
|
||||||
<Card className="w-full max-w-4xl mx-auto bg-black/50 text-white border-gray-700 transition-all duration-1000 animate-fade-in">
|
<Card className="w-full max-w-4xl mx-auto bg-black/50 text-white border-gray-700 transition-all duration-1000 animate-fade-in">
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
@ -344,7 +345,7 @@ const Index = () => {
|
|||||||
if (showingResult && currentResult) {
|
if (showingResult && currentResult) {
|
||||||
return (
|
return (
|
||||||
<div className="relative min-h-screen overflow-hidden">
|
<div className="relative min-h-screen overflow-hidden">
|
||||||
<GameBackground />
|
<GameBackground shouldStartAudio={shouldStartAudio} />
|
||||||
<div className="relative min-h-screen bg-transparent p-4 flex items-center justify-center">
|
<div className="relative min-h-screen bg-transparent p-4 flex items-center justify-center">
|
||||||
<Card className="w-full md:max-w-2xl bg-black/50 text-white border-gray-700 transition-all duration-1000 animate-fade-in">
|
<Card className="w-full md:max-w-2xl bg-black/50 text-white border-gray-700 transition-all duration-1000 animate-fade-in">
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
@ -395,7 +396,7 @@ const Index = () => {
|
|||||||
if (showingMonthTransition && nextStage !== null && stages[nextStage]) {
|
if (showingMonthTransition && nextStage !== null && stages[nextStage]) {
|
||||||
return (
|
return (
|
||||||
<div className="relative min-h-screen overflow-hidden">
|
<div className="relative min-h-screen overflow-hidden">
|
||||||
<GameBackground />
|
<GameBackground shouldStartAudio={shouldStartAudio} />
|
||||||
<div className="relative min-h-screen bg-transparent p-4 flex items-center justify-center">
|
<div className="relative min-h-screen bg-transparent p-4 flex items-center justify-center">
|
||||||
<MonthTransition
|
<MonthTransition
|
||||||
monthIndex={stages[nextStage]?.monthIndex ?? nextStage + 1}
|
monthIndex={stages[nextStage]?.monthIndex ?? nextStage + 1}
|
||||||
@ -409,7 +410,7 @@ const Index = () => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="relative min-h-screen overflow-hidden">
|
<div className="relative min-h-screen overflow-hidden">
|
||||||
<GameBackground />
|
<GameBackground shouldStartAudio={shouldStartAudio} />
|
||||||
<div className="relative min-h-screen bg-transparent md:p-4 flex flex-col">
|
<div className="relative min-h-screen bg-transparent md:p-4 flex flex-col">
|
||||||
<div className="flex-grow flex items-center">
|
<div className="flex-grow flex items-center">
|
||||||
<div className="w-full h-full md:max-w-4xl mx-auto md:px-4">
|
<div className="w-full h-full md:max-w-4xl mx-auto md:px-4">
|
||||||
|
|||||||
Загрузка…
x
Ссылка в новой задаче
Block a user