From: Ben Beltran Date: Wed, 20 Aug 2014 14:27:23 +0000 (-0500) Subject: Normalizes API for entities X-Git-Tag: v0.1.7 X-Git-Url: https://git.r.bdr.sh/rbdr/serpentity/commitdiff_plain/77dc64fee29f530ecef0b09d2380729734cf62dd?ds=sidebyside Normalizes API for entities --- diff --git a/README.md b/README.md index 6703b5f..6724652 100644 --- a/README.md +++ b/README.md @@ -45,9 +45,9 @@ eventually be consumed by "Systems" } }); -You can add components to entities by using the add method: +You can add components to entities by using the addComponent method: - entity.add(new PositionComponent()); + entity.addComponent(new PositionComponent()); Systems can refer to entities by requesting nodes. diff --git a/bin/test b/bin/test index 222a653..e5218df 100755 --- a/bin/test +++ b/bin/test @@ -114,7 +114,7 @@ engine.update(10); console.log("\n## Adding system to the engine and updating".bold.black) var entity = new Serpentity.Entity(); -entity.add(new TestComponent()); +entity.addComponent(new TestComponent()); engine.addEntity(entity); engine.update(10); @@ -134,7 +134,7 @@ engine.update(10); console.log("\n## Adding a second entity".bold.black) var entity = new Serpentity.Entity(); -entity.add(new TestComponent()); +entity.addComponent(new TestComponent()); engine.addEntity(entity); engine.update(10); diff --git a/bower.json b/bower.json index 67ade91..bf0a06a 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "serpentity", - "version": "0.1.6", + "version": "0.1.7", "homepage": "https://github.com/benbeltran/serpentity", "authors": [ "Ben Beltran " diff --git a/browser_test/index.html b/browser_test/index.html index 82921b7..1183efc 100644 --- a/browser_test/index.html +++ b/browser_test/index.html @@ -116,7 +116,7 @@ console.log("\n## Adding system to the engine and updating") var entity = new Serpentity.Entity(); - entity.add(new TestComponent()); + entity.addComponent(new TestComponent()); engine.addEntity(entity); engine.update(10); @@ -136,7 +136,7 @@ console.log("\n## Adding a second entity") var entity = new Serpentity.Entity(); - entity.add(new TestComponent()); + entity.addComponent(new TestComponent()); engine.addEntity(entity); engine.update(10); diff --git a/dist/serpentity.js b/dist/serpentity.js index 3522b06..1f9b250 100644 --- a/dist/serpentity.js +++ b/dist/serpentity.js @@ -50,7 +50,7 @@ eventually be consumed by "Systems" You can add components to entities by using the add method: - entity.add(new PositionComponent()); + entity.addComponent(new PositionComponent()); Systems can refer to entities by requesting nodes. @@ -287,7 +287,7 @@ Class(Serpentity, "Entity")({ * * returns true if added, false if already present */ - add : function add(component) { + addComponent : function addComponent(component) { if (this._componentKeys.indexOf(component.constructor) >= 0) { return false; } diff --git a/dist/serpentity.min.js b/dist/serpentity.min.js index 12aa23f..84ef4f1 100644 --- a/dist/serpentity.min.js +++ b/dist/serpentity.min.js @@ -1,5 +1,5 @@ "undefined"!=typeof require&&require("neon"),Class("Serpentity")({prototype:{systems:null,entities:null,_nodeCollections:null,_nodeCollectionKeys:null,init:function(e){var t;e=e||{},this.systems=[],this.entities=[],this._nodeCollections=[],this._nodeCollectionKeys=[];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){return this.entities.indexOf(e)>=0?!1:(this.entities.push(e),this._nodeCollections.forEach(function(t){t.add(e)}),!0)},removeEntity:function(e){var t;return t=this.entities.indexOf(e),t>=0?(this._nodeCollections.forEach(function(t){t.remove(e)}),this.entities.splice(t,1),!0):!1},getNodes:function(e){var t,i;return t=this._nodeCollectionKeys.indexOf(e),t>=0?this._nodeCollections[t].nodes:(i=new Serpentity.NodeCollection({type:e}),this._nodeCollectionKeys.push(e),this._nodeCollections.push(i),this.entities.forEach(function(e){i.add(e)}),i.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:{_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,"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])},addComponent: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.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")({prototype:{init:function(t){var n;t=t||{};for(n in t)t.hasOwnProperty(n)&&(this[n]=t[n])}}}); diff --git a/lib/serpentity/entity.js b/lib/serpentity/entity.js index d03f16b..c020f05 100644 --- a/lib/serpentity/entity.js +++ b/lib/serpentity/entity.js @@ -25,7 +25,7 @@ Class(Serpentity, "Entity")({ * * returns true if added, false if already present */ - add : function add(component) { + addComponent : function addComponent(component) { if (this._componentKeys.indexOf(component.constructor) >= 0) { return false; } diff --git a/lib/serpentity/serpentity.js b/lib/serpentity/serpentity.js index 18985c5..ed1a9df 100644 --- a/lib/serpentity/serpentity.js +++ b/lib/serpentity/serpentity.js @@ -50,7 +50,7 @@ eventually be consumed by "Systems" You can add components to entities by using the add method: - entity.add(new PositionComponent()); + entity.addComponent(new PositionComponent()); Systems can refer to entities by requesting nodes. diff --git a/package.json b/package.json index 642de3e..9443ed4 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "serpentity", "description": "A simple entity framework inspired by ash", - "version": "0.1.6", + "version": "0.1.7", "contributors": [ { "name": "Ben Beltran",