]> git.r.bdr.sh - rbdr/serpentity/blob - lib/serpentity/node.js
db33f171d677b5c5e439380809b555496dee7a3d
[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 property, types;
17
18 types = this.types;
19
20 for (property in types) {
21 if (types.hasOwnProperty(property)) {
22 let matched, type;
23
24 matched = false;
25 type = types[property];
26 if (entity.hasComponent(type)) {
27 matched = true;
28 }
29 if (!matched) {
30 return false;
31 }
32 }
33 }
34
35 return true;
36 }
37
38 constructor (config) {
39 this.types = {};
40
41 Object.assign(this, config || {});
42 }
43 };
44
45 if (typeof module !== 'undefined' && this.module !== module) {
46 module.exports = Node;
47 } else {
48 Serpentity.Node = Node;
49 }