import { _decorator, Component, Enum, Node, tween, Vec3 } from 'cc';
import { CupHeight } from '../TakeGobletGlobalInstance';
import { LevelAction } from '../LevelAction';
import { EventDispatcher } from 'db://assets/core_tgx/easy_ui_framework/EventDispatcher';
import { GameEvent } from '../Enum/GameEvent';
const { ccclass, property, executeInEditMode } = _decorator;

/** 原浆酒杯组件脚本*/
@ccclass('OriginCup')
@executeInEditMode
export class OriginCup extends Component {
    @property({ type: Enum(CupHeight), displayName: '杯高度' })
    cupHeight: CupHeight = CupHeight.Two

    @property(Node)
    waters: Node = null!;  //水节点

    @property({ type: Number, tooltip: "水层数量" })
    waterLayers: number = 5; // 改为可配置项

    start() {
        this.node.on(Node.EventType.TOUCH_END, () => {
            EventDispatcher.instance.emit(GameEvent.EVENT_CLICK_ORIGIN_CUP, this);
        });
    }

    update(deltaTime: number) {

    }

    destroyOriginCup() {
        const originalPos = this.node.position.clone();
        tween(this.node)
            .to(0.3, { scale: Vec3.ZERO })
            .call(() => {
                this.node.destroy();
                EventDispatcher.instance.emit(GameEvent.EVENT_ORIGIN_CUP_DESTROYED, this.node.uuid);
            })
            .start();
    }
}


