mirror of
https://github.com/vgstation-coders/vgstation13.git
synced 2025-12-10 02:16:05 +00:00
NTSL code cleanup.
This commit is contained in:
@@ -1,284 +1,299 @@
|
||||
/*
|
||||
* Holds procs designed to change one type of value, into another.
|
||||
* Contains:
|
||||
* text2list & list2text
|
||||
* file2list
|
||||
* angle2dir
|
||||
* angle2text
|
||||
* worldtime2text
|
||||
*/
|
||||
|
||||
// Concatenates a list of strings into a single string. A seperator may optionally be provided.
|
||||
/proc/list2text(list/ls, sep)
|
||||
if(ls && ls.len <= 1) // Early-out code for empty or singleton lists.
|
||||
return (ls && ls.len) ? ls[1] : ""
|
||||
|
||||
var/l = ls.len // Made local for sanic speed.
|
||||
var/i = 0 // Incremented every time a list index is accessed.
|
||||
|
||||
if(sep != null)
|
||||
// Macros expand to long argument lists like so: sep, ls[++i], sep, ls[++i], sep, ls[++i], etc...
|
||||
#define S1 sep, ls[++i]
|
||||
#define S4 S1, S1, S1, S1
|
||||
#define S16 S4, S4, S4, S4
|
||||
#define S64 S16, S16, S16, S16
|
||||
|
||||
. = "[ls[++i]]" // Make sure the initial element is converted to text.
|
||||
|
||||
// Having the small concatenations come before the large ones boosted speed by an average of at least 5%.
|
||||
if(l-1 & 0x01) // 'i' will always be 1 here.
|
||||
. = text("[][][]", ., S1) // Append 1 element if the remaining elements are not a multiple of 2.
|
||||
if(l-i & 0x02)
|
||||
. = text("[][][][][]", ., S1, S1) // Append 2 elements if the remaining elements are not a multiple of 4.
|
||||
if(l-i & 0x04)
|
||||
. = text("[][][][][][][][][]", ., S4) // And so on....
|
||||
if(l-i & 0x08)
|
||||
. = text("[][][][][][][][][][][][][][][][][]", ., S4, S4)
|
||||
if(l-i & 0x10)
|
||||
. = text("[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]", ., S16)
|
||||
if(l-i & 0x20)
|
||||
. = text("[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
|
||||
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]", ., S16, S16)
|
||||
if(l-i & 0x40)
|
||||
. = text("[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
|
||||
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
|
||||
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
|
||||
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]", ., S64)
|
||||
while(l > i) // Chomp through the rest of the list, 128 elements at a time.
|
||||
. = text("[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
|
||||
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
|
||||
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
|
||||
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
|
||||
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
|
||||
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
|
||||
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
|
||||
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]", ., S64, S64)
|
||||
|
||||
#undef S64
|
||||
#undef S16
|
||||
#undef S4
|
||||
#undef S1
|
||||
|
||||
else
|
||||
// Macros expand to long argument lists like so: ls[++i], ls[++i], ls[++i], etc...
|
||||
#define S1 ls[++i]
|
||||
#define S4 S1, S1, S1, S1
|
||||
#define S16 S4, S4, S4, S4
|
||||
#define S64 S16, S16, S16, S16
|
||||
|
||||
. = "[ls[++i]]" // Make sure the initial element is converted to text.
|
||||
|
||||
if(l-1 & 0x01) // 'i' will always be 1 here.
|
||||
. += "[S1]" // Append 1 element if the remaining elements are not a multiple of 2.
|
||||
if(l-i & 0x02)
|
||||
. = text("[][][]", ., S1, S1) // Append 2 elements if the remaining elements are not a multiple of 4.
|
||||
if(l-i & 0x04)
|
||||
. = text("[][][][][]", ., S4) // And so on...
|
||||
if(l-i & 0x08)
|
||||
. = text("[][][][][][][][][]", ., S4, S4)
|
||||
if(l-i & 0x10)
|
||||
. = text("[][][][][][][][][][][][][][][][][]", ., S16)
|
||||
if(l-i & 0x20)
|
||||
. = text("[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]", ., S16, S16)
|
||||
if(l-i & 0x40)
|
||||
. = text("[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
|
||||
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]", ., S64)
|
||||
while(l > i) // Chomp through the rest of the list, 128 elements at a time.
|
||||
. = text("[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
|
||||
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
|
||||
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
|
||||
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]", ., S64, S64)
|
||||
|
||||
#undef S64
|
||||
#undef S16
|
||||
#undef S4
|
||||
#undef S1
|
||||
|
||||
//slower then list2text, but correctly processes associative lists.
|
||||
proc/tg_list2text(list/list, glue=",")
|
||||
//writepanic("[__FILE__].[__LINE__] \\/proc/tg_list2text() called tick#: [world.time]")
|
||||
if(!istype(list) || !list.len)
|
||||
return
|
||||
var/output
|
||||
for(var/i=1 to list.len)
|
||||
output += (i!=1? glue : null)+(!isnull(list["[list[i]]"])?"[list["[list[i]]"]]":"[list[i]]")
|
||||
return output
|
||||
|
||||
// HTTP GET URL query builder thing.
|
||||
// list("a"="b","c"="d") -> ?a=b&c=d
|
||||
/proc/buildurlquery(list/list,sep="&")
|
||||
//writepanic("[__FILE__].[__LINE__] (no type)([usr ? usr.ckey : ""]) \\/proc/buildurlquery() called tick#: [world.time]")
|
||||
if(!istype(list) || !list.len)
|
||||
return
|
||||
var/output
|
||||
var/i=0
|
||||
var/start
|
||||
var/qmark="?" // God damnit byond
|
||||
for(var/key in list)
|
||||
start = i ? sep : qmark
|
||||
output += "[start][key]=[list[key]]"
|
||||
i++
|
||||
return output
|
||||
|
||||
//Converts a string into a list by splitting the string at each delimiter found. (discarding the seperator)
|
||||
/proc/text2list(text, delimiter="\n")
|
||||
//writepanic("[__FILE__].[__LINE__] (no type)([usr ? usr.ckey : ""]) \\/proc/text2list() called tick#: [world.time]")
|
||||
var/delim_len = length(delimiter)
|
||||
if(delim_len < 1) return list(text)
|
||||
. = list()
|
||||
var/last_found = 1
|
||||
var/found
|
||||
do
|
||||
found = findtext(text, delimiter, last_found, 0)
|
||||
. += copytext(text, last_found, found)
|
||||
last_found = found + delim_len
|
||||
while(found)
|
||||
|
||||
//Case Sensitive!
|
||||
/proc/text2listEx(text, delimiter="\n")
|
||||
//writepanic("[__FILE__].[__LINE__] (no type)([usr ? usr.ckey : ""]) \\/proc/text2listEx() called tick#: [world.time]")
|
||||
var/delim_len = length(delimiter)
|
||||
if(delim_len < 1) return list(text)
|
||||
. = list()
|
||||
var/last_found = 1
|
||||
var/found
|
||||
do
|
||||
found = findtextEx(text, delimiter, last_found, 0)
|
||||
. += copytext(text, last_found, found)
|
||||
last_found = found + delim_len
|
||||
while(found)
|
||||
|
||||
//Splits the text of a file at seperator and returns them in a list.
|
||||
/proc/file2list(filename, seperator="\n")
|
||||
//writepanic("[__FILE__].[__LINE__] (no type)([usr ? usr.ckey : ""]) \\/proc/file2list() called tick#: [world.time]")
|
||||
return text2list(return_file_text(filename),seperator)
|
||||
|
||||
|
||||
//Turns a direction into text
|
||||
|
||||
/proc/dir2text(direction)
|
||||
//writepanic("[__FILE__].[__LINE__] (no type)([usr ? usr.ckey : ""]) \\/proc/dir2text() called tick#: [world.time]")
|
||||
switch(direction)
|
||||
if(1.0)
|
||||
return "north"
|
||||
if(2.0)
|
||||
return "south"
|
||||
if(4.0)
|
||||
return "east"
|
||||
if(8.0)
|
||||
return "west"
|
||||
if(5.0)
|
||||
return "northeast"
|
||||
if(6.0)
|
||||
return "southeast"
|
||||
if(9.0)
|
||||
return "northwest"
|
||||
if(10.0)
|
||||
return "southwest"
|
||||
else
|
||||
return
|
||||
|
||||
//Turns text into proper directions
|
||||
/proc/text2dir(direction)
|
||||
//writepanic("[__FILE__].[__LINE__] (no type)([usr ? usr.ckey : ""]) \\/proc/text2dir() called tick#: [world.time]")
|
||||
switch(uppertext(direction))
|
||||
if("NORTH")
|
||||
return 1
|
||||
if("SOUTH")
|
||||
return 2
|
||||
if("EAST")
|
||||
return 4
|
||||
if("WEST")
|
||||
return 8
|
||||
if("NORTHEAST")
|
||||
return 5
|
||||
if("NORTHWEST")
|
||||
return 9
|
||||
if("SOUTHEAST")
|
||||
return 6
|
||||
if("SOUTHWEST")
|
||||
return 10
|
||||
else
|
||||
return
|
||||
|
||||
//Converts an angle (degrees) into an ss13 direction
|
||||
/proc/angle2dir(var/degree)
|
||||
//writepanic("[__FILE__].[__LINE__] (no type)([usr ? usr.ckey : ""]) \\/proc/angle2dir() called tick#: [world.time]")
|
||||
degree = ((degree+22.5)%365)
|
||||
if(degree < 45) return NORTH
|
||||
if(degree < 90) return NORTHEAST
|
||||
if(degree < 135) return EAST
|
||||
if(degree < 180) return SOUTHEAST
|
||||
if(degree < 225) return SOUTH
|
||||
if(degree < 270) return SOUTHWEST
|
||||
if(degree < 315) return WEST
|
||||
return NORTH|WEST
|
||||
|
||||
//returns the north-zero clockwise angle in degrees, given a direction
|
||||
|
||||
/proc/dir2angle(var/D)
|
||||
//writepanic("[__FILE__].[__LINE__] (no type)([usr ? usr.ckey : ""]) \\/proc/dir2angle() called tick#: [world.time]")
|
||||
switch(D)
|
||||
if(NORTH) return 0
|
||||
if(SOUTH) return 180
|
||||
if(EAST) return 90
|
||||
if(WEST) return 270
|
||||
if(NORTHEAST) return 45
|
||||
if(SOUTHEAST) return 135
|
||||
if(NORTHWEST) return 315
|
||||
if(SOUTHWEST) return 225
|
||||
else return null
|
||||
|
||||
//Returns the angle in english
|
||||
/proc/angle2text(var/degree)
|
||||
//writepanic("[__FILE__].[__LINE__] (no type)([usr ? usr.ckey : ""]) \\/proc/angle2text() called tick#: [world.time]")
|
||||
return dir2text(angle2dir(degree))
|
||||
|
||||
//Converts a blend_mode constant to one acceptable to icon.Blend()
|
||||
/proc/blendMode2iconMode(blend_mode)
|
||||
//writepanic("[__FILE__].[__LINE__] (no type)([usr ? usr.ckey : ""]) \\/proc/blendMode2iconMode() called tick#: [world.time]")
|
||||
switch(blend_mode)
|
||||
if(BLEND_MULTIPLY) return ICON_MULTIPLY
|
||||
if(BLEND_ADD) return ICON_ADD
|
||||
if(BLEND_SUBTRACT) return ICON_SUBTRACT
|
||||
else return ICON_OVERLAY
|
||||
|
||||
//Converts a rights bitfield into a string
|
||||
/proc/rights2text(rights,seperator="")
|
||||
//writepanic("[__FILE__].[__LINE__] (no type)([usr ? usr.ckey : ""]) \\/proc/rights2text() called tick#: [world.time]")
|
||||
if(rights & R_BUILDMODE) . += "[seperator]+BUILDMODE"
|
||||
if(rights & R_ADMIN) . += "[seperator]+ADMIN"
|
||||
if(rights & R_BAN) . += "[seperator]+BAN"
|
||||
if(rights & R_FUN) . += "[seperator]+FUN"
|
||||
if(rights & R_SERVER) . += "[seperator]+SERVER"
|
||||
if(rights & R_DEBUG) . += "[seperator]+DEBUG"
|
||||
if(rights & R_POSSESS) . += "[seperator]+POSSESS"
|
||||
if(rights & R_PERMISSIONS) . += "[seperator]+PERMISSIONS"
|
||||
if(rights & R_STEALTH) . += "[seperator]+STEALTH"
|
||||
if(rights & R_REJUVINATE) . += "[seperator]+REJUVINATE"
|
||||
if(rights & R_VAREDIT) . += "[seperator]+VAREDIT"
|
||||
if(rights & R_SOUNDS) . += "[seperator]+SOUND"
|
||||
if(rights & R_SPAWN) . += "[seperator]+SPAWN"
|
||||
if(rights & R_MOD) . += "[seperator]+MODERATOR"
|
||||
if(rights & R_ADMINBUS) . += "[seperator]+ADMINBUS"
|
||||
return .
|
||||
|
||||
/proc/ui_style2icon(ui_style)
|
||||
//writepanic("[__FILE__].[__LINE__] (no type)([usr ? usr.ckey : ""]) \\/proc/ui_style2icon() called tick#: [world.time]")
|
||||
switch(ui_style)
|
||||
if("old") return 'icons/mob/screen1_old.dmi'
|
||||
if("Orange") return 'icons/mob/screen1_Orange.dmi'
|
||||
else return 'icons/mob/screen1_Midnight.dmi'
|
||||
|
||||
/proc/num2septext(var/theNum, var/sigFig = 7,var/sep=",") // default sigFig (1,000,000)
|
||||
//writepanic("[__FILE__].[__LINE__] (no type)([usr ? usr.ckey : ""]) \\/proc/num2septext() called tick#: [world.time]")
|
||||
var/finalNum = num2text(theNum, sigFig)
|
||||
|
||||
// Start from the end, or from the decimal point
|
||||
var/end = findtextEx(finalNum, ".") || length(finalNum) + 1
|
||||
|
||||
// Moving towards start of string, insert comma every 3 characters
|
||||
for(var/pos = end - 3, pos > 1, pos -= 3)
|
||||
finalNum = copytext(finalNum, 1, pos) + sep + copytext(finalNum, pos)
|
||||
|
||||
/*
|
||||
* Holds procs designed to change one type of value, into another.
|
||||
* Contains:
|
||||
* text2list & list2text
|
||||
* file2list
|
||||
* angle2dir
|
||||
* angle2text
|
||||
* worldtime2text
|
||||
*/
|
||||
|
||||
// Concatenates a list of strings into a single string. A seperator may optionally be provided.
|
||||
/proc/list2text(list/ls, sep)
|
||||
if(ls && ls.len <= 1) // Early-out code for empty or singleton lists.
|
||||
return (ls && ls.len) ? ls[1] : ""
|
||||
|
||||
var/l = ls.len // Made local for sanic speed.
|
||||
var/i = 0 // Incremented every time a list index is accessed.
|
||||
|
||||
if(sep != null)
|
||||
// Macros expand to long argument lists like so: sep, ls[++i], sep, ls[++i], sep, ls[++i], etc...
|
||||
#define S1 sep, ls[++i]
|
||||
#define S4 S1, S1, S1, S1
|
||||
#define S16 S4, S4, S4, S4
|
||||
#define S64 S16, S16, S16, S16
|
||||
|
||||
. = "[ls[++i]]" // Make sure the initial element is converted to text.
|
||||
|
||||
// Having the small concatenations come before the large ones boosted speed by an average of at least 5%.
|
||||
if(l-1 & 0x01) // 'i' will always be 1 here.
|
||||
. = text("[][][]", ., S1) // Append 1 element if the remaining elements are not a multiple of 2.
|
||||
if(l-i & 0x02)
|
||||
. = text("[][][][][]", ., S1, S1) // Append 2 elements if the remaining elements are not a multiple of 4.
|
||||
if(l-i & 0x04)
|
||||
. = text("[][][][][][][][][]", ., S4) // And so on....
|
||||
if(l-i & 0x08)
|
||||
. = text("[][][][][][][][][][][][][][][][][]", ., S4, S4)
|
||||
if(l-i & 0x10)
|
||||
. = text("[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]", ., S16)
|
||||
if(l-i & 0x20)
|
||||
. = text("[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
|
||||
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]", ., S16, S16)
|
||||
if(l-i & 0x40)
|
||||
. = text("[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
|
||||
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
|
||||
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
|
||||
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]", ., S64)
|
||||
while(l > i) // Chomp through the rest of the list, 128 elements at a time.
|
||||
. = text("[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
|
||||
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
|
||||
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
|
||||
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
|
||||
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
|
||||
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
|
||||
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
|
||||
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]", ., S64, S64)
|
||||
|
||||
#undef S64
|
||||
#undef S16
|
||||
#undef S4
|
||||
#undef S1
|
||||
|
||||
else
|
||||
// Macros expand to long argument lists like so: ls[++i], ls[++i], ls[++i], etc...
|
||||
#define S1 ls[++i]
|
||||
#define S4 S1, S1, S1, S1
|
||||
#define S16 S4, S4, S4, S4
|
||||
#define S64 S16, S16, S16, S16
|
||||
|
||||
. = "[ls[++i]]" // Make sure the initial element is converted to text.
|
||||
|
||||
if(l-1 & 0x01) // 'i' will always be 1 here.
|
||||
. += "[S1]" // Append 1 element if the remaining elements are not a multiple of 2.
|
||||
if(l-i & 0x02)
|
||||
. = text("[][][]", ., S1, S1) // Append 2 elements if the remaining elements are not a multiple of 4.
|
||||
if(l-i & 0x04)
|
||||
. = text("[][][][][]", ., S4) // And so on...
|
||||
if(l-i & 0x08)
|
||||
. = text("[][][][][][][][][]", ., S4, S4)
|
||||
if(l-i & 0x10)
|
||||
. = text("[][][][][][][][][][][][][][][][][]", ., S16)
|
||||
if(l-i & 0x20)
|
||||
. = text("[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]", ., S16, S16)
|
||||
if(l-i & 0x40)
|
||||
. = text("[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
|
||||
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]", ., S64)
|
||||
while(l > i) // Chomp through the rest of the list, 128 elements at a time.
|
||||
. = text("[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
|
||||
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
|
||||
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]\
|
||||
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]", ., S64, S64)
|
||||
|
||||
#undef S64
|
||||
#undef S16
|
||||
#undef S4
|
||||
#undef S1
|
||||
|
||||
//slower then list2text, but correctly processes associative lists.
|
||||
proc/tg_list2text(list/list, glue = ",")
|
||||
//writepanic("[__FILE__].[__LINE__] \\/proc/tg_list2text() called tick#: [world.time]")
|
||||
if(!istype(list) || !list.len)
|
||||
return
|
||||
for(var/i=1 to list.len)
|
||||
. += (i != 1 ? glue : null)+ \
|
||||
(!isnull(list["[list[i]]"]) ? \
|
||||
"[list["[list[i]]"]]" : \
|
||||
"[list[i]]")
|
||||
return .
|
||||
|
||||
// Yeah, so list2text doesn't do assoc values, tg_list2text only does assoc values if they're available, and NTSL needs to stay relatively simple.
|
||||
/proc/vg_list2text(var/list/list, var/glue = ", ", var/assoc_glue = " = ")
|
||||
if(!islist(list) || !list.len)
|
||||
return // Valid lists you nerd.
|
||||
|
||||
for(var/i = 1 to list.len)
|
||||
if(isnull(list[list[i]]))
|
||||
. += "[list[i]][glue]"
|
||||
else
|
||||
. += "[list[i]][assoc_glue][list[list[i]]][glue]"
|
||||
|
||||
. = copytext(., 1, length(.) - length(glue) + 1) // Shush. (cut out the glue which is added to the end.)
|
||||
|
||||
// HTTP GET URL query builder thing.
|
||||
// list("a"="b","c"="d") -> ?a=b&c=d
|
||||
/proc/buildurlquery(list/list,sep="&")
|
||||
//writepanic("[__FILE__].[__LINE__] (no type)([usr ? usr.ckey : ""]) \\/proc/buildurlquery() called tick#: [world.time]")
|
||||
if(!istype(list) || !list.len)
|
||||
return
|
||||
var/output
|
||||
var/i=0
|
||||
var/start
|
||||
var/qmark="?" // God damnit byond
|
||||
for(var/key in list)
|
||||
start = i ? sep : qmark
|
||||
output += "[start][key]=[list[key]]"
|
||||
i++
|
||||
return output
|
||||
|
||||
//Converts a string into a list by splitting the string at each delimiter found. (discarding the seperator)
|
||||
/proc/text2list(text, delimiter = "\n")
|
||||
//writepanic("[__FILE__].[__LINE__] (no type)([usr ? usr.ckey : ""]) \\/proc/text2list() called tick#: [world.time]")
|
||||
var/delim_len = length(delimiter)
|
||||
if(delim_len < 1) return list(text)
|
||||
. = list()
|
||||
var/last_found = 1
|
||||
var/found
|
||||
do
|
||||
found = findtext(text, delimiter, last_found, 0)
|
||||
. += copytext(text, last_found, found)
|
||||
last_found = found + delim_len
|
||||
while(found)
|
||||
|
||||
//Case Sensitive!
|
||||
/proc/text2listEx(text, delimiter="\n")
|
||||
//writepanic("[__FILE__].[__LINE__] (no type)([usr ? usr.ckey : ""]) \\/proc/text2listEx() called tick#: [world.time]")
|
||||
var/delim_len = length(delimiter)
|
||||
if(delim_len < 1) return list(text)
|
||||
. = list()
|
||||
var/last_found = 1
|
||||
var/found
|
||||
do
|
||||
found = findtextEx(text, delimiter, last_found, 0)
|
||||
. += copytext(text, last_found, found)
|
||||
last_found = found + delim_len
|
||||
while(found)
|
||||
|
||||
//Splits the text of a file at seperator and returns them in a list.
|
||||
/proc/file2list(filename, seperator="\n")
|
||||
//writepanic("[__FILE__].[__LINE__] (no type)([usr ? usr.ckey : ""]) \\/proc/file2list() called tick#: [world.time]")
|
||||
return text2list(return_file_text(filename),seperator)
|
||||
|
||||
|
||||
//Turns a direction into text
|
||||
|
||||
/proc/dir2text(direction)
|
||||
//writepanic("[__FILE__].[__LINE__] (no type)([usr ? usr.ckey : ""]) \\/proc/dir2text() called tick#: [world.time]")
|
||||
switch(direction)
|
||||
if(1.0)
|
||||
return "north"
|
||||
if(2.0)
|
||||
return "south"
|
||||
if(4.0)
|
||||
return "east"
|
||||
if(8.0)
|
||||
return "west"
|
||||
if(5.0)
|
||||
return "northeast"
|
||||
if(6.0)
|
||||
return "southeast"
|
||||
if(9.0)
|
||||
return "northwest"
|
||||
if(10.0)
|
||||
return "southwest"
|
||||
else
|
||||
return
|
||||
|
||||
//Turns text into proper directions
|
||||
/proc/text2dir(direction)
|
||||
//writepanic("[__FILE__].[__LINE__] (no type)([usr ? usr.ckey : ""]) \\/proc/text2dir() called tick#: [world.time]")
|
||||
switch(uppertext(direction))
|
||||
if("NORTH")
|
||||
return 1
|
||||
if("SOUTH")
|
||||
return 2
|
||||
if("EAST")
|
||||
return 4
|
||||
if("WEST")
|
||||
return 8
|
||||
if("NORTHEAST")
|
||||
return 5
|
||||
if("NORTHWEST")
|
||||
return 9
|
||||
if("SOUTHEAST")
|
||||
return 6
|
||||
if("SOUTHWEST")
|
||||
return 10
|
||||
else
|
||||
return
|
||||
|
||||
//Converts an angle (degrees) into an ss13 direction
|
||||
/proc/angle2dir(var/degree)
|
||||
//writepanic("[__FILE__].[__LINE__] (no type)([usr ? usr.ckey : ""]) \\/proc/angle2dir() called tick#: [world.time]")
|
||||
degree = ((degree+22.5)%365)
|
||||
if(degree < 45) return NORTH
|
||||
if(degree < 90) return NORTHEAST
|
||||
if(degree < 135) return EAST
|
||||
if(degree < 180) return SOUTHEAST
|
||||
if(degree < 225) return SOUTH
|
||||
if(degree < 270) return SOUTHWEST
|
||||
if(degree < 315) return WEST
|
||||
return NORTH|WEST
|
||||
|
||||
//returns the north-zero clockwise angle in degrees, given a direction
|
||||
|
||||
/proc/dir2angle(var/D)
|
||||
//writepanic("[__FILE__].[__LINE__] (no type)([usr ? usr.ckey : ""]) \\/proc/dir2angle() called tick#: [world.time]")
|
||||
switch(D)
|
||||
if(NORTH) return 0
|
||||
if(SOUTH) return 180
|
||||
if(EAST) return 90
|
||||
if(WEST) return 270
|
||||
if(NORTHEAST) return 45
|
||||
if(SOUTHEAST) return 135
|
||||
if(NORTHWEST) return 315
|
||||
if(SOUTHWEST) return 225
|
||||
else return null
|
||||
|
||||
//Returns the angle in english
|
||||
/proc/angle2text(var/degree)
|
||||
//writepanic("[__FILE__].[__LINE__] (no type)([usr ? usr.ckey : ""]) \\/proc/angle2text() called tick#: [world.time]")
|
||||
return dir2text(angle2dir(degree))
|
||||
|
||||
//Converts a blend_mode constant to one acceptable to icon.Blend()
|
||||
/proc/blendMode2iconMode(blend_mode)
|
||||
//writepanic("[__FILE__].[__LINE__] (no type)([usr ? usr.ckey : ""]) \\/proc/blendMode2iconMode() called tick#: [world.time]")
|
||||
switch(blend_mode)
|
||||
if(BLEND_MULTIPLY) return ICON_MULTIPLY
|
||||
if(BLEND_ADD) return ICON_ADD
|
||||
if(BLEND_SUBTRACT) return ICON_SUBTRACT
|
||||
else return ICON_OVERLAY
|
||||
|
||||
//Converts a rights bitfield into a string
|
||||
/proc/rights2text(rights,seperator="")
|
||||
//writepanic("[__FILE__].[__LINE__] (no type)([usr ? usr.ckey : ""]) \\/proc/rights2text() called tick#: [world.time]")
|
||||
if(rights & R_BUILDMODE) . += "[seperator]+BUILDMODE"
|
||||
if(rights & R_ADMIN) . += "[seperator]+ADMIN"
|
||||
if(rights & R_BAN) . += "[seperator]+BAN"
|
||||
if(rights & R_FUN) . += "[seperator]+FUN"
|
||||
if(rights & R_SERVER) . += "[seperator]+SERVER"
|
||||
if(rights & R_DEBUG) . += "[seperator]+DEBUG"
|
||||
if(rights & R_POSSESS) . += "[seperator]+POSSESS"
|
||||
if(rights & R_PERMISSIONS) . += "[seperator]+PERMISSIONS"
|
||||
if(rights & R_STEALTH) . += "[seperator]+STEALTH"
|
||||
if(rights & R_REJUVINATE) . += "[seperator]+REJUVINATE"
|
||||
if(rights & R_VAREDIT) . += "[seperator]+VAREDIT"
|
||||
if(rights & R_SOUNDS) . += "[seperator]+SOUND"
|
||||
if(rights & R_SPAWN) . += "[seperator]+SPAWN"
|
||||
if(rights & R_MOD) . += "[seperator]+MODERATOR"
|
||||
if(rights & R_ADMINBUS) . += "[seperator]+ADMINBUS"
|
||||
return .
|
||||
|
||||
/proc/ui_style2icon(ui_style)
|
||||
//writepanic("[__FILE__].[__LINE__] (no type)([usr ? usr.ckey : ""]) \\/proc/ui_style2icon() called tick#: [world.time]")
|
||||
switch(ui_style)
|
||||
if("old") return 'icons/mob/screen1_old.dmi'
|
||||
if("Orange") return 'icons/mob/screen1_Orange.dmi'
|
||||
else return 'icons/mob/screen1_Midnight.dmi'
|
||||
|
||||
/proc/num2septext(var/theNum, var/sigFig = 7,var/sep=",") // default sigFig (1,000,000)
|
||||
//writepanic("[__FILE__].[__LINE__] (no type)([usr ? usr.ckey : ""]) \\/proc/num2septext() called tick#: [world.time]")
|
||||
var/finalNum = num2text(theNum, sigFig)
|
||||
|
||||
// Start from the end, or from the decimal point
|
||||
var/end = findtextEx(finalNum, ".") || length(finalNum) + 1
|
||||
|
||||
// Moving towards start of string, insert comma every 3 characters
|
||||
for(var/pos = end - 3, pos > 1, pos -= 3)
|
||||
finalNum = copytext(finalNum, 1, pos) + sep + copytext(finalNum, pos)
|
||||
|
||||
return finalNum
|
||||
Reference in New Issue
Block a user