import LanguageUtils from "../../Main/Common/LanguageUtils"; import Utils from "../../Main/Common/Utils"; import { InnerEventCode } from "../../Main/Config/InnerMsgCode"; export class CommercialData { private static _instance: CommercialData; public static get Instance(): CommercialData { if (!CommercialData._instance) { CommercialData._instance = new CommercialData(); } return CommercialData._instance; } private _diamondCount: number = 0; private _isVip: boolean = false; private _vipEndTime: number = 0; public get diamondCount(): number { return this._diamondCount; } public set diamondCount(value: number) { if (this._diamondCount !== value) { this._diamondCount = Math.max(0, value); Utils.sendInnerMsg(InnerEventCode.DiamondCountChanged, { count: this._diamondCount, }); } } public get isVip(): boolean { return this._isVip; } public set isVip(value: boolean) { if (this._isVip !== value) { this._isVip = value; Utils.sendInnerMsg(InnerEventCode.IsVipChanged, { isVip: this._isVip }); } } public get vipEndTime(): number { return this._vipEndTime; } public set vipEndTime(value: number) { if (this._vipEndTime !== value) { this._vipEndTime = Math.max(0, value); Utils.sendInnerMsg(InnerEventCode.VipEndDayChange, { vipEndTime: this._vipEndTime, }); } } private constructor() { this.loadData(); } public addDiamonds(amount: number): void { if (amount > 0) { this.diamondCount += amount; } } public spendDiamonds(amount: number): boolean { if (amount > 0 && this._diamondCount >= amount) { this.diamondCount -= amount; return true; } return false; } public setVipTime(timeInSeconds: number): void { this._vipEndTime = timeInSeconds; if (timeInSeconds > 0) { this.isVip = true; } } public getVipLeftTime(): string { const dateNow = new Date(); const timeDiff = Math.abs(this._vipEndTime - dateNow.getTime()); const hours = Math.floor(timeDiff / (1000 * 60 * 60)); if (hours >= 24) { return ( (hours % 24).toString() + LanguageUtils.getText("purchasepanel.day") ); } const minutes = Math.floor((timeDiff / (1000 * 60)) % 60); //const seconds = Math.floor((timeDiff / 1000) % 60); return `${hours}${LanguageUtils.getText( "purchasepanel.hour" )}:${minutes}${LanguageUtils.getText("purchasepanel.minute")}`; } private loadData(): void { //假数据 this._diamondCount = 18556; this._isVip = true; //const dateNow = new Date(); const dateEndTime = new Date("2025-08-30T12:00:00Z"); this._vipEndTime = dateEndTime.getTime(); } }