]>
git.r.bdr.sh - rbdr/serpentity/blob - lib/serpentity/entity.js
2a4b03fbc6d323677d6855025aff78ce159080ea
4 * The entity gives the entity framework its name. It exists only
8 const Entity
= class Entity
{
11 this._componentKeys
= [];
12 this._components
= [];
14 Object
.assign(this, config
);
18 * Adds a component to the entity.
20 * returns true if added, false if already present
22 addComponent(component
) {
24 if (this._componentKeys
.indexOf(component
.constructor) >= 0) {
27 this._componentKeys
.push(component
.constructor);
28 this._components
.push(component
);
33 * returns true if component is included, false otherwise
35 hasComponent(componentClass
) {
37 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
];
55 module
.exports
= Entity
;