PixelBullet  0.0.1
A C++ game engine
Loading...
Searching...
No Matches
ranged_hitscan_attack_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 float attack_range = 8.0f;
13 float cooldown_seconds = 0.75f;
14 int damage_amount = 1;
15
16 [[nodiscard]] bool operator==(const RangedHitscanAttackComponent&) const noexcept = default;
17};
18
19inline Node& operator<<(Node& node, const RangedHitscanAttackComponent& component)
20{
21 node["enabled"] << component.enabled;
22 node["attackRange"] << component.attack_range;
23 node["cooldownSeconds"] << component.cooldown_seconds;
24 node["damageAmount"] << component.damage_amount;
25 return node;
26}
27
28inline const Node& operator>>(const Node& node, RangedHitscanAttackComponent& component)
29{
30 if (node.HasProperty("enabled"))
31 {
32 node["enabled"] >> component.enabled;
33 }
34 else
35 {
36 component.enabled = true;
37 }
38
39 if (node.HasProperty("attackRange"))
40 {
41 node["attackRange"] >> component.attack_range;
42 }
43 else
44 {
45 component.attack_range = 8.0f;
46 }
47
48 if (node.HasProperty("cooldownSeconds"))
49 {
50 node["cooldownSeconds"] >> component.cooldown_seconds;
51 }
52 else
53 {
54 component.cooldown_seconds = 0.75f;
55 }
56
57 if (node.HasProperty("damageAmount"))
58 {
59 node["damageAmount"] >> component.damage_amount;
60 }
61 else
62 {
63 component.damage_amount = 1;
64 }
65
66 component.attack_range = std::max(component.attack_range, 0.0001f);
67 component.cooldown_seconds = std::max(component.cooldown_seconds, 0.0001f);
68 component.damage_amount = std::max(component.damage_amount, 1);
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 ranged_hitscan_attack_component.h:10