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