/** @format */ import {Data, Mgr} from '../GameControl' import {LOCAL, MOD} from '../enums/Enum' /** @format */ export class TimeManager { intervalID: number[] = [] timeoutID: number[] = [] globalTimeIntervalID: any reset() { this.intervalID.forEach(value => clearInterval(value)) this.timeoutID.forEach(value => clearTimeout(value)) this.intervalID.length = 0 this.timeoutID.length = 0 } setInterval(callback: Function, time: number, ...args: any[]) { let id = setInterval(callback, time, ...args) this.intervalID.push(id) return id } setTimeout(callback: Function, time: number, ...args: any[]) { let id = setTimeout(callback, time, ...args) this.timeoutID.push(id) return id } globalTimer() { if (this.globalTimeIntervalID) { clearInterval(this.globalTimeIntervalID) } this.globalTimeIntervalID = setInterval(() => { Data.main.globalTime += 0.1 let curSecond = Math.floor(Data.main.globalTime) if (curSecond != Data.main.secondTime) { Data.main.secondTime = curSecond Data.main.serverTime = Data.main.loginTime + Data.main.secondTime } let curMinutes = Math.floor(Data.main.globalTime / 60) if (curMinutes != Data.main.minutesTime) Data.main.minutesTime = curMinutes }, 100) } initLoginDate(time: number) { let lastTime = Mgr.storage.getNumber(LOCAL.loginDay, 1627508200) let lastZero = Date.getDayTime(lastTime, 0) let nowZero = Date.getDayTime(time, 0) Data.main.isSecondDay = nowZero > lastZero Mgr.storage.set(LOCAL.loginDay, nowZero) } }