diff --git a/frontend/src/js/hud.ts b/frontend/src/js/hud.ts index 7b7aee6738c0f3e5c36a691a4feeb2a5c41f4e46..935aa4069c7566f250af103f4c8d2d80c071dbab 100644 --- a/frontend/src/js/hud.ts +++ b/frontend/src/js/hud.ts @@ -1,4 +1,4 @@ -const ICONS = { +export const ICONS = { SCORE: "ï¸âï¸", CLOCK: "â²ï¸", HEALTH: "â¤ï¸ï¸", @@ -28,6 +28,17 @@ interface HudOptions { inputPosition: number; } +export const formatTime = (milliseconds: number) => { + const minutes = Math.floor(milliseconds / 60000); + const seconds = Math.floor((milliseconds % 60000) / 1000) + .toString() + .padStart(2, "0"); + const hundredths = Math.floor((milliseconds % 1000) / 10) + .toString() + .padStart(2, "0"); + return `${minutes}:${seconds}.${hundredths}`; +}; + export default class HUD { scene: Phaser.Scene; options: HudOptions; @@ -118,16 +129,7 @@ export default class HUD { } setClock(milliseconds: number) { - const minutes = Math.floor(milliseconds / 60000); - const seconds = Math.floor((milliseconds % 60000) / 1000) - .toString() - .padStart(2, "0"); - const hundredths = Math.floor((milliseconds % 1000) / 10) - .toString() - .padStart(2, "0"); - const formatted = `${minutes}:${seconds}.${hundredths}`; - // TODO: we can probably do away with the clock icon - this.clock.text = `${formatted}\u2009${ICONS.CLOCK}`; + this.clock.text = `${this.formatTime(milliseconds)}\u2009${ICONS.CLOCK}`; } showSubmitFeedback(color: string, input: string) {