File size: 5,434 Bytes
00373d6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e49fcf4
5ed1690
e49fcf4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5ed1690
f0da953
e49fcf4
 
 
f0da953
 
 
e49fcf4
54740d5
e49fcf4
 
 
 
 
 
5ed1690
e49fcf4
 
 
 
 
 
 
 
 
 
 
f0da953
 
 
 
 
 
e49fcf4
5ed1690
f0da953
 
 
 
 
9942bf5
e49fcf4
 
f0da953
e49fcf4
 
 
9942bf5
5ed1690
 
f0da953
5ed1690
 
 
 
 
f0da953
5ed1690
 
 
 
 
 
 
 
e49fcf4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5ed1690
e49fcf4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
// /$$$$$$  /$$$$$$ /$$    /$$ /$$$$$$$$       /$$      /$$ /$$$$$$$$        /$$$$$$           /$$$$$  /$$$$$$  /$$$$$$$ 
// /$$__  $$|_  $$_/| $$   | $$| $$_____/      | $$$    /$$$| $$_____/       /$$__  $$         |__  $$ /$$__  $$| $$__  $$
// | $$  \__/  | $$  | $$   | $$| $$            | $$$$  /$$$$| $$            | $$  \ $$            | $$| $$  \ $$| $$  \ $$
// | $$ /$$$$  | $$  |  $$ / $$/| $$$$$         | $$ $$/$$ $$| $$$$$         | $$$$$$$$            | $$| $$  | $$| $$$$$$$ 
// | $$|_  $$  | $$   \  $$ $$/ | $$__/         | $$  $$$| $$| $$__/         | $$__  $$       /$$  | $$| $$  | $$| $$__  $$
// | $$  \ $$  | $$    \  $$$/  | $$            | $$\  $ | $$| $$            | $$  | $$      | $$  | $$| $$  | $$| $$  \ $$
// |  $$$$$$/ /$$$$$$   \  $/   | $$$$$$$$      | $$ \/  | $$| $$$$$$$$      | $$  | $$      |  $$$$$$/|  $$$$$$/| $$$$$$$/
// \______/ |______/    \_/    |________/      |__/     |__/|________/      |__/  |__/       \______/  \______/ |_______/ 
//
// Hi, I'm Roland and i'm looking for a job.
// Resume in /public/resume.pdf
// [email protected]
// https://www.linkedin.com/in/roland-vrignon/
//


'use client';
import { FC, useEffect, useState, useRef } from 'react';
import Image from 'next/image';

interface CourtSceneProps {
  setNextScene: () => void;
  currentQuestion: string;
  reaction: string;
  round: number;
}

const CourtScene: FC<CourtSceneProps> = ({
  setNextScene,
  currentQuestion,
  reaction,
  round
}) => {
  const [showFirstImage, setShowFirstImage] = useState(true);
  const audioRef = useRef<HTMLAudioElement | null>(null);
  const isPlayingRef = useRef<boolean>(false);

  useEffect(() => {
    const playAudio = async () => {
      // Si déjà en train de jouer, on ne fait rien
      if (isPlayingRef.current || !currentQuestion) return;
      
      try {
        isPlayingRef.current = true;        
        const response = await fetch('/api/voice', {
          method: 'POST',
          headers: {
            'Content-Type': 'application/json',
          },
          body: JSON.stringify({
            language: 'en',
            text: reaction !== '' ? reaction + currentQuestion : currentQuestion,
            role: 'judge'
          })
        });

        if (!response.ok) {
          throw new Error('Failed to generate audio');
        }

        const audioBlob = await response.blob();
        const audioUrl = URL.createObjectURL(audioBlob);

        if (audioRef.current) {
          audioRef.current.pause();
          audioRef.current = null;
        }
        
        const audio = new Audio(audioUrl);
        audioRef.current = audio;
        
        audio.addEventListener('ended', () => {
          isPlayingRef.current = false;
        });

        await audio.play();
      } catch (error) {
        console.error('Error playing audio:', error);
        isPlayingRef.current = false;
      }
    };

    playAudio();

    return () => {
      isPlayingRef.current = false;
      if (audioRef.current) {
        audioRef.current.pause();
        audioRef.current = null;
      }
    };
  }, [currentQuestion, reaction]);

  const handleNextScene = () => {
    if (audioRef.current) {
      audioRef.current.pause();
      audioRef.current = null;
    }
    setNextScene();
  };

  useEffect(() => {
    const timer = setTimeout(() => {
      setShowFirstImage(false);
    }, 2000);

    return () => clearTimeout(timer);
  }, []);

  return (
    <div className="relative w-screen h-screen">
      {/* Image de fond statique */}
      <Image
        src="https://ik.imagekit.io/z0tzxea0wgx/MistralGameJam/DD_judge2_FoYazvSFmu.png?updatedAt=1737835883172"
        alt="Background"
        fill
        className="object-cover"
        priority
      />

      {/* Image superposée avec transition */}
      <div className={`absolute inset-0 transition-opacity duration-500 ${showFirstImage ? 'opacity-100' : 'opacity-0'}`}>
        <Image
          src="https://ik.imagekit.io/z0tzxea0wgx/MistralGameJam/DD_judge1_Bn04jNl_E.png?updatedAt=1737835883169"
          alt="Overlay"
          fill
          className="object-cover"
          priority
        />
      </div>

      {/* Rectangle noir en bas */}
      <div className="absolute bottom-0 left-1/2 transform -translate-x-1/2 w-[80%] bg-black/60 border border-black border-8 mb-[8vh] p-6">
        <div className="text-white roboto-slab">
          <p className="text-4xl mb-4">
            {reaction !== '' && round !== 1 ? reaction.replace(/\?/g, '') : ''} <br />
            {currentQuestion ? currentQuestion : '...'}
          </p>

          {/* Flèche à droite */}
          <div className="flex justify-end">
            <button
              onClick={handleNextScene}
              className="text-white hover:text-blue-400 transition-colors"
              aria-label="Continuer"
            >
              <svg
                xmlns="http://www.w3.org/2000/svg"
                className="h-12 w-12"
                fill="none"
                viewBox="0 0 24 24"
                stroke="currentColor"
              >
                <path
                  strokeLinecap="round"
                  strokeLinejoin="round"
                  strokeWidth={2}
                  d="M14 5l7 7m0 0l-7 7m7-7H3"
                />
              </svg>
            </button>
          </div>
        </div>
      </div>
    </div>
  );
};

export default CourtScene;