| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- import { _decorator, Component, Node, JsonAsset, EventHandler } from 'cc';
- import { Utils } from '../../core/utils/Utils';
- import { ConfigData } from '../../Data/ConfigData';
- import { g } from '../../Data/g';
- const { ccclass, property } = _decorator;
- @ccclass('FactoryCountDown')
- export class FactoryCountDown extends Component {
- @property({ tooltip: "配置ID" }) configID: number = 0;
- @property({ type: EventHandler, tooltip: "商品制作完成时的回调" }) onComplete: EventHandler;
- public progress: number = 0;
- public timerString: string = "";
- private config: any;
- async start() {
- this.config = ConfigData.configMap.get("product");
- }
- update() {
- let producting = g.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 = Utils.formatCountDown(producting[0].ripeDate - now);
- } else {
- this.onComplete && this.onComplete.emit([producting[0].productID]);
- g.gameData.getProductingList(this.configID).shift();
- }
- }
- }
- public async ripe() {
- let producting = g.gameData.getProductingList(this.configID);
- this.onComplete && this.onComplete.emit([producting[0].productID]);
- let build = ConfigData.configMap.get("build");
- if (build[this.configID]["sequence"] == 1) {
- let lastTime = producting[0].ripeDate - Date.now();
- g.gameData.getProductingList(this.configID).shift();
- for (let i = 0; i < g.gameData.getProductingList(this.configID).length; i++) {
- g.gameData.getProductingList(this.configID)[i].ripeDate -= lastTime;
- }
- } else {
- g.gameData.getProductingList(this.configID).shift();
- }
- }
- }
|