1#include "scene/components/AudioComponent.h"
3#include "scene/GameObject.h"
9 if (json.contains(
"audio"))
11 auto &clipsObject = json[
"audio"];
12 for (
auto &clip : clipsObject)
14 std::string name = clip.value(
"name",
"noname");
15 std::string path = clip.value(
"path",
"");
19 float volume = clip.value(
"volume", 1.0f);
20 audio->SetVolume(volume);
30 for (
auto &clip : m_clips)
32 if (clip.second->IsPlaying())
34 clip.second->SetPosition(pos);
46 auto it = m_clips.find(name);
47 if (it != m_clips.end())
51 it->second->Play(loop);
58 auto it = m_clips.find(name);
59 if (it != m_clips.end())
70 auto it = m_clips.find(name);
71 if (it != m_clips.end())
75 return it->second->IsPlaying();
void RegisterAudio(const std::string &name, std::shared_ptr< Audio > &clip)
Add a clip under name; later calls reference it by that key.
void LoadProperties(const nlohmann::json &json) override
Read clips and properties from a serialised scene JSON entry.
bool IsPlaying(const std::string &name)
True iff the named clip is currently playing.
void Play(const std::string &name, bool loop=false)
Start the named clip; loop true loops forever.
void Update(float deltaTime) override
Push the owner's world position to every registered clip.
void Stop(const std::string &name)
Stop the named clip if it is currently playing.
static std::shared_ptr< Audio > Load(const std::string &path)
Decode an audio file from disk and return a shared instance.
vec3 GetWorldPosition() const
Extract the world-space position from GetWorldTransform().