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