Files
fulpstation/code/__HELPERS/sanitize_values.dm
Nick 38091b4914 April TGU: Virologist is gone (#1200)
* Initial merge

* Map files

* dme mon ami

* Cult span renames

* updatepaths

* AltClick renamed to click_alt

* beefman hair color stuff

* bye bye beefman viro

* get_all_gear

* Updated mentor refresh verb

* bloodsucker rack atom_deconstruct

* removed LateInitialize from nanites machines

* brain trauama now calls parent on_lose

* readme

* greyscale fulp edit

* arrival sound fulp edit

* tgui routes fulp edit

* build.js fulp edit

* fulpui-patches

* Missed a couple of shuttles

* tgui files

* Map updates

* tgui tweaks and screenshots

* fixed typo

* halloween beacon texture

* Vault piggy banks

* beacon icon fr

* Selene cargo chat console

* selene labour shuttle

* Photobooths!

* Moved photobooth button on selene

* Theia updates

* Reset maps.txt

* Order consoles

* Ports TG's #82906, fixes plasma cutters

* Theia vault piggy bank

* CLICK_ACTION_SUCCESS for coffin alt clicking
2024-05-10 16:24:54 +02:00

99 lines
2.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_float(number, min=0, max=1, accuracy=1, default=0)
if(isnum(number))
number = round(number, accuracy)
if(round(min, accuracy) <= number && number <= round(max, accuracy))
return number
return default
/proc/sanitize_text(text, default="")
if(istext(text))
return text
return default
/proc/sanitize_islist(value, default)
if(islist(value) && length(value))
return value
if(default)
return default
/proc/sanitize_inlist(value, list/List, default)
if(value in List)
return value
if(default)
return default
if(List?.len)
return pick(List)
//more specialised stuff
/proc/sanitize_gender(gender,neuter=0,plural=1, default="male")
switch(gender)
if(MALE, FEMALE)
return gender
if(NEUTER)
if(neuter)
return gender
else
return default
if(PLURAL)
if(plural)
return gender
else
return default
return default
/proc/sanitize_hexcolor(color, desired_format = DEFAULT_HEX_COLOR_LEN, include_crunch = TRUE, default)
var/crunch = include_crunch ? "#" : ""
if(!istext(color))
color = ""
var/start = 1 + (text2ascii(color, 1) == 35)
var/len = length(color)
var/char = ""
// Used for conversion between RGBA hex formats.
var/format_input_ratio = "[desired_format]:[length_char(color)-(start-1)]"
. = ""
var/i = start
while(i <= len)
char = color[i]
i += length(char)
switch(text2ascii(char))
if(48 to 57) //numbers 0 to 9
. += char
if(97 to 102) //letters a to f
. += char
if(65 to 70) //letters A to F
char = LOWER_TEXT(char)
. += char
else
break
switch(format_input_ratio)
if("3:8", "4:8", "3:6", "4:6") //skip next one. RRGGBB(AA) -> RGB(A)
i += length(color[i])
if("6:4", "6:3", "8:4", "8:3") //add current char again. RGB(A) -> RRGGBB(AA)
. += char
if(length_char(.) == desired_format)
return crunch + .
switch(format_input_ratio) //add or remove alpha channel depending on desired format.
if("3:8", "3:4", "6:4")
return crunch + copytext(., 1, desired_format+1)
if("4:6", "4:3", "8:3")
return crunch + . + ((desired_format == 4) ? "f" : "ff")
else //not a supported hex color format.
return default ? default : crunch + repeat_string(desired_format, "0")
/// Makes sure the input color is text with a # at the start followed by 6 hexadecimal characters. Examples: "#ff1234", "#A38321", COLOR_GREEN_GRAY
/proc/sanitize_color(color)
return findtext(color, GLOB.is_color) ? color : GLOB.normal_ooc_colour