Skip to content

Commit

Permalink
replaces hex2num proc with define (#26649)
Browse files Browse the repository at this point in the history
  • Loading branch information
chuga-git authored Aug 30, 2024
1 parent b962a24 commit c7340b0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 35 deletions.
4 changes: 4 additions & 0 deletions code/__DEFINES/_math.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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))
35 changes: 0 additions & 35 deletions code/__HELPERS/type2type.dm
Original file line number Diff line number Diff line change
@@ -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)))
Expand Down

0 comments on commit c7340b0

Please sign in to comment.