#define VV_HTML_ENCODE(thing) ( sanitize ? html_encode(thing) : thing )
/// Get displayed variable in VV variable list
/proc/debug_variable(name, value, level, datum/D, sanitize = TRUE) //if D is a list, name will be index, and value will be assoc value.
var/header
if(D)
if(islist(D))
var/index = name
if (value)
name = D[name] //name is really the index until this line
else
value = D[name]
header = "
([VV_HREF_TARGET_1V(D, VV_HK_LIST_EDIT, "E", index)]) ([VV_HREF_TARGET_1V(D, VV_HK_LIST_CHANGE, "C", index)]) ([VV_HREF_TARGET_1V(D, VV_HK_LIST_REMOVE, "-", index)]) "
else
header = "([VV_HREF_TARGET_1V(D, VV_HK_BASIC_EDIT, "E", name)]) ([VV_HREF_TARGET_1V(D, VV_HK_BASIC_CHANGE, "C", name)]) ([VV_HREF_TARGET_1V(D, VV_HK_BASIC_MASSEDIT, "M", name)]) "
else
header = ""
var/item
var/name_part = VV_HTML_ENCODE(name)
if(level > 0 || islist(D)) //handling keys in assoc lists
if(istype(name,/datum))
name_part = "[VV_HTML_ENCODE(name)] [REF(name)]"
else if(islist(name))
var/list/L = name
name_part = " /list ([length(L)]) [REF(name)]"
if (isnull(value))
item = "[name_part] = null"
else if (istext(value))
item = "[name_part] = \"[VV_HTML_ENCODE(value)]\""
else if (isicon(value))
#ifdef VARSICON
var/icon/I = icon(value)
var/rnd = rand(1,10000)
var/rname = "tmp[REF(I)][rnd].png"
usr << browse_rsc(I, rname)
item = "[name_part] = ([value])
"
#else
item = "[name_part] = /icon ([value])"
#endif
else if (isfile(value))
item = "[name_part] = '[value]'"
else if(istype(value,/matrix)) // Needs to be before datum
var/matrix/M = value
item = {"[name_part] =
| |
| [M.a] | [M.d] | 0 |
| [M.b] | [M.e] | 0 |
| [M.c] | [M.f] | 1 |
| |
"} //TODO link to modify_transform wrapper for all matrices
else if (istype(value, /datum))
var/datum/DV = value
if ("[DV]" != "[DV.type]") //if the thing as a name var, lets use it.
item = "[name_part] = [DV] [DV.type] [REF(value)]"
else
item = "[name_part] = [DV.type] [REF(value)]"
else if (islist(value))
var/list/L = value
var/list/items = list()
if (L.len > 0 && !(name == "underlays" || name == "overlays" || L.len > (IS_NORMAL_LIST(L) ? VV_NORMAL_LIST_NO_EXPAND_THRESHOLD : VV_SPECIAL_LIST_NO_EXPAND_THRESHOLD)))
for (var/i in 1 to L.len)
var/key = L[i]
var/val
if (IS_NORMAL_LIST(L) && !isnum(key))
val = L[key]
if (isnull(val)) // we still want to display non-null false values, such as 0 or ""
val = key
key = i
items += debug_variable(key, val, level + 1, sanitize = sanitize)
item = "[name_part] = /list ([L.len])"
else
item = "[name_part] = /list ([L.len])"
else if (name in GLOB.bitfields)
var/list/flags = list()
for (var/i in GLOB.bitfields[name])
if (value & GLOB.bitfields[name][i])
flags += i
item = "[name_part] = [VV_HTML_ENCODE(jointext(flags, ", "))]"
else
item = "[name_part] = [VV_HTML_ENCODE(value)]"
return "[header][item]"
#undef VV_HTML_ENCODE