Move bitflag utils to shared
This commit is contained in:
@@ -1359,11 +1359,9 @@ function getDistance(vec1, vec2) {
|
||||
// ===========================================================================
|
||||
|
||||
function logToConsole(tempLogLevel, text) {
|
||||
if(typeof server != "undefined") {
|
||||
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;
|
||||
@@ -2805,3 +2803,49 @@ function isPosInPoly(poly, position) {
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
Reference in New Issue
Block a user