RType
SoundComponent.cpp
Go to the documentation of this file.
1 /*
2 ** EPITECH PROJECT, 2023
3 ** R-type
4 ** File description:
5 ** R-type
6 */
7 
9 
10 /**
11  * @brief Construct a new Sound Component:: Sound Component object
12  *
13  * @param core
14  * @param socket
15  */
16 SoundComponent::SoundComponent(ClientCore *core, std::shared_ptr<ClientSocket> socket) :
17  AComponent(core)
18 {
19  _type = ComponentType::SOUND;
20  if (!_buffer.loadFromFile("../src/client/assets/sounds/click.wav"))
21  throw std::runtime_error("Cannot load click.wav");
22  _sound.setBuffer(_buffer);
23  _socket = std::move(socket);
24 }
25 
26 void SoundComponent::display(sf::RenderWindow &window)
27 {
28 }
29 
30 /**
31  * @brief action, play the sound
32  */
34 {
35  _sound.play();
36 }
37 
38 void SoundComponent::handleEvent(const sf::Event &event, sf::RenderWindow &window)
39 {
40 }
41 
42 /**
43  * @brief setSound, set the sound
44  * @param path the path of the sound
45  */
46 void SoundComponent::setSound(const std::string &path)
47 {
48  if (!_buffer.loadFromFile(path))
49  throw std::runtime_error("Cannot load " + path);
50  _sound.setBuffer(_buffer);
51 }
52 
53 /**
54  * @brief stop, stop the sound
55  */
57 {
58  _sound.stop();
59 }