PixelBullet  0.0.1
A C++ game engine
Loading...
Searching...
No Matches
audio_source_component.h
1#pragma once
2
3#include "pixelbullet/audio/audio_load_mode.h"
4#include "pixelbullet/audio/audio_serialization.h"
5#include "pixelbullet/audio/audio_spatial_settings.h"
6#include "pixelbullet/filesystem/virtual_path.h"
7#include "pixelbullet/filesystem/virtual_path_serialization.h"
8#include "pixelbullet/serialization/node.h"
9
10namespace pixelbullet
11{
13{
14 bool enabled = true;
15 VirtualPath clip;
16 bool autoplay = true;
17 bool loop = false;
18 float volume = 1.0f;
19 AudioSpatialSettings spatial_settings;
20 AudioLoadMode load_mode = AudioLoadMode::Auto;
21
22 bool operator==(const AudioSourceComponent& other) const noexcept
23 {
24 return enabled == other.enabled && clip.logical_path() == other.clip.logical_path() && autoplay == other.autoplay &&
25 loop == other.loop && volume == other.volume && spatial_settings == other.spatial_settings && load_mode == other.load_mode;
26 }
27};
28
29inline Node& operator<<(Node& node, const AudioSourceComponent& component)
30{
31 node["enabled"] << component.enabled;
32 node["clip"] << component.clip;
33 node["autoplay"] << component.autoplay;
34 node["loop"] << component.loop;
35 node["volume"] << component.volume;
36 node["spatial"] << component.spatial_settings.enabled;
37 node["minDistance"] << component.spatial_settings.min_distance;
38 node["maxDistance"] << component.spatial_settings.max_distance;
39 node["loadMode"] << component.load_mode;
40 return node;
41}
42
43inline const Node& operator>>(const Node& node, AudioSourceComponent& component)
44{
45 if (node.has_property("enabled"))
46 {
47 node["enabled"] >> component.enabled;
48 }
49 if (node.has_property("clip"))
50 {
51 node["clip"] >> component.clip;
52 }
53 if (node.has_property("autoplay"))
54 {
55 node["autoplay"] >> component.autoplay;
56 }
57 if (node.has_property("loop"))
58 {
59 node["loop"] >> component.loop;
60 }
61 if (node.has_property("volume"))
62 {
63 node["volume"] >> component.volume;
64 }
65 if (node.has_property("spatial"))
66 {
67 node["spatial"] >> component.spatial_settings.enabled;
68 }
69 if (node.has_property("minDistance"))
70 {
71 node["minDistance"] >> component.spatial_settings.min_distance;
72 }
73 if (node.has_property("maxDistance"))
74 {
75 node["maxDistance"] >> component.spatial_settings.max_distance;
76 }
77 if (node.has_property("loadMode"))
78 {
79 node["loadMode"] >> component.load_mode;
80 }
81 return node;
82}
83} // namespace pixelbullet
Represents a hierarchical node capable of storing various data types and supporting YAML serializatio...
Definition node.h:49
Definition virtual_path.h:10
Definition audio_source_component.h:13
Definition audio_spatial_settings.h:6