File size: 3,163 Bytes
babeaf6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
/**
 * src/components/Characters/index.jsx
 * create and display characters
 * 
 * created by Lynchee on 7/16/23
 */

// Characters
import React, { useEffect, useState } from 'react';
import './style.css';
import raiden from '../../assets/images/raiden.png';
import loki from '../../assets/svgs/loki.svg';
import aiHelper from '../../assets/images/ai_helper.png';
import pi from '../../assets/images/pi.jpeg';
import elon from '../../assets/images/elon.png';
import bruce from '../../assets/images/bruce.png';
import steve from '../../assets/images/jobs.png';
import realchar from '../../assets/svgs/realchar.svg';
import sam from '../../assets/images/sam.png';

// create character groups
const createCharacterGroups = (message) => {
    const options = message.split('\n').slice(1);

    const imageMap = {
        'Raiden Shogun And Ei': raiden,
        'Loki': loki,
        'Ai Character Helper': aiHelper,
        'Reflection Pi': pi,
        'Elon Musk': elon,
        'Bruce Wayne': bruce,
        'Steve Jobs': steve,
        'Sam Altman': sam
    };

    const newCharacterGroups = [];
    options.forEach(option => {
        const match = option.match(/^(\d+)\s-\s(.+)$/);
        if (match) {
            let src = imageMap[match[2]];
            if (!src) {
                src = {realchar};
            }
            
            newCharacterGroups.push({
            id: match[1],
            name: match[2],
            imageSrc: src
            });
        }
    });

    return newCharacterGroups;
}

const Characters = ({ characterGroups, selectedCharacter, setSelectedCharacter, isPlaying, characterConfirmed }) => {
    const [pulseAnimation, setPulseAnimation] = useState(null);

    // when the character is talking, show animation 
    useEffect(() => {
        if (isPlaying) {
            setPulseAnimation(Math.random() > 0.5 ? "pulse-animation-1" : "pulse-animation-2");
        } else {
            setPulseAnimation(null);
        }
    }, [isPlaying]);

    const handleCharacterSelection = (e) => {
        setSelectedCharacter(e.target.value);
    };

    return (
        <div className="main-container">
            <div className='radio-buttons'>
                {characterGroups.map(group => (
                    (!characterConfirmed || group.id === selectedCharacter) && (
                    <label key={group.id} className="custom-radio">
                        <input 
                            type='radio' 
                            name='radio' 
                            value={group.id} 
                            onChange={handleCharacterSelection}
                        />
                        <span className={`radio-btn ${group.id === selectedCharacter ? pulseAnimation : ''}`}>
                            <div className='hobbies-icon'>
                                <img src={group.imageSrc} alt={group.name}/>
                                <h4>{group.name}</h4>
                            </div>
                        </span>
                    </label>
                    )
                ))}
            </div>
        </div>
    )
}
  
export { Characters, createCharacterGroups };