]> git.r.bdr.sh - rbdr/serpentity/blobdiff - lib/serpentity/node.js
Trim gitignore
[rbdr/serpentity] / lib / serpentity / node.js
index 00abde2b34c6d31efd1d2d99d50aa55100b1fa41..629e4ed8761adffc50e8a5776e370c358b9c2d0e 100644 (file)
@@ -2,49 +2,37 @@
  * A node describes a set of components in order to describe entities
  * that include them.
  */
-Class(Serpentity, "Node")({
+export class Node {
 
-    /*
-     * Returns true if the given entity matches the defined protocol,
-     * false otherwise
-     */
-    matches : function matches(entity) {
-            var property, matched, types;
+  /*
+   * Returns true if the given entity matches the defined protocol,
+   * false otherwise
+   */
+  static matches(entity) {
 
-            types = this.types;
+    const typeNames = Object.keys(this.types);
 
-            for (property in this.types) {
+    for (const typeName of typeNames) {
 
-                if (this.types.hasOwnProperty(property)) {
-                    matched = false;
+      const type = this.types[typeName];
+      let matched = false;
 
-                    if (entity.hasComponent(types[property])) {
-                        matched = true;
-                    }
+      if (entity.hasComponent(type)) {
+        matched = true;
+      }
 
-                    if (!matched) {
-                        return false;
-                    }
-                }
-            }
-
-            return true;
-    },
-
-    prototype : {
+      if (!matched) {
+        return false;
+      }
+    }
 
-        types : null,
+    return true;
+  }
 
-        init : function (config) {
-            var property;
+  constructor(config) {
 
-            this.types = {};
+    this.types = {};
 
-            for (property in this.constructor) {
-                if (this.constructor.hasOwnProperty(property)) {
-                    this.types[property] = this.constructor[property];
-                }
-            }
-        }
-    }
-});
+    Object.assign(this, config);
+  }
+}