"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DoubleTapToStickTC = void 0;
const core_1 = require("@vived/core");
const core_2 = require("@vived/core");
const TouchController_1 = require("../../TouchController");
const TryStickAppObjectUC_1 = require("../UCs/TryStickAppObjectUC");
class DoubleTapToStickTC extends core_1.AppObjectController {
    get touchInput() {
        return this.getCachedSingleton(TouchController_1.TouchInputEntity.type);
    }
    get tryStickSceneMesh() {
        return this.getCachedSingleton(TryStickAppObjectUC_1.TryStickAppObjectUC.type)?.tryWithPixel;
    }
    constructor(appObject) {
        super(appObject, DoubleTapToStickTC.type);
        this.tapTimeMS = 300;
        this.maxTapDistancePx = 30;
        this.initialTouchPos = core_2.Vector2.Zero();
        this.initialTouchTime = 0;
        this.tapCount = 0;
        this.onTap = (e) => {
            if (!this.tryStickSceneMesh) {
                this.error("Missing Component");
                return;
            }
            this.tapCount = 1 + this.tapCount;
            if (this.tapCount === 1) {
                this.initialTouchPos = e.touchCenter;
                this.initialTouchTime = Date.now();
            }
            else if (this.tapCount === 2) {
                const movement = core_2.Vector2.Subtract(this.initialTouchPos, e.touchCenter)
                    .magnitued;
                const passedTime = Date.now() - this.initialTouchTime;
                if (passedTime <= this.tapTimeMS && movement <= this.maxTapDistancePx) {
                    this.tryStickSceneMesh(e.touchCenter);
                }
                this.cancelDoubleTap();
            }
        };
        this.cancelDoubleTap = () => {
            this.initialTouchPos = core_2.Vector2.Zero();
            this.initialTouchTime = 0;
            this.tapCount = 0;
        };
        this.touchInput?.registerController(this);
    }
}
exports.DoubleTapToStickTC = DoubleTapToStickTC;
DoubleTapToStickTC.type = "DoubleTapToStickTC";
//# sourceMappingURL=DoubleTapToStickTC.js.map