feat: add poc
This commit is contained in:
parent
43d27b04d9
commit
4a4fa05ce4
53 changed files with 6191 additions and 0 deletions
58
src/core/Entity.js
Normal file
58
src/core/Entity.js
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
/**
|
||||
* Entity class - represents a game object with a unique ID
|
||||
* Entities are just containers for components
|
||||
*/
|
||||
export class Entity {
|
||||
static nextId = 0;
|
||||
|
||||
constructor() {
|
||||
this.id = Entity.nextId++;
|
||||
this.components = new Map();
|
||||
this.active = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a component to this entity
|
||||
*/
|
||||
addComponent(component) {
|
||||
this.components.set(component.type, component);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a component by type
|
||||
*/
|
||||
getComponent(type) {
|
||||
return this.components.get(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if entity has a component
|
||||
*/
|
||||
hasComponent(type) {
|
||||
return this.components.has(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if entity has all specified components
|
||||
*/
|
||||
hasComponents(...types) {
|
||||
return types.every(type => this.components.has(type));
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a component
|
||||
*/
|
||||
removeComponent(type) {
|
||||
this.components.delete(type);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all components
|
||||
*/
|
||||
getAllComponents() {
|
||||
return Array.from(this.components.values());
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue