]> git.r.bdr.sh - rbdr/serpentity/commitdiff
Fixes entity systems v0.1.4
authorBen Beltran <redacted>
Tue, 12 Aug 2014 18:17:33 +0000 (13:17 -0500)
committerBen Beltran <redacted>
Tue, 12 Aug 2014 18:17:33 +0000 (13:17 -0500)
bower.json
dist/serpentity.js
lib/serpentity/entity.js
lib/serpentity/node_collection.js
package.json

index a95b46f5c6f6b215ed075e5a1fc533bca6932f57..d387ed0f31e0aac3cf7e9e106a88a281c60e11e8 100644 (file)
@@ -1,6 +1,6 @@
 {
   "name": "serpentity",
-  "version": "0.1.3",
+  "version": "0.1.4",
   "homepage": "https://github.com/benbeltran/serpentity",
   "authors": [
     "Ben Beltran <ben@nsovocal.com>"
@@ -25,6 +25,8 @@
     "LICENSE",
     "bower.json",
     "README.md",
+    "gulpfile.js",
+    "package.json",
     "lib"
   ],
   "dependencies": {
index cfeb5c6e4adba69ece72d73a9608976264d72be6..22df2c79317214525b50d63d60c4eaf6f2f2f7ed 100644 (file)
@@ -1,6 +1,6 @@
 "undefined"!=typeof require&&require("neon"),Class("Serpentity")({prototype:{systems:null,nodeCollections:null,entities:null,init:function(e){var t;e=e||{},this.systems=[],this.entities=[],this.nodeCollections={};for(t in e)e.hasOwnProperty(t)&&(this[t]=e[t])},addSystem:function(e,t){var i,s;return this.systems.indexOf(e)>=0?!1:(e.priority=t,s=!1,i=0,this.systems.some(function(t,n){return i=n,t.priority>=e.priority?(s=!0,!0):void 0}),s||(i+=1),this.systems.splice(i,0,e),e.added(this),!0)},removeSystem:function(e){var t;return t=this.systems.indexOf(e),t>=0?(this.systems[t].removed(this),this.systems.splice(t,1),!0):!1},addEntity:function(e){var t;if(this.entities.indexOf(e)>=0)return!1;this.entities.push(e);for(t in this.nodeCollections)this.nodeCollections.hasOwnProperty(t)&&this.nodeCollections[t].add(e);return!0},removeEntity:function(e){var t;if(t=this.entities.indexOf(e),t>=0){for(property in this.nodeCollections)this.nodeCollections.hasOwnProperty(property)&&this.nodeCollections[property].remove(e);return this.entities.splice(t,1),!0}return!1},getNodes:function(e){var t;return this.nodeCollections.hasOwnProperty(e)?this.nodeCollections[e].nodes:(t=new Serpentity.NodeCollection({type:e}),this.nodeCollections[e]=t,this.entities.forEach(function(e){t.add(e)}),t.nodes)},update:function(e){this.systems.forEach(function(t){t.update(e)})}}}),"undefined"!=typeof require&&(require("./component.js"),require("./entity.js"),require("./node.js"),require("./node_collection.js"),require("./system.js"));
-Class(Serpentity,"Entity")({prototype:{addedComponents:null,init:function(n){var t;this.components={};for(t in n)n.hasOwnProperty(t)&&(this[t]=n[t])},add:function(n){return this.components.hasOwnProperty(n.constructor)?!1:(this.components[n.constructor]=n,!0)},hasComponent:function(n){return this.components.hasOwnProperty(n)?!0:!1}}});
+Class(Serpentity,"Entity")({prototype:{_components:null,_componentKeys:null,init:function(n){var t;this._componentKeys=[],this._components=[];for(t in n)n.hasOwnProperty(t)&&(this[t]=n[t])},add:function(n){return this._componentKeys.indexOf(n.constructor)>=0?!1:(this._componentKeys.push(n.constructor),this._components.push(n),!0)},hasComponent:function(n){return this._componentKeys.indexOf(n)>=0?!0:!1},getComponent:function(n){var t;return t=this._componentKeys.indexOf(n),t>=0?this._components[t]:void 0}}});
 Class(Serpentity,"Node")({matches:function(t){var s,r,n;n=this.types;for(s in this.types)if(this.types.hasOwnProperty(s)&&(r=!1,t.hasComponent(n[s])&&(r=!0),!r))return!1;return!0},prototype:{types:null,init:function(){var t;this.types={};for(t in this.constructor)this.constructor.hasOwnProperty(t)&&(this.types[t]=this.constructor[t])}}});
-Class(Serpentity,"NodeCollection")({prototype:{type:null,nodes:null,init:function(t){var n;t=t||{},this.nodes=[];for(n in t)t.hasOwnProperty(n)&&(this[n]=t[n])},add:function(t){var n,e,i;if(this.type.matches(t)&&!this._entityExists(t)){n=new this.type({}),n.entity=t,e=this.type.types;for(i in e)e.hasOwnProperty(i)&&(n[i]=t.components[e[i]]);return this.nodes.push(n),!0}return!1},remove:function(t){var n;return n=-1,this.nodes.forEach(function(e,i){e.entity===t&&(n=i)}),n>=0?(this.nodes.splice(n,1),!0):!1},_entityExists:function(t){var n;return n=!1,this.nodes.forEach(function(e){e.entity===t&&(n=!0)}),n}}});
+Class(Serpentity,"NodeCollection")({prototype:{type:null,nodes:null,init:function(t){var n;t=t||{},this.nodes=[];for(n in t)t.hasOwnProperty(n)&&(this[n]=t[n])},add:function(t){var n,e,i;if(this.type.matches(t)&&!this._entityExists(t)){n=new this.type({}),n.entity=t,e=this.type.types;for(i in e)e.hasOwnProperty(i)&&(n[i]=t.getComponent(e[i]));return this.nodes.push(n),!0}return!1},remove:function(t){var n;return n=-1,this.nodes.forEach(function(e,i){e.entity===t&&(n=i)}),n>=0?(this.nodes.splice(n,1),!0):!1},_entityExists:function(t){var n;return n=!1,this.nodes.forEach(function(e){e.entity===t&&(n=!0)}),n}}});
 Class(Serpentity,"Component")({});
 Class(Serpentity,"System")({prototype:{added:function(){},removed:function(){},update:function(){}}});
\ No newline at end of file
index cf2a623dd8bcb4844a182a2dc630249736339baf..d03f16baafcbdc1223dbf17db53b5bfe73033f8d 100644 (file)
@@ -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];
+            }
+         }
     }
 });
index 7bac90f5b82a463f59cb93bff73ead3cf71c1472..d1d25fc1fb33d8560dc5913dcde419405de75f3f 100644 (file)
@@ -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]);
                   }
                 }
 
index 5ab315744dd0345680ef93462fd8e7e54f7c72f7..d31805dc757c0a7f0a5725e02459ab2aa1356218 100644 (file)
@@ -1,7 +1,7 @@
 {
   "name": "serpentity",
   "description": "A simple entity framework inspired by ash",
-  "version": "0.1.3",
+  "version": "0.1.4",
   "contributors": [
     {
       "name": "Ben Beltran",