]>
Commit | Line | Data |
---|---|---|
85861d67 BB |
1 | /* |
2 | * A node describes a set of components in order to describe entities | |
3 | * that include them. | |
4 | */ | |
19e91cdd | 5 | export class Node { |
85861d67 | 6 | |
d0eb71f3 BB |
7 | /* |
8 | * Returns true if the given entity matches the defined protocol, | |
9 | * false otherwise | |
10 | */ | |
b3b840f8 RBR |
11 | static matches(entity) { |
12 | ||
13 | const typeNames = Object.keys(this.types); | |
85861d67 | 14 | |
b3b840f8 | 15 | for (const typeName of typeNames) { |
85861d67 | 16 | |
b3b840f8 RBR |
17 | const type = this.types[typeName]; |
18 | let matched = false; | |
85861d67 | 19 | |
b3b840f8 RBR |
20 | if (entity.hasComponent(type)) { |
21 | matched = true; | |
22 | } | |
6e4e4188 | 23 | |
b3b840f8 RBR |
24 | if (!matched) { |
25 | return false; | |
d0eb71f3 BB |
26 | } |
27 | } | |
85861d67 | 28 | |
d0eb71f3 BB |
29 | return true; |
30 | } | |
85861d67 | 31 | |
b3b840f8 RBR |
32 | constructor(config) { |
33 | ||
d0eb71f3 | 34 | this.types = {}; |
85861d67 | 35 | |
b3b840f8 | 36 | Object.assign(this, config); |
d0eb71f3 | 37 | } |
19e91cdd | 38 | } |