Source: Thing.UE/Environment/UTimeline.js

const blueprint = require('../BlueprintLoad');
const UE4 = require('../../Framework/Framework');

/** 
 * @description 24小时间线
 * @class UTimeline
 * @example
 * app.timeline = new THING.UE.Timeline();
 * // 切换至中午12点
 * app.timeline.setTime(12);
 */
class UTimeline {

	#dtn = null;
	#onTimeline = null;

	constructor(param) {

		this.#onTimeline = null;
		this.#dtn = new UE4.DTNObject();
		this.#dtn.bindDTN((hoursMinutes) => {
			if (this.#onTimeline) {
				this.#onTimeline(hoursMinutes);
			}
		});
	}

	bind(callback) {
		this.#onTimeline = callback;
	}

	unbind(callback) {
		this.#dtn.clearDTN();
	}

	dispoe() {
		if (this.#dtn && !this.#dtn.IsPendingKill()) {
			this.#dtn.ConditionalBeginDestroy();
		}
	}

	static getSky() {
		return blueprint.getByTag('SkyControl_BP');
	}

	static GetTime() {
		var dtn = UTimeline.getSky();
		if (dtn) {
			return dtn.GetFloat('TimeNow');
		}
	}

	static SetTime(time) {
		var dtn = UTimeline.getSky();
		if (dtn) {
			// dtn.SetFloat('TimeNow', time);
			dtn.TimeNow = time;
			dtn.CallFunction('ThingJsSetTime');
		}
	}

	static AutoPlay(play) {
		var dtn = UTimeline.getSky();
		if (dtn) {
			dtn.SetBool('AutoPlay', play);
		}
	}

	static getTimeViaStage(stage) {
		switch (stage) {
			case '上午':
				return 8;
			case '中午':
				return 12;
			case '傍晚':
				return 18;
			case '夜晚':
				return 22;
			case '深夜':
				return 2;
			default:
				return 13;
		}
	}

	static SetStage(stage) {
		var timeInHour = UTimeline.getTimeViaStage(stage);
		UTimeline.SetTime(timeInHour);
	}

	static ToNight() {
		this.SetTime(22);
	}

	static ToDaytime() {
		this.SetTime(14);
	}

	static dispose() {
		this.ToDaytime();
	}

	static getTime() {
		return UTimeline.GetTime();
	}

	/**
	 * @function
	 * @description 设置时间
	 * @param {Number} hour - 0-24小时
	 */
	static setTime(hour) {
		UTimeline.SetTime(hour);
	}

	/**
	 * @function
	 * @description 设置到14点
	 */
	static toDay() {
		UTimeline.ToDaytime();
	}

	/**
	 * @function
	 * @description 设置到22点
	 */
	static toNight() {
		UTimeline.ToNight();
	}
};

module.exports = UTimeline;