mirror of
https://github.com/PolarisSS13/Polaris.git
synced 2025-12-15 20:52:07 +00:00
Splits setup.dm into berjillion of smaller files vaguely named thematically.
Also moved __HELPERS and _defines around so defines actually come first.
This commit is contained in:
46
code/_helpers/sanitize_values.dm
Normal file
46
code/_helpers/sanitize_values.dm
Normal file
@@ -0,0 +1,46 @@
|
||||
//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(List && List.len)return List[1]
|
||||
|
||||
|
||||
|
||||
//more specialised stuff
|
||||
/proc/sanitize_gender(gender,neuter=0,plural=0, 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, 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
|
||||
return .
|
||||
Reference in New Issue
Block a user