aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBen Beltran <ben@nsovocal.com>2014-08-12 13:17:33 -0500
committerBen Beltran <ben@nsovocal.com>2014-08-12 13:17:33 -0500
commit21653e1d2688779376b509e6c2e7086553d55010 (patch)
treee7e5647d071f2d6796355986058fd8eb1984cde4 /lib
parent22d974aba0ac1da648548265b453173319631a16 (diff)
Fixes entity systemsv0.1.4
Diffstat (limited to 'lib')
-rw-r--r--lib/serpentity/entity.js26
-rw-r--r--lib/serpentity/node_collection.js2
2 files changed, 21 insertions, 7 deletions
diff --git a/lib/serpentity/entity.js b/lib/serpentity/entity.js
index cf2a623..d03f16b 100644
--- a/lib/serpentity/entity.js
+++ b/lib/serpentity/entity.js
@@ -4,12 +4,14 @@
*/
Class(Serpentity, "Entity")({
prototype : {
- addedComponents : null,
+ _components : null,
+ _componentKeys : null,
init : function init(config) {
var property;
- this.components = {};
+ this._componentKeys = [];
+ this._components = [];
for (property in config) {
if (config.hasOwnProperty(property)) {
@@ -24,10 +26,11 @@ Class(Serpentity, "Entity")({
* returns true if added, false if already present
*/
add : function add(component) {
- if (this.components.hasOwnProperty(component.constructor)) {
+ if (this._componentKeys.indexOf(component.constructor) >= 0) {
return false;
}
- this.components[component.constructor] = component;
+ this._componentKeys.push(component.constructor);
+ this._components.push(component);
return true;
},
@@ -35,10 +38,21 @@ Class(Serpentity, "Entity")({
* returns true if component is included, false otherwise
*/
hasComponent : function hasComponent(componentClass) {
- if (this.components.hasOwnProperty(componentClass)) {
+ if (this._componentKeys.indexOf(componentClass) >= 0) {
return true;
}
return false;
- }
+ },
+
+ /*
+ * returns the component associated with that key
+ */
+ getComponent : function getComponent(componentClass) {
+ var position;
+ position = this._componentKeys.indexOf(componentClass);
+ if (position >= 0) {
+ return this._components[position];
+ }
+ }
}
});
diff --git a/lib/serpentity/node_collection.js b/lib/serpentity/node_collection.js
index 7bac90f..d1d25fc 100644
--- a/lib/serpentity/node_collection.js
+++ b/lib/serpentity/node_collection.js
@@ -42,7 +42,7 @@ Class(Serpentity, "NodeCollection")({
for (property in types) {
if (types.hasOwnProperty(property)) {
- node[property] = entity.components[types[property]]
+ node[property] = entity.getComponent(types[property]);
}
}