-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgameplay_node.h
122 lines (96 loc) · 2.69 KB
/
gameplay_node.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#pragma once
#include "gameplay_api.h"
#include <core/os/thread.h>
#include <core/resource.h>
#include <core/vector.h>
#include <scene/main/node.h>
class GAMEPLAY_ABILITIES_API GameplayNode : public Node {
GDCLASS(GameplayNode, Node);
OBJ_CATEGORY("GameplayAbilities");
public:
virtual ~GameplayNode() = default;
template <class T>
T *find_child() const {
for (int i = 0, n = get_child_count(); i < n; i++) {
if (auto child = dynamic_cast<T *>(get_child(i))) {
return child;
}
}
return nullptr;
}
template <class T, class Predicate>
T *find_child(Predicate &&p) const {
for (int i = 0, n = get_child_count(); i < n; i++) {
if (auto child = dynamic_cast<T *>(get_child(i))) {
if (p(child)) {
return child;
}
}
}
return nullptr;
}
template <class T, class Predicate>
void for_each_child(Predicate &&p) const {
for (int i = 0, n = get_child_count(); i < n; i++) {
if (auto child = dynamic_cast<T *>(get_child(i))) {
p(child);
}
}
}
template <class T>
Vector<T *> find_all_children() const {
Vector<T *> result;
for (int i = 0, n = get_child_count(); i < n; i++) {
if (auto child = dynamic_cast<T *>(get_child(i))) {
result.push_back(child);
}
}
return result;
}
template <class T>
Vector<T *> find_all_children_multilevel() const {
Vector<T *> result;
Vector<Node *> nodes;
nodes.push_back(const_cast<GameplayNode *>(this));
for (int i = 0; i < nodes.size(); i++) {
auto node = nodes[i];
for (int j = 0, n = node->get_child_count(); j < n; i++) {
if (auto child = node->get_child(j)) {
nodes.push_back(child);
if (auto typed_node = dynamic_cast<T *>(child)) {
result.push_back(typed_node);
}
}
}
}
return result;
}
template <class... Args>
Variant execute(const StringName &method, Args &&... args) {
if (auto rpc_mode = get_node_rpc_mode(method)) {
if (rpc_mode->value() != MultiplayerAPI::RPC_MODE_DISABLED) {
return rpc(method, std::forward<Args>(args)...);
}
}
return call(method, std::forward<Args>(args)...);
}
Node *_bind_find_child(const String &class_name) const;
Array _bind_find_all_children(const String &class_name) const;
Array _bind_find_all_children_multilevel(const String &class_name) const;
Dictionary serialise() const;
void deserialise(const Dictionary &data);
private:
/** Bindings */
static void _bind_methods();
};
class GAMEPLAY_ABILITIES_API GameplayResource : public Resource {
GDCLASS(GameplayResource, Resource);
OBJ_CATEGORY("GameplayAbilities");
public:
virtual ~GameplayResource() = default;
Dictionary serialise() const;
void deserialise(const Dictionary &data);
private:
/** Bindings */
static void _bind_methods();
};