vectozavr-shooter/engine/SoundController.h

47 lines
1.2 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>
#include <SFML/Audio.hpp>
class SoundTag final {
private:
const std::string _name;
public:
explicit SoundTag(std::string name = "") : _name(std::move(name)) {}
[[nodiscard]] std::string str() const { return _name; }
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; }
};
class SoundController final {
private:
std::map<SoundTag, sf::Sound> _sounds;
static SoundController* _instance;
2021-10-29 23:44:37 +03:00
static bool _validInstance;
2021-10-17 19:38:16 +03:00
SoundController() = default;
public:
SoundController(const SoundController&) = delete;
SoundController& operator=(SoundController&) = delete;
static void playSound(const SoundTag& soundTag, const std::string& filename);
static void pauseSound(const SoundTag& soundTag);
static void stopSound(const SoundTag& soundTag);
static sf::Sound::Status getStatus(const SoundTag& soundTag);
static void init();
static void free();
};
#endif //SHOOTER_SOUNDCONTROLLER_H