"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RenderCanvasUC = void 0;
exports.makeRenderCanvasUC = makeRenderCanvasUC;
const core_1 = require("@vived/core");
const Babylon_1 = require("../../Babylon");
const KeyboardInput_1 = require("../../KeyboardInput");
const TouchController_1 = require("../../TouchController");
const MouseInput_1 = require("../../MouseInput");
class RenderCanvasUC extends core_1.AppObjectUC {
}
exports.RenderCanvasUC = RenderCanvasUC;
RenderCanvasUC.type = "RenderCanvasUC";
RenderCanvasUC.get = (appObjects) => (0, core_1.getSingletonComponent)(RenderCanvasUC.type, appObjects);
function makeRenderCanvasUC(appObject) {
    return new RenderCanvasUCImp(appObject);
}
class RenderCanvasUCImp extends RenderCanvasUC {
    submitCanvas(canvas) {
        const appObjects = this.appObject.appObjectRepo;
        const keyboardInput = KeyboardInput_1.KeyboardInputEntity.get(appObjects);
        if (keyboardInput) {
            keyboardInput.setEventElement(canvas);
        }
        else {
            this.warn("Unable to find KeyboardInputEntity");
        }
        const touchInput = TouchController_1.TouchInputEntity.get(appObjects);
        if (touchInput) {
            touchInput.setEventElement(canvas);
        }
        else {
            this.warn("Unable to find TouchInputEntity");
        }
        const mouseInput = MouseInput_1.MouseInputEntity.get(appObjects);
        if (mouseInput) {
            mouseInput.setEventElement(canvas);
        }
        else {
            this.warn("Unable to find MouseInputEntity");
        }
        const babylonRendering = Babylon_1.BabylonRenderingUC.get(appObjects);
        if (babylonRendering) {
            babylonRendering.submitRenderCanvas(canvas);
        }
        else {
            this.warn("Unable to find BabylonRenderingUC");
        }
        canvas.addEventListener("contextmenu", (e) => {
            e.preventDefault();
        }, false);
    }
    clearCanvas() {
        const appObjects = this.appObject.appObjectRepo;
        const keyboardInput = KeyboardInput_1.KeyboardInputEntity.get(appObjects);
        if (keyboardInput) {
            keyboardInput.clearInputElement();
        }
        else {
            this.warn("Unable to find KeyboardInputEntity");
        }
        const touchInput = TouchController_1.TouchInputEntity.get(appObjects);
        if (touchInput) {
            touchInput.clearInputElement();
        }
        else {
            this.warn("Unable to find TouchInputEntity");
        }
        const mouseInput = MouseInput_1.MouseInputEntity.get(appObjects);
        if (mouseInput) {
            mouseInput.clearInputElement();
        }
        else {
            this.warn("Unable to find MouseInputEntity");
        }
        const babylonRendering = Babylon_1.BabylonRenderingUC.get(appObjects);
        if (babylonRendering) {
            babylonRendering.clearRenderCanvas();
        }
        else {
            this.warn("Unable to find BabylonRenderingUC");
        }
    }
    constructor(appObject) {
        super(appObject, RenderCanvasUC.type);
    }
}
//# sourceMappingURL=RenderCanvasUC.js.map