]>
git.r.bdr.sh - rbdr/serpentity/blob - lib/serpentity/entity.js
add823e422fdf1a831ff40759e5dcaa686f6b14d
3 /* global Serpentity */
6 * The entity gives the entity framework its name. It exists only
10 let Entity
= class Entity
{
11 constructor (config
) {
12 this._componentKeys
= [];
13 this._components
= [];
15 Object
.assign(this, config
|| {});
19 * Adds a component to the entity.
21 * returns true if added, false if already present
23 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
) {
36 if (this._componentKeys
.indexOf(componentClass
) >= 0) {
43 * returns the component associated with that key
45 getComponent (componentClass
) {
46 let position
= this._componentKeys
.indexOf(componentClass
);
48 return this._components
[position
];
53 if (typeof module
!== 'undefined' && this.module
!== module
) {
54 module
.exports
= Entity
;
56 Serpentity
.Entity
= Entity
;