[refactor] Pulling out createStatusText from Engine

This commit is contained in:
Steven Evans
2018-07-19 12:17:43 -04:00
parent 7313d551f1
commit 56da0f9214
5 changed files with 47 additions and 34 deletions
+27
View File
@@ -0,0 +1,27 @@
import { getElementById } from "../../utils/uiHelpers/getElementById";
import { Action } from "../types";
const threeSeconds: number = 3000;
let x: number | undefined;
/**
* Displays a status message to the player for approximately 3 seconds.
* @param text The status text to display
*/
export function createStatusText(text: string) {
if (x !== undefined) {
clearTimeout(x);
// Likely not needed due to clearTimeout, but just in case...
x = undefined;
}
const statusElement: HTMLElement = getElementById("status-text");
statusElement.classList.add("status-text");
statusElement.innerText = text;
const handler: Action = () => {
statusElement.classList.remove("status-text");
statusElement.innerText = "";
};
x = setTimeout(handler, threeSeconds);
}