[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
+90 -12
View File
@@ -177,18 +177,93 @@ GLOBAL_DATUM_INIT(iconCache, /savefile, new("data/iconCache.sav")) //Cache of ic
var/list/partial = splittext(iconData, "{")
return replacetext(copytext(partial[2], 3, -5), "\n", "")
/proc/bicon(thing)
/proc/icon2html(thing, target, icon_state, dir, frame = 1, moving)
if (!thing)
return
var/static/datum/callback/CB = CALLBACK(GLOBAL_PROC, .proc/send_asset)
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
debug_usr("start")
if (!isicon(I))
debug_usr("not icon")
if (isfile(thing)) //special snowflake
debug_usr("file")
var/name = sanitize_filename("bicon.[thing]")
debug_usr("file:[name]")
register_asset(name, thing)
var/list/callbacks
var/list/callback_args = list()
for (var/thing2 in targets)
callbacks += CB
callback_args[++callback_args.len] = list(thing2, name, TRUE)
callback_select(callbacks, callback_args, savereturns = FALSE)
return "<img class='icon misc' src=\"[url_encode(name)]\">"
debug_usr("not file")
var/atom/A
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.
debug_usr("human")
var/icon/temp = I
I = icon()
I.Insert(temp, dir = SOUTH)
dir = SOUTH
else
debug_usr("icon")
if (isnull(dir))
dir = SOUTH
if (isnull(icon_state))
icon_state = ""
I = icon(I, icon_state, dir, frame)
key = sanitize_filename("bicon.[md5(icon2base64(I))].[icon_state].[dir].png")
debug_usr("key:[key]")
register_asset(key, I)
var/list/callbacks = list()
var/list/callback_args = list()
for (var/thing2 in targets)
callbacks += CB
callback_args[++callback_args.len] = list(thing2, key, TRUE)
callback_select(callbacks, callback_args, savereturns = FALSE)
return "<img class='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_md5 = md5(I)
if (!bicon_cache[icon_md5]) // Doesn't exist yet, make it.
I = icon(I) //copy it
I.Scale(16,16) //scale it
bicon_cache[icon_md5] = icon2base64(thing) //base64 it
return "<img class='icon misc' src='data:image/png;base64,[bicon_cache[icon_md5]]'>"
var/icon_base64 = icon2base64(I)
if (I.Height() > world.icon_size || I.Width() > world.icon_size)
var/icon_md5 = md5(icon_base64)
debug_admins(icon_md5)
icon_base64 = bicon_cache[icon_md5]
if (!icon_base64) // Doesn't exist yet, make it.
I = icon(I)
I.Scale(world.icon_size, world.icon_size)
bicon_cache[icon_md5] = icon_base64 = icon2base64(I)
return "<img class='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
@@ -197,25 +272,28 @@ GLOBAL_DATUM_INIT(iconCache, /savefile, new("data/iconCache.sav")) //Cache of ic
if (!bicon_cache[key]) // Doesn't exist, make it.
var/icon/I = icon(A.icon, A.icon_state, SOUTH, 1)
I.Scale(16,16)
if (ishuman(thing)) // Shitty workaround for a BYOND issue.
var/icon/temp = I
I = icon()
I.Insert(temp, dir = SOUTH)
if (I.Height() > world.icon_size || I.Width() > world.icon_size)
I.Scale(world.icon_size, world.icon_size)
bicon_cache[key] = icon2base64(I, key)
return "<img class='icon [A.icon_state]' src='data:image/png;base64,[bicon_cache[key]]'>"
//Costlier version of bicon() that uses getFlatIcon() to account for overlays, underlays, etc. Use with extreme moderation, ESPECIALLY on mobs.
/proc/costly_bicon(thing)
//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 bicon(thing)
return icon2html(thing, target)
var/icon/I = getFlatIcon(thing)
return bicon(I)
return icon2html(I, target)
/proc/to_chat(target, message)
if(!target)
+137
View File
@@ -0,0 +1,137 @@
diff a/code/modules/goonchat/browserOutput.dm b/code/modules/goonchat/browserOutput.dm (rejected hunks)
@@ -166,135 +166,6 @@ GLOBAL_DATUM_INIT(iconCache, /savefile, new("data/iconCache.sav")) //Cache of ic
//Global chat procs
-//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)
- if (!thing)
- return
- var/static/datum/callback/CB = CALLBACK(GLOBAL_PROC, .proc/send_asset)
-
- 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
- debug_usr("start")
- if (!isicon(I))
- debug_usr("not icon")
- if (isfile(thing)) //special snowflake
- debug_usr("file")
- var/name = sanitize_filename("bicon.[thing]")
- debug_usr("file:[name]")
- register_asset(name, thing)
- var/list/callbacks
- var/list/callback_args = list()
- for (var/thing2 in targets)
- callbacks += CB
- callback_args[++callback_args.len] = list(thing2, name, TRUE)
- callback_select(callbacks, callback_args, savereturns = FALSE)
- return "<img class='icon misc' src=\"[url_encode(name)]\">"
- debug_usr("not file")
- var/atom/A
- 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.
- debug_usr("human")
- var/icon/temp = I
- I = icon()
- I.Insert(temp, dir = SOUTH)
- dir = SOUTH
- else
- debug_usr("icon")
- if (isnull(dir))
- dir = SOUTH
- if (isnull(icon_state))
- icon_state = ""
-
- I = icon(I, icon_state, dir, frame)
-
- key = sanitize_filename("bicon.[md5(icon2base64(I))].[icon_state].[dir].png")
- debug_usr("key:[key]")
- register_asset(key, I)
- var/list/callbacks = list()
- var/list/callback_args = list()
- for (var/thing2 in targets)
- callbacks += CB
- callback_args[++callback_args.len] = list(thing2, key, TRUE)
-
- callback_select(callbacks, callback_args, savereturns = FALSE)
- return "<img class='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)
- debug_admins(icon_md5)
- icon_base64 = bicon_cache[icon_md5]
- if (!icon_base64) // Doesn't exist yet, make it.
- I = icon(I)
- I.Scale(world.icon_size, world.icon_size)
- bicon_cache[icon_md5] = icon_base64 = icon2base64(I)
-
-
- return "<img class='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)
-
- if (I.Height() > world.icon_size || I.Width() > world.icon_size)
- I.Scale(world.icon_size, world.icon_size)
-
- bicon_cache[key] = icon2base64(I, key)
-
- return "<img class='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)
-
/proc/to_chat(target, message)
if(!target)
return
@@ -28,10 +28,14 @@ img {
margin: 0;
padding: 0;
line-height: 1;
-ms-interpolation-mode: nearest-neighbor;
image-rendering: pixelated;
}
img.icon {
width: 16px;
height: 16px;
height: 1em;
min-height: 16px;
width: auto;
vertical-align: bottom;
}
a {color: #0000ff;}
@@ -357,7 +361,6 @@ h1.alert, h2.alert {color: #000000;}
.clown {color: #FF69Bf; font-size: 24px; font-family: "Comic Sans MS", cursive, sans-serif; font-weight: bold;}
.his_grace {color: #15D512; font-family: "Courier New", cursive, sans-serif; font-style: italic;}
BIG IMG.icon {width: 32px; height: 32px;}
.memo {color: #638500; text-align: center;}
.memoedit {text-align: center; font-size: 16px;}
@@ -29,6 +29,8 @@ var opts = {
'messageLimit': 2053, //A limit...for the messages...
'scrollSnapTolerance': 10, //If within x pixels of bottom
'clickTolerance': 10, //Keep focus if outside x pixels of mousedown position on mouseup
'imageRetryDelay': 50, //how long between attempts to reload images (in ms)
'imageRetryLimit': 50, //how many attempts should we make?
'popups': 0, //Amount of popups opened ever
'wasd': false, //Is the user in wasd mode?
'chatMode': 'default', //The mode the chat is in
@@ -146,6 +148,23 @@ function highlightTerms(el) {
el.innerHTML = newText;
}
}
function iconError(E) {
var that = this;
setTimeout(function() {
var attempts = $(that).data('reload_attempts');
if (typeof attempts === 'undefined' || !attempts) {
attempts = 1;
}
if (attempts > opts.imageRetryLimit)
return;
var src = that.src;
that.src = null;
that.src = src+'#'+attempts;
$(that).data('reload_attempts', ++attempts);
}, opts.imageRetryDelay);
}
//Send a message to the client
function output(message, flag) {
if (typeof message === 'undefined') {
@@ -271,7 +290,7 @@ function output(message, flag) {
entry.innerHTML = message.trim();
$messages[0].appendChild(entry);
$(entry).find("img.icon").error(iconError);
//Actually do the snap
if (!filteredOut && atBottom) {
$('body,html').scrollTop($messages.outerHeight());
@@ -861,7 +880,11 @@ $(function() {
$messages.empty();
opts.messageCount = 0;
});
$('img.icon').error(iconError);
/*****************************************
*