From cc3955ecc712ea38cd6a28dd24751a39317c7e9c Mon Sep 17 00:00:00 2001 From: Ghom <42542238+Ghommie@users.noreply.github.com> Date: Tue, 4 Feb 2020 06:04:43 +0100 Subject: [PATCH] Fixes pitch black characters --- code/__HELPERS/sanitize_values.dm | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/code/__HELPERS/sanitize_values.dm b/code/__HELPERS/sanitize_values.dm index 601ed966bf..faa8c22f38 100644 --- a/code/__HELPERS/sanitize_values.dm +++ b/code/__HELPERS/sanitize_values.dm @@ -46,19 +46,25 @@ var/start = 1 + (text2ascii(color, 1) == 35) var/len = length(color) var/char = "" + // RRGGBB -> RGB but awful + var/convert_to_shorthand = desired_format == 3 && length_char(color) > 3 . = "" - for(var/i = start, i <= len, i += length(char)) + var/i = start + while(i <= len) char = color[i] switch(text2ascii(char)) - if(48 to 57) //numbers 0 to 9 + if(48 to 57) //numbers 0 to 9 . += char - if(97 to 102) //letters a to f + if(97 to 102) //letters a to f . += char - if(65 to 70) //letters A to F - translates to lowercase + if(65 to 70) //letters A to F . += lowertext(char) else break + i += length(char) + if(convert_to_shorthand && i <= len) //skip next one + i += length(color[i]) if(length_char(.) != desired_format) if(default) @@ -73,4 +79,4 @@ 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)]" \ No newline at end of file + return "#[num2hex(RGB[1],2)][num2hex(RGB[2],2)][num2hex(RGB[3],2)]"