-
Notifications
You must be signed in to change notification settings - Fork 0
/
gcolors.txt
294 lines (230 loc) · 10.3 KB
/
gcolors.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
--@name gColors
--@author legokidlogan
--@shared
--[[
- A simple collection of colors for standardizing projects and making it easy to get colors quickly.
- Feel free to add colors of your own, this is just what I use for my scripts.
- Colors can be accessed either through COLORS.name or directly as a global var as c_name.
- ex: COLORS.red or c_red
- You can add or change colors specific to your project by manipulating the COLORS table.
- ex: COLORS.my_color_name = Color( 255, 0, 0, 255 )
- It's preferable to do this *before* running require( "lkl/gcolors.txt" )
- If you do it after, please do it in one of two ways:
A.
gColors.modifyColor( name, color )
-- Auto-updates the colors safely
B.
COLORS.my_color_name = Color( 255, 0, 0, 255 )
gColors.refreshColors()
-- Force-refreshes the colors. Will break localized versions of gColors.colorToName(), etc.
- There's various utility functions here, but this library is mostly just for quickly slapping down some color by using the global vars.
--]]
if COLORS and gColors then return end -- Don't run twice.
COLORS = COLORS or {} -- Where all the colors are stored
gColors = gColors or {} -- "Global Colors": A few simple library functions are kept here
-- Colors with these as their names will not get globalized as c_name. They will still be accessible through COLORS.name, however.
gColors.nameExceptions = gColors.nameExceptions or {
["fade"] = true,
}
----- COLOR DEFINITIONS -----
-- Simple colors
COLORS.white = Color( 255, 255, 255, 255 )
COLORS.black = Color( 0, 0, 0, 255 )
COLORS.empty = Color( 0, 0, 0, 0 )
COLORS.red = Color( 255, 0, 0, 255 )
COLORS.green = Color( 0, 255, 0, 255 )
COLORS.blue = Color( 0, 0, 255, 255 )
COLORS.cyan = Color( 0, 255, 255, 255 )
COLORS.magenta = Color( 255, 0, 255, 255 )
COLORS.yellow = Color( 255, 255, 0, 255 )
COLORS.orange = Color( 255, 150, 0, 255 )
COLORS.brown = Color( 190, 120, 75, 255 )
COLORS.grey = Color( 127, 127, 127, 255 )
COLORS.gray = COLORS.grey
COLORS.purple = Color( 150, 0, 255, 255 )
-- Modified colors
COLORS.pale_red = Color( 255, 150, 150, 255 )
COLORS.pale_green = Color( 150, 255, 150, 255 )
COLORS.pale_blue = Color( 150, 150, 255, 255 )
COLORS.pale_yellow = Color( 255, 255, 150, 255 )
COLORS.pale_orange = Color( 255, 170, 100, 255 )
COLORS.medium_blue = Color( 90, 90, 220, 255 )
COLORS.dark_brown = Color( 165, 75, 25, 255 )
COLORS.dark_grey = Color( 65, 65, 65, 255 )
COLORS.dark_gray = COLORS.dark_grey
COLORS.light_brown = Color( 225, 170, 140, 255 )
COLORS.light_grey = Color( 200, 200, 200, 255 )
COLORS.light_gray = COLORS.light_grey
-- Special colors
COLORS.alert_red = Color( 150, 0, 0, 255 )
COLORS.alert_green = Color( 0, 150, 0, 255 )
COLORS.attention_red = Color( 255, 0, 100, 255 )
COLORS.pend_orange = Color( 255, 127, 0, 255 )
COLORS.info_blue = Color( 50, 150, 200, 255 )
COLORS.technical_blue = Color( 0, 130, 255, 255 )
COLORS.arg_req = Color( 255, 215, 50 )
COLORS.arg_opt = Color( 145, 190, 230 )
COLORS.arg_return = Color( 180, 120, 230 )
COLORS.pvp = Color( 255, 80, 80, 255 )
COLORS.build = Color( 80, 80, 255, 255 )
COLORS.leotech_letter = Color( 255, 255, 0, 255 )
COLORS.leotech_circle = Color( 255, 140, 0, 255 )
COLORS.ulib_self = Color( 74, 0, 131 )
COLORS.table = Color( 100, 165, 170, 255 )
COLORS.custom_type = Color( 120, 120, 215, 255 )
COLORS.ply_console = Color( 50, 50, 65, 255 )
COLORS.realm_server = Color( 3, 169, 244, 255 )
COLORS.realm_client = Color( 222, 169, 9, 255 )
COLORS.realm_menu = Color( 76, 175, 80, 255 )
COLORS.realm_current = SERVER and COLORS.realm_server or COLORS.realm_client
COLORS.steam_id = Color( 70, 130, 200, 255 )
COLORS.url = Color( 22, 168, 252, 255 )
-- Code colors (based off of default colors for the Visual Studio Code glua extension by aStonedPenguin )
COLORS.code_text = Color( 212, 212, 212, 255 )
COLORS.code_comment = Color( 106, 153, 85, 255 )
COLORS.code_number = Color( 181, 206, 168, 255 )
COLORS.code_number_sat = Color( 150, 205, 75, 255 ) -- Improved saturation for GMod
COLORS.code_string = Color( 206, 145, 120, 255 )
COLORS.code_string_sat = Color( 205, 120, 80, 255 ) -- Improved saturation for GMod
COLORS.code_keyword = Color( 187, 134, 192, 255 )
COLORS.code_function = COLORS.code_keyword
COLORS.code_function_name = Color( 220, 220, 170, 255 )
COLORS.code_library_function = COLORS.code_function_name
COLORS.code_creation_function = COLORS.code_function_name
COLORS.code_core_constant = Color( 86, 156, 214, 255 )
COLORS.code_nil = COLORS.code_core_constant
COLORS.code_true = COLORS.code_core_constant
COLORS.code_false = COLORS.code_core_constant
COLORS.code_boolean = COLORS.code_core_constant
COLORS.code_bool = COLORS.code_core_constant
COLORS.code_server = COLORS.code_core_constant
COLORS.code_client = COLORS.code_core_constant
COLORS.code_arg = Color( 156, 220, 254, 255 )
-- Faded colors
COLORS.fade = Color( 1, 1, 1, 0.5 )
COLORS.white_faded = COLORS.white * COLORS.fade
COLORS.red_faded = COLORS.red * COLORS.fade
COLORS.green_faded = COLORS.green * COLORS.fade
COLORS.blue_faded = COLORS.blue * COLORS.fade
COLORS.yellow_faded = COLORS.yellow * COLORS.fade
----- LIBRARY FUNCTIONS -----
--[[
- Refreshes the global color variables, and some library functions that rely on localized values.
- If you directly modify the COLORS table, call this function afterwards. Note that this will break any localized versions of gColors.colorToName(), etc.
- ex:
COLORS.my_color_name = Color( 255, 0, 0, 255 )
gColors.refreshColors()
- This only applies to direct modifications, however; if you use gColors.modifyColor( name, col ) instead, it automatically updates things without needing a refresh.
--]]
function gColors.refreshColors()
local stringStartWith = string.startWith
local stringSub = string.sub
local colorNameLookup = {}
do
local colorNames = table.getKeys( COLORS )
for _, colorName in ipairs( colorNames ) do
local color = COLORS[colorName]
colorNameLookup[color] = colorName
end
end
--[[
- Modifies a global color and safely auto-updates the library.
--]]
function gColors.modifyColor( name, color )
COLORS[name] = color
colorNameLookup[color] = name
return name, color
end
--[[
- Converts a color object from the COLORS table into its name
- ex: gColors.colorToName( Color( 255, 255, 255, 255 ) ) ==> "white"
- If the color isn't recognized, output is nil.
--]]
function gColors.colorToName( color )
local str = colorNameLookup[color]
return str
end
--[[
- Converts a color object from the COLORS table into its standalone varaible name
- ex: gColors.colorToVarName( Color( 255, 255, 255, 255 ) ) ==> "c_white"
- If the color isn't recognized, output is nil.
--]]
function gColors.colorToVarName( color )
local str = colorNameLookup[color]
if not str then return end
return "c_" .. str
end
--[[
- Converts a color object from the COLORS table into its specialized string form
- ex: gColors.colorToString( Color( 255, 255, 255, 255 ) ) ==> "::c_white"
- If the color isn't recognized, output is "::c(r,g,b,a)" where r, g, b, a are the color channels.
- Mostly used for packing colors into strings for efficient netowrking.
--]]
function gColors.colorToString( color )
if type( color ) == "string" then return color end
local str = colorNameLookup[color]
if not str then
if type( color ) ~= "Color" then return end
return "::c(" .. color.r .. "," .. color.g .. "," .. color.b .. "," .. color.a .. ")"
end
return "::c_" .. str
end
--[[
- Converts a string (as name, var name, or specialized string) to its relevant color in the COLORS table
- ex: gColors.stringToColor( "::c_white" ) ==> c_white ==> Color( 255, 255, 255, 255 )
- ex: gColors.stringToColor( "white" ) ==> c_white ==> Color( 255, 255, 255, 255 )
- ex: gColors.stringToColor( "::c(1,2,3,4)" ) ==> Color( 1, 2, 3, 4 )
- If the color isn't recognized, output is nil.
--]]
function gColors.stringToColor( str )
if type( str ) == "Color" then return str end
if stringStartWith( str, "::c(" ) then
str = stringSub( str, 5, -2 )
--local r, g, b, a = str:match( "(%d+),(%d+),(%d+),(%d+)" )
local r, g, b, a = unpack( string.split( str, "," ) )
if not r or not g or not b or not a then return end
--return Color( r, g, b, a )
return Color( tonumber( r ), tonumber( g ), tonumber( b ), tonumber( a ) )
elseif stringStartWith( str, "::c_" ) then
str = stringSub( str, 5 )
elseif stringStartWith( str, "c_" ) then
str = stringSub( str, 3 )
end
return COLORS[str]
end
----- SETUP -----
do -- Globalize the colors (so they can be referenced as c_name instead of COLORS.name)
local nameExceptions = gColors.nameExceptions
for name, color in pairs( COLORS ) do
if not nameExceptions[name] then
_G["c_" .. name] = color
end
end
end
end
--[[
- Gets a faded (transparent) version of a color
- Ultimately just multiplies against the color's alpha.
colorOrName: (string or Color)
- The color (or the standard name of one) to fade.
- If given as a Color, it doesn't need to already be on the COLORS table.
fadeOverride: (optional) (number)
- Amount to fade by, from 0 to 1.
- Defaults to the amount specified in COLORS.fade
--]]
function gColors.fadeColor( colorOrName, fadeOverride )
local color = gColors.stringToColor( colorOrName )
if not color then return end
if fadeOverride then
return color * Color( 1, 1, 1, fadeOverride )
end
local name = gColors.colorToName( color )
if name then
local colorFaded = COLORS[name .. "_faded"]
if colorFaded then return colorFaded end
colorFaded = color * COLORS.fade
gColors.modifyColor( name, colorFaded )
end
return color * COLORS.fade
end
gColors.refreshColors()