* 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);
+ }
+}