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