PixelBullet  0.0.1
A C++ game engine
Loading...
Searching...
No Matches
goal_volume_component.h
1#pragma once
2
3#include "pixelbullet/filesystem/virtual_path_serialization.h"
4#include "pixelbullet/serialization/node.h"
5
6#include <string>
7#include <vector>
8
9namespace pixelbullet
10{
12{
13 bool enabled = true;
14 int required_key_count = 0;
15 std::vector<std::string> required_key_ids;
16 VirtualPath next_scene;
17
18 [[nodiscard]] bool operator==(const GoalVolumeComponent& other) const noexcept
19 {
20 return enabled == other.enabled && required_key_count == other.required_key_count &&
21 required_key_ids == other.required_key_ids &&
22 next_scene.LogicalPath() == other.next_scene.LogicalPath();
23 }
24};
25
26inline Node& operator<<(Node& node, const GoalVolumeComponent& component)
27{
28 node["enabled"] << component.enabled;
29 if (component.required_key_count > 0)
30 {
31 node["requiredKeyCount"] << component.required_key_count;
32 }
33 if (!component.required_key_ids.empty())
34 {
35 node["requiredKeyIds"] << component.required_key_ids;
36 }
37 if (!component.next_scene.Empty())
38 {
39 node["nextScene"] << component.next_scene;
40 }
41 return node;
42}
43
44inline const Node& operator>>(const Node& node, GoalVolumeComponent& component)
45{
46 if (node.HasProperty("enabled"))
47 {
48 node["enabled"] >> component.enabled;
49 }
50 else
51 {
52 component.enabled = true;
53 }
54
55 if (node.HasProperty("requiredKeyCount"))
56 {
57 node["requiredKeyCount"] >> component.required_key_count;
58 }
59 else
60 {
61 component.required_key_count = 0;
62 }
63
64 if (node.HasProperty("requiredKeyIds"))
65 {
66 node["requiredKeyIds"] >> component.required_key_ids;
67 }
68 else
69 {
70 component.required_key_ids.clear();
71 }
72
73 if (node.HasProperty("nextScene"))
74 {
75 node["nextScene"] >> component.next_scene;
76 }
77 else
78 {
79 component.next_scene = VirtualPath{};
80 }
81
82 return node;
83}
84} // namespace pixelbullet
Represents a hierarchical node capable of storing various data types and supporting YAML serializatio...
Definition node.h:45
Definition virtual_path.h:10
Definition goal_volume_component.h:12