import { BEAT_GUILD, eventTarget, STOP_GUILD_TAP } from "../Events";

const { ccclass, property } = cc._decorator;

@ccclass
export default class TapTutorialController extends cc.Component {
    private _hand: cc.Node;

    protected onLoad(): void {
        [this._hand] = this.node.children;
        eventTarget.on(STOP_GUILD_TAP, this.stopGuild, this);

        this.tutorialTap();
        // this.tutorialTapForFragements();
    }

    private stopGuild() {
        cc.Tween.stopAllByTarget(this._hand);
        this._hand.active = false;
    }

    private tutorialTap() {
        this._hand.active = true;
        cc.tween(this._hand)
            .repeatForever(cc.tween(this._hand)
                .to(0, { position: cc.v3(120, 100) })
                .to(0.2, { angle: 15 })
                .to(0.2, { angle: -15 })
                .to(0.15, { position: cc.v3(110, 80) })
                .call(() => eventTarget.emit(BEAT_GUILD))
                .delay(1)
            )
            .start();
    }

    private tutorialTapForFragements() {
        this._hand.active = true;
        cc.tween(this._hand)
            .repeatForever(cc.tween(this._hand)
                .to(0, { position: cc.v3(120, 100), opacity: 255 })
                .to(0.2, { angle: 15 })
                .to(0.2, { angle: -15 })
                .to(0.15, { position: cc.v3(110, 80) })
                .call(() => eventTarget.emit(BEAT_GUILD))
                .to(0.5, { opacity: 0 })
                .delay(2)
            )
            .start();
    }
}
