import { eventTarget, ROTATE_GUILD, STOP_GUILD_ROTATE } from "../Events";

const { ccclass, property } = cc._decorator;

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

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

        this.tutorialRotate();
    }

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

    private tutorialRotate() {
        this._hand.active = true;

        cc.tween(this._hand)
            .repeatForever(cc.tween(this._hand)
                .to(0, { position: cc.v3(350) })
                .to(0.5, { angle: -10 })
                .to(0.5, { angle: 15 })
                .call(() => eventTarget.emit(ROTATE_GUILD))
                .to(1.2, { position: cc.v3(-150) })
            )
            .start();
    }

}
