mirror of
https://github.com/ParadiseSS13/Paradise.git
synced 2026-07-13 16:13:19 +01:00
de6a54fbde
* Removes all mentions of `return .` * I can do this all day * Arthri review * Update code/__HELPERS/sanitize_values.dm Co-authored-by: Burzah <116982774+Burzah@users.noreply.github.com> * Update code/__HELPERS/sanitize_values.dm Co-authored-by: Burzah <116982774+Burzah@users.noreply.github.com> --------- Co-authored-by: Burzah <116982774+Burzah@users.noreply.github.com>
66 lines
1.6 KiB
Plaintext
66 lines
1.6 KiB
Plaintext
//general stuff
|
|
/proc/sanitize_integer(number, min=0, max=1, default=0)
|
|
if(isnum(number))
|
|
number = round(number)
|
|
if(min <= number && number <= max)
|
|
return number
|
|
return default
|
|
|
|
/proc/sanitize_text(text, default="")
|
|
if(istext(text))
|
|
return text
|
|
return default
|
|
|
|
/proc/sanitize_inlist(value, list/List, default)
|
|
if(value in List)
|
|
return value
|
|
if(default)
|
|
return default
|
|
if(length(List))
|
|
return pick(List)
|
|
|
|
/proc/sanitize_json(json_input)
|
|
if(length(json_input) && istext(json_input))
|
|
return json_decode(json_input)
|
|
return list()
|
|
|
|
|
|
//more specialised stuff
|
|
/proc/sanitize_gender(gender, neuter = FALSE, default = "male")
|
|
switch(gender)
|
|
if(MALE, FEMALE, PLURAL)
|
|
return gender
|
|
if(NEUTER)
|
|
if(neuter)
|
|
return gender
|
|
else
|
|
return default
|
|
return default
|
|
|
|
/proc/sanitize_hexcolor(color, default="#000000")
|
|
if(!istext(color))
|
|
return default
|
|
var/len = length(color)
|
|
if(len != 7 && len !=4)
|
|
return default
|
|
if(text2ascii(color, 1) != 35)
|
|
return default //35 is the ascii code for "#"
|
|
. = "#"
|
|
for(var/i=2,i<=len,i++)
|
|
var/ascii = text2ascii(color,i)
|
|
switch(ascii)
|
|
if(48 to 57)
|
|
. += ascii2text(ascii) //numbers 0 to 9
|
|
if(97 to 102)
|
|
. += ascii2text(ascii) //letters a to f
|
|
if(65 to 70)
|
|
. += ascii2text(ascii + 32) //letters A to F - translates to lowercase
|
|
else
|
|
return default
|
|
|
|
/proc/sanitize_ooccolor(color)
|
|
var/list/HSL = rgb2hsl(hex2num(copytext(color,2,4)),hex2num(copytext(color,4,6)),hex2num(copytext(color,6,8)))
|
|
HSL[3] = min(HSL[3],0.4)
|
|
var/list/RGB = hsl2rgb(arglist(HSL))
|
|
return "#[num2hex(RGB[1],2)][num2hex(RGB[2],2)][num2hex(RGB[3],2)]"
|