class Index {
	private static _instance: Index;
	static get instance(): Index {
		if (!this._instance) {
			this._instance = new Index();
		}
		return this._instance;
	}
	private startTs: number = 0;

	static readonly speed: number = -0.6;

	public uiIndex: UI_Index;

	public constructor() {
		this.openIndexView();
	}

	openIndexView(): void {
		this.uiIndex = UIController.instance.createView<UI_Index>(UI_Index);

		setTimeout(() => {
			egret.startTick(this.runGame, this);
		}, 3000);
	}

	//计时并派发事件
	private runGame(timestamp: number): boolean {
		if (this.startTs === 0) {
			this.startTs = timestamp;
		}

		timestamp -= this.startTs;

		this.uiIndex.renderTimeLabel(timestamp);

		if (GameMgr.instance.GameData.time.length === 0) return false;

		let data = GameMgr.instance.GameData.time[0];

		if (timestamp >= data.timestamp) {
			let event = new egret.Event(Channel.RUN_MSG);

			event.data = GameMgr.instance.GameData.time.shift();

			GameMgr.instance.dispatchEvent(event)
		}
	
		return false;
	}
	release(): void {

	}
}