diff options
| author | Ben Beltran <ben@nsovocal.com> | 2016-03-27 23:25:01 -0600 |
|---|---|---|
| committer | Ben Beltran <ben@nsovocal.com> | 2016-03-27 23:25:01 -0600 |
| commit | 6e4e4188e5e067aad7d228443d5bb512527c99b0 (patch) | |
| tree | fdd7440d72320ac2b3fd065c56f47bd39d514611 /lib | |
| parent | f77c12fd8d3f6c35ea61413d0544a0cd7030c849 (diff) | |
Adapts libraries to style guide
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/serpentity.js | 2 | ||||
| -rw-r--r-- | lib/serpentity/entity.js | 3 | ||||
| -rw-r--r-- | lib/serpentity/node.js | 13 | ||||
| -rw-r--r-- | lib/serpentity/node_collection.js | 20 |
4 files changed, 16 insertions, 22 deletions
diff --git a/lib/serpentity.js b/lib/serpentity.js index c5ccc97..1360f92 100644 --- a/lib/serpentity.js +++ b/lib/serpentity.js @@ -243,6 +243,4 @@ if (typeof module !== 'undefined' && this.module !== module) { Serpentity.System = require('./serpentity/system.js'); module.exports = Serpentity; -} else { - window.Serpentity = Serpentity; } diff --git a/lib/serpentity/entity.js b/lib/serpentity/entity.js index 2895158..add823e 100644 --- a/lib/serpentity/entity.js +++ b/lib/serpentity/entity.js @@ -43,8 +43,7 @@ let Entity = class Entity { * 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]; } diff --git a/lib/serpentity/node.js b/lib/serpentity/node.js index db33f17..fa0af75 100644 --- a/lib/serpentity/node.js +++ b/lib/serpentity/node.js @@ -13,19 +13,18 @@ let Node = class Node { * 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; } diff --git a/lib/serpentity/node_collection.js b/lib/serpentity/node_collection.js index f5b1794..7c51991 100644 --- a/lib/serpentity/node_collection.js +++ b/lib/serpentity/node_collection.js @@ -28,15 +28,15 @@ let NodeCollection = class NodeCollection { 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]); } } @@ -54,9 +54,8 @@ let NodeCollection = class NodeCollection { * 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; @@ -75,10 +74,9 @@ let NodeCollection = class NodeCollection { * 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; } |