]>
git.r.bdr.sh - rbdr/serpentity/blob - lib/serpentity/entity.js
c020f05514c0c8940a0d1079dacdb8d669fd2ee0
2 * The entity gives the entity framework its name. It exists only
5 Class(Serpentity
, "Entity")({
10 init : function init(config
) {
13 this._componentKeys
= [];
14 this._components
= [];
16 for (property
in config
) {
17 if (config
.hasOwnProperty(property
)) {
18 this[property
] = config
[property
];
24 * Adds a component to the entity.
26 * returns true if added, false if already present
28 addComponent : function addComponent(component
) {
29 if (this._componentKeys
.indexOf(component
.constructor) >= 0) {
32 this._componentKeys
.push(component
.constructor);
33 this._components
.push(component
);
38 * returns true if component is included, false otherwise
40 hasComponent : function hasComponent(componentClass
) {
41 if (this._componentKeys
.indexOf(componentClass
) >= 0) {
48 * returns the component associated with that key
50 getComponent : function getComponent(componentClass
) {
52 position
= this._componentKeys
.indexOf(componentClass
);
54 return this._components
[position
];