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;
}