From 8eef59c60b3904534ebaa79d35fa940b1ea9879b Mon Sep 17 00:00:00 2001 From: Vortrex <3858226+VortrexFTW@users.noreply.github.com> Date: Thu, 10 Feb 2022 18:01:40 -0600 Subject: [PATCH] Move some utilities to shared --- scripts/shared/utilities.js | 64 +++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/scripts/shared/utilities.js b/scripts/shared/utilities.js index a735c203..c61cd59a 100644 --- a/scripts/shared/utilities.js +++ b/scripts/shared/utilities.js @@ -1394,4 +1394,68 @@ function getElementTypeName(typeId) { return "Unknown"; } +// =========================================================================== + +function fillStringWithCharacter(character, amount) { + let tempString = ""; + for(let i = 0; i <= amount; i++) { + tempString = tempString + toString(character); + } + return tempString; +} + +// =========================================================================== + +function fixCharacterName(name) { + return String(name.charAt(0).toUpperCase()) + String(name.slice(1).toLowerCase()); +} + +// =========================================================================== + +function getCurrentTimeStampWithTimeZone(timeZone) { + let date = new Date(); + + let utcDate = new Date(date.toLocaleString('en-US', { timeZone: "UTC" })); + let tzDate = new Date(date.toLocaleString('en-US', { timeZone: timeZone })); + let offset = utcDate.getTime() - tzDate.getTime(); + + date.setTime( date.getTime() + offset ); + + return date; +}; + +// =========================================================================== + +function getSyncerFromId(syncerId) { + let clients = getClients(); + return clients[syncerId]; +} + +// =========================================================================== + +function isConsole(client) { + if(client == null) { + return false; + } + + return client.console; +} + +// =========================================================================== + +function isSamePlayer(client1, client2) { + return (client1 == client2); +} + +// =========================================================================== + +function getConsoleClient() { + let clients = getClients(); + for(let i in clients) { + if(isConsole(clients[i])) { + return clients[i]; + } + } +} + // =========================================================================== \ No newline at end of file