Move bitflag utils to shared

This commit is contained in:
Vortrex
2022-05-05 11:31:54 -05:00
parent 5a00015de8
commit e3a7e9867b

View File

@@ -1359,11 +1359,9 @@ function getDistance(vec1, vec2) {
// =========================================================================== // ===========================================================================
function logToConsole(tempLogLevel, text) { 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) { if(tempLogLevel & LOG_ERROR) {
consoleError(text); consoleError(text);
return true; return true;
@@ -2804,4 +2802,50 @@ function isPosInPoly(poly, position) {
return c; 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;
}
// =========================================================================== // ===========================================================================