vectozavr-shooter/engine/io/SoundController.h

56 lines
1.3 KiB
C
Raw Normal View History

2021-10-17 19:38:16 +03:00
//
// Created by Иван Ильин on 17.10.2021.
//
#ifndef SHOOTER_SOUNDCONTROLLER_H
#define SHOOTER_SOUNDCONTROLLER_H
#include <string>
#include <map>
2021-10-31 11:39:08 +03:00
2021-10-17 19:38:16 +03:00
#include <SFML/Audio.hpp>
class SoundTag final {
private:
const std::string _name;
public:
explicit SoundTag(std::string name = "") : _name(std::move(name)) {}
2021-10-31 11:39:08 +03:00
2021-10-17 19:38:16 +03:00
[[nodiscard]] std::string str() const { return _name; }
2021-10-31 11:39:08 +03:00
bool operator==(const SoundTag &tag) const { return _name == tag._name; }
bool operator!=(const SoundTag &tag) const { return _name != tag._name; }
bool operator<(const SoundTag &tag) const { return _name < tag._name; }
2021-10-17 19:38:16 +03:00
};
class SoundController final {
private:
std::map<SoundTag, sf::Sound> _sounds;
2021-10-31 11:39:08 +03:00
static SoundController *_instance;
2021-10-17 19:38:16 +03:00
SoundController() = default;
2021-10-31 11:39:08 +03:00
2021-10-17 19:38:16 +03:00
public:
2021-10-31 11:39:08 +03:00
SoundController(const SoundController &) = delete;
2021-10-17 19:38:16 +03:00
2021-10-31 11:39:08 +03:00
SoundController &operator=(SoundController &) = delete;
2022-02-23 17:29:42 +03:00
static void loadAndPlay(const SoundTag &soundTag, const std::string& filename);
2021-10-31 11:39:08 +03:00
2022-02-23 17:29:42 +03:00
static void playSound(const SoundTag &soundTag);
2021-10-31 11:39:08 +03:00
static void pauseSound(const SoundTag &soundTag);
static void stopSound(const SoundTag &soundTag);
static sf::Sound::Status getStatus(const SoundTag &soundTag);
2021-10-17 19:38:16 +03:00
static void init();
2021-10-31 11:39:08 +03:00
2021-10-17 19:38:16 +03:00
static void free();
};
#endif //SHOOTER_SOUNDCONTROLLER_H