From c7340b09b5dc594aa8be368120409bff60032bb9 Mon Sep 17 00:00:00 2001 From: chuga-git <98280110+chuga-git@users.noreply.github.com> Date: Fri, 30 Aug 2024 17:46:31 -0500 Subject: [PATCH] replaces hex2num proc with define (#26649) --- code/__DEFINES/_math.dm | 4 ++++ code/__HELPERS/type2type.dm | 35 ----------------------------------- 2 files changed, 4 insertions(+), 35 deletions(-) diff --git a/code/__DEFINES/_math.dm b/code/__DEFINES/_math.dm index 28c03149a60b..cd6c152f06d6 100644 --- a/code/__DEFINES/_math.dm +++ b/code/__DEFINES/_math.dm @@ -245,4 +245,8 @@ // Gives you the percent of two inputs #define PERCENT_OF(val1, val2) (val1 * (val2 / 100)) +///Returns an integer given a hex input, supports negative values "-ff". Skips preceding invalid characters. +#define hex2num(X) text2num(X, 16) + +/// Returns the hex value of a decimal number. len == length of returned string. #define num2hex(X, len) uppertext(num2text(X, len, 16)) diff --git a/code/__HELPERS/type2type.dm b/code/__HELPERS/type2type.dm index f883f0cec778..e8b6f970156c 100644 --- a/code/__HELPERS/type2type.dm +++ b/code/__HELPERS/type2type.dm @@ -1,47 +1,12 @@ /* * Holds procs designed to change one type of value, into another. * Contains: - * hex2num & num2hex * file2list * angle2dir * angle2text * worldtime2text */ -//Returns an integer given a hex input -/proc/hex2num(hex) - if(!(istext(hex))) - return - - var/num = 0 - var/power = 0 - var/i = null - i = length(hex) - while(i > 0) - var/char = copytext(hex, i, i + 1) - switch(char) - if("0") - pass() // Do nothing - if("9", "8", "7", "6", "5", "4", "3", "2", "1") - num += text2num(char) * 16 ** power - if("a", "A") - num += 16 ** power * 10 - if("b", "B") - num += 16 ** power * 11 - if("c", "C") - num += 16 ** power * 12 - if("d", "D") - num += 16 ** power * 13 - if("e", "E") - num += 16 ** power * 14 - if("f", "F") - num += 16 ** power * 15 - else - return - power++ - i-- - return num - //Returns an integer value for R of R/G/B given a hex color input. /proc/color2R(hex) if(!(istext(hex)))