PixelBullet  0.0.1
A C++ game engine
Loading...
Searching...
No Matches
patrol_route_component.h
1#pragma once
2
3#include "pixelbullet/serialization/node.h"
4
5#include <string>
6#include <string_view>
7
8namespace pixelbullet
9{
10enum class PatrolTraversalMode
11{
12 Loop,
13 PingPong,
14 Once,
15};
16
17[[nodiscard]] constexpr std::string_view ToString(const PatrolTraversalMode value) noexcept
18{
19 switch (value)
20 {
21 case PatrolTraversalMode::PingPong:
22 return "PingPong";
23 case PatrolTraversalMode::Once:
24 return "Once";
25 case PatrolTraversalMode::Loop:
26 default:
27 return "Loop";
28 }
29}
30
31inline Node& operator<<(Node& node, const PatrolTraversalMode& value)
32{
33 node << std::string(ToString(value));
34 return node;
35}
36
37inline const Node& operator>>(const Node& node, PatrolTraversalMode& value)
38{
39 std::string serialized;
40 node >> serialized;
41 if (serialized == "PingPong")
42 {
43 value = PatrolTraversalMode::PingPong;
44 }
45 else if (serialized == "Once")
46 {
47 value = PatrolTraversalMode::Once;
48 }
49 else
50 {
51 value = PatrolTraversalMode::Loop;
52 }
53 return node;
54}
55
57{
58 bool enabled = true;
59 PatrolTraversalMode traversal_mode = PatrolTraversalMode::Loop;
60
61 [[nodiscard]] bool operator==(const PatrolRouteComponent&) const noexcept = default;
62};
63
64inline Node& operator<<(Node& node, const PatrolRouteComponent& component)
65{
66 node["enabled"] << component.enabled;
67 node["traversalMode"] << component.traversal_mode;
68 return node;
69}
70
71inline const Node& operator>>(const Node& node, PatrolRouteComponent& component)
72{
73 if (node.HasProperty("enabled"))
74 {
75 node["enabled"] >> component.enabled;
76 }
77 else
78 {
79 component.enabled = true;
80 }
81
82 if (node.HasProperty("traversalMode"))
83 {
84 node["traversalMode"] >> component.traversal_mode;
85 }
86 else
87 {
88 component.traversal_mode = PatrolTraversalMode::Loop;
89 }
90
91 return node;
92}
93} // namespace pixelbullet
Represents a hierarchical node capable of storing various data types and supporting YAML serializatio...
Definition node.h:45
Definition patrol_route_component.h:57