* returns the component associated with that key
*/
getComponent (componentClass) {
- let position;
- position = this._componentKeys.indexOf(componentClass);
+ let position = this._componentKeys.indexOf(componentClass);
if (position >= 0) {
return this._components[position];
}
* false otherwise
*/
static matches (entity) {
- let property, types;
+ let types = this.types;
- types = this.types;
+ for (let typeName in types) {
+ if (types.hasOwnProperty(typeName)) {
- for (property in types) {
- if (types.hasOwnProperty(property)) {
- let matched, type;
+ let matched = false;
+ let type = types[typeName];
- matched = false;
- type = types[property];
if (entity.hasComponent(type)) {
matched = true;
}
+
if (!matched) {
return false;
}
add (entity) {
if (this.type.matches(entity) && !this._entityExists(entity)) {
- let node, types, property;
- node = new this.type({});
+ let node = new this.type({});
+ let types = this.type.types;
+
node.entity = entity;
- types = this.type.types;
- for (property in types) {
- if (types.hasOwnProperty(property)) {
- node[property] = entity.getComponent(types[property]);
+ for (let typeName in types) {
+ if (types.hasOwnProperty(typeName)) {
+ node[typeName] = entity.getComponent(types[typeName]);
}
}
* returns true if it was removed, false otherwise.
*/
remove (entity) {
- let found;
+ let found = -1;
- found = -1;
this.nodes.forEach(function (node, i) {
if (node.entity === entity) {
found = i;
* Checks whether we already have nodes for this entity.
*/
_entityExists (entity) {
- let found, node;
+ let found = false;
- found = false;
- for (node of this.nodes) {
+ for (let node of this.nodes) {
if (node.entity === entity) {
found = true;
}