127 lines
2.7 KiB
Lua
127 lines
2.7 KiB
Lua
|
AddCSLuaFile()
|
||
|
|
||
|
local cbox = cbox
|
||
|
|
||
|
local MsgC = MsgC
|
||
|
local Color = Color
|
||
|
local ipairs = ipairs
|
||
|
local tonumber = tonumber
|
||
|
local tostring = tostring
|
||
|
|
||
|
local string = string
|
||
|
|
||
|
local string_Explode = string.Explode
|
||
|
|
||
|
local color_white = Color(255, 255, 255)
|
||
|
|
||
|
local utils = {}
|
||
|
utils.colors = {
|
||
|
BRAND = Color(132, 206, 181),
|
||
|
CLIENT = Color(143, 218, 230),
|
||
|
SERVER = Color(230, 218, 112),
|
||
|
SHARED = Color( 93, 200, 92),
|
||
|
ERROR = Color(255, 90, 90),
|
||
|
}
|
||
|
|
||
|
---Parses a string into a color
|
||
|
---@param str string Input color as "R G B" or "R G B A"
|
||
|
---@param alpha? boolean Whether to parse alpha or not (default false)
|
||
|
---@return Color
|
||
|
function utils.ParseColorString(str, alpha)
|
||
|
alpha = alpha ~= nil and alpha or false
|
||
|
|
||
|
local split = string_Explode(" ", str)
|
||
|
local r = tonumber(split[1]) or 255
|
||
|
local g = tonumber(split[2]) or 255
|
||
|
local b = tonumber(split[3]) or 255
|
||
|
local a = alpha and tonumber(split[4] or 255) or 255
|
||
|
|
||
|
return Color(r, g, b, a)
|
||
|
end
|
||
|
|
||
|
---Prints to console with realm prefix
|
||
|
---@vararg any
|
||
|
function utils.RealmPrint(...)
|
||
|
local args = {...}
|
||
|
for i, arg in ipairs(args) do
|
||
|
args[i] = tostring(arg)
|
||
|
end
|
||
|
|
||
|
MsgC(utils.colors.BRAND, "[cbox -> ")
|
||
|
|
||
|
local realm, realm_color = "???", utils.colors.SHARED
|
||
|
if CLIENT then
|
||
|
realm = "CLIENT"
|
||
|
realm_color = utils.colors.CLIENT
|
||
|
elseif SERVER then
|
||
|
realm = "SERVER"
|
||
|
realm_color = utils.colors.SERVER
|
||
|
end
|
||
|
MsgC(realm_color, realm)
|
||
|
|
||
|
MsgC(utils.colors.BRAND, "] ")
|
||
|
|
||
|
MsgC(color_white, table.concat(args, " "), "\n")
|
||
|
end
|
||
|
|
||
|
---Prints to console with the "shared" prefix
|
||
|
---@vararg any
|
||
|
function utils.SharedPrint(...)
|
||
|
local args = {...}
|
||
|
for i, arg in ipairs(args) do
|
||
|
args[i] = tostring(arg)
|
||
|
end
|
||
|
|
||
|
MsgC(utils.colors.BRAND, "[cbox -> ")
|
||
|
|
||
|
MsgC(utils.colors.SHARED, "SHARED")
|
||
|
|
||
|
MsgC(utils.colors.BRAND, "] ")
|
||
|
|
||
|
MsgC(color_white, table.concat(args, " "), "\n")
|
||
|
end
|
||
|
|
||
|
---Prints to console with realm prefix, but in red
|
||
|
---@vararg any
|
||
|
function utils.RealmError(...)
|
||
|
local args = {...}
|
||
|
for i, arg in ipairs(args) do
|
||
|
args[i] = tostring(arg)
|
||
|
end
|
||
|
|
||
|
MsgC(utils.colors.BRAND, "[cbox -> ")
|
||
|
|
||
|
local realm, realm_color = "???", utils.colors.SHARED
|
||
|
if CLIENT then
|
||
|
realm = "CLIENT"
|
||
|
realm_color = utils.colors.CLIENT
|
||
|
elseif SERVER then
|
||
|
realm = "SERVER"
|
||
|
realm_color = utils.colors.SERVER
|
||
|
end
|
||
|
MsgC(realm_color, realm)
|
||
|
|
||
|
MsgC(utils.colors.BRAND, "] ")
|
||
|
|
||
|
MsgC(utils.colors.ERROR, table.concat(args, " "), "\n")
|
||
|
end
|
||
|
|
||
|
---Prints to console with the "shared" prefix, but in red
|
||
|
---@vararg any
|
||
|
function utils.SharedError(...)
|
||
|
local args = {...}
|
||
|
for i, arg in ipairs(args) do
|
||
|
args[i] = tostring(arg)
|
||
|
end
|
||
|
|
||
|
MsgC(utils.colors.BRAND, "[cbox -> ")
|
||
|
|
||
|
MsgC(utils.colors.SHARED, "SHARED")
|
||
|
|
||
|
MsgC(utils.colors.BRAND, "] ")
|
||
|
|
||
|
MsgC(utils.colors.ERROR, table.concat(args, " "), "\n")
|
||
|
end
|
||
|
|
||
|
cbox.utils = utils
|