Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 112x 112x 112x 112x 112x 112x 112x 112x 112x 112x 91x 91x 112x 112x 14x 14x 112x 112x 1x 1x 112x 112x 378x 378x 112x 112x 2x 1x 1x 1x 1x 2x 112x 112x 174x 174x 112x | import { ComponentInterface } from "./component";
export interface EntityInterface {
getId(): string;
getComponent(name: string): ComponentInterface | undefined;
getComponents(): Map<string, ComponentInterface>;
addComponent(component: ComponentInterface): void;
removeComponent(component: ComponentInterface): void;
hasComponent(name: string): boolean;
}
export class Entity implements EntityInterface {
protected id: string;
protected components: Map<string, ComponentInterface>;
public constructor(id: string) {
this.id = id;
this.components = new Map<string, ComponentInterface>();
}
public getId(): string {
return this.id;
}
public getComponents(): Map<string, ComponentInterface> {
return this.components;
}
public getComponent(name: string): ComponentInterface | undefined {
return this.components.get(name);
}
public addComponent(component: ComponentInterface): Map<string, ComponentInterface> {
return this.components.set(component.getName(), component);
}
public removeComponent(component: ComponentInterface): boolean {
if (this.components.has(component.getName())) {
return this.components.delete(component.getName());
}
return true;
}
public hasComponent(name: string): boolean {
return this.components.has(name);
}
}
|