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