From e3a7e9867b442154eb4cf2a22a36b8a85f03a219 Mon Sep 17 00:00:00 2001 From: Vortrex <3858226+VortrexFTW@users.noreply.github.com> Date: Thu, 5 May 2022 11:31:54 -0500 Subject: [PATCH] Move bitflag utils to shared --- scripts/shared/utilities.js | 52 ++++++++++++++++++++++++++++++++++--- 1 file changed, 48 insertions(+), 4 deletions(-) diff --git a/scripts/shared/utilities.js b/scripts/shared/utilities.js index cc3830f6..9fce75c8 100644 --- a/scripts/shared/utilities.js +++ b/scripts/shared/utilities.js @@ -1359,11 +1359,9 @@ function getDistance(vec1, vec2) { // =========================================================================== function logToConsole(tempLogLevel, text) { - if(typeof server != "undefined") { - text = removeColoursInMessage(text); - } + text = removeColoursInMessage(text); - if((logLevel & tempLogLevel)) { + if(hasBitFlag(logLevel, tempLogLevel) || hasBitFlag(logLevel, LOG_ERROR) || hasBitFlag(logLevel, LOG_WARN)) { if(tempLogLevel & LOG_ERROR) { consoleError(text); return true; @@ -2804,4 +2802,50 @@ function isPosInPoly(poly, position) { return c; } +// =========================================================================== + +function createBitFlagTable(keyNames) { + let bitVal = 0; + let bitTable = {}; + let incVal = 1; + + for(let i in keyNames) { + let key = keyNames[i]; + bitTable[key] = bitVal; + bitVal = 1 << incVal; + incVal++; + } + return bitTable; +} + +// =========================================================================== + +function hasBitFlag(allFlags, checkForFlag) { + if(allFlags == 0) { + return false; + } + + if(allFlags == -1) { + return true; + } + + if((allFlags & checkForFlag) == checkForFlag) { + return true; + } + + return false; +} + +// =========================================================================== + +function addBitFlag(allFlags, flagValue) { + return allFlags | flagValue; +} + +// =========================================================================== + +function removeBitFlag(allFlags, flagValue) { + return allFlags ^ flagValue; +} + // =========================================================================== \ No newline at end of file