2019-02-20 09:42:27 +01:00
|
|
|
import { setTimeoutRef } from "../utils/SetTimeoutRef";
|
2018-07-19 18:17:43 +02:00
|
|
|
import { getElementById } from "../../utils/uiHelpers/getElementById";
|
|
|
|
import { Action } from "../types";
|
|
|
|
|
2021-04-30 05:52:56 +02:00
|
|
|
const threeSeconds = 3000;
|
2018-07-19 18:17:43 +02:00
|
|
|
let x: number | undefined;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Displays a status message to the player for approximately 3 seconds.
|
|
|
|
* @param text The status text to display
|
|
|
|
*/
|
2021-05-01 09:17:31 +02:00
|
|
|
export function createStatusText(text: string): void {
|
2018-07-19 18:17:43 +02:00
|
|
|
if (x !== undefined) {
|
|
|
|
clearTimeout(x);
|
|
|
|
// Likely not needed due to clearTimeout, but just in case...
|
|
|
|
x = undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
const statusElement: HTMLElement = getElementById("status-text");
|
2019-03-14 04:10:28 +01:00
|
|
|
statusElement.style.display = "block";
|
2018-07-19 18:17:43 +02:00
|
|
|
statusElement.classList.add("status-text");
|
|
|
|
statusElement.innerText = text;
|
|
|
|
const handler: Action = () => {
|
|
|
|
statusElement.innerText = "";
|
2019-03-14 04:10:28 +01:00
|
|
|
statusElement.style.display = "none";
|
|
|
|
statusElement.classList.remove("status-text");
|
2018-07-19 18:17:43 +02:00
|
|
|
};
|
|
|
|
|
2019-02-20 09:42:27 +01:00
|
|
|
x = setTimeoutRef(handler, threeSeconds);
|
2018-07-19 18:17:43 +02:00
|
|
|
}
|