mirror of
https://github.com/PolarisSS13/Polaris.git
synced 2026-08-23 05:06:50 +01:00
removes some legacy procs, adds some other procs
NUFC removed add_lspace — unused removed add_tspace — unused removed invertHTML — unused removed hsl2rgb — unimplemented removed hex2num — replaced with define removed num2hex — replaced with define removed add_zero — replaced with pad_left removed add_zero2 — replaced with pad_left removes hex2rgb — replaced with behavior of rgb2num() removes hex2rgb_r — replaced with behavior of rgb2num() removes hex2rgb_g — replaced with behavior of rgb2num() removes hex2rgb_b — replaced with behavior of rgb2num() removes assorted inline list(rgb) > hex — replaced with behavior of rgb() removes assorted inline rand > hex — replace with random_hex_text added hex2num define added num2hex define added random_hex_text added generate_padding added pad_left added pad_right
This commit is contained in:
+50
-15
@@ -213,23 +213,58 @@
|
||||
t = replacetext(t, char, repl_chars[char])
|
||||
return t
|
||||
|
||||
//Adds 'u' number of zeros ahead of the text 't'
|
||||
/proc/add_zero(t, u)
|
||||
while (length(t) < u)
|
||||
t = "0[t]"
|
||||
return t
|
||||
|
||||
//Adds 'u' number of spaces ahead of the text 't'
|
||||
/proc/add_lspace(t, u)
|
||||
while(length(t) < u)
|
||||
t = " [t]"
|
||||
return t
|
||||
/// Returns a string of hexadecimal characters of length size, uppercased if uppercase is truthy
|
||||
/proc/random_hex_text(size, uppercase)
|
||||
if (!ISINTEGER(size))
|
||||
return
|
||||
var/list/result = list()
|
||||
for (var/i = size to 1 step -1)
|
||||
result += num2hex(rand(0, 0xF))
|
||||
result = jointext(result, null)
|
||||
if (uppercase)
|
||||
return uppertext(result)
|
||||
return result
|
||||
|
||||
//Adds 'u' number of spaces behind the text 't'
|
||||
/proc/add_tspace(t, u)
|
||||
while(length(t) < u)
|
||||
t = "[t] "
|
||||
return t
|
||||
|
||||
/// Builds a string of padding repeated until its character count meets or exceeds size
|
||||
/proc/generate_padding(size, padding)
|
||||
var/padding_size = length_char(padding)
|
||||
if (!padding_size)
|
||||
return ""
|
||||
var/padding_count = CEILING(size / padding_size, 1)
|
||||
var/list/result = list()
|
||||
for (var/i = padding_count to 1 step -1)
|
||||
result += padding // pow2 strategies could be used here at the cost of complexity
|
||||
return result.Join(null)
|
||||
|
||||
|
||||
/// Pads the matter of padding onto the start of text until the result length is size
|
||||
/proc/pad_left(text, size, padding)
|
||||
var/text_length = length_char(text)
|
||||
if (text_length >= size)
|
||||
return text
|
||||
if (!text_length)
|
||||
text = ""
|
||||
var/result = "[generate_padding(size - text_length, padding)][text]"
|
||||
var/length_difference = length_char(result) - size
|
||||
if (!length_difference)
|
||||
return result
|
||||
return copytext_char(result, length_difference + 1)
|
||||
|
||||
|
||||
/// Pads the matter of padding onto the start of text until the result length is size
|
||||
/proc/pad_right(text, size, padding)
|
||||
var/text_length = length_char(text)
|
||||
if (text_length >= size)
|
||||
return text
|
||||
if (!text_length)
|
||||
text = ""
|
||||
var/result = "[text][generate_padding(size - text_length, padding)]"
|
||||
var/length_difference = length_char(result) - size
|
||||
if (!length_difference)
|
||||
return result
|
||||
return copytext_char(result, 1, -length_difference)
|
||||
|
||||
//Returns a string with reserved characters and spaces before the first letter removed
|
||||
/proc/trim_left(text)
|
||||
|
||||
@@ -110,8 +110,8 @@ GLOBAL_VAR_INIT(round_start_time, 0)
|
||||
var/mins = round((mills % 36000) / 600)
|
||||
var/hours = round(mills / 36000)
|
||||
|
||||
mins = mins < 10 ? add_zero(mins, 1) : mins
|
||||
hours = hours < 10 ? add_zero(hours, 1) : hours
|
||||
mins = pad_left("[mins]", 2, "0")
|
||||
hours = pad_left("[hours]", 2, "0")
|
||||
|
||||
last_round_duration = "[hours]:[mins]"
|
||||
next_duration_update = world.time + 1 MINUTES
|
||||
|
||||
@@ -1,55 +1,3 @@
|
||||
/*
|
||||
* Holds procs designed to change one type of value, into another.
|
||||
* Contains:
|
||||
* hex2num & num2hex
|
||||
* text2list & list2text
|
||||
* file2list
|
||||
* angle2dir
|
||||
* angle2text
|
||||
* worldtime2text
|
||||
*/
|
||||
|
||||
// Returns an integer given a hexadecimal number string as input.
|
||||
/proc/hex2num(hex)
|
||||
if (!istext(hex))
|
||||
return
|
||||
|
||||
var/num = 0
|
||||
var/power = 1
|
||||
var/i = length(hex)
|
||||
|
||||
while (i)
|
||||
var/char = text2ascii(hex, i)
|
||||
switch(char)
|
||||
if(48) // 0 -- do nothing
|
||||
if(49 to 57) num += (char - 48) * power // 1-9
|
||||
if(97, 65) num += power * 10 // A
|
||||
if(98, 66) num += power * 11 // B
|
||||
if(99, 67) num += power * 12 // C
|
||||
if(100, 68) num += power * 13 // D
|
||||
if(101, 69) num += power * 14 // E
|
||||
if(102, 70) num += power * 15 // F
|
||||
else
|
||||
return
|
||||
power *= 16
|
||||
i--
|
||||
return num
|
||||
|
||||
// Returns the hex value of a number given a value assumed to be a base-ten value
|
||||
/proc/num2hex(num, padlength)
|
||||
var/global/list/hexdigits = list("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F")
|
||||
|
||||
. = ""
|
||||
while(num > 0)
|
||||
var/hexdigit = hexdigits[(num & 0xF) + 1]
|
||||
. = "[hexdigit][.]"
|
||||
num >>= 4 //go to the next half-byte
|
||||
|
||||
//pad with zeroes
|
||||
var/left = padlength - length(.)
|
||||
while (left-- > 0)
|
||||
. = "0[.]"
|
||||
|
||||
/proc/text2numlist(text, delimiter="\n")
|
||||
var/list/num_list = list()
|
||||
for(var/x in splittext(text, delimiter))
|
||||
@@ -151,25 +99,6 @@
|
||||
if (rights & R_EVENT) . += "[seperator]+EVENT"
|
||||
return .
|
||||
|
||||
// Converts a hexadecimal color (e.g. #FF0050) to a list of numbers for red, green, and blue (e.g. list(255,0,80) ).
|
||||
/proc/hex2rgb(hex)
|
||||
// Strips the starting #, in case this is ever supplied without one, so everything doesn't break.
|
||||
if(findtext(hex,"#",1,2))
|
||||
hex = copytext(hex, 2)
|
||||
return list(hex2rgb_r(hex), hex2rgb_g(hex), hex2rgb_b(hex))
|
||||
|
||||
// The three procs below require that the '#' part of the hex be stripped, which hex2rgb() does automatically.
|
||||
/proc/hex2rgb_r(hex)
|
||||
var/hex_to_work_on = copytext(hex,1,3)
|
||||
return hex2num(hex_to_work_on)
|
||||
|
||||
/proc/hex2rgb_g(hex)
|
||||
var/hex_to_work_on = copytext(hex,3,5)
|
||||
return hex2num(hex_to_work_on)
|
||||
|
||||
/proc/hex2rgb_b(hex)
|
||||
var/hex_to_work_on = copytext(hex,5,7)
|
||||
return hex2num(hex_to_work_on)
|
||||
|
||||
// heat2color functions. Adapted from: http://www.tannerhelland.com/4435/convert-temperature-rgb-algorithm-code/
|
||||
/proc/heat2color(temp)
|
||||
|
||||
@@ -14,30 +14,6 @@
|
||||
locate(min(CENTER.x+(RADIUS),world.maxx), min(CENTER.y+(RADIUS),world.maxy), CENTER.z) \
|
||||
)
|
||||
|
||||
//Inverts the colour of an HTML string
|
||||
/proc/invertHTML(HTMLstring)
|
||||
|
||||
if (!( istext(HTMLstring) ))
|
||||
CRASH("Given non-text argument!")
|
||||
else
|
||||
if (length(HTMLstring) != 7)
|
||||
CRASH("Given non-HTML argument!")
|
||||
var/textr = copytext(HTMLstring, 2, 4)
|
||||
var/textg = copytext(HTMLstring, 4, 6)
|
||||
var/textb = copytext(HTMLstring, 6, 8)
|
||||
var/r = hex2num(textr)
|
||||
var/g = hex2num(textg)
|
||||
var/b = hex2num(textb)
|
||||
textr = num2hex(255 - r)
|
||||
textg = num2hex(255 - g)
|
||||
textb = num2hex(255 - b)
|
||||
if (length(textr) < 2)
|
||||
textr = text("0[]", textr)
|
||||
if (length(textg) < 2)
|
||||
textr = text("0[]", textg)
|
||||
if (length(textb) < 2)
|
||||
textr = text("0[]", textb)
|
||||
return text("#[][][]", textr, textg, textb)
|
||||
|
||||
//Returns the middle-most value
|
||||
/proc/dd_range(var/low, var/high, var/num)
|
||||
@@ -1279,7 +1255,7 @@ var/list/WALLITEMS = list(
|
||||
return colour
|
||||
|
||||
/proc/color_square(red, green, blue, hex)
|
||||
var/color = hex ? hex : "#[num2hex(red, 2)][num2hex(green, 2)][num2hex(blue, 2)]"
|
||||
var/color = hex || rgb(red, green, blue)
|
||||
return "<span style='font-face: fixedsys; font-size: 14px; background-color: [color]; color: [color]'>___</span>"
|
||||
|
||||
var/mob/dview/dview_mob = new
|
||||
|
||||
Reference in New Issue
Block a user