import { eventTarget, RESET_BOTTLE } from "../Events";

const { ccclass, property } = cc._decorator;

@ccclass
export default class SlotJar extends cc.Component {

    private _slotBreak2thNodes: cc.Node[] = [];
    private _slotBreak1thNodes: cc.Node[] = [];

    protected onLoad(): void {
        this._slotBreak1thNodes = this.node.children;
        this._slotBreak2thNodes = this._slotBreak1thNodes.map(node => node.children[0]);

        this.resetSlots();
        eventTarget.on(RESET_BOTTLE, this.resetSlots, this);
    }

    public showSlots(breakCount: number): void {
        this._slotBreak1thNodes.forEach(node => node.active = true);
        this._slotBreak2thNodes.forEach(node => node.active = breakCount >= 2);
    }

    private resetSlots(): void {
        this._slotBreak1thNodes.forEach(node => node.active = false);
        this._slotBreak2thNodes.map(node => node.active = false);
    }
}
