]> git.r.bdr.sh - rbdr/serpentity/blob - lib/serpentity/entity.js
cf2a623dd8bcb4844a182a2dc630249736339baf
[rbdr/serpentity] / lib / serpentity / entity.js
1 /*
2 * The entity gives the entity framework its name. It exists only
3 * to hold components.
4 */
5 Class(Serpentity, "Entity")({
6 prototype : {
7 addedComponents : null,
8
9 init : function init(config) {
10 var property;
11
12 this.components = {};
13
14 for (property in config) {
15 if (config.hasOwnProperty(property)) {
16 this[property] = config[property];
17 }
18 }
19 },
20
21 /*
22 * Adds a component to the entity.
23 *
24 * returns true if added, false if already present
25 */
26 add : function add(component) {
27 if (this.components.hasOwnProperty(component.constructor)) {
28 return false;
29 }
30 this.components[component.constructor] = component;
31 return true;
32 },
33
34 /*
35 * returns true if component is included, false otherwise
36 */
37 hasComponent : function hasComponent(componentClass) {
38 if (this.components.hasOwnProperty(componentClass)) {
39 return true;
40 }
41 return false;
42 }
43 }
44 });