All files / games/engine/src/systems system.ts

100% Statements 11/11
87.5% Branches 7/8
100% Functions 4/4
100% Lines 11/11

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          5x 16x           16x 16x 16x 16x 27x 9x       16x 7x             5x          
import { SystemInterface } from "jga-patterns-ecs";
 
import { ComponentName } from "../components";
import { Entity } from "../entities";
 
export abstract class System implements SystemInterface {
    protected entities: Map<string, Entity> = new Map<string, Entity>();
 
    public constructor(
        entities: Map<string, Entity>,
        filters: ComponentName[],
    ) {
        Eif (null != entities) {
            entities.forEach((entity, key): void => {
                let found = 0;
                filters.forEach((filter): void => {
                    if (null != entity && entity.hasComponent(filter)) {
                        found++;
                    }
                });
 
                if (found === filters.length) {
                    this.entities.set(key, entity);
                }
            });
        }
    }
 
    public getEntities(): Map<string, Entity> {
        return this.entities;
    }
 
    public abstract run(): void;
}