import GamePlay from "../../GamePlay";
import GameConst from "../../data/GameConst";

const { ccclass, property } = cc._decorator;

@ccclass
export default class SelectCellItemBtn extends cc.Component {

    /**cellItem的ani效果 */
    @property(cc.Sprite)
    spr_icon: cc.Sprite = null;

    /**类型 */
    public type: number = 0;

    start() {
        this.node.on(cc.Node.EventType.TOUCH_END, this.onClick, this);
    }

    /**初始化 */
    init(cellItemType: number) {

        this.type = cellItemType;

        this.spr_icon.node.width = 70;
        this.spr_icon.node.height = 70;

        mk.loader.load(`game/texture/cellItemIcon/${GameConst.iconIndex}/${this.type}`, cc.SpriteFrame).then((spriteFrame) => {
            this.spr_icon.spriteFrame = spriteFrame;
        })
    }

    onClick() {
        GamePlay.Inst.node_changeCellItemUI.active = false;
        GamePlay.Inst.changeCellItemType(this.type);
    }
}
