[ready]Makes bIcon better

This commit is contained in:
CitadelStationBot
2017-08-13 17:41:12 -05:00
parent 6d72705ff5
commit bd35823012
68 changed files with 644 additions and 180 deletions
+108 -1
View File
@@ -167,7 +167,7 @@ mob
Output_Icon()
set name = "2. Output Icon"
to_chat(src, "Icon is: [bicon(getFlatIcon(src))]")
to_chat(src, "Icon is: [icon2base64html(getFlatIcon(src))]")
Label_Icon()
set name = "3. Label Icon"
@@ -993,3 +993,110 @@ GLOBAL_LIST_EMPTY(friendly_animal_types)
#undef FROZEN_RED_COLOR
#undef FROZEN_GREEN_COLOR
#undef FROZEN_BLUE_COLOR
//Converts an icon to base64. Operates by putting the icon in the iconCache savefile,
// exporting it as text, and then parsing the base64 from that.
// (This relies on byond automatically storing icons in savefiles as base64)
/proc/icon2base64(icon/icon, iconKey = "misc")
if (!isicon(icon))
return FALSE
WRITE_FILE(GLOB.iconCache[iconKey], icon)
var/iconData = GLOB.iconCache.ExportText(iconKey)
var/list/partial = splittext(iconData, "{")
return replacetext(copytext(partial[2], 3, -5), "\n", "")
/proc/icon2html(thing, target, icon_state, dir, frame = 1, moving = FALSE)
if (!thing)
return
var/key
var/icon/I = thing
if (!target)
return
if (target == world)
target = GLOB.clients
var/list/targets
if (!islist(target))
targets = list(target)
else
targets = target
if (!targets.len)
return
if (!isicon(I))
if (isfile(thing)) //special snowflake
var/name = sanitize_filename("[generate_asset_name(thing)].png")
register_asset(name, thing)
for (var/thing2 in targets)
send_asset(thing2, key, FALSE)
return "<img class='icon icon-misc' src=\"[url_encode(name)]\">"
var/atom/A = thing
if (isnull(dir))
dir = A.dir
if (isnull(icon_state))
icon_state = A.icon_state
I = A.icon
if (ishuman(thing)) // Shitty workaround for a BYOND issue.
var/icon/temp = I
I = icon()
I.Insert(temp, dir = SOUTH)
dir = SOUTH
else
if (isnull(dir))
dir = SOUTH
if (isnull(icon_state))
icon_state = ""
I = icon(I, icon_state, dir, frame, moving)
key = "[generate_asset_name(I)].png"
register_asset(key, I)
for (var/thing2 in targets)
send_asset(thing2, key, FALSE)
return "<img class='icon icon-[icon_state]' src=\"[url_encode(key)]\">"
/proc/icon2base64html(thing)
if (!thing)
return
var/static/list/bicon_cache = list()
if (isicon(thing))
var/icon/I = thing
var/icon_base64 = icon2base64(I)
if (I.Height() > world.icon_size || I.Width() > world.icon_size)
var/icon_md5 = md5(icon_base64)
icon_base64 = bicon_cache[icon_md5]
if (!icon_base64) // Doesn't exist yet, make it.
bicon_cache[icon_md5] = icon_base64 = icon2base64(I)
return "<img class='icon icon-misc' src='data:image/png;base64,[icon_base64]'>"
// Either an atom or somebody fucked up and is gonna get a runtime, which I'm fine with.
var/atom/A = thing
var/key = "[istype(A.icon, /icon) ? "\ref[A.icon]" : A.icon]:[A.icon_state]"
if (!bicon_cache[key]) // Doesn't exist, make it.
var/icon/I = icon(A.icon, A.icon_state, SOUTH, 1)
if (ishuman(thing)) // Shitty workaround for a BYOND issue.
var/icon/temp = I
I = icon()
I.Insert(temp, dir = SOUTH)
bicon_cache[key] = icon2base64(I, key)
return "<img class='icon icon-[A.icon_state]' src='data:image/png;base64,[bicon_cache[key]]'>"
//Costlier version of icon2html() that uses getFlatIcon() to account for overlays, underlays, etc. Use with extreme moderation, ESPECIALLY on mobs.
/proc/costly_icon2html(thing, target)
if (!thing)
return
if (isicon(thing))
return icon2html(thing, target)
var/icon/I = getFlatIcon(thing)
return icon2html(I, target)
+4 -1
View File
@@ -45,6 +45,9 @@
index = findtext(t, char, index+1)
return t
/proc/sanitize_filename(t)
return sanitize_simple(t, list("\n"="", "\t"="", "/"="", "\\"="", "?"="", "%"="", "*"="", ":"="", "|"="", "\""="", "<"="", ">"=""))
//Runs byond's sanitization proc along-side sanitize_simple
/proc/sanitize(t,list/repl_chars = null)
return html_encode(sanitize_simple(t,repl_chars))
@@ -560,7 +563,7 @@ GLOBAL_LIST_INIT(binary, list("0","1"))
var/next_backslash = findtext(string, "\\")
if(!next_backslash)
return string
var/leng = length(string)
var/next_space = findtext(string, " ", next_backslash + 1)
+2 -2
View File
@@ -845,11 +845,11 @@ GLOBAL_LIST_INIT(WALLITEMS_INVERSE, typecacheof(list(
/obj/proc/atmosanalyzer_scan(datum/gas_mixture/air_contents, mob/user, obj/target = src)
var/obj/icon = target
user.visible_message("[user] has used the analyzer on [bicon(icon)] [target].", "<span class='notice'>You use the analyzer on [bicon(icon)] [target].</span>")
user.visible_message("[user] has used the analyzer on [icon2html(icon, viewers(src))] [target].", "<span class='notice'>You use the analyzer on [icon2html(icon, user)] [target].</span>")
var/pressure = air_contents.return_pressure()
var/total_moles = air_contents.total_moles()
to_chat(user, "<span class='notice'>Results of analysis of [bicon(icon)] [target].</span>")
to_chat(user, "<span class='notice'>Results of analysis of [icon2html(icon, user)] [target].</span>")
if(total_moles>0)
to_chat(user, "<span class='notice'>Pressure: [round(pressure,0.1)] kPa</span>")