All files / games/roguelike/src/game/engine/systems position.ts

100% Statements 11/11
100% Branches 4/4
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 36 37 38 39 40 4121x               21x   21x             5x   5x 3x         2x       2x 1x 1x       1x          
import {
    ComponentName,
    PositionComponent,
    PositionInterface,
} from "../components";
 
import { Entity } from "../entity";
 
import { System } from "./system";
 
export class PositionSystem extends System {
    protected position: PositionInterface;
 
    public constructor(
        entities: Map<string, Entity>,
        position?: PositionInterface,
    ) {
        super(entities, [ComponentName.POSITION]);
 
        if (null != position) {
            this.position = position;
        }
    }
 
    public getPosition(): PositionInterface {
        return this.position;
    }
 
    public run(): void {
        if (null != this.position) {
            this.entities.forEach((entity, key): void => {
                const positionComponent = entity.getComponent(
                    ComponentName.POSITION,
                ) as PositionComponent;
 
                positionComponent.setPosition(this.position);
            });
        }
    }
}