multyx
Version:
Framework designed to simplify the creation of multiplayer browser games by addressing the complexities of managing server-client communication, shared state, and input handling
31 lines (30 loc) • 895 B
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.GenerateUUID = GenerateUUID;
exports.AddUUID = AddUUID;
const UUIDSet = new Set();
/**
* Generate a unique identifier across Multyx ecosystem
* @param length Length of UUID
* @param radix Base number to use for UUID characters
* @returns
*/
function GenerateUUID(length = 8, radix = 36) {
const unit = radix ** (length - 1);
const uuid = Math.floor(Math.random() * (radix * unit - unit) + unit).toString(radix);
if (UUIDSet.has(uuid))
return GenerateUUID(length, radix);
UUIDSet.add(uuid);
return uuid;
}
/**
* Add a UUID to the Multyx ecosystem global set
* @param uuid UUID to add to set
* @returns True if success, false if UUID already exists in set
*/
function AddUUID(uuid) {
if (UUIDSet.has(uuid))
return false;
UUIDSet.add(uuid);
return true;
}
;