Files
Bubberstation/code/__HELPERS/sanitize_values.dm
SkyratBot 124ddd7cca [MIRROR] tgui Preferences Menu + total rewrite of the preferences backend (#8153)
* tgui Preferences Menu + total rewrite of the preferences backend

* nah, we dont need to ping those people

* trying to remove the funny stuff

* unmodularizing this

* prefs reset

* this may need to be reverted, who knows

* okay, this part

* perhaps

* EEEEEEEEE

* unsanitary

* E

* Stage 1 + loadout system

* more fixes

* E

* I mean, it launches?

* More fixes and reorganisation

* E

* customisation code is spaget.

* disable ERP prefs

* Update erp_preferences.dm

* Update erp_preferences.dm

* E

* Slowly getting there

* It may be time for help :)

* tri...colors... help

* preferences now pass preferences

* Update dna.dm

* Fuck this man

* missing savefile return, set_species works, removed dumb stuff from updateappearance

* https://github.com/Skyrat-SS13/Skyrat-tg/pull/8199

* https://github.com/Skyrat-SS13/Skyrat-tg/pull/8224

* https://github.com/tgstation/tgstation/pull/61519

* https://github.com/Skyrat-SS13/Skyrat-tg/pull/8278

* e

* le butonAZARAK HELLO

* hhh

* Proper recognition where it's due, MrMelbert!

* EEEE

* examine block

* Better gen hit sounds from whitedream

* final loadout touches, more bug fixes im sure to come

* i said there would be bugfixes

* Update LoadoutManager.js

* Missing preferences in the html menu

* LIVE TESTING PHASE BABY

* Update LoadoutManager.js

* EEE

* LAUNCH TEST FIRE

* Update job.dm

* Update new_player.dm

* 50gb DAY ONE PATCH

* EEE

* Update preferences.dm

* buggle fixes

* Update examine.dm

* >LOOC starts on

Co-authored-by: Mothblocks <35135081+Mothblocks@users.noreply.github.com>
Co-authored-by: jjpark-kb <55967837+jjpark-kb@users.noreply.github.com>
Co-authored-by: Gandalf <jzo123@hotmail.com>
Co-authored-by: Azarak <azarak10@gmail.com>
2021-09-23 00:40:37 +01:00

104 lines
2.7 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(min <= number && number <= max)
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 = 3, include_crunch = FALSE, default)
var/crunch = include_crunch ? "#" : ""
//SKYRAT EDIT ADDITION BEGIN - CUSTOMIZATION
if(islist(color))
var/list/color_list = color
color = color_list.Join()
//SKYRAT EDIT ADDITION END
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 = lowertext(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