var t = require; var e = module; var i = exports; Object.defineProperty(i, "__esModule", {value: !0}); const o = t("App"), u = t("GameText"), a = t("Toast"), n = t("RedPoinAnim"), r = t("MachineLvUpAni"), l = t("RoleUnlockAni"), h = t("GameConst"), p = t("MachineAttr"), c = t("CurrencyService"), s = t("MachineService"), f = t("MapService"), g = t("SlotData"); i.default = class { constructor() { (this.cfg = null), (this.menu = null), (this.unlockFrameBg = null), (this.foodBg = null), (this.slots = []), (this.unlockSlots = []), (this.unlockCnt = 0), (this.attr = null), (this.foodImg = null), (this.name = ""), (this.tipNode = null); } getPos() { const t = this.foodBg.node.position; return (t.x += this.foodBg.node.parent.x), (t.y += this.foodBg.node.parent.y + this.foodBg.node.height / 2), t; } updateMoney() { this.attr.isUnlock ? (this.tipNode.active = this.canLevelUp()) : (this.tipNode.active = this.canUnlock()); } setMemento(e) { const i = (this.attr = new p.default()), s = f.default.ins.define, t = f.default.ins.curCfg; i.init( e, this.cfg, t.machine_max_lv, t.machine_slot_max, t.stage < 1e4 ? s.machine_slot_add_lv : s.event_machine_slot_add_lv, s.machine_value_doubleup_lv ); var o = this.slots.length; for (let t = 0; t < o; t++) { const e = this.slots[t], s = i.slotCnt > t; s && ((this.unlockSlots[t] = e), (this.unlockCnt = t + 1)), e.setActive(s); } i.isUnlock ? (this.foodBg.spriteFrame = this.unlockFrameBg) : (this.foodImg.node.active = !1), this.foodBg.node.on(cc.Node.EventType.TOUCH_END, this.onTouchUnlock, this), this.updateMoney(); } onTouchUnlock() { (this.attr.isUnlock ? s.default.ins.lvUpBox : s.default.ins.machineUnlockBox).showBox(this); } canUnlock() { return f.default.ins.mapSaveData.money >= this.attr.installCost; } canLevelUp() { return !this.attr.isMaxLevel() && f.default.ins.mapSaveData.money >= this.attr.upgradeCost; } unlockSlot(t) { const e = this.slots[t]; this.unlockCnt = t + 1; const i = o.default.NodePoolMsr.cookUnlockAni.pop(), s = i.getComponent(l.default); (i.position = e.selfPos), f.default.ins.uiLayer.addChild(i), s.init(() => { e.unlock(), this.unlockSlots.push(e); for (const t of this.slots) t.updateSiblingIndex(); o.default.NotificationCenter.dispatch(h.GameNotificationConst.UNLOCK_SLOT, e); }, this); } unlock() { this.attr.unlockSelf(), this.unlockSlot(0), (this.foodImg.node.active = !0), (this.foodBg.spriteFrame = this.unlockFrameBg); } lvUp() { if (!this.attr.isMaxLevel()) { var e = -this.attr.upgradeCost; if (c.default.ins.checkMoneyEnough(e)) { var i = this.attr.levelUp(); this.attr.slotCnt > this.unlockCnt && this.unlockSlot(this.attr.slotCnt - 1), c.default.ins.moneyChange(e); const s = this.tipNode.parent; let t = o.default.NodePoolMsr.machineLvUpAni.pop(); return s.addChild(t), t.getComponent(r.default).playAni(), i; } return a.default.launch("金币不足!"), !1; } a.default.launch("已经是最大等级!"); } replacBtn(t, e) { let i = t.getChildByName("FoodOrder"); (this.unlockFrameBg = i.getComponent(cc.Sprite).spriteFrame), i.parent.addChild(e), (e.x = i.x), (e.y = i.y), i.destroy(); let s = i.children[0]; s ? s.removeFromParent(!1) : (s = new cc.Node()), e.addChild(s); let o = s.getComponent(cc.Sprite); (o = o || s.addComponent(cc.Sprite)), (this.foodImg = o), (this.foodBg = e.getComponent(cc.Sprite)), (this.tipNode = e.getChildByName("arrow")), this.tipNode.getComponent(n.RedPoinAnim) || this.tipNode.addComponent(n.RedPoinAnim); } parse(e, i, s) { this.replacBtn(e, i), (this.menu = s), (this.name = u.GameText.getTextByStr(s.name)), (this.attr = new p.default()); const o = e.getChildByName("slots"), a = e.x + o.x, n = e.y + o.y, r = -e.width * e.anchorX, l = e.width - e.width * e.anchorX, h = o.children, c = f.default.ins.layer; for (let t = h.length - 1; 0 <= t; t--) { const e = h[t], i = new g.default(); i.machineData = this; const s = e.children[0]; if ( ((i.direction = parseInt(s.name.slice(5))), e.children[1] && ((i.ani = e.children[1].getComponent(cc.Animation)), i.ani && 6 === i.direction)) ) { const e = i.ani.node; 1 < e.children.length ? (e.children[1].scaleX = -1) : (e.scaleX = -1); } (i.chefPos = cc.v2(s.x + a + e.x, s.y + n + e.y)), (i.selfPos = cc.v2(a + e.x, n + e.y)), s.destroy(); const p = parseInt(e.name.split("_")[1]); (this.slots[p] = i), i.stopCook(), (i.node = e), (i.siblingIndex = t); var d = o.x + e.x; e.getComponent(cc.Sprite) && (d < r || l < d) ? (e.removeFromParent(!1), c.addChild(e), (e.x = a + e.x), (e.y = n + e.y), (i.parentNode = c)) : (i.parentNode = e.parent); } } getEmpSlot() { for (const t of this.unlockSlots) if (!t.isWorking) return t; return null; } };