All files / ts/factories factoryInput.ts

100% Statements 16/16
100% Branches 2/2
100% Functions 2/2
100% Lines 16/16

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    1x 1x 1x 1x 1x 1x         1x           4x 4x 4x       3x 1x   2x 2x 2x 2x    
import { IEngineCanvas } from "../engineCanvas.js";
import { IEngineCore } from "../engineCore.js";
import { IInputController, InputController } from "../controller/input/inputController.js";
import { InputReceiver } from "../controller/input/inputReceiver.js";
import { IFactory, Factory } from "../models/factory.js";
import { InvalidOperationException } from "../environment/exceptions.js";
import { InputTypePointer } from "../controller/input/types/inputTypePointer.js";
import { InputTypeKeyboard } from "../controller/input/types/inputTypeKeyboard.js";
 
export interface IFactoryInput extends IFactory<IInputController> {
    create(engineCore?: IEngineCore): IInputController;
}
export class FactoryInput extends Factory<IInputController> implements IFactoryInput {
 
    private readonly _inputReceiver: InputReceiver;
    private readonly _engineCanvas: IEngineCanvas;
 
    public constructor(engineCanvas: IEngineCanvas) {
        super();
        this._engineCanvas = engineCanvas;
        this._inputReceiver = new InputReceiver(engineCanvas);
    }
 
    public create(engineCore?: IEngineCore): IInputController {
        if (!engineCore) {
            throw new InvalidOperationException("IEngineCore is needed for creation.");
        }
        const inputController = new InputController(engineCore, this._inputReceiver);
        inputController.add("Pointer", new InputTypePointer(this._engineCanvas));
        inputController.add("Keyboard", new InputTypeKeyboard());
        return inputController;
    }
}