PixelBullet  0.0.1
A C++ game engine
Loading...
Searching...
No Matches
audio_serialization.h
1#pragma once
2
3#include "pixelbullet/audio/audio_load_mode.h"
4#include "pixelbullet/serialization/node.h"
5#include "pixelbullet/serialization/node_reader.h"
6
7#include <string>
8
9namespace pixelbullet
10{
11inline Node& operator<<(Node& node, const AudioLoadMode& value)
12{
13 switch (value)
14 {
15 case AudioLoadMode::Auto:
16 node << "Auto";
17 break;
18 case AudioLoadMode::Stream:
19 node << "Stream";
20 break;
21 case AudioLoadMode::Decode:
22 node << "Decode";
23 break;
24 }
25 return node;
26}
27
28inline const Node& operator>>(const Node& node, AudioLoadMode& value)
29{
30 std::string serialized;
31 node >> serialized;
32 if (serialized == "Stream")
33 {
34 value = AudioLoadMode::Stream;
35 }
36 else if (serialized == "Decode")
37 {
38 value = AudioLoadMode::Decode;
39 }
40 else
41 {
42 value = AudioLoadMode::Auto;
43 }
44 return node;
45}
46
47[[nodiscard]] inline bool TryReadNode(const Node& node, AudioLoadMode& value, serialization::NodeReader& reader)
48{
49 std::string serialized;
50 if (!serialization::TryReadNode(node, serialized, reader))
51 {
52 return false;
53 }
54
55 if (serialized == "Stream")
56 {
57 value = AudioLoadMode::Stream;
58 }
59 else if (serialized == "Decode")
60 {
61 value = AudioLoadMode::Decode;
62 }
63 else
64 {
65 value = AudioLoadMode::Auto;
66 }
67 return true;
68}
69} // namespace pixelbullet
Represents a hierarchical node capable of storing various data types and supporting YAML serializatio...
Definition node.h:49
Definition node_reader.h:48