Files
GTA4RP/scripts/server/colour.js
2020-12-04 02:48:16 -06:00

52 lines
1.7 KiB
JavaScript

// ===========================================================================
// Asshat-Gaming Roleplay
// https://github.com/VortrexFTW/gtac_asshat_rp
// Copyright (c) 2020 Asshat-Gaming (https://asshatgaming.com)
// ---------------------------------------------------------------------------
// FILE: colour.js
// DESC: Provides colours, functions and usage
// TYPE: Server (JavaScript)
// ===========================================================================
// ----------------------------------------------------------------------------
function getColourByType(typeName) {
return serverConfig.colour.byType[typeName];
}
// ----------------------------------------------------------------------------
function getColourByName(colourName) {
return serverConfig.colour.byName[colourName];
}
// ---------------------------------------------------------------------------
function rgbToHex(red, green, blue) {
return "#" + componentToHex(red) + componentToHex(green) + componentToHex(blue);
}
// ---------------------------------------------------------------------------
function componentToHex(component) {
let hex = component.toString(16);
return hex.length == 1 ? "0" + hex : hex;
}
// ---------------------------------------------------------------------------
function hexToRGB(hex) {
let red = parseInt((cutHex(hex)).substring(0,2),16);
let green = parseInt((cutHex(hex)).substring(2,4),16);
let blue = parseInt((cutHex(hex)).substring(4,6),16);
return {r: red, g: green, b: blue};
}
// ---------------------------------------------------------------------------
function cutHex(hex) {
return (hex.charAt(0)=="#") ? hex.substring(1,7) : hex;
}
// ---------------------------------------------------------------------------