PixelBullet  0.0.1
A C++ game engine
Loading...
Searching...
No Matches
behavior_state_machine_component.h
1#pragma once
2
3#include "pixelbullet/filesystem/virtual_path.h"
4#include "pixelbullet/filesystem/virtual_path_serialization.h"
5#include "pixelbullet/scene/behavior_state_machine_asset.h"
6
7namespace pixelbullet
8{
10{
11 bool enabled = true;
12 VirtualPath behavior_asset;
13 std::vector<BehaviorBinding> bindings;
14 std::vector<BehaviorStringParameterValue> string_parameter_overrides;
15
16 [[nodiscard]] bool operator==(const BehaviorStateMachineComponent& other) const noexcept
17 {
18 return enabled == other.enabled && behavior_asset.LogicalPath() == other.behavior_asset.LogicalPath() &&
19 bindings == other.bindings && string_parameter_overrides == other.string_parameter_overrides;
20 }
21};
22
23inline Node& operator<<(Node& node, const BehaviorStateMachineComponent& component)
24{
25 node["enabled"] << component.enabled;
26 node["behaviorAsset"] << component.behavior_asset;
27 node["bindings"] << component.bindings;
28 if (!component.string_parameter_overrides.empty())
29 {
30 node["stringParameterOverrides"] << component.string_parameter_overrides;
31 }
32 return node;
33}
34
35inline const Node& operator>>(const Node& node, BehaviorStateMachineComponent& component)
36{
37 if (node.HasProperty("enabled"))
38 {
39 node["enabled"] >> component.enabled;
40 }
41 else
42 {
43 component.enabled = true;
44 }
45
46 if (node.HasProperty("behaviorAsset"))
47 {
48 node["behaviorAsset"] >> component.behavior_asset;
49 }
50 else
51 {
52 component.behavior_asset = {};
53 }
54
55 if (node.HasProperty("bindings"))
56 {
57 node["bindings"] >> component.bindings;
58 }
59 else
60 {
61 component.bindings.clear();
62 }
63
64 if (node.HasProperty("stringParameterOverrides"))
65 {
66 node["stringParameterOverrides"] >> component.string_parameter_overrides;
67 }
68 else
69 {
70 component.string_parameter_overrides.clear();
71 }
72
73 NormalizeBehaviorBindings(component.bindings);
74 NormalizeBehaviorStringParameterOverrides(component.string_parameter_overrides);
75 return node;
76}
77} // 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 behavior_state_machine_component.h:10