]> git.r.bdr.sh - rbdr/serpentity/blob - lib/serpentity/node.js
00abde2b34c6d31efd1d2d99d50aa55100b1fa41
[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 Class(Serpentity, "Node")({
6
7 /*
8 * Returns true if the given entity matches the defined protocol,
9 * false otherwise
10 */
11 matches : function matches(entity) {
12 var property, matched, types;
13
14 types = this.types;
15
16 for (property in this.types) {
17
18 if (this.types.hasOwnProperty(property)) {
19 matched = false;
20
21 if (entity.hasComponent(types[property])) {
22 matched = true;
23 }
24
25 if (!matched) {
26 return false;
27 }
28 }
29 }
30
31 return true;
32 },
33
34 prototype : {
35
36 types : null,
37
38 init : function (config) {
39 var property;
40
41 this.types = {};
42
43 for (property in this.constructor) {
44 if (this.constructor.hasOwnProperty(property)) {
45 this.types[property] = this.constructor[property];
46 }
47 }
48 }
49 }
50 });