From: Ben Beltran Date: Mon, 28 Mar 2016 05:25:01 +0000 (-0600) Subject: Adapts libraries to style guide X-Git-Tag: 1.0.0^2~4 X-Git-Url: https://git.r.bdr.sh/rbdr/serpentity/commitdiff_plain/6e4e4188e5e067aad7d228443d5bb512527c99b0?hp=--cc Adapts libraries to style guide --- 6e4e4188e5e067aad7d228443d5bb512527c99b0 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; }