import Util from "../util/Util"; const { ccclass, property } = cc._decorator; @ccclass export class FactoryCountDown extends cc.Component { @property({ tooltip: "配置ID" }) configID: number = 0; @property({ type: cc.Component.EventHandler, tooltip: "商品制作完成时的回调" }) onComplete: cc.Component.EventHandler = null; public progress: number = 0; public timerString: string = ""; private config: any; async start() { this.config = gData.configData.configMap.get("product"); } update() { let producting = gData.gameData.getProductingList(this.configID); let now = Date.now(); if (producting.length > 0 && this.config) { let totleTime = this.config[producting[0].productID]["time"]; if (producting[0].ripeDate > now) { this.progress = 1 - ((producting[0].ripeDate - now) / (totleTime * 1000)); this.timerString = Util.formatCountDown(producting[0].ripeDate - now); } else { this.onComplete && this.onComplete.emit([producting[0].productID]); gData.gameData.getProductingList(this.configID).shift(); } } } public async ripe() { let producting = gData.gameData.getProductingList(this.configID); this.onComplete && this.onComplete.emit([producting[0].productID]); let build = gData.configData.configMap.get("build"); if (build[this.configID]["sequence"] == 1) { let lastTime = producting[0].ripeDate - Date.now(); gData.gameData.getProductingList(this.configID).shift(); for (let i = 0; i < gData.gameData.getProductingList(this.configID).length; i++) { gData.gameData.getProductingList(this.configID)[i].ripeDate -= lastTime; } } else { gData.gameData.getProductingList(this.configID).shift(); } } }