All files / games/screens/src screen.ts

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

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