]>
git.r.bdr.sh - rbdr/serpentity/blob - lib/serpentity/entity.js
2 * The entity gives the entity framework its name. It exists only
9 this._componentKeys
= [];
10 this._components
= [];
12 Object
.assign(this, config
);
16 * Adds a component to the entity.
18 * returns true if added, false if already present
20 addComponent(component
) {
22 if (this._componentKeys
.indexOf(component
.constructor) >= 0) {
26 this._componentKeys
.push(component
.constructor);
27 this._components
.push(component
);
32 * returns true if component is included, false otherwise
34 hasComponent(componentClass
) {
36 if (this._componentKeys
.indexOf(componentClass
) >= 0) {
44 * returns the component associated with that key
46 getComponent(componentClass
) {
48 const position
= this._componentKeys
.indexOf(componentClass
);
50 return this._components
[position
];