All files / games/screens/src screen.ts

100% Statements 17/17
100% Branches 0/0
100% Functions 4/4
100% Lines 17/17

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  2x 2x 2x 2x 2x     3x 3x 3x 3x 3x 3x 3x 3x     1x     1x     3x     2x                                  
import { Observable, ObservableInterface, ObserverInterface } from "jga-patterns-observer";
 
import { World, Entity, Player } from "jga-games-engine";
 
import { DisplayInterface } from "jga-games-display";
 
import { InputDataInterface, ScreenInterface } from "./interface";
import { ScreenObserver } from "./observer";
 
import { Console, HTMLConsoleRenderer } from "jga-games-console";
 
export abstract class Screen extends Observable implements ObservableInterface, ScreenInterface {
    protected observers: ObserverInterface[] = [];
    protected name: string;
    protected engine: World;
    protected display: DisplayInterface;
 
    public constructor(name: string, engine: World, display: DisplayInterface) {
        super();
 
        this.name = name;
        this.engine = engine;
        this.display = display;
 
        const console = new Console(new HTMLConsoleRenderer());
        const observer = new ScreenObserver(console);
        this.attach(observer);
    }
 
    public enter(): void {
        return this.notify(`Enter ${this.name} screen`);
    }
 
    public exit(): void {
        return this.notify(`Exit ${this.name} screen`);
    }
 
    public getObservers(): ObserverInterface[] {
        return this.observers;
    }
 
    public abstract render(entities?: Entity[], player?: Player): void;
    public abstract handleInput(inputType?: string, inputData?: InputDataInterface): string | null;
}