Advertisement
Guest User

Untitled

a guest
Apr 14th, 2017
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var currentRAF = null;
  2. var pendingLogs = [];
  3. var pendingsByType = {
  4.     Loot: [],
  5.     Unlocks: [],
  6.     Combat: [],
  7.     Notices: []
  8. }
  9. function message(messageString, type, lootIcon, extraClass, extraTag, htmlPrefix) {
  10. if (extraTag && typeof game.global.messages[type][extraTag] !== 'undefined' && !game.global.messages[type][extraTag]) return;
  11.     var log = document.getElementById("log");
  12.     var displayType = (game.global.messages[type].enabled) ? "block" : "none";
  13.     var prefix = "";
  14.     var addId = "";
  15.     if (messageString == "Game Saved!" || extraClass == 'save') {
  16.         addId = " id='saveGame'";
  17.         if (document.getElementById('saveGame') !== null){
  18.             log.removeChild(document.getElementById('saveGame'));
  19.         }
  20.     }
  21.     if (game.options.menu.timestamps.enabled){
  22.         messageString = ((game.options.menu.timestamps.enabled == 1) ? getCurrentTime() : updatePortalTimer(true)) + " " + messageString;
  23.     }
  24.     if (!htmlPrefix){
  25.         if (lootIcon && lootIcon.charAt(0) == "*") {
  26.             lootIcon = lootIcon.replace("*", "");
  27.             prefix =  "icomoon icon-";
  28.         }
  29.         else prefix = "glyphicon glyphicon-";
  30.         if (type == "Story") messageString = "<span class='glyphicon glyphicon-star'></span> " + messageString;
  31.         if (type == "Combat") messageString = "<span class='glyphicon glyphicon-flag'></span> " + messageString;
  32.         if (type == "Loot" && lootIcon) messageString = "<span class='" + prefix + lootIcon + "'></span> " + messageString;
  33.         if (type == "Notices"){
  34.             messageString = "<span class='glyphicon glyphicon-off'></span> " + messageString;
  35.         }
  36.     }
  37.     else messageString = htmlPrefix + " " + messageString;
  38.     var messageHTML = "<span" + addId + " class='" + type + "Message message" +  " " + extraClass + "' style='display: " + displayType + "'>" + messageString + "</span>";
  39.     pendingLogs.push(messageHTML);
  40.     if (type != "Story"){
  41.         var pendingArray = pendingsByType[type];
  42.         if (!pendingArray) console.log(type);
  43.         pendingArray.push(pendingLogs.length - 1);
  44.         if (pendingArray.length > 10){
  45.             pendingLogs.splice(pendingArray[0], 1)
  46.             pendingArray.splice(0, 1);
  47.         }
  48.     }
  49.     if (currentRAF != null) cancelAnimationFrame(currentRAF);
  50.     currentRAF = requestAnimationFrame(function() {
  51.         var needsScroll = ((log.scrollTop + 10) > (log.scrollHeight - log.clientHeight));
  52.         var pendingMessages = pendingLogs.join('');
  53.         log.innerHTML += pendingMessages;
  54.         pendingLogs = [];
  55.         for (var item in pendingsByType){
  56.             if (pendingsByType[item].length)
  57.                 trimMessages(item);
  58.             pendingsByType[item] = [];
  59.         }
  60.         if (needsScroll) log.scrollTop = log.scrollHeight;
  61.     });
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement