"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MoveTransformSC = void 0;
const core_1 = require("@vived/core");
const Stylus_1 = require("../../../Stylus");
const UC_1 = require("../../UC");
class MoveTransformSC extends core_1.AppObjectController {
    get stylus() {
        return this.getCachedSingleton(Stylus_1.StylusEntity.type);
    }
    get tryMoveUC() {
        return this.getCachedLocalComponent(UC_1.TryMoveTransformUC.type);
    }
    constructor(appObject) {
        super(appObject, MoveTransformSC.type);
        this.doUpdate = false;
        this.allow = (button) => {
            if (button === 0)
                return true;
            return false;
        };
        this.onButtonDown = (button) => {
            this.doUpdate = false;
            if (!this.stylus || !this.tryMoveUC)
                return;
            if (!this.allow(button))
                return;
            this.doUpdate = this.tryMoveUC.tryWithRay(this.stylus.pickRay);
        };
        this.onStylusMove = () => {
            if (!this.stylus || !this.tryMoveUC)
                return;
            if (!this.doUpdate)
                return;
            this.tryMoveUC.moveWithRay(this.stylus.pickRay);
        };
        this.onButtonUp = () => {
            if (!this.doUpdate)
                return;
            this.doUpdate = false;
            if (!this.tryMoveUC)
                return;
            this.tryMoveUC.stop();
        };
        this.stylus?.registerController(this);
    }
}
exports.MoveTransformSC = MoveTransformSC;
MoveTransformSC.type = "MoveTransformSC";
//# sourceMappingURL=MoveTransformSC.js.map