PixelBullet  0.0.1
A C++ game engine
Loading...
Searching...
No Matches
combatant_vitality_component.h
1#pragma once
2
3#include "pixelbullet/serialization/node.h"
4
5#include <algorithm>
6
7namespace pixelbullet
8{
10{
11 bool enabled = true;
12 int max_health = 3;
13 float recent_damage_reaction_seconds = 0.3f;
14
15 [[nodiscard]] bool operator==(const CombatantVitalityComponent&) const noexcept = default;
16};
17
18inline Node& operator<<(Node& node, const CombatantVitalityComponent& component)
19{
20 node["enabled"] << component.enabled;
21 node["maxHealth"] << component.max_health;
22 node["recentDamageReactionSeconds"] << component.recent_damage_reaction_seconds;
23 return node;
24}
25
26inline const Node& operator>>(const Node& node, CombatantVitalityComponent& component)
27{
28 if (node.HasProperty("enabled"))
29 {
30 node["enabled"] >> component.enabled;
31 }
32 else
33 {
34 component.enabled = true;
35 }
36
37 if (node.HasProperty("maxHealth"))
38 {
39 node["maxHealth"] >> component.max_health;
40 }
41 else
42 {
43 component.max_health = 3;
44 }
45
46 if (node.HasProperty("recentDamageReactionSeconds"))
47 {
48 node["recentDamageReactionSeconds"] >> component.recent_damage_reaction_seconds;
49 }
50 else
51 {
52 component.recent_damage_reaction_seconds = 0.3f;
53 }
54
55 component.max_health = std::max(component.max_health, 1);
56 component.recent_damage_reaction_seconds = std::max(component.recent_damage_reaction_seconds, 0.0f);
57 return node;
58}
59} // namespace pixelbullet
Represents a hierarchical node capable of storing various data types and supporting YAML serializatio...
Definition node.h:45
Definition combatant_vitality_component.h:10