From 0f5291b41c3991a4950556478ed686c37045220f Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Wed, 2 Dec 2020 21:53:19 +0100 Subject: [PATCH 001/106] Cleaned CM.Disp.FormatTime --- CookieMonster.js | 65 +++++++++++++++--------------------------------- src/Disp.js | 65 +++++++++++++++--------------------------------- 2 files changed, 40 insertions(+), 90 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index d1f554e..a2f0dbd 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -844,55 +844,30 @@ CM.Data.ValCookies = ['Pure heart biscuits', 'Ardent heart biscuits', 'Sour hear * Disp * ********/ -CM.Disp.FormatTime = function(time, format) { +// General functions to format or beautify strings + +CM.Disp.FormatTime = function(time, longFormat) { if (time == Infinity) return time; + time = Math.ceil(time); + var y = Math.floor(time / 31557600); + var d = Math.floor(time % 31557600 / 86400); + var h = Math.floor(time % 86400 / 3600); + var m = Math.floor(time % 3600 / 60); + var s = Math.floor(time % 60); + var str = ''; if (CM.Config.TimeFormat) { if (time > 3155760000) return 'XX:XX:XX:XX:XX'; - time = Math.ceil(time); - var y = Math.floor(time / 31557600); - var d = Math.floor(time % 31557600 / 86400); - var h = Math.floor(time % 86400 / 3600); - var m = Math.floor(time % 3600 / 60); - var s = Math.floor(time % 60); - var str = ''; - if (y < 10) { - str += '0'; - } - str += y + ':'; - if (d < 10) { - str += '0'; - } - str += d + ':'; - if (h < 10) { - str += '0'; - } - str += h + ':'; - if (m < 10) { - str += '0'; - } - str += m + ':'; - if (s < 10) { - str += '0'; - } - str += s; + str += (y < 10 ? '0' : '') + y + ':'; + str += (d < 10 ? '0' : '') + d + ':'; + str += (h < 10 ? '0' : '') + h + ':'; + str += (m < 10 ? '0' : '') + m + ':'; + str += (s < 10 ? '0' : '') + s + ':'; } else { - if (time > 777600000) return format ? 'Over 9000 days!' : '>9000d'; - time = Math.ceil(time); - var d = Math.floor(time / 86400); - var h = Math.floor(time % 86400 / 3600); - var m = Math.floor(time % 3600 / 60); - var s = Math.floor(time % 60); - var str = ''; - if (d > 0) { - str += d + (format ? (d == 1 ? ' day' : ' days') : 'd') + ', '; - } - if (str.length > 0 || h > 0) { - str += h + (format ? (h == 1 ? ' hour' : ' hours') : 'h') + ', '; - } - if (str.length > 0 || m > 0) { - str += m + (format ? (m == 1 ? ' minute' : ' minutes') : 'm') + ', '; - } - str += s + (format ? (s == 1 ? ' second' : ' seconds') : 's'); + if (time > 777600000) return longFormat ? 'Over 9000 days!' : '>9000d'; + str += (d > 0 ? d + (longFormat ? (d == 1 ? ' day' : ' days') : 'd') + ', ': ""); + if (str.length > 0 || h > 0) str += h + (longFormat ? (h == 1 ? ' hour' : ' hours') : 'h') + ', '; + if (str.length > 0 || m > 0) str += m + (longFormat ? (m == 1 ? ' minute' : ' minutes') : 'm') + ', '; + str += s + (longFormat ? (s == 1 ? ' second' : ' seconds') : 's'); } return str; } diff --git a/src/Disp.js b/src/Disp.js index 154065c..7505163 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -2,55 +2,30 @@ * Disp * ********/ -CM.Disp.FormatTime = function(time, format) { +// General functions to format or beautify strings + +CM.Disp.FormatTime = function(time, longFormat) { if (time == Infinity) return time; + time = Math.ceil(time); + var y = Math.floor(time / 31557600); + var d = Math.floor(time % 31557600 / 86400); + var h = Math.floor(time % 86400 / 3600); + var m = Math.floor(time % 3600 / 60); + var s = Math.floor(time % 60); + var str = ''; if (CM.Config.TimeFormat) { if (time > 3155760000) return 'XX:XX:XX:XX:XX'; - time = Math.ceil(time); - var y = Math.floor(time / 31557600); - var d = Math.floor(time % 31557600 / 86400); - var h = Math.floor(time % 86400 / 3600); - var m = Math.floor(time % 3600 / 60); - var s = Math.floor(time % 60); - var str = ''; - if (y < 10) { - str += '0'; - } - str += y + ':'; - if (d < 10) { - str += '0'; - } - str += d + ':'; - if (h < 10) { - str += '0'; - } - str += h + ':'; - if (m < 10) { - str += '0'; - } - str += m + ':'; - if (s < 10) { - str += '0'; - } - str += s; + str += (y < 10 ? '0' : '') + y + ':'; + str += (d < 10 ? '0' : '') + d + ':'; + str += (h < 10 ? '0' : '') + h + ':'; + str += (m < 10 ? '0' : '') + m + ':'; + str += (s < 10 ? '0' : '') + s + ':'; } else { - if (time > 777600000) return format ? 'Over 9000 days!' : '>9000d'; - time = Math.ceil(time); - var d = Math.floor(time / 86400); - var h = Math.floor(time % 86400 / 3600); - var m = Math.floor(time % 3600 / 60); - var s = Math.floor(time % 60); - var str = ''; - if (d > 0) { - str += d + (format ? (d == 1 ? ' day' : ' days') : 'd') + ', '; - } - if (str.length > 0 || h > 0) { - str += h + (format ? (h == 1 ? ' hour' : ' hours') : 'h') + ', '; - } - if (str.length > 0 || m > 0) { - str += m + (format ? (m == 1 ? ' minute' : ' minutes') : 'm') + ', '; - } - str += s + (format ? (s == 1 ? ' second' : ' seconds') : 's'); + if (time > 777600000) return longFormat ? 'Over 9000 days!' : '>9000d'; + str += (d > 0 ? d + (longFormat ? (d == 1 ? ' day' : ' days') : 'd') + ', ': ""); + if (str.length > 0 || h > 0) str += h + (longFormat ? (h == 1 ? ' hour' : ' hours') : 'h') + ', '; + if (str.length > 0 || m > 0) str += m + (longFormat ? (m == 1 ? ' minute' : ' minutes') : 'm') + ', '; + str += s + (longFormat ? (s == 1 ? ' second' : ' seconds') : 's'); } return str; } From e256d39101a60d352df2e47e29171016a83c759e Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Wed, 2 Dec 2020 21:55:57 +0100 Subject: [PATCH 002/106] Added annotations to CM.Disp.FormatTime --- CookieMonster.js | 4 ++++ src/Disp.js | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/CookieMonster.js b/CookieMonster.js index a2f0dbd..3a8b8d7 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -846,6 +846,10 @@ CM.Data.ValCookies = ['Pure heart biscuits', 'Ardent heart biscuits', 'Sour hear // General functions to format or beautify strings +/** + * This function returns time as a string depending on TimeFormat setting + * @param type Time as number, longFormat 1 or 0. + */ CM.Disp.FormatTime = function(time, longFormat) { if (time == Infinity) return time; time = Math.ceil(time); diff --git a/src/Disp.js b/src/Disp.js index 7505163..6c567bd 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -4,6 +4,10 @@ // General functions to format or beautify strings +/** + * This function returns time as a string depending on TimeFormat setting + * @param type Time as number, longFormat 1 or 0. + */ CM.Disp.FormatTime = function(time, longFormat) { if (time == Infinity) return time; time = Math.ceil(time); From 7efbd590622b16f3ad72743a57fc699bb3dbb9b9 Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Wed, 2 Dec 2020 22:23:17 +0100 Subject: [PATCH 003/106] Reorgainzed src/Disp.js --- CookieMonster.js | 1863 ++++++++++++++++++++++++---------------------- src/Disp.js | 1863 ++++++++++++++++++++++++---------------------- 2 files changed, 1922 insertions(+), 1804 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index 3a8b8d7..3a3b3e9 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -844,37 +844,10 @@ CM.Data.ValCookies = ['Pure heart biscuits', 'Ardent heart biscuits', 'Sour hear * Disp * ********/ -// General functions to format or beautify strings - -/** - * This function returns time as a string depending on TimeFormat setting - * @param type Time as number, longFormat 1 or 0. - */ -CM.Disp.FormatTime = function(time, longFormat) { - if (time == Infinity) return time; - time = Math.ceil(time); - var y = Math.floor(time / 31557600); - var d = Math.floor(time % 31557600 / 86400); - var h = Math.floor(time % 86400 / 3600); - var m = Math.floor(time % 3600 / 60); - var s = Math.floor(time % 60); - var str = ''; - if (CM.Config.TimeFormat) { - if (time > 3155760000) return 'XX:XX:XX:XX:XX'; - str += (y < 10 ? '0' : '') + y + ':'; - str += (d < 10 ? '0' : '') + d + ':'; - str += (h < 10 ? '0' : '') + h + ':'; - str += (m < 10 ? '0' : '') + m + ':'; - str += (s < 10 ? '0' : '') + s + ':'; - } else { - if (time > 777600000) return longFormat ? 'Over 9000 days!' : '>9000d'; - str += (d > 0 ? d + (longFormat ? (d == 1 ? ' day' : ' days') : 'd') + ', ': ""); - if (str.length > 0 || h > 0) str += h + (longFormat ? (h == 1 ? ' hour' : ' hours') : 'h') + ', '; - if (str.length > 0 || m > 0) str += m + (longFormat ? (m == 1 ? ' minute' : ' minutes') : 'm') + ', '; - str += s + (longFormat ? (s == 1 ? ' second' : ' seconds') : 's'); - } - return str; -} +/******** + * Section: Unsorted functions + * TODO: Annotate most functions + * TODO: Sort functionsn in relevant (new) sections or files */ CM.Disp.GetTimeColor = function(price, bank, cps, time) { var color; @@ -949,6 +922,279 @@ CM.Disp.GetLumpColor = function(type) { return {text: name, color: color}; }; +CM.Disp.GetWrinkConfigBank = function() { + if (CM.Config.CalcWrink) + return CM.Cache.WrinkBank; + else + return 0; +} + +CM.Disp.GetCPS = function() { + if (CM.Config.CPSMode) + return CM.Cache.AvgCPS; + else + return (Game.cookiesPs * (1 - Game.cpsSucked)); +} + +CM.Disp.UpdateBackground = function() { + Game.Background.canvas.width = Game.Background.canvas.parentNode.offsetWidth; + Game.Background.canvas.height = Game.Background.canvas.parentNode.offsetHeight; + Game.LeftBackground.canvas.width = Game.LeftBackground.canvas.parentNode.offsetWidth; + Game.LeftBackground.canvas.height = Game.LeftBackground.canvas.parentNode.offsetHeight; +} + +CM.Disp.GetConfigDisplay = function(config) { + return CM.ConfigData[config].label[CM.Config[config]]; +} + +CM.Disp.AddJscolor = function() { + CM.Disp.Jscolor = document.createElement('script'); + CM.Disp.Jscolor.type = 'text/javascript'; + CM.Disp.Jscolor.setAttribute('src', 'https://aktanusa.github.io/CookieMonster/jscolor/jscolor.js'); + document.head.appendChild(CM.Disp.Jscolor); +} + +CM.Disp.CreateCssArea = function() { + CM.Disp.Css = document.createElement('style'); + CM.Disp.Css.type = 'text/css'; + + document.head.appendChild(CM.Disp.Css); + + // given the architecture of your code, you probably want these lines somewhere else, + // but I stuck them here for convenience + l("products").style.display = "grid"; + l("storeBulk").style.gridRow = "1/1"; + + l("upgrades").style.display = "flex"; + l("upgrades").style["flex-wrap"] = "wrap"; +} + +CM.Disp.UpdateUpgrades = function() { + if (CM.Config.UpBarColor > 0) { + var blue = 0; + var green = 0; + var yellow = 0; + var orange = 0; + var red = 0; + var purple = 0; + var gray = 0; + + for (var i in Game.UpgradesInStore) { + var me = Game.UpgradesInStore[i]; + var addedColor = false; + for (var j = 0; j < l('upgrade' + i).childNodes.length; j++) { + if (l('upgrade' + i).childNodes[j].className.indexOf(CM.Disp.colorBackPre) != -1) { + l('upgrade' + i).childNodes[j].className = CM.Disp.colorBackPre + CM.Cache.Upgrades[me.name].color; + addedColor = true; + break; + } + } + if (!addedColor) { + var div = document.createElement('div'); + div.style.width = '10px'; + div.style.height = '10px'; + div.className = CM.Disp.colorBackPre + CM.Cache.Upgrades[me.name].color; + l('upgrade' + i).appendChild(div); + } + if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorBlue) blue++; + else if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorGreen) green++; + else if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorYellow) yellow++; + else if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorOrange) orange++; + else if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorRed) red++; + else if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorPurple) purple++; + else if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorGray) gray++; + } + + l('CMUpgradeBarBlue').textContent = blue; + l('CMUpgradeBarGreen').textContent = green; + l('CMUpgradeBarYellow').textContent = yellow; + l('CMUpgradeBarOrange').textContent = orange; + l('CMUpgradeBarRed').textContent = red; + l('CMUpgradeBarPurple').textContent = purple; + l('CMUpgradeBarGray').textContent = gray; + } + + // Build array of pointers, sort by pp, set flex positions + var arr = []; + for (var x = 0; x < Game.UpgradesInStore.length; x++){ + var o = {}; + o.name = Game.UpgradesInStore[x].name; + o.price = Game.UpgradesInStore[x].basePrice; + o.pp = CM.Cache.Upgrades[o.name].pp; + arr.push(o); + } + + if (CM.Config.SortUpgrades) + arr.sort((a, b) => a.pp - b.pp); + else + arr.sort((a, b) => a.price - b.price); + + for (var x = 0; x < Game.UpgradesInStore.length; x++){ + l("upgrade" + x).style.order = arr.findIndex(e => e.name === Game.UpgradesInStore[x].name) + 1 + } +} + +CM.Disp.UpdateColors = function() { + var str = ''; + for (var i = 0; i < CM.Disp.colors.length; i++) { + str += '.' + CM.Disp.colorTextPre + CM.Disp.colors[i] + ' { color: ' + CM.Config.Colors[CM.Disp.colors[i]] + '; }\n'; + } + for (var i = 0; i < CM.Disp.colors.length; i++) { + str += '.' + CM.Disp.colorBackPre + CM.Disp.colors[i] + ' { background-color: ' + CM.Config.Colors[CM.Disp.colors[i]] + '; }\n'; + } + for (var i = 0; i < CM.Disp.colors.length; i++) { + str += '.' + CM.Disp.colorBorderPre + CM.Disp.colors[i] + ' { border: 1px solid ' + CM.Config.Colors[CM.Disp.colors[i]] + '; }\n'; + } + CM.Disp.Css.textContent = str; + CM.Disp.UpdateBuildings(); // Class has been already set +} + +CM.Disp.CreateWhiteScreen = function() { + CM.Disp.WhiteScreen = document.createElement('div'); + CM.Disp.WhiteScreen.id = 'CMWhiteScreen'; + CM.Disp.WhiteScreen.style.width = '100%'; + CM.Disp.WhiteScreen.style.height = '100%'; + CM.Disp.WhiteScreen.style.backgroundColor = 'white'; + CM.Disp.WhiteScreen.style.display = 'none'; + CM.Disp.WhiteScreen.style.zIndex = '9999999999'; + CM.Disp.WhiteScreen.style.position = 'absolute'; + + l('wrapper').appendChild(CM.Disp.WhiteScreen); +} + +CM.Disp.FindShimmer = function() { + CM.Disp.currSpawnedGoldenCookieState = 0 + CM.Disp.goldenShimmersByID = {} + for (var i in Game.shimmers) { + CM.Disp.goldenShimmersByID[Game.shimmers[i].id] = Game.shimmers[i] + if (Game.shimmers[i].spawnLead && Game.shimmers[i].type == 'golden') { + CM.Disp.spawnedGoldenShimmer = Game.shimmers[i]; + CM.Disp.currSpawnedGoldenCookieState += 1; + } + } +} + +CM.Disp.CollectWrinklers = function() { + for (var i in Game.wrinklers) { + if (Game.wrinklers[i].sucked > 0 && Game.wrinklers[i].type == 0) { + Game.wrinklers[i].hp = 0; + } + } +} + +CM.Disp.FixMouseY = function(target) { + if (CM.Config.TimerBar == 1 && CM.Config.TimerBarPos == 0) { + var timerBarHeight = parseInt(CM.Disp.TimerBar.style.height); + Game.mouseY -= timerBarHeight; + target(); + Game.mouseY += timerBarHeight; + } + else { + target(); + } +} + +CM.Disp.CalculateGrimoireRefillTime = function(currentMagic, maxMagic, targetMagic) { + var count = 0; + while (currentMagic < targetMagic) { + currentMagic += Math.max(0.002, Math.pow(currentMagic / Math.max(maxMagic, 100), 0.5)) * 0.002; + count++; + } + return count / Game.fps; +} + +CM.Disp.AddWrinklerAreaDetect = function() { + l('backgroundLeftCanvas').onmouseover = function() {CM.Disp.TooltipWrinklerArea = 1;}; + l('backgroundLeftCanvas').onmouseout = function() { + CM.Disp.TooltipWrinklerArea = 0; + Game.tooltip.hide(); + for (var i in Game.wrinklers) { + CM.Disp.TooltipWrinklerCache[i] = 0; + } + }; +} + +CM.Disp.UpdateAscendState = function() { + if (Game.OnAscend) { + l('game').style.bottom = '0px'; + if (CM.Config.BotBar == 1) CM.Disp.BotBar.style.display = 'none'; + if (CM.Config.TimerBar == 1) CM.Disp.TimerBar.style.display = 'none'; + } + else { + CM.Disp.ToggleBotBar(); + CM.Disp.ToggleTimerBar(); + } + + CM.Disp.UpdateBackground(); +} + +CM.Disp.UpdateAuraDescription = function() { + return "function(aura)\ + {\ + l('dragonAuraInfo').innerHTML=\ + '

'+Game.dragonAuras[aura].name+'

'+\ + '
'+\ + Game.dragonAuras[aura].desc+\ + '
'+\ + CM.\ + '
';\ + }" +} + +CM.Disp.ToggleSayTime = function() { + if (CM.Config.SayTime == 1) { + Game.sayTime = CM.Disp.sayTime; + } + else { + Game.sayTime = CM.Backup.sayTime; + } +} + +CM.Disp.RefreshScale = function() { + BeautifyAll(); + Game.RefreshStore(); + Game.RebuildUpgrades(); + + CM.Disp.UpdateBotBarOther(); + CM.Disp.UpdateBuildings(); + CM.Disp.UpdateUpgrades(); +} +/******** + * Section: General functions to format or beautify strings + * TODO: Annotate most functions */ + +/** + * This function returns time as a string depending on TimeFormat setting + * @param {number} time Time as number + * @param {number} longFormat 1 or 0 + * @return {string} + */ +CM.Disp.FormatTime = function(time, longFormat) { + if (time == Infinity) return time; + time = Math.ceil(time); + var y = Math.floor(time / 31557600); + var d = Math.floor(time % 31557600 / 86400); + var h = Math.floor(time % 86400 / 3600); + var m = Math.floor(time % 3600 / 60); + var s = Math.floor(time % 60); + var str = ''; + if (CM.Config.TimeFormat) { + if (time > 3155760000) return 'XX:XX:XX:XX:XX'; + str += (y < 10 ? '0' : '') + y + ':'; + str += (d < 10 ? '0' : '') + d + ':'; + str += (h < 10 ? '0' : '') + h + ':'; + str += (m < 10 ? '0' : '') + m + ':'; + str += (s < 10 ? '0' : '') + s + ':'; + } else { + if (time > 777600000) return longFormat ? 'Over 9000 days!' : '>9000d'; + str += (d > 0 ? d + (longFormat ? (d == 1 ? ' day' : ' days') : 'd') + ', ': ""); + if (str.length > 0 || h > 0) str += h + (longFormat ? (h == 1 ? ' hour' : ' hours') : 'h') + ', '; + if (str.length > 0 || m > 0) str += m + (longFormat ? (m == 1 ? ' minute' : ' minutes') : 'm') + ', '; + str += s + (longFormat ? (s == 1 ? ' second' : ' seconds') : 's'); + } + return str; +} + CM.Disp.Beautify = function(num, frac) { if (CM.Config.Scale != 0 && isFinite(num)) { var answer = ''; @@ -1052,52 +1298,9 @@ CM.Disp.Beautify = function(num, frac) { } } -CM.Disp.GetWrinkConfigBank = function() { - if (CM.Config.CalcWrink) - return CM.Cache.WrinkBank; - else - return 0; -} - -CM.Disp.GetCPS = function() { - if (CM.Config.CPSMode) - return CM.Cache.AvgCPS; - else - return (Game.cookiesPs * (1 - Game.cpsSucked)); -} - -CM.Disp.UpdateBackground = function() { - Game.Background.canvas.width = Game.Background.canvas.parentNode.offsetWidth; - Game.Background.canvas.height = Game.Background.canvas.parentNode.offsetHeight; - Game.LeftBackground.canvas.width = Game.LeftBackground.canvas.parentNode.offsetWidth; - Game.LeftBackground.canvas.height = Game.LeftBackground.canvas.parentNode.offsetHeight; -} - -CM.Disp.GetConfigDisplay = function(config) { - return CM.ConfigData[config].label[CM.Config[config]]; -} - -CM.Disp.AddJscolor = function() { - CM.Disp.Jscolor = document.createElement('script'); - CM.Disp.Jscolor.type = 'text/javascript'; - CM.Disp.Jscolor.setAttribute('src', 'https://aktanusa.github.io/CookieMonster/jscolor/jscolor.js'); - document.head.appendChild(CM.Disp.Jscolor); -} - -CM.Disp.CreateCssArea = function() { - CM.Disp.Css = document.createElement('style'); - CM.Disp.Css.type = 'text/css'; - - document.head.appendChild(CM.Disp.Css); - - // given the architecture of your code, you probably want these lines somewhere else, - // but I stuck them here for convenience - l("products").style.display = "grid"; - l("storeBulk").style.gridRow = "1/1"; - - l("upgrades").style.display = "flex"; - l("upgrades").style["flex-wrap"] = "wrap"; -} +/******** + * Section: Functions related to the Bottom Bar + * TODO: Annotate functions */ /** * Extends the bottom bar (created by CM.Disp.CreateBotBar) with a column for the given building. @@ -1220,6 +1423,10 @@ CM.Disp.UpdateBotBarTime = function() { } } +/******** + * Section: Functions related to the Timer Bar + * TODO: Annotate functions */ + CM.Disp.CreateTimerBar = function() { CM.Disp.TimerBar = document.createElement('div'); CM.Disp.TimerBar.id = 'CMTimerBar'; @@ -1479,6 +1686,10 @@ CM.Disp.UpdateBotTimerBarDisplay = function() { CM.Disp.UpdateBackground(); } +/******** + * Section: Functions related to column of buildings/objects + * TODO: Annotate functions */ + CM.Disp.UpdateBuildings = function() { if (CM.Config.BuildColor == 1 && Game.buyMode == 1) { var target = ''; @@ -1542,6 +1753,10 @@ CM.Disp.UpdateBuildings = function() { } } +/******** + * Section: Functions related to the Upgrade Bar + * TODO: Annotate functions */ + CM.Disp.CreateUpgradeBar = function() { CM.Disp.UpgradeBar = document.createElement('div'); CM.Disp.UpgradeBar.id = 'CMUpgradeBar'; @@ -1623,86 +1838,6 @@ CM.Disp.ToggleUpBarColor = function() { } } -CM.Disp.UpdateUpgrades = function() { - if (CM.Config.UpBarColor > 0) { - var blue = 0; - var green = 0; - var yellow = 0; - var orange = 0; - var red = 0; - var purple = 0; - var gray = 0; - - for (var i in Game.UpgradesInStore) { - var me = Game.UpgradesInStore[i]; - var addedColor = false; - for (var j = 0; j < l('upgrade' + i).childNodes.length; j++) { - if (l('upgrade' + i).childNodes[j].className.indexOf(CM.Disp.colorBackPre) != -1) { - l('upgrade' + i).childNodes[j].className = CM.Disp.colorBackPre + CM.Cache.Upgrades[me.name].color; - addedColor = true; - break; - } - } - if (!addedColor) { - var div = document.createElement('div'); - div.style.width = '10px'; - div.style.height = '10px'; - div.className = CM.Disp.colorBackPre + CM.Cache.Upgrades[me.name].color; - l('upgrade' + i).appendChild(div); - } - if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorBlue) blue++; - else if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorGreen) green++; - else if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorYellow) yellow++; - else if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorOrange) orange++; - else if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorRed) red++; - else if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorPurple) purple++; - else if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorGray) gray++; - } - - l('CMUpgradeBarBlue').textContent = blue; - l('CMUpgradeBarGreen').textContent = green; - l('CMUpgradeBarYellow').textContent = yellow; - l('CMUpgradeBarOrange').textContent = orange; - l('CMUpgradeBarRed').textContent = red; - l('CMUpgradeBarPurple').textContent = purple; - l('CMUpgradeBarGray').textContent = gray; - } - - // Build array of pointers, sort by pp, set flex positions - var arr = []; - for (var x = 0; x < Game.UpgradesInStore.length; x++){ - var o = {}; - o.name = Game.UpgradesInStore[x].name; - o.price = Game.UpgradesInStore[x].basePrice; - o.pp = CM.Cache.Upgrades[o.name].pp; - arr.push(o); - } - - if (CM.Config.SortUpgrades) - arr.sort((a, b) => a.pp - b.pp); - else - arr.sort((a, b) => a.price - b.price); - - for (var x = 0; x < Game.UpgradesInStore.length; x++){ - l("upgrade" + x).style.order = arr.findIndex(e => e.name === Game.UpgradesInStore[x].name) + 1 - } -} - -CM.Disp.UpdateColors = function() { - var str = ''; - for (var i = 0; i < CM.Disp.colors.length; i++) { - str += '.' + CM.Disp.colorTextPre + CM.Disp.colors[i] + ' { color: ' + CM.Config.Colors[CM.Disp.colors[i]] + '; }\n'; - } - for (var i = 0; i < CM.Disp.colors.length; i++) { - str += '.' + CM.Disp.colorBackPre + CM.Disp.colors[i] + ' { background-color: ' + CM.Config.Colors[CM.Disp.colors[i]] + '; }\n'; - } - for (var i = 0; i < CM.Disp.colors.length; i++) { - str += '.' + CM.Disp.colorBorderPre + CM.Disp.colors[i] + ' { border: 1px solid ' + CM.Config.Colors[CM.Disp.colors[i]] + '; }\n'; - } - CM.Disp.Css.textContent = str; - CM.Disp.UpdateBuildings(); // Class has been already set -} - CM.Disp.ToggleUpgradeBarFixedPos = function() { if (CM.Config.UpgradeBarFixedPos == 1) { CM.Disp.UpgradeBar.style.position = 'sticky'; @@ -1713,18 +1848,9 @@ CM.Disp.ToggleUpgradeBarFixedPos = function() { } } -CM.Disp.CreateWhiteScreen = function() { - CM.Disp.WhiteScreen = document.createElement('div'); - CM.Disp.WhiteScreen.id = 'CMWhiteScreen'; - CM.Disp.WhiteScreen.style.width = '100%'; - CM.Disp.WhiteScreen.style.height = '100%'; - CM.Disp.WhiteScreen.style.backgroundColor = 'white'; - CM.Disp.WhiteScreen.style.display = 'none'; - CM.Disp.WhiteScreen.style.zIndex = '9999999999'; - CM.Disp.WhiteScreen.style.position = 'absolute'; - - l('wrapper').appendChild(CM.Disp.WhiteScreen); -} +/******** + * Section: Functions related to the flashes/sound/notifications + * TODO: Annotate functions */ CM.Disp.Flash = function(mode, config) { if ((CM.Config[config] == 1 && mode == 3) || mode == 1) { @@ -1761,19 +1887,9 @@ CM.Disp.Notification = function(notifyConfig, title, message) { } } - -CM.Disp.FindShimmer = function() { - CM.Disp.currSpawnedGoldenCookieState = 0 - CM.Disp.goldenShimmersByID = {} - for (var i in Game.shimmers) { - CM.Disp.goldenShimmersByID[Game.shimmers[i].id] = Game.shimmers[i] - if (Game.shimmers[i].spawnLead && Game.shimmers[i].type == 'golden') { - CM.Disp.spawnedGoldenShimmer = Game.shimmers[i]; - CM.Disp.currSpawnedGoldenCookieState += 1; - } - } - -} +/******** + * Section: Functions related to updating the tab in the browser's tab-bar + * TODO: Annotate functions */ CM.Disp.CreateFavicon = function() { CM.Disp.Favicon = document.createElement('link'); @@ -1797,6 +1913,84 @@ CM.Disp.UpdateFavicon = function() { } } +CM.Disp.UpdateTitle = function() { + if (Game.OnAscend || CM.Config.Title == 0) { + document.title = CM.Cache.Title; + } + else if (CM.Config.Title == 1) { + var addFC = false; + var addSP = false; + + var titleGC; + var titleFC; + var titleSP; + if (CM.Disp.lastGoldenCookieState) { + if (CM.Disp.spawnedGoldenShimmer.wrath) { + titleGC = '[W ' + Math.ceil(CM.Disp.spawnedGoldenShimmer.life / Game.fps) + ']'; + } + else { + titleGC = '[G ' + Math.ceil(CM.Disp.spawnedGoldenShimmer.life / Game.fps) + ']'; + } + } + else if (!Game.Has('Golden switch [off]')) { + titleGC = '[' + Math.ceil((Game.shimmerTypes['golden'].maxTime - Game.shimmerTypes['golden'].time) / Game.fps) + ']'; + } + else { + titleGC = '[GS]' + } + if (CM.Disp.lastTickerFortuneState) { + addFC = true; + titleFC = '[F]'; + } + if (Game.season == 'christmas') { + addSP = true; + if (CM.Disp.lastSeasonPopupState) { + titleSP = '[R ' + Math.ceil(CM.Disp.seasonPopShimmer.life / Game.fps) + ']'; + } + else { + titleSP = '[' + Math.ceil((Game.shimmerTypes['reindeer'].maxTime - Game.shimmerTypes['reindeer'].time) / Game.fps) + ']'; + } + } + + var str = CM.Cache.Title; + if (str.charAt(0) == '[') { + str = str.substring(str.lastIndexOf(']') + 1); + } + + document.title = titleGC + (addFC ? titleFC : '') + (addSP ? titleSP : '') + ' ' + str; + } + else if (CM.Config.Title == 2) { + var str = ''; + var spawn = false; + if (CM.Disp.lastGoldenCookieState) { + spawn = true; + if (CM.Disp.spawnedGoldenShimmer.wrath) { + str += '[W ' + Math.ceil(CM.Disp.spawnedGoldenShimmer.life / Game.fps) + ']'; + } + else { + str += '[G ' + Math.ceil(CM.Disp.spawnedGoldenShimmer.life / Game.fps) + ']'; + } + } + if (CM.Disp.lastTickerFortuneState) { + spawn = true; + str += '[F]'; + } + if (Game.season == 'christmas' && CM.Disp.lastSeasonPopupState) { + str += '[R ' + Math.ceil(CM.Disp.seasonPopShimmer.life / Game.fps) + ']'; + spawn = true; + } + if (spawn) str += ' - '; + var title = 'Cookie Clicker'; + if (Game.season == 'fools') title = 'Cookie Baker'; + str += title; + document.title = str; + } +} + +/******** + * Section: Functions related to the Golden Cookie Timers + * TODO: Annotate functions */ + CM.Disp.CreateGCTimer = function(cookie) { GCTimer = document.createElement('div'); GCTimer.id = 'GCTimer' + cookie.id @@ -1837,6 +2031,11 @@ CM.Disp.ToggleGCTimer = function() { } } +/******** + * Section: Functions related to checking for changes in Minigames/GC's/Ticker + * TODO: Annotate functions + * TODO: Possibly move this section */ + CM.Disp.CheckGoldenCookie = function() { CM.Disp.FindShimmer(); for (var i in CM.Disp.GCTimers) { @@ -1964,87 +2163,9 @@ CM.Disp.CheckWrinklerCount = function() { } } -CM.Disp.UpdateTitle = function() { - if (Game.OnAscend || CM.Config.Title == 0) { - document.title = CM.Cache.Title; - } - else if (CM.Config.Title == 1) { - var addFC = false; - var addSP = false; - - var titleGC; - var titleFC; - var titleSP; - if (CM.Disp.lastGoldenCookieState) { - if (CM.Disp.spawnedGoldenShimmer.wrath) { - titleGC = '[W ' + Math.ceil(CM.Disp.spawnedGoldenShimmer.life / Game.fps) + ']'; - } - else { - titleGC = '[G ' + Math.ceil(CM.Disp.spawnedGoldenShimmer.life / Game.fps) + ']'; - } - } - else if (!Game.Has('Golden switch [off]')) { - titleGC = '[' + Math.ceil((Game.shimmerTypes['golden'].maxTime - Game.shimmerTypes['golden'].time) / Game.fps) + ']'; - } - else { - titleGC = '[GS]' - } - if (CM.Disp.lastTickerFortuneState) { - addFC = true; - titleFC = '[F]'; - } - if (Game.season == 'christmas') { - addSP = true; - if (CM.Disp.lastSeasonPopupState) { - titleSP = '[R ' + Math.ceil(CM.Disp.seasonPopShimmer.life / Game.fps) + ']'; - } - else { - titleSP = '[' + Math.ceil((Game.shimmerTypes['reindeer'].maxTime - Game.shimmerTypes['reindeer'].time) / Game.fps) + ']'; - } - } - - var str = CM.Cache.Title; - if (str.charAt(0) == '[') { - str = str.substring(str.lastIndexOf(']') + 1); - } - - document.title = titleGC + (addFC ? titleFC : '') + (addSP ? titleSP : '') + ' ' + str; - } - else if (CM.Config.Title == 2) { - var str = ''; - var spawn = false; - if (CM.Disp.lastGoldenCookieState) { - spawn = true; - if (CM.Disp.spawnedGoldenShimmer.wrath) { - str += '[W ' + Math.ceil(CM.Disp.spawnedGoldenShimmer.life / Game.fps) + ']'; - } - else { - str += '[G ' + Math.ceil(CM.Disp.spawnedGoldenShimmer.life / Game.fps) + ']'; - } - } - if (CM.Disp.lastTickerFortuneState) { - spawn = true; - str += '[F]'; - } - if (Game.season == 'christmas' && CM.Disp.lastSeasonPopupState) { - str += '[R ' + Math.ceil(CM.Disp.seasonPopShimmer.life / Game.fps) + ']'; - spawn = true; - } - if (spawn) str += ' - '; - var title = 'Cookie Clicker'; - if (Game.season == 'fools') title = 'Cookie Baker'; - str += title; - document.title = str; - } -} - -CM.Disp.CollectWrinklers = function() { - for (var i in Game.wrinklers) { - if (Game.wrinklers[i].sucked > 0 && Game.wrinklers[i].type == 0) { - Game.wrinklers[i].hp = 0; - } - } -} +/******** + * Section: Functions related to Tooltips + * TODO: Annotate functions */ CM.Disp.CreateTooltip = function(placeholder, text, minWidth) { CM.Disp[placeholder] = document.createElement('div'); @@ -2058,6 +2179,576 @@ CM.Disp.CreateTooltip = function(placeholder, text, minWidth) { CM.Disp[placeholder].appendChild(desc); } +CM.Disp.UpdateTooltipLocation = function() { + if (Game.tooltip.origin == 'store') { + var warnOffset = 0; + if (CM.Config.ToolWarnLucky == 1 && CM.Config.ToolWarnPos == 1) warnOffset = CM.Disp.TooltipWarn.clientHeight - 4; + Game.tooltip.tta.style.top = Math.min(parseInt(Game.tooltip.tta.style.top), (l('game').clientHeight + l('topBar').clientHeight) - Game.tooltip.tt.clientHeight - warnOffset - 46) + 'px'; + } + // Kept for future possible use if the code changes again + /*else if (!Game.onCrate && !Game.OnAscend && CM.Config.TimerBar == 1 && CM.Config.TimerBarPos == 0) { + Game.tooltip.tta.style.top = (parseInt(Game.tooltip.tta.style.top) + parseInt(CM.Disp.TimerBar.style.height)) + 'px'; + }*/ +} + +CM.Disp.CreateTooltipWarn = function() { + CM.Disp.TooltipWarn = document.createElement('div'); + CM.Disp.TooltipWarn.style.position = 'absolute'; + CM.Disp.TooltipWarn.style.display = 'none'; + CM.Disp.TooltipWarn.style.left = 'auto'; + CM.Disp.TooltipWarn.style.bottom = 'auto'; + + var create = function(boxId, color, labelTextFront, labelTextBack, deficitId) { + var box = document.createElement('div'); + box.id = boxId; + box.style.display = 'none'; + box.style.WebkitTransition = 'opacity 0.1s ease-out'; + box.style.MozTransition = 'opacity 0.1s ease-out'; + box.style.MsTransition = 'opacity 0.1s ease-out'; + box.style.OTransition = 'opacity 0.1s ease-out'; + box.style.transition = 'opacity 0.1s ease-out'; + box.className = CM.Disp.colorBorderPre + color; + box.style.padding = '2px'; + box.style.background = '#000 url(img/darkNoise.png)'; + var labelDiv = document.createElement('div'); + box.appendChild(labelDiv); + var labelSpan = document.createElement('span'); + labelSpan.className = CM.Disp.colorTextPre + color; + labelSpan.style.fontWeight = 'bold'; + labelSpan.textContent = labelTextFront; + labelDiv.appendChild(labelSpan); + labelDiv.appendChild(document.createTextNode(labelTextBack)); + var deficitDiv = document.createElement('div'); + box.appendChild(deficitDiv); + var deficitSpan = document.createElement('span'); + deficitSpan.id = deficitId; + deficitDiv.appendChild(document.createTextNode('Deficit: ')); + deficitDiv.appendChild(deficitSpan); + return box; + } + CM.Disp.TooltipWarn.appendChild(create('CMDispTooltipWarnLucky', CM.Disp.colorRed, 'Warning: ', 'Purchase of this item will put you under the number of Cookies required for "Lucky!"', 'CMDispTooltipWarnLuckyText')); + CM.Disp.TooltipWarn.firstChild.style.marginBottom = '4px'; + CM.Disp.TooltipWarn.appendChild(create('CMDispTooltipWarnLuckyFrenzy', CM.Disp.colorYellow, 'Warning: ', 'Purchase of this item will put you under the number of Cookies required for "Lucky!" (Frenzy)', 'CMDispTooltipWarnLuckyFrenzyText')); + CM.Disp.TooltipWarn.lastChild.style.marginBottom = '4px'; + CM.Disp.TooltipWarn.appendChild(create('CMDispTooltipWarnConjure', CM.Disp.colorPurple, 'Warning: ', 'Purchase of this item will put you under the number of Cookies required for "Conjure Baked Goods"', 'CMDispTooltipWarnConjureText')); + + + l('tooltipAnchor').appendChild(CM.Disp.TooltipWarn); +} + +CM.Disp.ToggleToolWarnPos = function() { + if (CM.Config.ToolWarnPos == 0) { + CM.Disp.TooltipWarn.style.top = 'auto'; + CM.Disp.TooltipWarn.style.margin = '4px -4px'; + CM.Disp.TooltipWarn.style.padding = '3px 4px'; + } + else { + CM.Disp.TooltipWarn.style.right = 'auto'; + CM.Disp.TooltipWarn.style.margin = '4px'; + CM.Disp.TooltipWarn.style.padding = '4px 3px'; + } +} + +CM.Disp.AddTooltipBuild = function() { + CM.Disp.TooltipBuildBack = []; + for (var i in Game.Objects) { + var me = Game.Objects[i]; + if (l('product' + me.id).onmouseover != null) { + CM.Disp.TooltipBuildBack[i] = l('product' + me.id).onmouseover; + eval('l(\'product\' + me.id).onmouseover = function() {Game.tooltip.dynamic = 1; Game.tooltip.draw(this, function() {return CM.Disp.Tooltip(\'b\', \'' + i + '\');}, \'store\'); Game.tooltip.wobble();}'); + } + } +} + +CM.Disp.AddTooltipUpgrade = function() { + CM.Disp.TooltipUpgradeBack = []; + for (var i in Game.UpgradesInStore) { + var me = Game.UpgradesInStore[i]; + if (l('upgrade' + i).onmouseover != null) { + CM.Disp.TooltipUpgradeBack[i] = l('upgrade' + i).onmouseover; + eval('l(\'upgrade\' + i).onmouseover = function() {if (!Game.mouseDown) {Game.setOnCrate(this); Game.tooltip.dynamic = 1; Game.tooltip.draw(this, function() {return CM.Disp.Tooltip(\'u\', \'' + i + '\');}, \'store\'); Game.tooltip.wobble();}}'); + } + } +} + +CM.Disp.AddTooltipGrimoire = function() { + if (Game.Objects['Wizard tower'].minigameLoaded) { + CM.Disp.TooltipGrimoireBack = []; + for (var i in Game.Objects['Wizard tower'].minigame.spellsById) { + if (l('grimoireSpell' + i).onmouseover != null) { + CM.Disp.TooltipGrimoireBack[i] = l('grimoireSpell' + i).onmouseover; + eval('l(\'grimoireSpell\' + i).onmouseover = function() {Game.tooltip.dynamic = 1; Game.tooltip.draw(this, function() {return CM.Disp.Tooltip(\'g\', \'' + i + '\');}, \'this\'); Game.tooltip.wobble();}'); + } + } + } +} + +/** + * This function improves Sugar Lump tooltip by adding extra infromation. + * @constructor + */ +CM.Disp.AddTooltipLump = function() { + if (Game.canLumps()) { + CM.Disp.TooltipLumpBack = l('lumps').onmouseover; + eval('l(\'lumps\').onmouseover = function() {Game.tooltip.dynamic = 1; Game.tooltip.draw(this, function() {return CM.Disp.Tooltip(\'s\', \'Lump\');}, \'this\'); Game.tooltip.wobble();}'); + } +}; + +CM.Disp.Tooltip = function(type, name) { + if (type == 'b') { + l('tooltip').innerHTML = Game.Objects[name].tooltip(); + if (CM.Config.TooltipAmor == 1) { + var buildPrice = CM.Sim.BuildingGetPrice(Game.Objects[name], Game.Objects[name].basePrice, 0, Game.Objects[name].free, Game.Objects[name].amount); + var amortizeAmount = buildPrice - Game.Objects[name].totalCookies; + if (amortizeAmount > 0) { + l('tooltip').innerHTML = l('tooltip').innerHTML + .split('so far') + .join('so far
' + Beautify(amortizeAmount) + ' ' + (Math.floor(amortizeAmount) == 1 ? 'cookie' : 'cookies') + ' left to amortize (' + CM.Disp.GetTimeColor(buildPrice, Game.Objects[name].totalCookies, (Game.Objects[name].storedTotalCps * Game.globalCpsMult)).text + ')'); + } + } + if (Game.buyMode == 1) { + var target = ''; + var change = false; + if (Game.buyBulk == 10) { + target = 'Objects10'; + change = true; + } + else if (Game.buyBulk == 100) { + target = 'Objects100'; + change = true; + } + if (change) { + l('tooltip').innerHTML = l('tooltip').innerHTML.split(Beautify(Game.Objects[name].getPrice())).join(Beautify(CM.Cache[target][name].price)); + } + } + else if (Game.buyMode == -1) { + /* + * Fix sell price displayed in the object tooltip. + * + * The buildings sell price displayed by the game itself (without any mod) is incorrect. + * The following line of code fixes this issue, and can be safely removed when the game gets fixed. + * + * This issue is extensively detailed here: https://github.com/Aktanusa/CookieMonster/issues/359#issuecomment-735658262 + */ + l('tooltip').innerHTML = l('tooltip').innerHTML.split(Beautify(Game.Objects[name].bulkPrice)).join(Beautify(CM.Sim.BuildingSell(Game.Objects[name], Game.Objects[name].basePrice, Game.Objects[name].amount, Game.Objects[name].free, Game.buyBulk, 1))); + } + } + else if (type == 'u') { + if (!Game.UpgradesInStore[name]) return ''; + l('tooltip').innerHTML = Game.crateTooltip(Game.UpgradesInStore[name], 'store'); + } + else if (type === 's') { + // Sugar Lump + l('tooltip').innerHTML = Game.lumpTooltip(); + } + else { // Grimoire + l('tooltip').innerHTML = Game.Objects['Wizard tower'].minigame.spellTooltip(name)(); + } + + var area = document.createElement('div'); + area.id = 'CMTooltipArea'; + l('tooltip').appendChild(area); + + if (CM.Config.TooltipBuildUp == 1 && (type == 'u' || (type == 'b' && Game.buyMode == 1))) { + l('tooltip').firstChild.style.paddingBottom = '4px'; + var tooltip = document.createElement('div'); + tooltip.style.border = '1px solid'; + tooltip.style.padding = '4px'; + tooltip.style.margin = '0px -4px'; + tooltip.id = 'CMTooltipBorder'; + + var header = function(text) { + var div = document.createElement('div'); + div.style.fontWeight = 'bold'; + div.className = CM.Disp.colorTextPre + CM.Disp.colorBlue; + div.textContent = text; + return div; + } + + tooltip.appendChild(header('Bonus Income')); + var income = document.createElement('div'); + income.style.marginBottom = '4px'; + income.style.color = 'white'; + income.id = 'CMTooltipIncome'; + tooltip.appendChild(income); + tooltip.appendChild(header('Payback Period')); + var pp = document.createElement('div'); + pp.style.marginBottom = '4px'; + pp.id = 'CMTooltipPP'; + tooltip.appendChild(pp); + tooltip.appendChild(header('Time Left')); + var time = document.createElement('div'); + time.id = 'CMTooltipTime'; + tooltip.appendChild(time); + if (type == 'b') { + tooltip.appendChild(header('Production left till next achievement')); + tooltip.lastChild.id = 'CMTooltipProductionHeader'; + var production = document.createElement('div'); + production.id = 'CMTooltipProduction'; + tooltip.appendChild(production); + } + + area.appendChild(tooltip); + } + + CM.Disp.tooltipType = type; + CM.Disp.tooltipName = name; + + CM.Disp.UpdateTooltip(); + + return l('tooltip').innerHTML; +} + +CM.Disp.UpdateTooltip = function() { + CM.Sim.CopyData(); + if (l('tooltipAnchor').style.display != 'none') { + + if (l('CMTooltipArea') != null) { + if (CM.Disp.tooltipType == 'b' || CM.Disp.tooltipType == 'u') { + // Error checking + if (CM.Disp.tooltipType == 'u' && (typeof Game.UpgradesInStore[CM.Disp.tooltipName] === 'undefined' || typeof CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name] === 'undefined')) { + return; + } + var price; + var bonus; + if (CM.Disp.tooltipType == 'b') { + var target = ''; + if (Game.buyMode == 1 && Game.buyBulk == 10) { + target = 'Objects10'; + price = CM.Cache[target][CM.Disp.tooltipName].price; + } + else if (Game.buyMode == 1 && Game.buyBulk == 100) { + target = 'Objects100'; + price = CM.Cache[target][CM.Disp.tooltipName].price; + } + else { + target = 'Objects'; + price = Game.Objects[CM.Disp.tooltipName].getPrice(); + } + bonus = CM.Cache[target][CM.Disp.tooltipName].bonus; + if (CM.Config.TooltipBuildUp == 1 && Game.buyMode == 1) { + l('CMTooltipBorder').className = CM.Disp.colorTextPre + CM.Cache[target][CM.Disp.tooltipName].color; + l('CMTooltipPP').textContent = Beautify(CM.Cache[target][CM.Disp.tooltipName].pp, 2); + l('CMTooltipPP').className = CM.Disp.colorTextPre + CM.Cache[target][CM.Disp.tooltipName].color; + } + if (CM.Config.TooltipBuildUp) { + for (var i in Game.Objects[CM.Disp.tooltipName].productionAchievs) { + if (!CM.Sim.HasAchiev(Game.Objects[CM.Disp.tooltipName].productionAchievs[i].achiev.name)) { + var nextProductionAchiev = Game.Objects[CM.Disp.tooltipName].productionAchievs[i] + break + } + } + if (typeof nextProductionAchiev != "undefined") { + l('CMTooltipTime').style.marginBottom = '4px'; + l('CMTooltipProductionHeader').style.display = ""; + l('CMTooltipProduction').className = "ProdAchievement" + CM.Disp.tooltipName; + l('CMTooltipProduction').textContent = Beautify(nextProductionAchiev.pow - CM.Sim.Objects[CM.Disp.tooltipName].totalCookies, 15); + l('CMTooltipProduction').style.color = "white"; + } else { + l('CMTooltipProductionHeader').style.display = "none"; + l('CMTooltipTime').style.marginBottom = '0px'; + } + } + } + else { // Upgrades + bonus = CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].bonus; + price = Game.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].getPrice(); + if (CM.Config.TooltipBuildUp == 1) { + l('CMTooltipBorder').className = CM.Disp.colorTextPre + CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].color; + l('CMTooltipPP').textContent = Beautify(CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].pp, 2); + l('CMTooltipPP').className = CM.Disp.colorTextPre + CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].color; + } + } + if (CM.Config.TooltipBuildUp == 1 && (CM.Disp.tooltipType != 'b' || Game.buyMode == 1)) { + l('CMTooltipIncome').textContent = Beautify(bonus, 2); + + var increase = Math.round(bonus / Game.cookiesPs * 10000); + if (isFinite(increase) && increase != 0) { + l('CMTooltipIncome').textContent += ' (' + (increase / 100) + '% of income)'; + } + + var timeColor = CM.Disp.GetTimeColor(price, (Game.cookies + CM.Disp.GetWrinkConfigBank()), CM.Disp.GetCPS()); + l('CMTooltipTime').textContent = timeColor.text; + l('CMTooltipTime').className = CM.Disp.colorTextPre + timeColor.color; + } + + if (CM.Config.ToolWarnPos == 0) { + CM.Disp.TooltipWarn.style.right = '0px'; + } + else { + CM.Disp.TooltipWarn.style.top = (l('tooltip').offsetHeight) + 'px'; + } + CM.Disp.TooltipWarn.style.width = (l('tooltip').offsetWidth - 6) + 'px'; + + if (CM.Config.ToolWarnLucky == 1) { + CM.Disp.TooltipWarn.style.display = 'block'; + var limitLucky = CM.Cache.Lucky; + if (CM.Config.ToolWarnBon == 1) { + var bonusNoFren = bonus; + bonusNoFren /= CM.Sim.getCPSBuffMult(); + limitLucky += ((bonusNoFren * 60 * 15) / 0.15); + } + var limitLuckyFrenzy = limitLucky * 7; + var amount = (Game.cookies + CM.Disp.GetWrinkConfigBank()) - price; + if ((amount < limitLucky || amount < limitLuckyFrenzy) && (CM.Disp.tooltipType != 'b' || Game.buyMode == 1)) { + if (amount < limitLucky) { + l('CMDispTooltipWarnLucky').style.display = ''; + l('CMDispTooltipWarnLuckyText').textContent = Beautify(limitLucky - amount) + ' (' + CM.Disp.FormatTime((limitLucky - amount) / CM.Disp.GetCPS()) + ')'; + l('CMDispTooltipWarnLuckyFrenzy').style.display = ''; + l('CMDispTooltipWarnLuckyFrenzyText').textContent = Beautify(limitLuckyFrenzy - amount) + ' (' + CM.Disp.FormatTime((limitLuckyFrenzy - amount) / CM.Disp.GetCPS()) + ')'; + } + else if (amount < limitLuckyFrenzy) { + l('CMDispTooltipWarnLuckyFrenzy').style.display = ''; + l('CMDispTooltipWarnLuckyFrenzyText').textContent = Beautify(limitLuckyFrenzy - amount) + ' (' + CM.Disp.FormatTime((limitLuckyFrenzy - amount) / CM.Disp.GetCPS()) + ')'; + l('CMDispTooltipWarnLucky').style.display = 'none'; + } + } else { + l('CMDispTooltipWarnLucky').style.display = 'none'; + l('CMDispTooltipWarnLuckyFrenzy').style.display = 'none'; + } + } + else { + l('CMDispTooltipWarnLucky').style.display = 'none'; + l('CMDispTooltipWarnLuckyFrenzy').style.display = 'none'; + } + + if (CM.Config.ToolWarnConjure == 1) { + CM.Disp.TooltipWarn.style.display = 'block'; + var limitLucky = CM.Cache.Lucky; + if (CM.Config.ToolWarnBon == 1) { + var bonusNoFren = bonus; + bonusNoFren /= CM.Sim.getCPSBuffMult(); + limitLucky += ((bonusNoFren * 60 * 15) / 0.15); + } + var limitConjure = limitLucky * 2; + var amount = (Game.cookies + CM.Disp.GetWrinkConfigBank()) - price; + if ((amount < limitConjure) && (CM.Disp.tooltipType != 'b' || Game.buyMode == 1)) { + l('CMDispTooltipWarnConjure').style.display = ''; + l('CMDispTooltipWarnConjureText').textContent = Beautify(limitConjure - amount) + ' (' + CM.Disp.FormatTime((limitConjure - amount) / CM.Disp.GetCPS()) + ')'; + } else { + l('CMDispTooltipWarnConjure').style.display = 'none'; + } + } + else { + l('CMDispTooltipWarnConjure').style.display = 'none'; + } + } + else if (CM.Disp.tooltipType === 's') { + // Adding information about Sugar Lumps. + + CM.Disp.TooltipWarn.style.display = 'none'; + l('CMDispTooltipWarnLucky').style.display = 'none'; + l('CMDispTooltipWarnLuckyFrenzy').style.display = 'none'; + l('CMDispTooltipWarnConjure').style.display = 'none'; + + if (CM.Config.TooltipLump === 1) { + l('CMTooltipArea').innerHTML = ''; + + l('tooltip').firstChild.style.paddingBottom = '4px'; + var lumpTooltip = document.createElement('div'); + lumpTooltip.style.border = '1px solid'; + lumpTooltip.style.padding = '4px'; + lumpTooltip.style.margin = '0px -4px'; + lumpTooltip.id = 'CMTooltipBorder'; + lumpTooltip.className = CM.Disp.colorTextPre + CM.Disp.colorGray; + + var lumpHeader = document.createElement('div'); + lumpHeader.style.fontWeight = 'bold'; + lumpHeader.className = CM.Disp.colorTextPre + CM.Disp.colorBlue; + lumpHeader.textContent = 'Current Sugar Lump'; + + lumpTooltip.appendChild(lumpHeader); + var lumpType = document.createElement('div'); + lumpType.id = 'CMTooltipTime'; + lumpTooltip.appendChild(lumpType); + var lumpColor = CM.Disp.GetLumpColor(Game.lumpCurrentType); + lumpType.textContent = lumpColor.text; + lumpType.className = CM.Disp.colorTextPre + lumpColor.color; + + l('CMTooltipArea').appendChild(lumpTooltip); + } + } + else if (CM.Disp.tooltipType === 'g') { + // Grimoire + CM.Disp.TooltipWarn.style.display = 'none'; + l('CMDispTooltipWarnLucky').style.display = 'none'; + l('CMDispTooltipWarnLuckyFrenzy').style.display = 'none'; + l('CMDispTooltipWarnConjure').style.display = 'none'; + + var minigame = Game.Objects['Wizard tower'].minigame; + var spellCost = minigame.getSpellCost(minigame.spellsById[CM.Disp.tooltipName]); + + if (CM.Config.TooltipGrim == 1 && spellCost <= minigame.magicM) { + l('CMTooltipArea').innerHTML = ''; + + l('tooltip').firstChild.style.paddingBottom = '4px'; + var tooltip = document.createElement('div'); + tooltip.style.border = '1px solid'; + tooltip.style.padding = '4px'; + tooltip.style.margin = '0px -4px'; + tooltip.id = 'CMTooltipBorder'; + tooltip.className = CM.Disp.colorTextPre + CM.Disp.colorGray; + + var header = function(text) { + var div = document.createElement('div'); + div.style.fontWeight = 'bold'; + div.className = CM.Disp.colorTextPre + CM.Disp.colorBlue; + div.textContent = text; + return div; + } + + tooltip.appendChild(header('Time Left')); + var time = document.createElement('div'); + time.id = 'CMTooltipTime'; + tooltip.appendChild(time); + var timeColor = CM.Disp.GetTimeColor(spellCost, minigame.magic, undefined, CM.Disp.CalculateGrimoireRefillTime(minigame.magic, minigame.magicM, spellCost)); + time.textContent = timeColor.text; + time.className = CM.Disp.colorTextPre + timeColor.color; + + if (spellCost <= minigame.magic) { + tooltip.appendChild(header('Recover Time')); + var recover = document.createElement('div'); + recover.id = 'CMTooltipRecover'; + tooltip.appendChild(recover); + var recoverColor = CM.Disp.GetTimeColor(minigame.magic, Math.max(0, minigame.magic - spellCost), undefined, CM.Disp.CalculateGrimoireRefillTime(Math.max(0, minigame.magic - spellCost), minigame.magicM, minigame.magic)); + recover.textContent = recoverColor.text; + recover.className = CM.Disp.colorTextPre + recoverColor.color; + } + + // Extra information when spell is Conjure Baked Goods (Name == 0) + if (CM.Disp.tooltipName == 0) { + tooltip.appendChild(header('Cookies to be gained/lost')); + var conjure = document.createElement('div'); + conjure.id = 'CMTooltipConjure'; + tooltip.appendChild(conjure); + var reward = document.createElement('span'); + reward.style.color = "#33FF00" + reward.textContent = Beautify(Math.min((Game.cookies + CM.Disp.GetWrinkConfigBank()) * 0.15, CM.Cache.NoGoldSwitchCookiesPS * 60 * 30), 2) + conjure.appendChild(reward) + var seperator = document.createElement('span'); + seperator.textContent = ' / ' + conjure.appendChild(seperator) + var loss = document.createElement('span'); + loss.style.color = "red" + loss.textContent = Beautify((CM.Cache.NoGoldSwitchCookiesPS * 60 * 15), 2); + conjure.appendChild(loss) + } + + l('CMTooltipArea').appendChild(tooltip); + } + } + } + else { + CM.Disp.TooltipWarn.style.display = 'none'; + } + } +} + +CM.Disp.DrawTooltipWarn = function() { + if (CM.Config.ToolWarnLucky == 1) { + l('CMDispTooltipWarnLucky').style.opacity = '0'; + l('CMDispTooltipWarnLuckyFrenzy').style.opacity = '0'; + } + if (CM.Config.ToolWarnConjure == 1) { + l('CMDispTooltipWarnConjure').style.opacity = '0'; + } +} + +CM.Disp.UpdateTooltipWarn = function() { + if (CM.Config.ToolWarnLucky == 1 && l('tooltipAnchor').style.display != 'none' && l('CMTooltipArea') != null) { + l('CMDispTooltipWarnLucky').style.opacity = '1'; + l('CMDispTooltipWarnLuckyFrenzy').style.opacity = '1'; + } + if (CM.Config.ToolWarnConjure == 1 && l('tooltipAnchor').style.display != 'none' && l('CMTooltipArea') != null) { + l('CMDispTooltipWarnConjure').style.opacity = '1'; + } +} + +CM.Disp.CheckWrinklerTooltip = function() { + if (CM.Config.ToolWrink == 1 && CM.Disp.TooltipWrinklerArea == 1) { + var showingTooltip = false; + for (var i in Game.wrinklers) { + var me = Game.wrinklers[i]; + if (me.phase > 0 && me.selected) { + showingTooltip = true; + if (CM.Disp.TooltipWrinklerCache[i] == 0) { + var placeholder = document.createElement('div'); + var wrinkler = document.createElement('div'); + wrinkler.style.minWidth = '120px'; + wrinkler.style.marginBottom = '4px'; + var div = document.createElement('div'); + div.style.textAlign = 'center'; + div.id = 'CMTooltipWrinkler'; + wrinkler.appendChild(div); + placeholder.appendChild(wrinkler); + Game.tooltip.draw(this, escape(placeholder.innerHTML)); + CM.Disp.TooltipWrinkler = i; + CM.Disp.TooltipWrinklerCache[i] = 1; + } + else break; + } + else { + CM.Disp.TooltipWrinklerCache[i] = 0; + } + } + if (!showingTooltip) { + Game.tooltip.hide(); + } + } +} + +CM.Disp.UpdateWrinklerTooltip = function() { + if (CM.Config.ToolWrink == 1 && l('CMTooltipWrinkler') != null) { + var sucked = Game.wrinklers[CM.Disp.TooltipWrinkler].sucked; + var toSuck = 1.1; + if (Game.Has('Sacrilegious corruption')) toSuck *= 1.05; + if (Game.wrinklers[CM.Disp.TooltipWrinkler].type == 1) toSuck *= 3; // Shiny wrinklers + sucked *= toSuck; + if (Game.Has('Wrinklerspawn')) sucked *= 1.05; + if (CM.Sim.Objects.Temple.minigameLoaded) { + var godLvl = CM.Sim.hasGod('scorn'); + if (godLvl == 1) sucked *= 1.15; + else if (godLvl == 2) sucked *= 1.1; + else if (godLvl == 3) sucked *= 1.05; + } + l('CMTooltipWrinkler').textContent = Beautify(sucked); + } +} + +/******** + * Section: General functions related to the Options/Stats pages + * TODO: Annotate functions */ + +CM.Disp.AddMenu = function() { + var title = function() { + var div = document.createElement('div'); + div.className = 'title ' + CM.Disp.colorTextPre + CM.Disp.colorBlue; + div.textContent = 'Cookie Monster Goodies'; + return div; + } + + if (Game.onMenu == 'prefs') { + CM.Disp.AddMenuPref(title); + } + else if (Game.onMenu == 'stats') { + if (CM.Config.Stats) { + CM.Disp.AddMenuStats(title); + } + + if (CM.Config.MissingUpgrades) { + CM.Disp.AddMissingUpgrades(); + } + } +} + +CM.Disp.RefreshMenu = function() { + if (CM.Config.UpStats && Game.onMenu == 'stats' && (Game.drawT - 1) % (Game.fps * 5) != 0 && (Game.drawT - 1) % Game.fps == 0) Game.UpdateMenu(); +} + +/******** + * Section: Functions related to the Options page + * TODO: Annotate functions */ + CM.Disp.AddMenuPref = function(title) { var header = function(text, config) { var div = document.createElement('div'); @@ -2286,6 +2977,10 @@ CM.Disp.AddMenuPref = function(title) { //l('formatButton').onclick = function() {Game.Toggle('format', 'formatButton', 'Short numbers OFF', 'Short numbers ON', '1'); PlaySound('snd/tick.mp3'); CM.Disp.RefreshScale();}; } +/******** + * Section: Functions related to the Stats page + * TODO: Annotate functions */ + CM.Disp.AddMenuStats = function(title) { var header = function(text, config) { var div = document.createElement('div'); @@ -2786,645 +3481,9 @@ CM.Disp.AddMissingUpgrades = function() { } } -CM.Disp.AddMenu = function() { - var title = function() { - var div = document.createElement('div'); - div.className = 'title ' + CM.Disp.colorTextPre + CM.Disp.colorBlue; - div.textContent = 'Cookie Monster Goodies'; - return div; - } - - if (Game.onMenu == 'prefs') { - CM.Disp.AddMenuPref(title); - } - else if (Game.onMenu == 'stats') { - if (CM.Config.Stats) { - CM.Disp.AddMenuStats(title); - } - - if (CM.Config.MissingUpgrades) { - CM.Disp.AddMissingUpgrades(); - } - } -} - -CM.Disp.RefreshMenu = function() { - if (CM.Config.UpStats && Game.onMenu == 'stats' && (Game.drawT - 1) % (Game.fps * 5) != 0 && (Game.drawT - 1) % Game.fps == 0) Game.UpdateMenu(); -} - -CM.Disp.FixMouseY = function(target) { - if (CM.Config.TimerBar == 1 && CM.Config.TimerBarPos == 0) { - var timerBarHeight = parseInt(CM.Disp.TimerBar.style.height); - Game.mouseY -= timerBarHeight; - target(); - Game.mouseY += timerBarHeight; - } - else { - target(); - } -} - -CM.Disp.UpdateTooltipLocation = function() { - if (Game.tooltip.origin == 'store') { - var warnOffset = 0; - if (CM.Config.ToolWarnLucky == 1 && CM.Config.ToolWarnPos == 1) warnOffset = CM.Disp.TooltipWarn.clientHeight - 4; - Game.tooltip.tta.style.top = Math.min(parseInt(Game.tooltip.tta.style.top), (l('game').clientHeight + l('topBar').clientHeight) - Game.tooltip.tt.clientHeight - warnOffset - 46) + 'px'; - } - // Kept for future possible use if the code changes again - /*else if (!Game.onCrate && !Game.OnAscend && CM.Config.TimerBar == 1 && CM.Config.TimerBarPos == 0) { - Game.tooltip.tta.style.top = (parseInt(Game.tooltip.tta.style.top) + parseInt(CM.Disp.TimerBar.style.height)) + 'px'; - }*/ -} - -CM.Disp.CreateTooltipWarn = function() { - CM.Disp.TooltipWarn = document.createElement('div'); - CM.Disp.TooltipWarn.style.position = 'absolute'; - CM.Disp.TooltipWarn.style.display = 'none'; - CM.Disp.TooltipWarn.style.left = 'auto'; - CM.Disp.TooltipWarn.style.bottom = 'auto'; - - var create = function(boxId, color, labelTextFront, labelTextBack, deficitId) { - var box = document.createElement('div'); - box.id = boxId; - box.style.display = 'none'; - box.style.WebkitTransition = 'opacity 0.1s ease-out'; - box.style.MozTransition = 'opacity 0.1s ease-out'; - box.style.MsTransition = 'opacity 0.1s ease-out'; - box.style.OTransition = 'opacity 0.1s ease-out'; - box.style.transition = 'opacity 0.1s ease-out'; - box.className = CM.Disp.colorBorderPre + color; - box.style.padding = '2px'; - box.style.background = '#000 url(img/darkNoise.png)'; - var labelDiv = document.createElement('div'); - box.appendChild(labelDiv); - var labelSpan = document.createElement('span'); - labelSpan.className = CM.Disp.colorTextPre + color; - labelSpan.style.fontWeight = 'bold'; - labelSpan.textContent = labelTextFront; - labelDiv.appendChild(labelSpan); - labelDiv.appendChild(document.createTextNode(labelTextBack)); - var deficitDiv = document.createElement('div'); - box.appendChild(deficitDiv); - var deficitSpan = document.createElement('span'); - deficitSpan.id = deficitId; - deficitDiv.appendChild(document.createTextNode('Deficit: ')); - deficitDiv.appendChild(deficitSpan); - return box; - } - CM.Disp.TooltipWarn.appendChild(create('CMDispTooltipWarnLucky', CM.Disp.colorRed, 'Warning: ', 'Purchase of this item will put you under the number of Cookies required for "Lucky!"', 'CMDispTooltipWarnLuckyText')); - CM.Disp.TooltipWarn.firstChild.style.marginBottom = '4px'; - CM.Disp.TooltipWarn.appendChild(create('CMDispTooltipWarnLuckyFrenzy', CM.Disp.colorYellow, 'Warning: ', 'Purchase of this item will put you under the number of Cookies required for "Lucky!" (Frenzy)', 'CMDispTooltipWarnLuckyFrenzyText')); - CM.Disp.TooltipWarn.lastChild.style.marginBottom = '4px'; - CM.Disp.TooltipWarn.appendChild(create('CMDispTooltipWarnConjure', CM.Disp.colorPurple, 'Warning: ', 'Purchase of this item will put you under the number of Cookies required for "Conjure Baked Goods"', 'CMDispTooltipWarnConjureText')); - - - l('tooltipAnchor').appendChild(CM.Disp.TooltipWarn); -} - -CM.Disp.ToggleToolWarnPos = function() { - if (CM.Config.ToolWarnPos == 0) { - CM.Disp.TooltipWarn.style.top = 'auto'; - CM.Disp.TooltipWarn.style.margin = '4px -4px'; - CM.Disp.TooltipWarn.style.padding = '3px 4px'; - } - else { - CM.Disp.TooltipWarn.style.right = 'auto'; - CM.Disp.TooltipWarn.style.margin = '4px'; - CM.Disp.TooltipWarn.style.padding = '4px 3px'; - } -} - -CM.Disp.CalculateGrimoireRefillTime = function(currentMagic, maxMagic, targetMagic) { - var count = 0; - while (currentMagic < targetMagic) { - currentMagic += Math.max(0.002, Math.pow(currentMagic / Math.max(maxMagic, 100), 0.5)) * 0.002; - count++; - } - return count / Game.fps; -} - -CM.Disp.AddTooltipBuild = function() { - CM.Disp.TooltipBuildBack = []; - for (var i in Game.Objects) { - var me = Game.Objects[i]; - if (l('product' + me.id).onmouseover != null) { - CM.Disp.TooltipBuildBack[i] = l('product' + me.id).onmouseover; - eval('l(\'product\' + me.id).onmouseover = function() {Game.tooltip.dynamic = 1; Game.tooltip.draw(this, function() {return CM.Disp.Tooltip(\'b\', \'' + i + '\');}, \'store\'); Game.tooltip.wobble();}'); - } - } -} - -CM.Disp.AddTooltipUpgrade = function() { - CM.Disp.TooltipUpgradeBack = []; - for (var i in Game.UpgradesInStore) { - var me = Game.UpgradesInStore[i]; - if (l('upgrade' + i).onmouseover != null) { - CM.Disp.TooltipUpgradeBack[i] = l('upgrade' + i).onmouseover; - eval('l(\'upgrade\' + i).onmouseover = function() {if (!Game.mouseDown) {Game.setOnCrate(this); Game.tooltip.dynamic = 1; Game.tooltip.draw(this, function() {return CM.Disp.Tooltip(\'u\', \'' + i + '\');}, \'store\'); Game.tooltip.wobble();}}'); - } - } -} - -CM.Disp.AddTooltipGrimoire = function() { - if (Game.Objects['Wizard tower'].minigameLoaded) { - CM.Disp.TooltipGrimoireBack = []; - for (var i in Game.Objects['Wizard tower'].minigame.spellsById) { - if (l('grimoireSpell' + i).onmouseover != null) { - CM.Disp.TooltipGrimoireBack[i] = l('grimoireSpell' + i).onmouseover; - eval('l(\'grimoireSpell\' + i).onmouseover = function() {Game.tooltip.dynamic = 1; Game.tooltip.draw(this, function() {return CM.Disp.Tooltip(\'g\', \'' + i + '\');}, \'this\'); Game.tooltip.wobble();}'); - } - } - } -} - -/** - * This function improves Sugar Lump tooltip by adding extra infromation. - * @constructor - */ -CM.Disp.AddTooltipLump = function() { - if (Game.canLumps()) { - CM.Disp.TooltipLumpBack = l('lumps').onmouseover; - eval('l(\'lumps\').onmouseover = function() {Game.tooltip.dynamic = 1; Game.tooltip.draw(this, function() {return CM.Disp.Tooltip(\'s\', \'Lump\');}, \'this\'); Game.tooltip.wobble();}'); - } -}; - -CM.Disp.Tooltip = function(type, name) { - if (type == 'b') { - l('tooltip').innerHTML = Game.Objects[name].tooltip(); - if (CM.Config.TooltipAmor == 1) { - var buildPrice = CM.Sim.BuildingGetPrice(Game.Objects[name], Game.Objects[name].basePrice, 0, Game.Objects[name].free, Game.Objects[name].amount); - var amortizeAmount = buildPrice - Game.Objects[name].totalCookies; - if (amortizeAmount > 0) { - l('tooltip').innerHTML = l('tooltip').innerHTML - .split('so far') - .join('so far
' + Beautify(amortizeAmount) + ' ' + (Math.floor(amortizeAmount) == 1 ? 'cookie' : 'cookies') + ' left to amortize (' + CM.Disp.GetTimeColor(buildPrice, Game.Objects[name].totalCookies, (Game.Objects[name].storedTotalCps * Game.globalCpsMult)).text + ')'); - } - } - if (Game.buyMode == 1) { - var target = ''; - var change = false; - if (Game.buyBulk == 10) { - target = 'Objects10'; - change = true; - } - else if (Game.buyBulk == 100) { - target = 'Objects100'; - change = true; - } - if (change) { - l('tooltip').innerHTML = l('tooltip').innerHTML.split(Beautify(Game.Objects[name].getPrice())).join(Beautify(CM.Cache[target][name].price)); - } - } - else if (Game.buyMode == -1) { - /* - * Fix sell price displayed in the object tooltip. - * - * The buildings sell price displayed by the game itself (without any mod) is incorrect. - * The following line of code fixes this issue, and can be safely removed when the game gets fixed. - * - * This issue is extensively detailed here: https://github.com/Aktanusa/CookieMonster/issues/359#issuecomment-735658262 - */ - l('tooltip').innerHTML = l('tooltip').innerHTML.split(Beautify(Game.Objects[name].bulkPrice)).join(Beautify(CM.Sim.BuildingSell(Game.Objects[name], Game.Objects[name].basePrice, Game.Objects[name].amount, Game.Objects[name].free, Game.buyBulk, 1))); - } - } - else if (type == 'u') { - if (!Game.UpgradesInStore[name]) return ''; - l('tooltip').innerHTML = Game.crateTooltip(Game.UpgradesInStore[name], 'store'); - } - else if (type === 's') { - // Sugar Lump - l('tooltip').innerHTML = Game.lumpTooltip(); - } - else { // Grimoire - l('tooltip').innerHTML = Game.Objects['Wizard tower'].minigame.spellTooltip(name)(); - } - - var area = document.createElement('div'); - area.id = 'CMTooltipArea'; - l('tooltip').appendChild(area); - - if (CM.Config.TooltipBuildUp == 1 && (type == 'u' || (type == 'b' && Game.buyMode == 1))) { - l('tooltip').firstChild.style.paddingBottom = '4px'; - var tooltip = document.createElement('div'); - tooltip.style.border = '1px solid'; - tooltip.style.padding = '4px'; - tooltip.style.margin = '0px -4px'; - tooltip.id = 'CMTooltipBorder'; - - var header = function(text) { - var div = document.createElement('div'); - div.style.fontWeight = 'bold'; - div.className = CM.Disp.colorTextPre + CM.Disp.colorBlue; - div.textContent = text; - return div; - } - - tooltip.appendChild(header('Bonus Income')); - var income = document.createElement('div'); - income.style.marginBottom = '4px'; - income.style.color = 'white'; - income.id = 'CMTooltipIncome'; - tooltip.appendChild(income); - tooltip.appendChild(header('Payback Period')); - var pp = document.createElement('div'); - pp.style.marginBottom = '4px'; - pp.id = 'CMTooltipPP'; - tooltip.appendChild(pp); - tooltip.appendChild(header('Time Left')); - var time = document.createElement('div'); - time.id = 'CMTooltipTime'; - tooltip.appendChild(time); - if (type == 'b') { - tooltip.appendChild(header('Production left till next achievement')); - tooltip.lastChild.id = 'CMTooltipProductionHeader'; - var production = document.createElement('div'); - production.id = 'CMTooltipProduction'; - tooltip.appendChild(production); - } - - area.appendChild(tooltip); - } - - CM.Disp.tooltipType = type; - CM.Disp.tooltipName = name; - - CM.Disp.UpdateTooltip(); - - return l('tooltip').innerHTML; -} - -CM.Disp.UpdateTooltip = function() { - CM.Sim.CopyData(); - if (l('tooltipAnchor').style.display != 'none') { - - if (l('CMTooltipArea') != null) { - if (CM.Disp.tooltipType == 'b' || CM.Disp.tooltipType == 'u') { - // Error checking - if (CM.Disp.tooltipType == 'u' && (typeof Game.UpgradesInStore[CM.Disp.tooltipName] === 'undefined' || typeof CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name] === 'undefined')) { - return; - } - var price; - var bonus; - if (CM.Disp.tooltipType == 'b') { - var target = ''; - if (Game.buyMode == 1 && Game.buyBulk == 10) { - target = 'Objects10'; - price = CM.Cache[target][CM.Disp.tooltipName].price; - } - else if (Game.buyMode == 1 && Game.buyBulk == 100) { - target = 'Objects100'; - price = CM.Cache[target][CM.Disp.tooltipName].price; - } - else { - target = 'Objects'; - price = Game.Objects[CM.Disp.tooltipName].getPrice(); - } - bonus = CM.Cache[target][CM.Disp.tooltipName].bonus; - if (CM.Config.TooltipBuildUp == 1 && Game.buyMode == 1) { - l('CMTooltipBorder').className = CM.Disp.colorTextPre + CM.Cache[target][CM.Disp.tooltipName].color; - l('CMTooltipPP').textContent = Beautify(CM.Cache[target][CM.Disp.tooltipName].pp, 2); - l('CMTooltipPP').className = CM.Disp.colorTextPre + CM.Cache[target][CM.Disp.tooltipName].color; - } - if (CM.Config.TooltipBuildUp) { - for (var i in Game.Objects[CM.Disp.tooltipName].productionAchievs) { - if (!CM.Sim.HasAchiev(Game.Objects[CM.Disp.tooltipName].productionAchievs[i].achiev.name)) { - var nextProductionAchiev = Game.Objects[CM.Disp.tooltipName].productionAchievs[i] - break - } - } - if (typeof nextProductionAchiev != "undefined") { - l('CMTooltipTime').style.marginBottom = '4px'; - l('CMTooltipProductionHeader').style.display = ""; - l('CMTooltipProduction').className = "ProdAchievement" + CM.Disp.tooltipName; - l('CMTooltipProduction').textContent = Beautify(nextProductionAchiev.pow - CM.Sim.Objects[CM.Disp.tooltipName].totalCookies, 15); - l('CMTooltipProduction').style.color = "white"; - } else { - l('CMTooltipProductionHeader').style.display = "none"; - l('CMTooltipTime').style.marginBottom = '0px'; - } - } - } - else { // Upgrades - bonus = CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].bonus; - price = Game.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].getPrice(); - if (CM.Config.TooltipBuildUp == 1) { - l('CMTooltipBorder').className = CM.Disp.colorTextPre + CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].color; - l('CMTooltipPP').textContent = Beautify(CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].pp, 2); - l('CMTooltipPP').className = CM.Disp.colorTextPre + CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].color; - } - } - if (CM.Config.TooltipBuildUp == 1 && (CM.Disp.tooltipType != 'b' || Game.buyMode == 1)) { - l('CMTooltipIncome').textContent = Beautify(bonus, 2); - - var increase = Math.round(bonus / Game.cookiesPs * 10000); - if (isFinite(increase) && increase != 0) { - l('CMTooltipIncome').textContent += ' (' + (increase / 100) + '% of income)'; - } - - var timeColor = CM.Disp.GetTimeColor(price, (Game.cookies + CM.Disp.GetWrinkConfigBank()), CM.Disp.GetCPS()); - l('CMTooltipTime').textContent = timeColor.text; - l('CMTooltipTime').className = CM.Disp.colorTextPre + timeColor.color; - } - - if (CM.Config.ToolWarnPos == 0) { - CM.Disp.TooltipWarn.style.right = '0px'; - } - else { - CM.Disp.TooltipWarn.style.top = (l('tooltip').offsetHeight) + 'px'; - } - CM.Disp.TooltipWarn.style.width = (l('tooltip').offsetWidth - 6) + 'px'; - - if (CM.Config.ToolWarnLucky == 1) { - CM.Disp.TooltipWarn.style.display = 'block'; - var limitLucky = CM.Cache.Lucky; - if (CM.Config.ToolWarnBon == 1) { - var bonusNoFren = bonus; - bonusNoFren /= CM.Sim.getCPSBuffMult(); - limitLucky += ((bonusNoFren * 60 * 15) / 0.15); - } - var limitLuckyFrenzy = limitLucky * 7; - var amount = (Game.cookies + CM.Disp.GetWrinkConfigBank()) - price; - if ((amount < limitLucky || amount < limitLuckyFrenzy) && (CM.Disp.tooltipType != 'b' || Game.buyMode == 1)) { - if (amount < limitLucky) { - l('CMDispTooltipWarnLucky').style.display = ''; - l('CMDispTooltipWarnLuckyText').textContent = Beautify(limitLucky - amount) + ' (' + CM.Disp.FormatTime((limitLucky - amount) / CM.Disp.GetCPS()) + ')'; - l('CMDispTooltipWarnLuckyFrenzy').style.display = ''; - l('CMDispTooltipWarnLuckyFrenzyText').textContent = Beautify(limitLuckyFrenzy - amount) + ' (' + CM.Disp.FormatTime((limitLuckyFrenzy - amount) / CM.Disp.GetCPS()) + ')'; - } - else if (amount < limitLuckyFrenzy) { - l('CMDispTooltipWarnLuckyFrenzy').style.display = ''; - l('CMDispTooltipWarnLuckyFrenzyText').textContent = Beautify(limitLuckyFrenzy - amount) + ' (' + CM.Disp.FormatTime((limitLuckyFrenzy - amount) / CM.Disp.GetCPS()) + ')'; - l('CMDispTooltipWarnLucky').style.display = 'none'; - } - } else { - l('CMDispTooltipWarnLucky').style.display = 'none'; - l('CMDispTooltipWarnLuckyFrenzy').style.display = 'none'; - } - } - else { - l('CMDispTooltipWarnLucky').style.display = 'none'; - l('CMDispTooltipWarnLuckyFrenzy').style.display = 'none'; - } - - if (CM.Config.ToolWarnConjure == 1) { - CM.Disp.TooltipWarn.style.display = 'block'; - var limitLucky = CM.Cache.Lucky; - if (CM.Config.ToolWarnBon == 1) { - var bonusNoFren = bonus; - bonusNoFren /= CM.Sim.getCPSBuffMult(); - limitLucky += ((bonusNoFren * 60 * 15) / 0.15); - } - var limitConjure = limitLucky * 2; - var amount = (Game.cookies + CM.Disp.GetWrinkConfigBank()) - price; - if ((amount < limitConjure) && (CM.Disp.tooltipType != 'b' || Game.buyMode == 1)) { - l('CMDispTooltipWarnConjure').style.display = ''; - l('CMDispTooltipWarnConjureText').textContent = Beautify(limitConjure - amount) + ' (' + CM.Disp.FormatTime((limitConjure - amount) / CM.Disp.GetCPS()) + ')'; - } else { - l('CMDispTooltipWarnConjure').style.display = 'none'; - } - } - else { - l('CMDispTooltipWarnConjure').style.display = 'none'; - } - } - else if (CM.Disp.tooltipType === 's') { - // Adding information about Sugar Lumps. - - CM.Disp.TooltipWarn.style.display = 'none'; - l('CMDispTooltipWarnLucky').style.display = 'none'; - l('CMDispTooltipWarnLuckyFrenzy').style.display = 'none'; - l('CMDispTooltipWarnConjure').style.display = 'none'; - - if (CM.Config.TooltipLump === 1) { - l('CMTooltipArea').innerHTML = ''; - - l('tooltip').firstChild.style.paddingBottom = '4px'; - var lumpTooltip = document.createElement('div'); - lumpTooltip.style.border = '1px solid'; - lumpTooltip.style.padding = '4px'; - lumpTooltip.style.margin = '0px -4px'; - lumpTooltip.id = 'CMTooltipBorder'; - lumpTooltip.className = CM.Disp.colorTextPre + CM.Disp.colorGray; - - var lumpHeader = document.createElement('div'); - lumpHeader.style.fontWeight = 'bold'; - lumpHeader.className = CM.Disp.colorTextPre + CM.Disp.colorBlue; - lumpHeader.textContent = 'Current Sugar Lump'; - - lumpTooltip.appendChild(lumpHeader); - var lumpType = document.createElement('div'); - lumpType.id = 'CMTooltipTime'; - lumpTooltip.appendChild(lumpType); - var lumpColor = CM.Disp.GetLumpColor(Game.lumpCurrentType); - lumpType.textContent = lumpColor.text; - lumpType.className = CM.Disp.colorTextPre + lumpColor.color; - - l('CMTooltipArea').appendChild(lumpTooltip); - } - } - else if (CM.Disp.tooltipType === 'g') { - // Grimoire - CM.Disp.TooltipWarn.style.display = 'none'; - l('CMDispTooltipWarnLucky').style.display = 'none'; - l('CMDispTooltipWarnLuckyFrenzy').style.display = 'none'; - l('CMDispTooltipWarnConjure').style.display = 'none'; - - var minigame = Game.Objects['Wizard tower'].minigame; - var spellCost = minigame.getSpellCost(minigame.spellsById[CM.Disp.tooltipName]); - - if (CM.Config.TooltipGrim == 1 && spellCost <= minigame.magicM) { - l('CMTooltipArea').innerHTML = ''; - - l('tooltip').firstChild.style.paddingBottom = '4px'; - var tooltip = document.createElement('div'); - tooltip.style.border = '1px solid'; - tooltip.style.padding = '4px'; - tooltip.style.margin = '0px -4px'; - tooltip.id = 'CMTooltipBorder'; - tooltip.className = CM.Disp.colorTextPre + CM.Disp.colorGray; - - var header = function(text) { - var div = document.createElement('div'); - div.style.fontWeight = 'bold'; - div.className = CM.Disp.colorTextPre + CM.Disp.colorBlue; - div.textContent = text; - return div; - } - - tooltip.appendChild(header('Time Left')); - var time = document.createElement('div'); - time.id = 'CMTooltipTime'; - tooltip.appendChild(time); - var timeColor = CM.Disp.GetTimeColor(spellCost, minigame.magic, undefined, CM.Disp.CalculateGrimoireRefillTime(minigame.magic, minigame.magicM, spellCost)); - time.textContent = timeColor.text; - time.className = CM.Disp.colorTextPre + timeColor.color; - - if (spellCost <= minigame.magic) { - tooltip.appendChild(header('Recover Time')); - var recover = document.createElement('div'); - recover.id = 'CMTooltipRecover'; - tooltip.appendChild(recover); - var recoverColor = CM.Disp.GetTimeColor(minigame.magic, Math.max(0, minigame.magic - spellCost), undefined, CM.Disp.CalculateGrimoireRefillTime(Math.max(0, minigame.magic - spellCost), minigame.magicM, minigame.magic)); - recover.textContent = recoverColor.text; - recover.className = CM.Disp.colorTextPre + recoverColor.color; - } - - // Extra information when spell is Conjure Baked Goods (Name == 0) - if (CM.Disp.tooltipName == 0) { - tooltip.appendChild(header('Cookies to be gained/lost')); - var conjure = document.createElement('div'); - conjure.id = 'CMTooltipConjure'; - tooltip.appendChild(conjure); - var reward = document.createElement('span'); - reward.style.color = "#33FF00" - reward.textContent = Beautify(Math.min((Game.cookies + CM.Disp.GetWrinkConfigBank()) * 0.15, CM.Cache.NoGoldSwitchCookiesPS * 60 * 30), 2) - conjure.appendChild(reward) - var seperator = document.createElement('span'); - seperator.textContent = ' / ' - conjure.appendChild(seperator) - var loss = document.createElement('span'); - loss.style.color = "red" - loss.textContent = Beautify((CM.Cache.NoGoldSwitchCookiesPS * 60 * 15), 2); - conjure.appendChild(loss) - } - - l('CMTooltipArea').appendChild(tooltip); - } - } - } - else { - CM.Disp.TooltipWarn.style.display = 'none'; - } - } -} - -CM.Disp.DrawTooltipWarn = function() { - if (CM.Config.ToolWarnLucky == 1) { - l('CMDispTooltipWarnLucky').style.opacity = '0'; - l('CMDispTooltipWarnLuckyFrenzy').style.opacity = '0'; - } - if (CM.Config.ToolWarnConjure == 1) { - l('CMDispTooltipWarnConjure').style.opacity = '0'; - } -} - -CM.Disp.UpdateTooltipWarn = function() { - if (CM.Config.ToolWarnLucky == 1 && l('tooltipAnchor').style.display != 'none' && l('CMTooltipArea') != null) { - l('CMDispTooltipWarnLucky').style.opacity = '1'; - l('CMDispTooltipWarnLuckyFrenzy').style.opacity = '1'; - } - if (CM.Config.ToolWarnConjure == 1 && l('tooltipAnchor').style.display != 'none' && l('CMTooltipArea') != null) { - l('CMDispTooltipWarnConjure').style.opacity = '1'; - } -} - -CM.Disp.AddWrinklerAreaDetect = function() { - l('backgroundLeftCanvas').onmouseover = function() {CM.Disp.TooltipWrinklerArea = 1;}; - l('backgroundLeftCanvas').onmouseout = function() { - CM.Disp.TooltipWrinklerArea = 0; - Game.tooltip.hide(); - for (var i in Game.wrinklers) { - CM.Disp.TooltipWrinklerCache[i] = 0; - } - }; -} - -CM.Disp.CheckWrinklerTooltip = function() { - if (CM.Config.ToolWrink == 1 && CM.Disp.TooltipWrinklerArea == 1) { - var showingTooltip = false; - for (var i in Game.wrinklers) { - var me = Game.wrinklers[i]; - if (me.phase > 0 && me.selected) { - showingTooltip = true; - if (CM.Disp.TooltipWrinklerCache[i] == 0) { - var placeholder = document.createElement('div'); - var wrinkler = document.createElement('div'); - wrinkler.style.minWidth = '120px'; - wrinkler.style.marginBottom = '4px'; - var div = document.createElement('div'); - div.style.textAlign = 'center'; - div.id = 'CMTooltipWrinkler'; - wrinkler.appendChild(div); - placeholder.appendChild(wrinkler); - Game.tooltip.draw(this, escape(placeholder.innerHTML)); - CM.Disp.TooltipWrinkler = i; - CM.Disp.TooltipWrinklerCache[i] = 1; - } - else break; - } - else { - CM.Disp.TooltipWrinklerCache[i] = 0; - } - } - if (!showingTooltip) { - Game.tooltip.hide(); - } - } -} - -CM.Disp.UpdateWrinklerTooltip = function() { - if (CM.Config.ToolWrink == 1 && l('CMTooltipWrinkler') != null) { - var sucked = Game.wrinklers[CM.Disp.TooltipWrinkler].sucked; - var toSuck = 1.1; - if (Game.Has('Sacrilegious corruption')) toSuck *= 1.05; - if (Game.wrinklers[CM.Disp.TooltipWrinkler].type == 1) toSuck *= 3; // Shiny wrinklers - sucked *= toSuck; - if (Game.Has('Wrinklerspawn')) sucked *= 1.05; - if (CM.Sim.Objects.Temple.minigameLoaded) { - var godLvl = CM.Sim.hasGod('scorn'); - if (godLvl == 1) sucked *= 1.15; - else if (godLvl == 2) sucked *= 1.1; - else if (godLvl == 3) sucked *= 1.05; - } - l('CMTooltipWrinkler').textContent = Beautify(sucked); - } -} - -CM.Disp.UpdateAscendState = function() { - if (Game.OnAscend) { - l('game').style.bottom = '0px'; - if (CM.Config.BotBar == 1) CM.Disp.BotBar.style.display = 'none'; - if (CM.Config.TimerBar == 1) CM.Disp.TimerBar.style.display = 'none'; - } - else { - CM.Disp.ToggleBotBar(); - CM.Disp.ToggleTimerBar(); - } - - CM.Disp.UpdateBackground(); -} - -CM.Disp.UpdateAuraDescription = function() { - return "function(aura)\ - {\ - l('dragonAuraInfo').innerHTML=\ - '

'+Game.dragonAuras[aura].name+'

'+\ - '
'+\ - Game.dragonAuras[aura].desc+\ - '
'+\ - CM.\ - '
';\ - }" -} - -CM.Disp.ToggleSayTime = function() { - if (CM.Config.SayTime == 1) { - Game.sayTime = CM.Disp.sayTime; - } - else { - Game.sayTime = CM.Backup.sayTime; - } -} - -CM.Disp.RefreshScale = function() { - BeautifyAll(); - Game.RefreshStore(); - Game.RebuildUpgrades(); - - CM.Disp.UpdateBotBarOther(); - CM.Disp.UpdateBuildings(); - CM.Disp.UpdateUpgrades(); -} +/******** + * Section: Variables used in Disp functions + * TODO: Move certain variables to src/Data.js (e.g., CM.Disp.metric & CM.Disp.shortScale) */ CM.Disp.colorTextPre = 'CMText'; CM.Disp.colorBackPre = 'CMBack'; diff --git a/src/Disp.js b/src/Disp.js index 6c567bd..c1dd66d 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -2,37 +2,10 @@ * Disp * ********/ -// General functions to format or beautify strings - -/** - * This function returns time as a string depending on TimeFormat setting - * @param type Time as number, longFormat 1 or 0. - */ -CM.Disp.FormatTime = function(time, longFormat) { - if (time == Infinity) return time; - time = Math.ceil(time); - var y = Math.floor(time / 31557600); - var d = Math.floor(time % 31557600 / 86400); - var h = Math.floor(time % 86400 / 3600); - var m = Math.floor(time % 3600 / 60); - var s = Math.floor(time % 60); - var str = ''; - if (CM.Config.TimeFormat) { - if (time > 3155760000) return 'XX:XX:XX:XX:XX'; - str += (y < 10 ? '0' : '') + y + ':'; - str += (d < 10 ? '0' : '') + d + ':'; - str += (h < 10 ? '0' : '') + h + ':'; - str += (m < 10 ? '0' : '') + m + ':'; - str += (s < 10 ? '0' : '') + s + ':'; - } else { - if (time > 777600000) return longFormat ? 'Over 9000 days!' : '>9000d'; - str += (d > 0 ? d + (longFormat ? (d == 1 ? ' day' : ' days') : 'd') + ', ': ""); - if (str.length > 0 || h > 0) str += h + (longFormat ? (h == 1 ? ' hour' : ' hours') : 'h') + ', '; - if (str.length > 0 || m > 0) str += m + (longFormat ? (m == 1 ? ' minute' : ' minutes') : 'm') + ', '; - str += s + (longFormat ? (s == 1 ? ' second' : ' seconds') : 's'); - } - return str; -} +/******** + * Section: Unsorted functions + * TODO: Annotate most functions + * TODO: Sort functionsn in relevant (new) sections or files */ CM.Disp.GetTimeColor = function(price, bank, cps, time) { var color; @@ -107,6 +80,279 @@ CM.Disp.GetLumpColor = function(type) { return {text: name, color: color}; }; +CM.Disp.GetWrinkConfigBank = function() { + if (CM.Config.CalcWrink) + return CM.Cache.WrinkBank; + else + return 0; +} + +CM.Disp.GetCPS = function() { + if (CM.Config.CPSMode) + return CM.Cache.AvgCPS; + else + return (Game.cookiesPs * (1 - Game.cpsSucked)); +} + +CM.Disp.UpdateBackground = function() { + Game.Background.canvas.width = Game.Background.canvas.parentNode.offsetWidth; + Game.Background.canvas.height = Game.Background.canvas.parentNode.offsetHeight; + Game.LeftBackground.canvas.width = Game.LeftBackground.canvas.parentNode.offsetWidth; + Game.LeftBackground.canvas.height = Game.LeftBackground.canvas.parentNode.offsetHeight; +} + +CM.Disp.GetConfigDisplay = function(config) { + return CM.ConfigData[config].label[CM.Config[config]]; +} + +CM.Disp.AddJscolor = function() { + CM.Disp.Jscolor = document.createElement('script'); + CM.Disp.Jscolor.type = 'text/javascript'; + CM.Disp.Jscolor.setAttribute('src', 'https://aktanusa.github.io/CookieMonster/jscolor/jscolor.js'); + document.head.appendChild(CM.Disp.Jscolor); +} + +CM.Disp.CreateCssArea = function() { + CM.Disp.Css = document.createElement('style'); + CM.Disp.Css.type = 'text/css'; + + document.head.appendChild(CM.Disp.Css); + + // given the architecture of your code, you probably want these lines somewhere else, + // but I stuck them here for convenience + l("products").style.display = "grid"; + l("storeBulk").style.gridRow = "1/1"; + + l("upgrades").style.display = "flex"; + l("upgrades").style["flex-wrap"] = "wrap"; +} + +CM.Disp.UpdateUpgrades = function() { + if (CM.Config.UpBarColor > 0) { + var blue = 0; + var green = 0; + var yellow = 0; + var orange = 0; + var red = 0; + var purple = 0; + var gray = 0; + + for (var i in Game.UpgradesInStore) { + var me = Game.UpgradesInStore[i]; + var addedColor = false; + for (var j = 0; j < l('upgrade' + i).childNodes.length; j++) { + if (l('upgrade' + i).childNodes[j].className.indexOf(CM.Disp.colorBackPre) != -1) { + l('upgrade' + i).childNodes[j].className = CM.Disp.colorBackPre + CM.Cache.Upgrades[me.name].color; + addedColor = true; + break; + } + } + if (!addedColor) { + var div = document.createElement('div'); + div.style.width = '10px'; + div.style.height = '10px'; + div.className = CM.Disp.colorBackPre + CM.Cache.Upgrades[me.name].color; + l('upgrade' + i).appendChild(div); + } + if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorBlue) blue++; + else if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorGreen) green++; + else if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorYellow) yellow++; + else if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorOrange) orange++; + else if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorRed) red++; + else if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorPurple) purple++; + else if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorGray) gray++; + } + + l('CMUpgradeBarBlue').textContent = blue; + l('CMUpgradeBarGreen').textContent = green; + l('CMUpgradeBarYellow').textContent = yellow; + l('CMUpgradeBarOrange').textContent = orange; + l('CMUpgradeBarRed').textContent = red; + l('CMUpgradeBarPurple').textContent = purple; + l('CMUpgradeBarGray').textContent = gray; + } + + // Build array of pointers, sort by pp, set flex positions + var arr = []; + for (var x = 0; x < Game.UpgradesInStore.length; x++){ + var o = {}; + o.name = Game.UpgradesInStore[x].name; + o.price = Game.UpgradesInStore[x].basePrice; + o.pp = CM.Cache.Upgrades[o.name].pp; + arr.push(o); + } + + if (CM.Config.SortUpgrades) + arr.sort((a, b) => a.pp - b.pp); + else + arr.sort((a, b) => a.price - b.price); + + for (var x = 0; x < Game.UpgradesInStore.length; x++){ + l("upgrade" + x).style.order = arr.findIndex(e => e.name === Game.UpgradesInStore[x].name) + 1 + } +} + +CM.Disp.UpdateColors = function() { + var str = ''; + for (var i = 0; i < CM.Disp.colors.length; i++) { + str += '.' + CM.Disp.colorTextPre + CM.Disp.colors[i] + ' { color: ' + CM.Config.Colors[CM.Disp.colors[i]] + '; }\n'; + } + for (var i = 0; i < CM.Disp.colors.length; i++) { + str += '.' + CM.Disp.colorBackPre + CM.Disp.colors[i] + ' { background-color: ' + CM.Config.Colors[CM.Disp.colors[i]] + '; }\n'; + } + for (var i = 0; i < CM.Disp.colors.length; i++) { + str += '.' + CM.Disp.colorBorderPre + CM.Disp.colors[i] + ' { border: 1px solid ' + CM.Config.Colors[CM.Disp.colors[i]] + '; }\n'; + } + CM.Disp.Css.textContent = str; + CM.Disp.UpdateBuildings(); // Class has been already set +} + +CM.Disp.CreateWhiteScreen = function() { + CM.Disp.WhiteScreen = document.createElement('div'); + CM.Disp.WhiteScreen.id = 'CMWhiteScreen'; + CM.Disp.WhiteScreen.style.width = '100%'; + CM.Disp.WhiteScreen.style.height = '100%'; + CM.Disp.WhiteScreen.style.backgroundColor = 'white'; + CM.Disp.WhiteScreen.style.display = 'none'; + CM.Disp.WhiteScreen.style.zIndex = '9999999999'; + CM.Disp.WhiteScreen.style.position = 'absolute'; + + l('wrapper').appendChild(CM.Disp.WhiteScreen); +} + +CM.Disp.FindShimmer = function() { + CM.Disp.currSpawnedGoldenCookieState = 0 + CM.Disp.goldenShimmersByID = {} + for (var i in Game.shimmers) { + CM.Disp.goldenShimmersByID[Game.shimmers[i].id] = Game.shimmers[i] + if (Game.shimmers[i].spawnLead && Game.shimmers[i].type == 'golden') { + CM.Disp.spawnedGoldenShimmer = Game.shimmers[i]; + CM.Disp.currSpawnedGoldenCookieState += 1; + } + } +} + +CM.Disp.CollectWrinklers = function() { + for (var i in Game.wrinklers) { + if (Game.wrinklers[i].sucked > 0 && Game.wrinklers[i].type == 0) { + Game.wrinklers[i].hp = 0; + } + } +} + +CM.Disp.FixMouseY = function(target) { + if (CM.Config.TimerBar == 1 && CM.Config.TimerBarPos == 0) { + var timerBarHeight = parseInt(CM.Disp.TimerBar.style.height); + Game.mouseY -= timerBarHeight; + target(); + Game.mouseY += timerBarHeight; + } + else { + target(); + } +} + +CM.Disp.CalculateGrimoireRefillTime = function(currentMagic, maxMagic, targetMagic) { + var count = 0; + while (currentMagic < targetMagic) { + currentMagic += Math.max(0.002, Math.pow(currentMagic / Math.max(maxMagic, 100), 0.5)) * 0.002; + count++; + } + return count / Game.fps; +} + +CM.Disp.AddWrinklerAreaDetect = function() { + l('backgroundLeftCanvas').onmouseover = function() {CM.Disp.TooltipWrinklerArea = 1;}; + l('backgroundLeftCanvas').onmouseout = function() { + CM.Disp.TooltipWrinklerArea = 0; + Game.tooltip.hide(); + for (var i in Game.wrinklers) { + CM.Disp.TooltipWrinklerCache[i] = 0; + } + }; +} + +CM.Disp.UpdateAscendState = function() { + if (Game.OnAscend) { + l('game').style.bottom = '0px'; + if (CM.Config.BotBar == 1) CM.Disp.BotBar.style.display = 'none'; + if (CM.Config.TimerBar == 1) CM.Disp.TimerBar.style.display = 'none'; + } + else { + CM.Disp.ToggleBotBar(); + CM.Disp.ToggleTimerBar(); + } + + CM.Disp.UpdateBackground(); +} + +CM.Disp.UpdateAuraDescription = function() { + return "function(aura)\ + {\ + l('dragonAuraInfo').innerHTML=\ + '

'+Game.dragonAuras[aura].name+'

'+\ + '
'+\ + Game.dragonAuras[aura].desc+\ + '
'+\ + CM.\ + '
';\ + }" +} + +CM.Disp.ToggleSayTime = function() { + if (CM.Config.SayTime == 1) { + Game.sayTime = CM.Disp.sayTime; + } + else { + Game.sayTime = CM.Backup.sayTime; + } +} + +CM.Disp.RefreshScale = function() { + BeautifyAll(); + Game.RefreshStore(); + Game.RebuildUpgrades(); + + CM.Disp.UpdateBotBarOther(); + CM.Disp.UpdateBuildings(); + CM.Disp.UpdateUpgrades(); +} +/******** + * Section: General functions to format or beautify strings + * TODO: Annotate most functions */ + +/** + * This function returns time as a string depending on TimeFormat setting + * @param {number} time Time as number + * @param {number} longFormat 1 or 0 + * @return {string} + */ +CM.Disp.FormatTime = function(time, longFormat) { + if (time == Infinity) return time; + time = Math.ceil(time); + var y = Math.floor(time / 31557600); + var d = Math.floor(time % 31557600 / 86400); + var h = Math.floor(time % 86400 / 3600); + var m = Math.floor(time % 3600 / 60); + var s = Math.floor(time % 60); + var str = ''; + if (CM.Config.TimeFormat) { + if (time > 3155760000) return 'XX:XX:XX:XX:XX'; + str += (y < 10 ? '0' : '') + y + ':'; + str += (d < 10 ? '0' : '') + d + ':'; + str += (h < 10 ? '0' : '') + h + ':'; + str += (m < 10 ? '0' : '') + m + ':'; + str += (s < 10 ? '0' : '') + s + ':'; + } else { + if (time > 777600000) return longFormat ? 'Over 9000 days!' : '>9000d'; + str += (d > 0 ? d + (longFormat ? (d == 1 ? ' day' : ' days') : 'd') + ', ': ""); + if (str.length > 0 || h > 0) str += h + (longFormat ? (h == 1 ? ' hour' : ' hours') : 'h') + ', '; + if (str.length > 0 || m > 0) str += m + (longFormat ? (m == 1 ? ' minute' : ' minutes') : 'm') + ', '; + str += s + (longFormat ? (s == 1 ? ' second' : ' seconds') : 's'); + } + return str; +} + CM.Disp.Beautify = function(num, frac) { if (CM.Config.Scale != 0 && isFinite(num)) { var answer = ''; @@ -210,52 +456,9 @@ CM.Disp.Beautify = function(num, frac) { } } -CM.Disp.GetWrinkConfigBank = function() { - if (CM.Config.CalcWrink) - return CM.Cache.WrinkBank; - else - return 0; -} - -CM.Disp.GetCPS = function() { - if (CM.Config.CPSMode) - return CM.Cache.AvgCPS; - else - return (Game.cookiesPs * (1 - Game.cpsSucked)); -} - -CM.Disp.UpdateBackground = function() { - Game.Background.canvas.width = Game.Background.canvas.parentNode.offsetWidth; - Game.Background.canvas.height = Game.Background.canvas.parentNode.offsetHeight; - Game.LeftBackground.canvas.width = Game.LeftBackground.canvas.parentNode.offsetWidth; - Game.LeftBackground.canvas.height = Game.LeftBackground.canvas.parentNode.offsetHeight; -} - -CM.Disp.GetConfigDisplay = function(config) { - return CM.ConfigData[config].label[CM.Config[config]]; -} - -CM.Disp.AddJscolor = function() { - CM.Disp.Jscolor = document.createElement('script'); - CM.Disp.Jscolor.type = 'text/javascript'; - CM.Disp.Jscolor.setAttribute('src', 'https://aktanusa.github.io/CookieMonster/jscolor/jscolor.js'); - document.head.appendChild(CM.Disp.Jscolor); -} - -CM.Disp.CreateCssArea = function() { - CM.Disp.Css = document.createElement('style'); - CM.Disp.Css.type = 'text/css'; - - document.head.appendChild(CM.Disp.Css); - - // given the architecture of your code, you probably want these lines somewhere else, - // but I stuck them here for convenience - l("products").style.display = "grid"; - l("storeBulk").style.gridRow = "1/1"; - - l("upgrades").style.display = "flex"; - l("upgrades").style["flex-wrap"] = "wrap"; -} +/******** + * Section: Functions related to the Bottom Bar + * TODO: Annotate functions */ /** * Extends the bottom bar (created by CM.Disp.CreateBotBar) with a column for the given building. @@ -378,6 +581,10 @@ CM.Disp.UpdateBotBarTime = function() { } } +/******** + * Section: Functions related to the Timer Bar + * TODO: Annotate functions */ + CM.Disp.CreateTimerBar = function() { CM.Disp.TimerBar = document.createElement('div'); CM.Disp.TimerBar.id = 'CMTimerBar'; @@ -637,6 +844,10 @@ CM.Disp.UpdateBotTimerBarDisplay = function() { CM.Disp.UpdateBackground(); } +/******** + * Section: Functions related to column of buildings/objects + * TODO: Annotate functions */ + CM.Disp.UpdateBuildings = function() { if (CM.Config.BuildColor == 1 && Game.buyMode == 1) { var target = ''; @@ -700,6 +911,10 @@ CM.Disp.UpdateBuildings = function() { } } +/******** + * Section: Functions related to the Upgrade Bar + * TODO: Annotate functions */ + CM.Disp.CreateUpgradeBar = function() { CM.Disp.UpgradeBar = document.createElement('div'); CM.Disp.UpgradeBar.id = 'CMUpgradeBar'; @@ -781,86 +996,6 @@ CM.Disp.ToggleUpBarColor = function() { } } -CM.Disp.UpdateUpgrades = function() { - if (CM.Config.UpBarColor > 0) { - var blue = 0; - var green = 0; - var yellow = 0; - var orange = 0; - var red = 0; - var purple = 0; - var gray = 0; - - for (var i in Game.UpgradesInStore) { - var me = Game.UpgradesInStore[i]; - var addedColor = false; - for (var j = 0; j < l('upgrade' + i).childNodes.length; j++) { - if (l('upgrade' + i).childNodes[j].className.indexOf(CM.Disp.colorBackPre) != -1) { - l('upgrade' + i).childNodes[j].className = CM.Disp.colorBackPre + CM.Cache.Upgrades[me.name].color; - addedColor = true; - break; - } - } - if (!addedColor) { - var div = document.createElement('div'); - div.style.width = '10px'; - div.style.height = '10px'; - div.className = CM.Disp.colorBackPre + CM.Cache.Upgrades[me.name].color; - l('upgrade' + i).appendChild(div); - } - if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorBlue) blue++; - else if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorGreen) green++; - else if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorYellow) yellow++; - else if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorOrange) orange++; - else if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorRed) red++; - else if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorPurple) purple++; - else if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorGray) gray++; - } - - l('CMUpgradeBarBlue').textContent = blue; - l('CMUpgradeBarGreen').textContent = green; - l('CMUpgradeBarYellow').textContent = yellow; - l('CMUpgradeBarOrange').textContent = orange; - l('CMUpgradeBarRed').textContent = red; - l('CMUpgradeBarPurple').textContent = purple; - l('CMUpgradeBarGray').textContent = gray; - } - - // Build array of pointers, sort by pp, set flex positions - var arr = []; - for (var x = 0; x < Game.UpgradesInStore.length; x++){ - var o = {}; - o.name = Game.UpgradesInStore[x].name; - o.price = Game.UpgradesInStore[x].basePrice; - o.pp = CM.Cache.Upgrades[o.name].pp; - arr.push(o); - } - - if (CM.Config.SortUpgrades) - arr.sort((a, b) => a.pp - b.pp); - else - arr.sort((a, b) => a.price - b.price); - - for (var x = 0; x < Game.UpgradesInStore.length; x++){ - l("upgrade" + x).style.order = arr.findIndex(e => e.name === Game.UpgradesInStore[x].name) + 1 - } -} - -CM.Disp.UpdateColors = function() { - var str = ''; - for (var i = 0; i < CM.Disp.colors.length; i++) { - str += '.' + CM.Disp.colorTextPre + CM.Disp.colors[i] + ' { color: ' + CM.Config.Colors[CM.Disp.colors[i]] + '; }\n'; - } - for (var i = 0; i < CM.Disp.colors.length; i++) { - str += '.' + CM.Disp.colorBackPre + CM.Disp.colors[i] + ' { background-color: ' + CM.Config.Colors[CM.Disp.colors[i]] + '; }\n'; - } - for (var i = 0; i < CM.Disp.colors.length; i++) { - str += '.' + CM.Disp.colorBorderPre + CM.Disp.colors[i] + ' { border: 1px solid ' + CM.Config.Colors[CM.Disp.colors[i]] + '; }\n'; - } - CM.Disp.Css.textContent = str; - CM.Disp.UpdateBuildings(); // Class has been already set -} - CM.Disp.ToggleUpgradeBarFixedPos = function() { if (CM.Config.UpgradeBarFixedPos == 1) { CM.Disp.UpgradeBar.style.position = 'sticky'; @@ -871,18 +1006,9 @@ CM.Disp.ToggleUpgradeBarFixedPos = function() { } } -CM.Disp.CreateWhiteScreen = function() { - CM.Disp.WhiteScreen = document.createElement('div'); - CM.Disp.WhiteScreen.id = 'CMWhiteScreen'; - CM.Disp.WhiteScreen.style.width = '100%'; - CM.Disp.WhiteScreen.style.height = '100%'; - CM.Disp.WhiteScreen.style.backgroundColor = 'white'; - CM.Disp.WhiteScreen.style.display = 'none'; - CM.Disp.WhiteScreen.style.zIndex = '9999999999'; - CM.Disp.WhiteScreen.style.position = 'absolute'; - - l('wrapper').appendChild(CM.Disp.WhiteScreen); -} +/******** + * Section: Functions related to the flashes/sound/notifications + * TODO: Annotate functions */ CM.Disp.Flash = function(mode, config) { if ((CM.Config[config] == 1 && mode == 3) || mode == 1) { @@ -919,19 +1045,9 @@ CM.Disp.Notification = function(notifyConfig, title, message) { } } - -CM.Disp.FindShimmer = function() { - CM.Disp.currSpawnedGoldenCookieState = 0 - CM.Disp.goldenShimmersByID = {} - for (var i in Game.shimmers) { - CM.Disp.goldenShimmersByID[Game.shimmers[i].id] = Game.shimmers[i] - if (Game.shimmers[i].spawnLead && Game.shimmers[i].type == 'golden') { - CM.Disp.spawnedGoldenShimmer = Game.shimmers[i]; - CM.Disp.currSpawnedGoldenCookieState += 1; - } - } - -} +/******** + * Section: Functions related to updating the tab in the browser's tab-bar + * TODO: Annotate functions */ CM.Disp.CreateFavicon = function() { CM.Disp.Favicon = document.createElement('link'); @@ -955,6 +1071,84 @@ CM.Disp.UpdateFavicon = function() { } } +CM.Disp.UpdateTitle = function() { + if (Game.OnAscend || CM.Config.Title == 0) { + document.title = CM.Cache.Title; + } + else if (CM.Config.Title == 1) { + var addFC = false; + var addSP = false; + + var titleGC; + var titleFC; + var titleSP; + if (CM.Disp.lastGoldenCookieState) { + if (CM.Disp.spawnedGoldenShimmer.wrath) { + titleGC = '[W ' + Math.ceil(CM.Disp.spawnedGoldenShimmer.life / Game.fps) + ']'; + } + else { + titleGC = '[G ' + Math.ceil(CM.Disp.spawnedGoldenShimmer.life / Game.fps) + ']'; + } + } + else if (!Game.Has('Golden switch [off]')) { + titleGC = '[' + Math.ceil((Game.shimmerTypes['golden'].maxTime - Game.shimmerTypes['golden'].time) / Game.fps) + ']'; + } + else { + titleGC = '[GS]' + } + if (CM.Disp.lastTickerFortuneState) { + addFC = true; + titleFC = '[F]'; + } + if (Game.season == 'christmas') { + addSP = true; + if (CM.Disp.lastSeasonPopupState) { + titleSP = '[R ' + Math.ceil(CM.Disp.seasonPopShimmer.life / Game.fps) + ']'; + } + else { + titleSP = '[' + Math.ceil((Game.shimmerTypes['reindeer'].maxTime - Game.shimmerTypes['reindeer'].time) / Game.fps) + ']'; + } + } + + var str = CM.Cache.Title; + if (str.charAt(0) == '[') { + str = str.substring(str.lastIndexOf(']') + 1); + } + + document.title = titleGC + (addFC ? titleFC : '') + (addSP ? titleSP : '') + ' ' + str; + } + else if (CM.Config.Title == 2) { + var str = ''; + var spawn = false; + if (CM.Disp.lastGoldenCookieState) { + spawn = true; + if (CM.Disp.spawnedGoldenShimmer.wrath) { + str += '[W ' + Math.ceil(CM.Disp.spawnedGoldenShimmer.life / Game.fps) + ']'; + } + else { + str += '[G ' + Math.ceil(CM.Disp.spawnedGoldenShimmer.life / Game.fps) + ']'; + } + } + if (CM.Disp.lastTickerFortuneState) { + spawn = true; + str += '[F]'; + } + if (Game.season == 'christmas' && CM.Disp.lastSeasonPopupState) { + str += '[R ' + Math.ceil(CM.Disp.seasonPopShimmer.life / Game.fps) + ']'; + spawn = true; + } + if (spawn) str += ' - '; + var title = 'Cookie Clicker'; + if (Game.season == 'fools') title = 'Cookie Baker'; + str += title; + document.title = str; + } +} + +/******** + * Section: Functions related to the Golden Cookie Timers + * TODO: Annotate functions */ + CM.Disp.CreateGCTimer = function(cookie) { GCTimer = document.createElement('div'); GCTimer.id = 'GCTimer' + cookie.id @@ -995,6 +1189,11 @@ CM.Disp.ToggleGCTimer = function() { } } +/******** + * Section: Functions related to checking for changes in Minigames/GC's/Ticker + * TODO: Annotate functions + * TODO: Possibly move this section */ + CM.Disp.CheckGoldenCookie = function() { CM.Disp.FindShimmer(); for (var i in CM.Disp.GCTimers) { @@ -1122,87 +1321,9 @@ CM.Disp.CheckWrinklerCount = function() { } } -CM.Disp.UpdateTitle = function() { - if (Game.OnAscend || CM.Config.Title == 0) { - document.title = CM.Cache.Title; - } - else if (CM.Config.Title == 1) { - var addFC = false; - var addSP = false; - - var titleGC; - var titleFC; - var titleSP; - if (CM.Disp.lastGoldenCookieState) { - if (CM.Disp.spawnedGoldenShimmer.wrath) { - titleGC = '[W ' + Math.ceil(CM.Disp.spawnedGoldenShimmer.life / Game.fps) + ']'; - } - else { - titleGC = '[G ' + Math.ceil(CM.Disp.spawnedGoldenShimmer.life / Game.fps) + ']'; - } - } - else if (!Game.Has('Golden switch [off]')) { - titleGC = '[' + Math.ceil((Game.shimmerTypes['golden'].maxTime - Game.shimmerTypes['golden'].time) / Game.fps) + ']'; - } - else { - titleGC = '[GS]' - } - if (CM.Disp.lastTickerFortuneState) { - addFC = true; - titleFC = '[F]'; - } - if (Game.season == 'christmas') { - addSP = true; - if (CM.Disp.lastSeasonPopupState) { - titleSP = '[R ' + Math.ceil(CM.Disp.seasonPopShimmer.life / Game.fps) + ']'; - } - else { - titleSP = '[' + Math.ceil((Game.shimmerTypes['reindeer'].maxTime - Game.shimmerTypes['reindeer'].time) / Game.fps) + ']'; - } - } - - var str = CM.Cache.Title; - if (str.charAt(0) == '[') { - str = str.substring(str.lastIndexOf(']') + 1); - } - - document.title = titleGC + (addFC ? titleFC : '') + (addSP ? titleSP : '') + ' ' + str; - } - else if (CM.Config.Title == 2) { - var str = ''; - var spawn = false; - if (CM.Disp.lastGoldenCookieState) { - spawn = true; - if (CM.Disp.spawnedGoldenShimmer.wrath) { - str += '[W ' + Math.ceil(CM.Disp.spawnedGoldenShimmer.life / Game.fps) + ']'; - } - else { - str += '[G ' + Math.ceil(CM.Disp.spawnedGoldenShimmer.life / Game.fps) + ']'; - } - } - if (CM.Disp.lastTickerFortuneState) { - spawn = true; - str += '[F]'; - } - if (Game.season == 'christmas' && CM.Disp.lastSeasonPopupState) { - str += '[R ' + Math.ceil(CM.Disp.seasonPopShimmer.life / Game.fps) + ']'; - spawn = true; - } - if (spawn) str += ' - '; - var title = 'Cookie Clicker'; - if (Game.season == 'fools') title = 'Cookie Baker'; - str += title; - document.title = str; - } -} - -CM.Disp.CollectWrinklers = function() { - for (var i in Game.wrinklers) { - if (Game.wrinklers[i].sucked > 0 && Game.wrinklers[i].type == 0) { - Game.wrinklers[i].hp = 0; - } - } -} +/******** + * Section: Functions related to Tooltips + * TODO: Annotate functions */ CM.Disp.CreateTooltip = function(placeholder, text, minWidth) { CM.Disp[placeholder] = document.createElement('div'); @@ -1216,6 +1337,576 @@ CM.Disp.CreateTooltip = function(placeholder, text, minWidth) { CM.Disp[placeholder].appendChild(desc); } +CM.Disp.UpdateTooltipLocation = function() { + if (Game.tooltip.origin == 'store') { + var warnOffset = 0; + if (CM.Config.ToolWarnLucky == 1 && CM.Config.ToolWarnPos == 1) warnOffset = CM.Disp.TooltipWarn.clientHeight - 4; + Game.tooltip.tta.style.top = Math.min(parseInt(Game.tooltip.tta.style.top), (l('game').clientHeight + l('topBar').clientHeight) - Game.tooltip.tt.clientHeight - warnOffset - 46) + 'px'; + } + // Kept for future possible use if the code changes again + /*else if (!Game.onCrate && !Game.OnAscend && CM.Config.TimerBar == 1 && CM.Config.TimerBarPos == 0) { + Game.tooltip.tta.style.top = (parseInt(Game.tooltip.tta.style.top) + parseInt(CM.Disp.TimerBar.style.height)) + 'px'; + }*/ +} + +CM.Disp.CreateTooltipWarn = function() { + CM.Disp.TooltipWarn = document.createElement('div'); + CM.Disp.TooltipWarn.style.position = 'absolute'; + CM.Disp.TooltipWarn.style.display = 'none'; + CM.Disp.TooltipWarn.style.left = 'auto'; + CM.Disp.TooltipWarn.style.bottom = 'auto'; + + var create = function(boxId, color, labelTextFront, labelTextBack, deficitId) { + var box = document.createElement('div'); + box.id = boxId; + box.style.display = 'none'; + box.style.WebkitTransition = 'opacity 0.1s ease-out'; + box.style.MozTransition = 'opacity 0.1s ease-out'; + box.style.MsTransition = 'opacity 0.1s ease-out'; + box.style.OTransition = 'opacity 0.1s ease-out'; + box.style.transition = 'opacity 0.1s ease-out'; + box.className = CM.Disp.colorBorderPre + color; + box.style.padding = '2px'; + box.style.background = '#000 url(img/darkNoise.png)'; + var labelDiv = document.createElement('div'); + box.appendChild(labelDiv); + var labelSpan = document.createElement('span'); + labelSpan.className = CM.Disp.colorTextPre + color; + labelSpan.style.fontWeight = 'bold'; + labelSpan.textContent = labelTextFront; + labelDiv.appendChild(labelSpan); + labelDiv.appendChild(document.createTextNode(labelTextBack)); + var deficitDiv = document.createElement('div'); + box.appendChild(deficitDiv); + var deficitSpan = document.createElement('span'); + deficitSpan.id = deficitId; + deficitDiv.appendChild(document.createTextNode('Deficit: ')); + deficitDiv.appendChild(deficitSpan); + return box; + } + CM.Disp.TooltipWarn.appendChild(create('CMDispTooltipWarnLucky', CM.Disp.colorRed, 'Warning: ', 'Purchase of this item will put you under the number of Cookies required for "Lucky!"', 'CMDispTooltipWarnLuckyText')); + CM.Disp.TooltipWarn.firstChild.style.marginBottom = '4px'; + CM.Disp.TooltipWarn.appendChild(create('CMDispTooltipWarnLuckyFrenzy', CM.Disp.colorYellow, 'Warning: ', 'Purchase of this item will put you under the number of Cookies required for "Lucky!" (Frenzy)', 'CMDispTooltipWarnLuckyFrenzyText')); + CM.Disp.TooltipWarn.lastChild.style.marginBottom = '4px'; + CM.Disp.TooltipWarn.appendChild(create('CMDispTooltipWarnConjure', CM.Disp.colorPurple, 'Warning: ', 'Purchase of this item will put you under the number of Cookies required for "Conjure Baked Goods"', 'CMDispTooltipWarnConjureText')); + + + l('tooltipAnchor').appendChild(CM.Disp.TooltipWarn); +} + +CM.Disp.ToggleToolWarnPos = function() { + if (CM.Config.ToolWarnPos == 0) { + CM.Disp.TooltipWarn.style.top = 'auto'; + CM.Disp.TooltipWarn.style.margin = '4px -4px'; + CM.Disp.TooltipWarn.style.padding = '3px 4px'; + } + else { + CM.Disp.TooltipWarn.style.right = 'auto'; + CM.Disp.TooltipWarn.style.margin = '4px'; + CM.Disp.TooltipWarn.style.padding = '4px 3px'; + } +} + +CM.Disp.AddTooltipBuild = function() { + CM.Disp.TooltipBuildBack = []; + for (var i in Game.Objects) { + var me = Game.Objects[i]; + if (l('product' + me.id).onmouseover != null) { + CM.Disp.TooltipBuildBack[i] = l('product' + me.id).onmouseover; + eval('l(\'product\' + me.id).onmouseover = function() {Game.tooltip.dynamic = 1; Game.tooltip.draw(this, function() {return CM.Disp.Tooltip(\'b\', \'' + i + '\');}, \'store\'); Game.tooltip.wobble();}'); + } + } +} + +CM.Disp.AddTooltipUpgrade = function() { + CM.Disp.TooltipUpgradeBack = []; + for (var i in Game.UpgradesInStore) { + var me = Game.UpgradesInStore[i]; + if (l('upgrade' + i).onmouseover != null) { + CM.Disp.TooltipUpgradeBack[i] = l('upgrade' + i).onmouseover; + eval('l(\'upgrade\' + i).onmouseover = function() {if (!Game.mouseDown) {Game.setOnCrate(this); Game.tooltip.dynamic = 1; Game.tooltip.draw(this, function() {return CM.Disp.Tooltip(\'u\', \'' + i + '\');}, \'store\'); Game.tooltip.wobble();}}'); + } + } +} + +CM.Disp.AddTooltipGrimoire = function() { + if (Game.Objects['Wizard tower'].minigameLoaded) { + CM.Disp.TooltipGrimoireBack = []; + for (var i in Game.Objects['Wizard tower'].minigame.spellsById) { + if (l('grimoireSpell' + i).onmouseover != null) { + CM.Disp.TooltipGrimoireBack[i] = l('grimoireSpell' + i).onmouseover; + eval('l(\'grimoireSpell\' + i).onmouseover = function() {Game.tooltip.dynamic = 1; Game.tooltip.draw(this, function() {return CM.Disp.Tooltip(\'g\', \'' + i + '\');}, \'this\'); Game.tooltip.wobble();}'); + } + } + } +} + +/** + * This function improves Sugar Lump tooltip by adding extra infromation. + * @constructor + */ +CM.Disp.AddTooltipLump = function() { + if (Game.canLumps()) { + CM.Disp.TooltipLumpBack = l('lumps').onmouseover; + eval('l(\'lumps\').onmouseover = function() {Game.tooltip.dynamic = 1; Game.tooltip.draw(this, function() {return CM.Disp.Tooltip(\'s\', \'Lump\');}, \'this\'); Game.tooltip.wobble();}'); + } +}; + +CM.Disp.Tooltip = function(type, name) { + if (type == 'b') { + l('tooltip').innerHTML = Game.Objects[name].tooltip(); + if (CM.Config.TooltipAmor == 1) { + var buildPrice = CM.Sim.BuildingGetPrice(Game.Objects[name], Game.Objects[name].basePrice, 0, Game.Objects[name].free, Game.Objects[name].amount); + var amortizeAmount = buildPrice - Game.Objects[name].totalCookies; + if (amortizeAmount > 0) { + l('tooltip').innerHTML = l('tooltip').innerHTML + .split('so far') + .join('so far
' + Beautify(amortizeAmount) + ' ' + (Math.floor(amortizeAmount) == 1 ? 'cookie' : 'cookies') + ' left to amortize (' + CM.Disp.GetTimeColor(buildPrice, Game.Objects[name].totalCookies, (Game.Objects[name].storedTotalCps * Game.globalCpsMult)).text + ')'); + } + } + if (Game.buyMode == 1) { + var target = ''; + var change = false; + if (Game.buyBulk == 10) { + target = 'Objects10'; + change = true; + } + else if (Game.buyBulk == 100) { + target = 'Objects100'; + change = true; + } + if (change) { + l('tooltip').innerHTML = l('tooltip').innerHTML.split(Beautify(Game.Objects[name].getPrice())).join(Beautify(CM.Cache[target][name].price)); + } + } + else if (Game.buyMode == -1) { + /* + * Fix sell price displayed in the object tooltip. + * + * The buildings sell price displayed by the game itself (without any mod) is incorrect. + * The following line of code fixes this issue, and can be safely removed when the game gets fixed. + * + * This issue is extensively detailed here: https://github.com/Aktanusa/CookieMonster/issues/359#issuecomment-735658262 + */ + l('tooltip').innerHTML = l('tooltip').innerHTML.split(Beautify(Game.Objects[name].bulkPrice)).join(Beautify(CM.Sim.BuildingSell(Game.Objects[name], Game.Objects[name].basePrice, Game.Objects[name].amount, Game.Objects[name].free, Game.buyBulk, 1))); + } + } + else if (type == 'u') { + if (!Game.UpgradesInStore[name]) return ''; + l('tooltip').innerHTML = Game.crateTooltip(Game.UpgradesInStore[name], 'store'); + } + else if (type === 's') { + // Sugar Lump + l('tooltip').innerHTML = Game.lumpTooltip(); + } + else { // Grimoire + l('tooltip').innerHTML = Game.Objects['Wizard tower'].minigame.spellTooltip(name)(); + } + + var area = document.createElement('div'); + area.id = 'CMTooltipArea'; + l('tooltip').appendChild(area); + + if (CM.Config.TooltipBuildUp == 1 && (type == 'u' || (type == 'b' && Game.buyMode == 1))) { + l('tooltip').firstChild.style.paddingBottom = '4px'; + var tooltip = document.createElement('div'); + tooltip.style.border = '1px solid'; + tooltip.style.padding = '4px'; + tooltip.style.margin = '0px -4px'; + tooltip.id = 'CMTooltipBorder'; + + var header = function(text) { + var div = document.createElement('div'); + div.style.fontWeight = 'bold'; + div.className = CM.Disp.colorTextPre + CM.Disp.colorBlue; + div.textContent = text; + return div; + } + + tooltip.appendChild(header('Bonus Income')); + var income = document.createElement('div'); + income.style.marginBottom = '4px'; + income.style.color = 'white'; + income.id = 'CMTooltipIncome'; + tooltip.appendChild(income); + tooltip.appendChild(header('Payback Period')); + var pp = document.createElement('div'); + pp.style.marginBottom = '4px'; + pp.id = 'CMTooltipPP'; + tooltip.appendChild(pp); + tooltip.appendChild(header('Time Left')); + var time = document.createElement('div'); + time.id = 'CMTooltipTime'; + tooltip.appendChild(time); + if (type == 'b') { + tooltip.appendChild(header('Production left till next achievement')); + tooltip.lastChild.id = 'CMTooltipProductionHeader'; + var production = document.createElement('div'); + production.id = 'CMTooltipProduction'; + tooltip.appendChild(production); + } + + area.appendChild(tooltip); + } + + CM.Disp.tooltipType = type; + CM.Disp.tooltipName = name; + + CM.Disp.UpdateTooltip(); + + return l('tooltip').innerHTML; +} + +CM.Disp.UpdateTooltip = function() { + CM.Sim.CopyData(); + if (l('tooltipAnchor').style.display != 'none') { + + if (l('CMTooltipArea') != null) { + if (CM.Disp.tooltipType == 'b' || CM.Disp.tooltipType == 'u') { + // Error checking + if (CM.Disp.tooltipType == 'u' && (typeof Game.UpgradesInStore[CM.Disp.tooltipName] === 'undefined' || typeof CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name] === 'undefined')) { + return; + } + var price; + var bonus; + if (CM.Disp.tooltipType == 'b') { + var target = ''; + if (Game.buyMode == 1 && Game.buyBulk == 10) { + target = 'Objects10'; + price = CM.Cache[target][CM.Disp.tooltipName].price; + } + else if (Game.buyMode == 1 && Game.buyBulk == 100) { + target = 'Objects100'; + price = CM.Cache[target][CM.Disp.tooltipName].price; + } + else { + target = 'Objects'; + price = Game.Objects[CM.Disp.tooltipName].getPrice(); + } + bonus = CM.Cache[target][CM.Disp.tooltipName].bonus; + if (CM.Config.TooltipBuildUp == 1 && Game.buyMode == 1) { + l('CMTooltipBorder').className = CM.Disp.colorTextPre + CM.Cache[target][CM.Disp.tooltipName].color; + l('CMTooltipPP').textContent = Beautify(CM.Cache[target][CM.Disp.tooltipName].pp, 2); + l('CMTooltipPP').className = CM.Disp.colorTextPre + CM.Cache[target][CM.Disp.tooltipName].color; + } + if (CM.Config.TooltipBuildUp) { + for (var i in Game.Objects[CM.Disp.tooltipName].productionAchievs) { + if (!CM.Sim.HasAchiev(Game.Objects[CM.Disp.tooltipName].productionAchievs[i].achiev.name)) { + var nextProductionAchiev = Game.Objects[CM.Disp.tooltipName].productionAchievs[i] + break + } + } + if (typeof nextProductionAchiev != "undefined") { + l('CMTooltipTime').style.marginBottom = '4px'; + l('CMTooltipProductionHeader').style.display = ""; + l('CMTooltipProduction').className = "ProdAchievement" + CM.Disp.tooltipName; + l('CMTooltipProduction').textContent = Beautify(nextProductionAchiev.pow - CM.Sim.Objects[CM.Disp.tooltipName].totalCookies, 15); + l('CMTooltipProduction').style.color = "white"; + } else { + l('CMTooltipProductionHeader').style.display = "none"; + l('CMTooltipTime').style.marginBottom = '0px'; + } + } + } + else { // Upgrades + bonus = CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].bonus; + price = Game.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].getPrice(); + if (CM.Config.TooltipBuildUp == 1) { + l('CMTooltipBorder').className = CM.Disp.colorTextPre + CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].color; + l('CMTooltipPP').textContent = Beautify(CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].pp, 2); + l('CMTooltipPP').className = CM.Disp.colorTextPre + CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].color; + } + } + if (CM.Config.TooltipBuildUp == 1 && (CM.Disp.tooltipType != 'b' || Game.buyMode == 1)) { + l('CMTooltipIncome').textContent = Beautify(bonus, 2); + + var increase = Math.round(bonus / Game.cookiesPs * 10000); + if (isFinite(increase) && increase != 0) { + l('CMTooltipIncome').textContent += ' (' + (increase / 100) + '% of income)'; + } + + var timeColor = CM.Disp.GetTimeColor(price, (Game.cookies + CM.Disp.GetWrinkConfigBank()), CM.Disp.GetCPS()); + l('CMTooltipTime').textContent = timeColor.text; + l('CMTooltipTime').className = CM.Disp.colorTextPre + timeColor.color; + } + + if (CM.Config.ToolWarnPos == 0) { + CM.Disp.TooltipWarn.style.right = '0px'; + } + else { + CM.Disp.TooltipWarn.style.top = (l('tooltip').offsetHeight) + 'px'; + } + CM.Disp.TooltipWarn.style.width = (l('tooltip').offsetWidth - 6) + 'px'; + + if (CM.Config.ToolWarnLucky == 1) { + CM.Disp.TooltipWarn.style.display = 'block'; + var limitLucky = CM.Cache.Lucky; + if (CM.Config.ToolWarnBon == 1) { + var bonusNoFren = bonus; + bonusNoFren /= CM.Sim.getCPSBuffMult(); + limitLucky += ((bonusNoFren * 60 * 15) / 0.15); + } + var limitLuckyFrenzy = limitLucky * 7; + var amount = (Game.cookies + CM.Disp.GetWrinkConfigBank()) - price; + if ((amount < limitLucky || amount < limitLuckyFrenzy) && (CM.Disp.tooltipType != 'b' || Game.buyMode == 1)) { + if (amount < limitLucky) { + l('CMDispTooltipWarnLucky').style.display = ''; + l('CMDispTooltipWarnLuckyText').textContent = Beautify(limitLucky - amount) + ' (' + CM.Disp.FormatTime((limitLucky - amount) / CM.Disp.GetCPS()) + ')'; + l('CMDispTooltipWarnLuckyFrenzy').style.display = ''; + l('CMDispTooltipWarnLuckyFrenzyText').textContent = Beautify(limitLuckyFrenzy - amount) + ' (' + CM.Disp.FormatTime((limitLuckyFrenzy - amount) / CM.Disp.GetCPS()) + ')'; + } + else if (amount < limitLuckyFrenzy) { + l('CMDispTooltipWarnLuckyFrenzy').style.display = ''; + l('CMDispTooltipWarnLuckyFrenzyText').textContent = Beautify(limitLuckyFrenzy - amount) + ' (' + CM.Disp.FormatTime((limitLuckyFrenzy - amount) / CM.Disp.GetCPS()) + ')'; + l('CMDispTooltipWarnLucky').style.display = 'none'; + } + } else { + l('CMDispTooltipWarnLucky').style.display = 'none'; + l('CMDispTooltipWarnLuckyFrenzy').style.display = 'none'; + } + } + else { + l('CMDispTooltipWarnLucky').style.display = 'none'; + l('CMDispTooltipWarnLuckyFrenzy').style.display = 'none'; + } + + if (CM.Config.ToolWarnConjure == 1) { + CM.Disp.TooltipWarn.style.display = 'block'; + var limitLucky = CM.Cache.Lucky; + if (CM.Config.ToolWarnBon == 1) { + var bonusNoFren = bonus; + bonusNoFren /= CM.Sim.getCPSBuffMult(); + limitLucky += ((bonusNoFren * 60 * 15) / 0.15); + } + var limitConjure = limitLucky * 2; + var amount = (Game.cookies + CM.Disp.GetWrinkConfigBank()) - price; + if ((amount < limitConjure) && (CM.Disp.tooltipType != 'b' || Game.buyMode == 1)) { + l('CMDispTooltipWarnConjure').style.display = ''; + l('CMDispTooltipWarnConjureText').textContent = Beautify(limitConjure - amount) + ' (' + CM.Disp.FormatTime((limitConjure - amount) / CM.Disp.GetCPS()) + ')'; + } else { + l('CMDispTooltipWarnConjure').style.display = 'none'; + } + } + else { + l('CMDispTooltipWarnConjure').style.display = 'none'; + } + } + else if (CM.Disp.tooltipType === 's') { + // Adding information about Sugar Lumps. + + CM.Disp.TooltipWarn.style.display = 'none'; + l('CMDispTooltipWarnLucky').style.display = 'none'; + l('CMDispTooltipWarnLuckyFrenzy').style.display = 'none'; + l('CMDispTooltipWarnConjure').style.display = 'none'; + + if (CM.Config.TooltipLump === 1) { + l('CMTooltipArea').innerHTML = ''; + + l('tooltip').firstChild.style.paddingBottom = '4px'; + var lumpTooltip = document.createElement('div'); + lumpTooltip.style.border = '1px solid'; + lumpTooltip.style.padding = '4px'; + lumpTooltip.style.margin = '0px -4px'; + lumpTooltip.id = 'CMTooltipBorder'; + lumpTooltip.className = CM.Disp.colorTextPre + CM.Disp.colorGray; + + var lumpHeader = document.createElement('div'); + lumpHeader.style.fontWeight = 'bold'; + lumpHeader.className = CM.Disp.colorTextPre + CM.Disp.colorBlue; + lumpHeader.textContent = 'Current Sugar Lump'; + + lumpTooltip.appendChild(lumpHeader); + var lumpType = document.createElement('div'); + lumpType.id = 'CMTooltipTime'; + lumpTooltip.appendChild(lumpType); + var lumpColor = CM.Disp.GetLumpColor(Game.lumpCurrentType); + lumpType.textContent = lumpColor.text; + lumpType.className = CM.Disp.colorTextPre + lumpColor.color; + + l('CMTooltipArea').appendChild(lumpTooltip); + } + } + else if (CM.Disp.tooltipType === 'g') { + // Grimoire + CM.Disp.TooltipWarn.style.display = 'none'; + l('CMDispTooltipWarnLucky').style.display = 'none'; + l('CMDispTooltipWarnLuckyFrenzy').style.display = 'none'; + l('CMDispTooltipWarnConjure').style.display = 'none'; + + var minigame = Game.Objects['Wizard tower'].minigame; + var spellCost = minigame.getSpellCost(minigame.spellsById[CM.Disp.tooltipName]); + + if (CM.Config.TooltipGrim == 1 && spellCost <= minigame.magicM) { + l('CMTooltipArea').innerHTML = ''; + + l('tooltip').firstChild.style.paddingBottom = '4px'; + var tooltip = document.createElement('div'); + tooltip.style.border = '1px solid'; + tooltip.style.padding = '4px'; + tooltip.style.margin = '0px -4px'; + tooltip.id = 'CMTooltipBorder'; + tooltip.className = CM.Disp.colorTextPre + CM.Disp.colorGray; + + var header = function(text) { + var div = document.createElement('div'); + div.style.fontWeight = 'bold'; + div.className = CM.Disp.colorTextPre + CM.Disp.colorBlue; + div.textContent = text; + return div; + } + + tooltip.appendChild(header('Time Left')); + var time = document.createElement('div'); + time.id = 'CMTooltipTime'; + tooltip.appendChild(time); + var timeColor = CM.Disp.GetTimeColor(spellCost, minigame.magic, undefined, CM.Disp.CalculateGrimoireRefillTime(minigame.magic, minigame.magicM, spellCost)); + time.textContent = timeColor.text; + time.className = CM.Disp.colorTextPre + timeColor.color; + + if (spellCost <= minigame.magic) { + tooltip.appendChild(header('Recover Time')); + var recover = document.createElement('div'); + recover.id = 'CMTooltipRecover'; + tooltip.appendChild(recover); + var recoverColor = CM.Disp.GetTimeColor(minigame.magic, Math.max(0, minigame.magic - spellCost), undefined, CM.Disp.CalculateGrimoireRefillTime(Math.max(0, minigame.magic - spellCost), minigame.magicM, minigame.magic)); + recover.textContent = recoverColor.text; + recover.className = CM.Disp.colorTextPre + recoverColor.color; + } + + // Extra information when spell is Conjure Baked Goods (Name == 0) + if (CM.Disp.tooltipName == 0) { + tooltip.appendChild(header('Cookies to be gained/lost')); + var conjure = document.createElement('div'); + conjure.id = 'CMTooltipConjure'; + tooltip.appendChild(conjure); + var reward = document.createElement('span'); + reward.style.color = "#33FF00" + reward.textContent = Beautify(Math.min((Game.cookies + CM.Disp.GetWrinkConfigBank()) * 0.15, CM.Cache.NoGoldSwitchCookiesPS * 60 * 30), 2) + conjure.appendChild(reward) + var seperator = document.createElement('span'); + seperator.textContent = ' / ' + conjure.appendChild(seperator) + var loss = document.createElement('span'); + loss.style.color = "red" + loss.textContent = Beautify((CM.Cache.NoGoldSwitchCookiesPS * 60 * 15), 2); + conjure.appendChild(loss) + } + + l('CMTooltipArea').appendChild(tooltip); + } + } + } + else { + CM.Disp.TooltipWarn.style.display = 'none'; + } + } +} + +CM.Disp.DrawTooltipWarn = function() { + if (CM.Config.ToolWarnLucky == 1) { + l('CMDispTooltipWarnLucky').style.opacity = '0'; + l('CMDispTooltipWarnLuckyFrenzy').style.opacity = '0'; + } + if (CM.Config.ToolWarnConjure == 1) { + l('CMDispTooltipWarnConjure').style.opacity = '0'; + } +} + +CM.Disp.UpdateTooltipWarn = function() { + if (CM.Config.ToolWarnLucky == 1 && l('tooltipAnchor').style.display != 'none' && l('CMTooltipArea') != null) { + l('CMDispTooltipWarnLucky').style.opacity = '1'; + l('CMDispTooltipWarnLuckyFrenzy').style.opacity = '1'; + } + if (CM.Config.ToolWarnConjure == 1 && l('tooltipAnchor').style.display != 'none' && l('CMTooltipArea') != null) { + l('CMDispTooltipWarnConjure').style.opacity = '1'; + } +} + +CM.Disp.CheckWrinklerTooltip = function() { + if (CM.Config.ToolWrink == 1 && CM.Disp.TooltipWrinklerArea == 1) { + var showingTooltip = false; + for (var i in Game.wrinklers) { + var me = Game.wrinklers[i]; + if (me.phase > 0 && me.selected) { + showingTooltip = true; + if (CM.Disp.TooltipWrinklerCache[i] == 0) { + var placeholder = document.createElement('div'); + var wrinkler = document.createElement('div'); + wrinkler.style.minWidth = '120px'; + wrinkler.style.marginBottom = '4px'; + var div = document.createElement('div'); + div.style.textAlign = 'center'; + div.id = 'CMTooltipWrinkler'; + wrinkler.appendChild(div); + placeholder.appendChild(wrinkler); + Game.tooltip.draw(this, escape(placeholder.innerHTML)); + CM.Disp.TooltipWrinkler = i; + CM.Disp.TooltipWrinklerCache[i] = 1; + } + else break; + } + else { + CM.Disp.TooltipWrinklerCache[i] = 0; + } + } + if (!showingTooltip) { + Game.tooltip.hide(); + } + } +} + +CM.Disp.UpdateWrinklerTooltip = function() { + if (CM.Config.ToolWrink == 1 && l('CMTooltipWrinkler') != null) { + var sucked = Game.wrinklers[CM.Disp.TooltipWrinkler].sucked; + var toSuck = 1.1; + if (Game.Has('Sacrilegious corruption')) toSuck *= 1.05; + if (Game.wrinklers[CM.Disp.TooltipWrinkler].type == 1) toSuck *= 3; // Shiny wrinklers + sucked *= toSuck; + if (Game.Has('Wrinklerspawn')) sucked *= 1.05; + if (CM.Sim.Objects.Temple.minigameLoaded) { + var godLvl = CM.Sim.hasGod('scorn'); + if (godLvl == 1) sucked *= 1.15; + else if (godLvl == 2) sucked *= 1.1; + else if (godLvl == 3) sucked *= 1.05; + } + l('CMTooltipWrinkler').textContent = Beautify(sucked); + } +} + +/******** + * Section: General functions related to the Options/Stats pages + * TODO: Annotate functions */ + +CM.Disp.AddMenu = function() { + var title = function() { + var div = document.createElement('div'); + div.className = 'title ' + CM.Disp.colorTextPre + CM.Disp.colorBlue; + div.textContent = 'Cookie Monster Goodies'; + return div; + } + + if (Game.onMenu == 'prefs') { + CM.Disp.AddMenuPref(title); + } + else if (Game.onMenu == 'stats') { + if (CM.Config.Stats) { + CM.Disp.AddMenuStats(title); + } + + if (CM.Config.MissingUpgrades) { + CM.Disp.AddMissingUpgrades(); + } + } +} + +CM.Disp.RefreshMenu = function() { + if (CM.Config.UpStats && Game.onMenu == 'stats' && (Game.drawT - 1) % (Game.fps * 5) != 0 && (Game.drawT - 1) % Game.fps == 0) Game.UpdateMenu(); +} + +/******** + * Section: Functions related to the Options page + * TODO: Annotate functions */ + CM.Disp.AddMenuPref = function(title) { var header = function(text, config) { var div = document.createElement('div'); @@ -1444,6 +2135,10 @@ CM.Disp.AddMenuPref = function(title) { //l('formatButton').onclick = function() {Game.Toggle('format', 'formatButton', 'Short numbers OFF', 'Short numbers ON', '1'); PlaySound('snd/tick.mp3'); CM.Disp.RefreshScale();}; } +/******** + * Section: Functions related to the Stats page + * TODO: Annotate functions */ + CM.Disp.AddMenuStats = function(title) { var header = function(text, config) { var div = document.createElement('div'); @@ -1944,645 +2639,9 @@ CM.Disp.AddMissingUpgrades = function() { } } -CM.Disp.AddMenu = function() { - var title = function() { - var div = document.createElement('div'); - div.className = 'title ' + CM.Disp.colorTextPre + CM.Disp.colorBlue; - div.textContent = 'Cookie Monster Goodies'; - return div; - } - - if (Game.onMenu == 'prefs') { - CM.Disp.AddMenuPref(title); - } - else if (Game.onMenu == 'stats') { - if (CM.Config.Stats) { - CM.Disp.AddMenuStats(title); - } - - if (CM.Config.MissingUpgrades) { - CM.Disp.AddMissingUpgrades(); - } - } -} - -CM.Disp.RefreshMenu = function() { - if (CM.Config.UpStats && Game.onMenu == 'stats' && (Game.drawT - 1) % (Game.fps * 5) != 0 && (Game.drawT - 1) % Game.fps == 0) Game.UpdateMenu(); -} - -CM.Disp.FixMouseY = function(target) { - if (CM.Config.TimerBar == 1 && CM.Config.TimerBarPos == 0) { - var timerBarHeight = parseInt(CM.Disp.TimerBar.style.height); - Game.mouseY -= timerBarHeight; - target(); - Game.mouseY += timerBarHeight; - } - else { - target(); - } -} - -CM.Disp.UpdateTooltipLocation = function() { - if (Game.tooltip.origin == 'store') { - var warnOffset = 0; - if (CM.Config.ToolWarnLucky == 1 && CM.Config.ToolWarnPos == 1) warnOffset = CM.Disp.TooltipWarn.clientHeight - 4; - Game.tooltip.tta.style.top = Math.min(parseInt(Game.tooltip.tta.style.top), (l('game').clientHeight + l('topBar').clientHeight) - Game.tooltip.tt.clientHeight - warnOffset - 46) + 'px'; - } - // Kept for future possible use if the code changes again - /*else if (!Game.onCrate && !Game.OnAscend && CM.Config.TimerBar == 1 && CM.Config.TimerBarPos == 0) { - Game.tooltip.tta.style.top = (parseInt(Game.tooltip.tta.style.top) + parseInt(CM.Disp.TimerBar.style.height)) + 'px'; - }*/ -} - -CM.Disp.CreateTooltipWarn = function() { - CM.Disp.TooltipWarn = document.createElement('div'); - CM.Disp.TooltipWarn.style.position = 'absolute'; - CM.Disp.TooltipWarn.style.display = 'none'; - CM.Disp.TooltipWarn.style.left = 'auto'; - CM.Disp.TooltipWarn.style.bottom = 'auto'; - - var create = function(boxId, color, labelTextFront, labelTextBack, deficitId) { - var box = document.createElement('div'); - box.id = boxId; - box.style.display = 'none'; - box.style.WebkitTransition = 'opacity 0.1s ease-out'; - box.style.MozTransition = 'opacity 0.1s ease-out'; - box.style.MsTransition = 'opacity 0.1s ease-out'; - box.style.OTransition = 'opacity 0.1s ease-out'; - box.style.transition = 'opacity 0.1s ease-out'; - box.className = CM.Disp.colorBorderPre + color; - box.style.padding = '2px'; - box.style.background = '#000 url(img/darkNoise.png)'; - var labelDiv = document.createElement('div'); - box.appendChild(labelDiv); - var labelSpan = document.createElement('span'); - labelSpan.className = CM.Disp.colorTextPre + color; - labelSpan.style.fontWeight = 'bold'; - labelSpan.textContent = labelTextFront; - labelDiv.appendChild(labelSpan); - labelDiv.appendChild(document.createTextNode(labelTextBack)); - var deficitDiv = document.createElement('div'); - box.appendChild(deficitDiv); - var deficitSpan = document.createElement('span'); - deficitSpan.id = deficitId; - deficitDiv.appendChild(document.createTextNode('Deficit: ')); - deficitDiv.appendChild(deficitSpan); - return box; - } - CM.Disp.TooltipWarn.appendChild(create('CMDispTooltipWarnLucky', CM.Disp.colorRed, 'Warning: ', 'Purchase of this item will put you under the number of Cookies required for "Lucky!"', 'CMDispTooltipWarnLuckyText')); - CM.Disp.TooltipWarn.firstChild.style.marginBottom = '4px'; - CM.Disp.TooltipWarn.appendChild(create('CMDispTooltipWarnLuckyFrenzy', CM.Disp.colorYellow, 'Warning: ', 'Purchase of this item will put you under the number of Cookies required for "Lucky!" (Frenzy)', 'CMDispTooltipWarnLuckyFrenzyText')); - CM.Disp.TooltipWarn.lastChild.style.marginBottom = '4px'; - CM.Disp.TooltipWarn.appendChild(create('CMDispTooltipWarnConjure', CM.Disp.colorPurple, 'Warning: ', 'Purchase of this item will put you under the number of Cookies required for "Conjure Baked Goods"', 'CMDispTooltipWarnConjureText')); - - - l('tooltipAnchor').appendChild(CM.Disp.TooltipWarn); -} - -CM.Disp.ToggleToolWarnPos = function() { - if (CM.Config.ToolWarnPos == 0) { - CM.Disp.TooltipWarn.style.top = 'auto'; - CM.Disp.TooltipWarn.style.margin = '4px -4px'; - CM.Disp.TooltipWarn.style.padding = '3px 4px'; - } - else { - CM.Disp.TooltipWarn.style.right = 'auto'; - CM.Disp.TooltipWarn.style.margin = '4px'; - CM.Disp.TooltipWarn.style.padding = '4px 3px'; - } -} - -CM.Disp.CalculateGrimoireRefillTime = function(currentMagic, maxMagic, targetMagic) { - var count = 0; - while (currentMagic < targetMagic) { - currentMagic += Math.max(0.002, Math.pow(currentMagic / Math.max(maxMagic, 100), 0.5)) * 0.002; - count++; - } - return count / Game.fps; -} - -CM.Disp.AddTooltipBuild = function() { - CM.Disp.TooltipBuildBack = []; - for (var i in Game.Objects) { - var me = Game.Objects[i]; - if (l('product' + me.id).onmouseover != null) { - CM.Disp.TooltipBuildBack[i] = l('product' + me.id).onmouseover; - eval('l(\'product\' + me.id).onmouseover = function() {Game.tooltip.dynamic = 1; Game.tooltip.draw(this, function() {return CM.Disp.Tooltip(\'b\', \'' + i + '\');}, \'store\'); Game.tooltip.wobble();}'); - } - } -} - -CM.Disp.AddTooltipUpgrade = function() { - CM.Disp.TooltipUpgradeBack = []; - for (var i in Game.UpgradesInStore) { - var me = Game.UpgradesInStore[i]; - if (l('upgrade' + i).onmouseover != null) { - CM.Disp.TooltipUpgradeBack[i] = l('upgrade' + i).onmouseover; - eval('l(\'upgrade\' + i).onmouseover = function() {if (!Game.mouseDown) {Game.setOnCrate(this); Game.tooltip.dynamic = 1; Game.tooltip.draw(this, function() {return CM.Disp.Tooltip(\'u\', \'' + i + '\');}, \'store\'); Game.tooltip.wobble();}}'); - } - } -} - -CM.Disp.AddTooltipGrimoire = function() { - if (Game.Objects['Wizard tower'].minigameLoaded) { - CM.Disp.TooltipGrimoireBack = []; - for (var i in Game.Objects['Wizard tower'].minigame.spellsById) { - if (l('grimoireSpell' + i).onmouseover != null) { - CM.Disp.TooltipGrimoireBack[i] = l('grimoireSpell' + i).onmouseover; - eval('l(\'grimoireSpell\' + i).onmouseover = function() {Game.tooltip.dynamic = 1; Game.tooltip.draw(this, function() {return CM.Disp.Tooltip(\'g\', \'' + i + '\');}, \'this\'); Game.tooltip.wobble();}'); - } - } - } -} - -/** - * This function improves Sugar Lump tooltip by adding extra infromation. - * @constructor - */ -CM.Disp.AddTooltipLump = function() { - if (Game.canLumps()) { - CM.Disp.TooltipLumpBack = l('lumps').onmouseover; - eval('l(\'lumps\').onmouseover = function() {Game.tooltip.dynamic = 1; Game.tooltip.draw(this, function() {return CM.Disp.Tooltip(\'s\', \'Lump\');}, \'this\'); Game.tooltip.wobble();}'); - } -}; - -CM.Disp.Tooltip = function(type, name) { - if (type == 'b') { - l('tooltip').innerHTML = Game.Objects[name].tooltip(); - if (CM.Config.TooltipAmor == 1) { - var buildPrice = CM.Sim.BuildingGetPrice(Game.Objects[name], Game.Objects[name].basePrice, 0, Game.Objects[name].free, Game.Objects[name].amount); - var amortizeAmount = buildPrice - Game.Objects[name].totalCookies; - if (amortizeAmount > 0) { - l('tooltip').innerHTML = l('tooltip').innerHTML - .split('so far') - .join('so far
' + Beautify(amortizeAmount) + ' ' + (Math.floor(amortizeAmount) == 1 ? 'cookie' : 'cookies') + ' left to amortize (' + CM.Disp.GetTimeColor(buildPrice, Game.Objects[name].totalCookies, (Game.Objects[name].storedTotalCps * Game.globalCpsMult)).text + ')'); - } - } - if (Game.buyMode == 1) { - var target = ''; - var change = false; - if (Game.buyBulk == 10) { - target = 'Objects10'; - change = true; - } - else if (Game.buyBulk == 100) { - target = 'Objects100'; - change = true; - } - if (change) { - l('tooltip').innerHTML = l('tooltip').innerHTML.split(Beautify(Game.Objects[name].getPrice())).join(Beautify(CM.Cache[target][name].price)); - } - } - else if (Game.buyMode == -1) { - /* - * Fix sell price displayed in the object tooltip. - * - * The buildings sell price displayed by the game itself (without any mod) is incorrect. - * The following line of code fixes this issue, and can be safely removed when the game gets fixed. - * - * This issue is extensively detailed here: https://github.com/Aktanusa/CookieMonster/issues/359#issuecomment-735658262 - */ - l('tooltip').innerHTML = l('tooltip').innerHTML.split(Beautify(Game.Objects[name].bulkPrice)).join(Beautify(CM.Sim.BuildingSell(Game.Objects[name], Game.Objects[name].basePrice, Game.Objects[name].amount, Game.Objects[name].free, Game.buyBulk, 1))); - } - } - else if (type == 'u') { - if (!Game.UpgradesInStore[name]) return ''; - l('tooltip').innerHTML = Game.crateTooltip(Game.UpgradesInStore[name], 'store'); - } - else if (type === 's') { - // Sugar Lump - l('tooltip').innerHTML = Game.lumpTooltip(); - } - else { // Grimoire - l('tooltip').innerHTML = Game.Objects['Wizard tower'].minigame.spellTooltip(name)(); - } - - var area = document.createElement('div'); - area.id = 'CMTooltipArea'; - l('tooltip').appendChild(area); - - if (CM.Config.TooltipBuildUp == 1 && (type == 'u' || (type == 'b' && Game.buyMode == 1))) { - l('tooltip').firstChild.style.paddingBottom = '4px'; - var tooltip = document.createElement('div'); - tooltip.style.border = '1px solid'; - tooltip.style.padding = '4px'; - tooltip.style.margin = '0px -4px'; - tooltip.id = 'CMTooltipBorder'; - - var header = function(text) { - var div = document.createElement('div'); - div.style.fontWeight = 'bold'; - div.className = CM.Disp.colorTextPre + CM.Disp.colorBlue; - div.textContent = text; - return div; - } - - tooltip.appendChild(header('Bonus Income')); - var income = document.createElement('div'); - income.style.marginBottom = '4px'; - income.style.color = 'white'; - income.id = 'CMTooltipIncome'; - tooltip.appendChild(income); - tooltip.appendChild(header('Payback Period')); - var pp = document.createElement('div'); - pp.style.marginBottom = '4px'; - pp.id = 'CMTooltipPP'; - tooltip.appendChild(pp); - tooltip.appendChild(header('Time Left')); - var time = document.createElement('div'); - time.id = 'CMTooltipTime'; - tooltip.appendChild(time); - if (type == 'b') { - tooltip.appendChild(header('Production left till next achievement')); - tooltip.lastChild.id = 'CMTooltipProductionHeader'; - var production = document.createElement('div'); - production.id = 'CMTooltipProduction'; - tooltip.appendChild(production); - } - - area.appendChild(tooltip); - } - - CM.Disp.tooltipType = type; - CM.Disp.tooltipName = name; - - CM.Disp.UpdateTooltip(); - - return l('tooltip').innerHTML; -} - -CM.Disp.UpdateTooltip = function() { - CM.Sim.CopyData(); - if (l('tooltipAnchor').style.display != 'none') { - - if (l('CMTooltipArea') != null) { - if (CM.Disp.tooltipType == 'b' || CM.Disp.tooltipType == 'u') { - // Error checking - if (CM.Disp.tooltipType == 'u' && (typeof Game.UpgradesInStore[CM.Disp.tooltipName] === 'undefined' || typeof CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name] === 'undefined')) { - return; - } - var price; - var bonus; - if (CM.Disp.tooltipType == 'b') { - var target = ''; - if (Game.buyMode == 1 && Game.buyBulk == 10) { - target = 'Objects10'; - price = CM.Cache[target][CM.Disp.tooltipName].price; - } - else if (Game.buyMode == 1 && Game.buyBulk == 100) { - target = 'Objects100'; - price = CM.Cache[target][CM.Disp.tooltipName].price; - } - else { - target = 'Objects'; - price = Game.Objects[CM.Disp.tooltipName].getPrice(); - } - bonus = CM.Cache[target][CM.Disp.tooltipName].bonus; - if (CM.Config.TooltipBuildUp == 1 && Game.buyMode == 1) { - l('CMTooltipBorder').className = CM.Disp.colorTextPre + CM.Cache[target][CM.Disp.tooltipName].color; - l('CMTooltipPP').textContent = Beautify(CM.Cache[target][CM.Disp.tooltipName].pp, 2); - l('CMTooltipPP').className = CM.Disp.colorTextPre + CM.Cache[target][CM.Disp.tooltipName].color; - } - if (CM.Config.TooltipBuildUp) { - for (var i in Game.Objects[CM.Disp.tooltipName].productionAchievs) { - if (!CM.Sim.HasAchiev(Game.Objects[CM.Disp.tooltipName].productionAchievs[i].achiev.name)) { - var nextProductionAchiev = Game.Objects[CM.Disp.tooltipName].productionAchievs[i] - break - } - } - if (typeof nextProductionAchiev != "undefined") { - l('CMTooltipTime').style.marginBottom = '4px'; - l('CMTooltipProductionHeader').style.display = ""; - l('CMTooltipProduction').className = "ProdAchievement" + CM.Disp.tooltipName; - l('CMTooltipProduction').textContent = Beautify(nextProductionAchiev.pow - CM.Sim.Objects[CM.Disp.tooltipName].totalCookies, 15); - l('CMTooltipProduction').style.color = "white"; - } else { - l('CMTooltipProductionHeader').style.display = "none"; - l('CMTooltipTime').style.marginBottom = '0px'; - } - } - } - else { // Upgrades - bonus = CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].bonus; - price = Game.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].getPrice(); - if (CM.Config.TooltipBuildUp == 1) { - l('CMTooltipBorder').className = CM.Disp.colorTextPre + CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].color; - l('CMTooltipPP').textContent = Beautify(CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].pp, 2); - l('CMTooltipPP').className = CM.Disp.colorTextPre + CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].color; - } - } - if (CM.Config.TooltipBuildUp == 1 && (CM.Disp.tooltipType != 'b' || Game.buyMode == 1)) { - l('CMTooltipIncome').textContent = Beautify(bonus, 2); - - var increase = Math.round(bonus / Game.cookiesPs * 10000); - if (isFinite(increase) && increase != 0) { - l('CMTooltipIncome').textContent += ' (' + (increase / 100) + '% of income)'; - } - - var timeColor = CM.Disp.GetTimeColor(price, (Game.cookies + CM.Disp.GetWrinkConfigBank()), CM.Disp.GetCPS()); - l('CMTooltipTime').textContent = timeColor.text; - l('CMTooltipTime').className = CM.Disp.colorTextPre + timeColor.color; - } - - if (CM.Config.ToolWarnPos == 0) { - CM.Disp.TooltipWarn.style.right = '0px'; - } - else { - CM.Disp.TooltipWarn.style.top = (l('tooltip').offsetHeight) + 'px'; - } - CM.Disp.TooltipWarn.style.width = (l('tooltip').offsetWidth - 6) + 'px'; - - if (CM.Config.ToolWarnLucky == 1) { - CM.Disp.TooltipWarn.style.display = 'block'; - var limitLucky = CM.Cache.Lucky; - if (CM.Config.ToolWarnBon == 1) { - var bonusNoFren = bonus; - bonusNoFren /= CM.Sim.getCPSBuffMult(); - limitLucky += ((bonusNoFren * 60 * 15) / 0.15); - } - var limitLuckyFrenzy = limitLucky * 7; - var amount = (Game.cookies + CM.Disp.GetWrinkConfigBank()) - price; - if ((amount < limitLucky || amount < limitLuckyFrenzy) && (CM.Disp.tooltipType != 'b' || Game.buyMode == 1)) { - if (amount < limitLucky) { - l('CMDispTooltipWarnLucky').style.display = ''; - l('CMDispTooltipWarnLuckyText').textContent = Beautify(limitLucky - amount) + ' (' + CM.Disp.FormatTime((limitLucky - amount) / CM.Disp.GetCPS()) + ')'; - l('CMDispTooltipWarnLuckyFrenzy').style.display = ''; - l('CMDispTooltipWarnLuckyFrenzyText').textContent = Beautify(limitLuckyFrenzy - amount) + ' (' + CM.Disp.FormatTime((limitLuckyFrenzy - amount) / CM.Disp.GetCPS()) + ')'; - } - else if (amount < limitLuckyFrenzy) { - l('CMDispTooltipWarnLuckyFrenzy').style.display = ''; - l('CMDispTooltipWarnLuckyFrenzyText').textContent = Beautify(limitLuckyFrenzy - amount) + ' (' + CM.Disp.FormatTime((limitLuckyFrenzy - amount) / CM.Disp.GetCPS()) + ')'; - l('CMDispTooltipWarnLucky').style.display = 'none'; - } - } else { - l('CMDispTooltipWarnLucky').style.display = 'none'; - l('CMDispTooltipWarnLuckyFrenzy').style.display = 'none'; - } - } - else { - l('CMDispTooltipWarnLucky').style.display = 'none'; - l('CMDispTooltipWarnLuckyFrenzy').style.display = 'none'; - } - - if (CM.Config.ToolWarnConjure == 1) { - CM.Disp.TooltipWarn.style.display = 'block'; - var limitLucky = CM.Cache.Lucky; - if (CM.Config.ToolWarnBon == 1) { - var bonusNoFren = bonus; - bonusNoFren /= CM.Sim.getCPSBuffMult(); - limitLucky += ((bonusNoFren * 60 * 15) / 0.15); - } - var limitConjure = limitLucky * 2; - var amount = (Game.cookies + CM.Disp.GetWrinkConfigBank()) - price; - if ((amount < limitConjure) && (CM.Disp.tooltipType != 'b' || Game.buyMode == 1)) { - l('CMDispTooltipWarnConjure').style.display = ''; - l('CMDispTooltipWarnConjureText').textContent = Beautify(limitConjure - amount) + ' (' + CM.Disp.FormatTime((limitConjure - amount) / CM.Disp.GetCPS()) + ')'; - } else { - l('CMDispTooltipWarnConjure').style.display = 'none'; - } - } - else { - l('CMDispTooltipWarnConjure').style.display = 'none'; - } - } - else if (CM.Disp.tooltipType === 's') { - // Adding information about Sugar Lumps. - - CM.Disp.TooltipWarn.style.display = 'none'; - l('CMDispTooltipWarnLucky').style.display = 'none'; - l('CMDispTooltipWarnLuckyFrenzy').style.display = 'none'; - l('CMDispTooltipWarnConjure').style.display = 'none'; - - if (CM.Config.TooltipLump === 1) { - l('CMTooltipArea').innerHTML = ''; - - l('tooltip').firstChild.style.paddingBottom = '4px'; - var lumpTooltip = document.createElement('div'); - lumpTooltip.style.border = '1px solid'; - lumpTooltip.style.padding = '4px'; - lumpTooltip.style.margin = '0px -4px'; - lumpTooltip.id = 'CMTooltipBorder'; - lumpTooltip.className = CM.Disp.colorTextPre + CM.Disp.colorGray; - - var lumpHeader = document.createElement('div'); - lumpHeader.style.fontWeight = 'bold'; - lumpHeader.className = CM.Disp.colorTextPre + CM.Disp.colorBlue; - lumpHeader.textContent = 'Current Sugar Lump'; - - lumpTooltip.appendChild(lumpHeader); - var lumpType = document.createElement('div'); - lumpType.id = 'CMTooltipTime'; - lumpTooltip.appendChild(lumpType); - var lumpColor = CM.Disp.GetLumpColor(Game.lumpCurrentType); - lumpType.textContent = lumpColor.text; - lumpType.className = CM.Disp.colorTextPre + lumpColor.color; - - l('CMTooltipArea').appendChild(lumpTooltip); - } - } - else if (CM.Disp.tooltipType === 'g') { - // Grimoire - CM.Disp.TooltipWarn.style.display = 'none'; - l('CMDispTooltipWarnLucky').style.display = 'none'; - l('CMDispTooltipWarnLuckyFrenzy').style.display = 'none'; - l('CMDispTooltipWarnConjure').style.display = 'none'; - - var minigame = Game.Objects['Wizard tower'].minigame; - var spellCost = minigame.getSpellCost(minigame.spellsById[CM.Disp.tooltipName]); - - if (CM.Config.TooltipGrim == 1 && spellCost <= minigame.magicM) { - l('CMTooltipArea').innerHTML = ''; - - l('tooltip').firstChild.style.paddingBottom = '4px'; - var tooltip = document.createElement('div'); - tooltip.style.border = '1px solid'; - tooltip.style.padding = '4px'; - tooltip.style.margin = '0px -4px'; - tooltip.id = 'CMTooltipBorder'; - tooltip.className = CM.Disp.colorTextPre + CM.Disp.colorGray; - - var header = function(text) { - var div = document.createElement('div'); - div.style.fontWeight = 'bold'; - div.className = CM.Disp.colorTextPre + CM.Disp.colorBlue; - div.textContent = text; - return div; - } - - tooltip.appendChild(header('Time Left')); - var time = document.createElement('div'); - time.id = 'CMTooltipTime'; - tooltip.appendChild(time); - var timeColor = CM.Disp.GetTimeColor(spellCost, minigame.magic, undefined, CM.Disp.CalculateGrimoireRefillTime(minigame.magic, minigame.magicM, spellCost)); - time.textContent = timeColor.text; - time.className = CM.Disp.colorTextPre + timeColor.color; - - if (spellCost <= minigame.magic) { - tooltip.appendChild(header('Recover Time')); - var recover = document.createElement('div'); - recover.id = 'CMTooltipRecover'; - tooltip.appendChild(recover); - var recoverColor = CM.Disp.GetTimeColor(minigame.magic, Math.max(0, minigame.magic - spellCost), undefined, CM.Disp.CalculateGrimoireRefillTime(Math.max(0, minigame.magic - spellCost), minigame.magicM, minigame.magic)); - recover.textContent = recoverColor.text; - recover.className = CM.Disp.colorTextPre + recoverColor.color; - } - - // Extra information when spell is Conjure Baked Goods (Name == 0) - if (CM.Disp.tooltipName == 0) { - tooltip.appendChild(header('Cookies to be gained/lost')); - var conjure = document.createElement('div'); - conjure.id = 'CMTooltipConjure'; - tooltip.appendChild(conjure); - var reward = document.createElement('span'); - reward.style.color = "#33FF00" - reward.textContent = Beautify(Math.min((Game.cookies + CM.Disp.GetWrinkConfigBank()) * 0.15, CM.Cache.NoGoldSwitchCookiesPS * 60 * 30), 2) - conjure.appendChild(reward) - var seperator = document.createElement('span'); - seperator.textContent = ' / ' - conjure.appendChild(seperator) - var loss = document.createElement('span'); - loss.style.color = "red" - loss.textContent = Beautify((CM.Cache.NoGoldSwitchCookiesPS * 60 * 15), 2); - conjure.appendChild(loss) - } - - l('CMTooltipArea').appendChild(tooltip); - } - } - } - else { - CM.Disp.TooltipWarn.style.display = 'none'; - } - } -} - -CM.Disp.DrawTooltipWarn = function() { - if (CM.Config.ToolWarnLucky == 1) { - l('CMDispTooltipWarnLucky').style.opacity = '0'; - l('CMDispTooltipWarnLuckyFrenzy').style.opacity = '0'; - } - if (CM.Config.ToolWarnConjure == 1) { - l('CMDispTooltipWarnConjure').style.opacity = '0'; - } -} - -CM.Disp.UpdateTooltipWarn = function() { - if (CM.Config.ToolWarnLucky == 1 && l('tooltipAnchor').style.display != 'none' && l('CMTooltipArea') != null) { - l('CMDispTooltipWarnLucky').style.opacity = '1'; - l('CMDispTooltipWarnLuckyFrenzy').style.opacity = '1'; - } - if (CM.Config.ToolWarnConjure == 1 && l('tooltipAnchor').style.display != 'none' && l('CMTooltipArea') != null) { - l('CMDispTooltipWarnConjure').style.opacity = '1'; - } -} - -CM.Disp.AddWrinklerAreaDetect = function() { - l('backgroundLeftCanvas').onmouseover = function() {CM.Disp.TooltipWrinklerArea = 1;}; - l('backgroundLeftCanvas').onmouseout = function() { - CM.Disp.TooltipWrinklerArea = 0; - Game.tooltip.hide(); - for (var i in Game.wrinklers) { - CM.Disp.TooltipWrinklerCache[i] = 0; - } - }; -} - -CM.Disp.CheckWrinklerTooltip = function() { - if (CM.Config.ToolWrink == 1 && CM.Disp.TooltipWrinklerArea == 1) { - var showingTooltip = false; - for (var i in Game.wrinklers) { - var me = Game.wrinklers[i]; - if (me.phase > 0 && me.selected) { - showingTooltip = true; - if (CM.Disp.TooltipWrinklerCache[i] == 0) { - var placeholder = document.createElement('div'); - var wrinkler = document.createElement('div'); - wrinkler.style.minWidth = '120px'; - wrinkler.style.marginBottom = '4px'; - var div = document.createElement('div'); - div.style.textAlign = 'center'; - div.id = 'CMTooltipWrinkler'; - wrinkler.appendChild(div); - placeholder.appendChild(wrinkler); - Game.tooltip.draw(this, escape(placeholder.innerHTML)); - CM.Disp.TooltipWrinkler = i; - CM.Disp.TooltipWrinklerCache[i] = 1; - } - else break; - } - else { - CM.Disp.TooltipWrinklerCache[i] = 0; - } - } - if (!showingTooltip) { - Game.tooltip.hide(); - } - } -} - -CM.Disp.UpdateWrinklerTooltip = function() { - if (CM.Config.ToolWrink == 1 && l('CMTooltipWrinkler') != null) { - var sucked = Game.wrinklers[CM.Disp.TooltipWrinkler].sucked; - var toSuck = 1.1; - if (Game.Has('Sacrilegious corruption')) toSuck *= 1.05; - if (Game.wrinklers[CM.Disp.TooltipWrinkler].type == 1) toSuck *= 3; // Shiny wrinklers - sucked *= toSuck; - if (Game.Has('Wrinklerspawn')) sucked *= 1.05; - if (CM.Sim.Objects.Temple.minigameLoaded) { - var godLvl = CM.Sim.hasGod('scorn'); - if (godLvl == 1) sucked *= 1.15; - else if (godLvl == 2) sucked *= 1.1; - else if (godLvl == 3) sucked *= 1.05; - } - l('CMTooltipWrinkler').textContent = Beautify(sucked); - } -} - -CM.Disp.UpdateAscendState = function() { - if (Game.OnAscend) { - l('game').style.bottom = '0px'; - if (CM.Config.BotBar == 1) CM.Disp.BotBar.style.display = 'none'; - if (CM.Config.TimerBar == 1) CM.Disp.TimerBar.style.display = 'none'; - } - else { - CM.Disp.ToggleBotBar(); - CM.Disp.ToggleTimerBar(); - } - - CM.Disp.UpdateBackground(); -} - -CM.Disp.UpdateAuraDescription = function() { - return "function(aura)\ - {\ - l('dragonAuraInfo').innerHTML=\ - '

'+Game.dragonAuras[aura].name+'

'+\ - '
'+\ - Game.dragonAuras[aura].desc+\ - '
'+\ - CM.\ - '
';\ - }" -} - -CM.Disp.ToggleSayTime = function() { - if (CM.Config.SayTime == 1) { - Game.sayTime = CM.Disp.sayTime; - } - else { - Game.sayTime = CM.Backup.sayTime; - } -} - -CM.Disp.RefreshScale = function() { - BeautifyAll(); - Game.RefreshStore(); - Game.RebuildUpgrades(); - - CM.Disp.UpdateBotBarOther(); - CM.Disp.UpdateBuildings(); - CM.Disp.UpdateUpgrades(); -} +/******** + * Section: Variables used in Disp functions + * TODO: Move certain variables to src/Data.js (e.g., CM.Disp.metric & CM.Disp.shortScale) */ CM.Disp.colorTextPre = 'CMText'; CM.Disp.colorBackPre = 'CMBack'; From 391b70017a48a00198c4b37fe0b075464a68b4de Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Thu, 3 Dec 2020 10:50:00 +0100 Subject: [PATCH 004/106] Cleaned up CM.Disp.Beautify --- CookieMonster.js | 150 ++++++++++++++++++++-------------------------- src/Disp.js | 153 ++++++++++++++++++++--------------------------- 2 files changed, 129 insertions(+), 174 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index 3a3b3e9..ff2f2d7 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -1165,9 +1165,9 @@ CM.Disp.RefreshScale = function() { /** * This function returns time as a string depending on TimeFormat setting - * @param {number} time Time as number + * @param {number} time Time to be formatted * @param {number} longFormat 1 or 0 - * @return {string} + * @return {string} Formatted time` */ CM.Disp.FormatTime = function(time, longFormat) { if (time == Infinity) return time; @@ -1195,105 +1195,83 @@ CM.Disp.FormatTime = function(time, longFormat) { return str; } -CM.Disp.Beautify = function(num, frac) { - if (CM.Config.Scale != 0 && isFinite(num)) { +/** + * This function returns formats number based on the Scale setting + * @param {number} num Number to be beautified + * @param {any} frac Used in some scenario's by CM.Backup.Beautify (Game's original function) + * @param {number} forced Used to force (type 3) in certains cases + * @return {string} Formatted number + * TODO: Add functionality to choose amount of decimals and separators + */ +CM.Disp.Beautify = function(num, frac, forced) { + var decimals = 3; // This can be used to implement function to let user choose amount of decimals + if (CM.Config.Scale == 0) { + return CM.Backup.Beautify(num, frac); + } + else if (isFinite(num)) { var answer = ''; - var negative = false; if (num < 0) { num = Math.abs(num); - negative = true; + var negative = true; } - - if (CM.Config.Scale == 3) { - if (num >= 999999) { - var count = 0; - while (num >= 10) { - count++; - num /= 10; - } - answer = +(Math.round(num + "e+2") + "e-2") + 'E+' + count; - } - else if (num < -999999 && num != 0) { - var count = 0; - while (num < 1) { - count++; - num *= 10; - } - answer = +(Math.round(num + "e+2") + "e-2") + 'E-' + count; - } - else { - answer = CM.Backup.Beautify(num, frac); - } + num = num.toString(); + var timesTenToPowerThree = Math.trunc(Math.log10(num) / 3) + if (timesTenToPowerThree < 2) { + answer = num; } - else if (CM.Config.Scale == 4) { - if (um >= 999999) { - var count = 0; - while (num >= 1000) { - count++; - num /= 1000; - } - answer = +(Math.round(num + "e+2") + "e-2") + 'E+' + (count * 3); - } - else if (num < -999999 && num != 0) { - var count = 0; - while (num < 1) { - count++; - num *= 1000; - } - answer = +(Math.round(num + "e+2") + "e-2") + 'E-' + (count * 3); - } - else { - answer = CM.Backup.Beautify(num, frac); + else if (CM.Config.Scale == 3 && !forced || forced == 3) { // Scientific notation, 123456789 => 1.235E+8 + answer = num[0] + '.' + i = 0; + while (i < decimals - 1) { + answer += num[i + 2]; // num has a 0-based index and [1] is a '.' + i++; } + answer += Math.round(num[i + 2] + '.' + num[i + 3]); + answer += 'E+' + Math.trunc(Math.log10(num)); } else { - for (var i = (CM.Disp.shortScale.length - 1); i >= 0; i--) { - if (i < CM.Disp.metric.length && CM.Config.Scale == 1) { - // Revert to Scientific Notation from e27 - if (Math.log10(num) > 27) { - if (num >= 999999) { - var count = 0; - while (num >= 10) { - count++; - num /= 10; - } - answer = +(Math.round(num + "e+2") + "e-2") + 'E+' + count; - } - else if (num < -999999 && num != 0) { - var count = 0; - while (num < 1) { - count++; - num *= 10; - } - answer = +(Math.round(num + "e+2") + "e-2") + 'E-' + count; - } - else { - answer = CM.Backup.Beautify(num, frac); - } - } - else if (num >= Math.pow(1000, i + 2)) { - answer = (Math.round(num / Math.pow(1000, i + 1)) / 1000).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',') + ' ' + CM.Disp.metric[i]; - break; - } + var restOfNumber = (num / Math.pow(10, (timesTenToPowerThree * 3))).toString(); + numbersToAdd = (restOfNumber.indexOf('.') > -1 ? restOfNumber.indexOf('.') + 1 + decimals : (restOfNumber.length)) + i = 0 + while (i < numbersToAdd - 1) { + answer += restOfNumber[i]; + i++ + } + answer += (i + 1 < restOfNumber.length ? Math.round(restOfNumber[i] + '.' + restOfNumber[i + 1]) : restOfNumber[i]); + + // answer is now "xxx.xx" (e.g., 123456789 would be 123.46) + if (CM.Config.Scale == 1 && !forced || forced == 1) { // Metric scale, 123456789 => 123.457 M + if (timesTenToPowerThree - 1 < CM.Disp.metric.length) { + answer += ' ' + CM.Disp.metric[timesTenToPowerThree - 1] } - else if (CM.Config.Scale == 2) { - if (num >= Math.pow(1000, i + 2)) { - answer = (Math.round(num / Math.pow(1000, i + 1)) / 1000) + ' ' + CM.Disp.shortScale[i]; - break; - } + else { // If number is too large, revert to scientific notation + return CM.Disp.Beautify(num, 0, 3); } } + else if (CM.Config.Scale == 2 && !forced || forced == 2) { // Short scale, 123456789 => 123.457 M + if (timesTenToPowerThree < CM.Disp.shortScale.length + 1) { + answer += ' ' + CM.Disp.shortScale[timesTenToPowerThree - 1]; + } + else { // If number is too large, revert to scientific notation + return CM.Disp.Beautify(num, 0, 3); + } + } + else if (CM.Config.Scale == 4 && !forced || forced == 4) { // Engineering notation, 123456789 => 123.457E+6 + answer += 'E+' + (timesTenToPowerThree * 3); + } } if (answer == '') { - answer = CM.Backup.Beautify(num, frac); - } - - if (negative) { - answer = '-' + answer; + console.log("Could not beautify number with CM.Disp.Beautify"); + answer = CM.Backup.Beautify(num, frac); } + if (negative) answer = '-' + answer; return answer; } + else if (num == Infinity) { + return "Infinity"; + } else { + console.log("Could not beautify number with CM.Disp.Beautify"); return CM.Backup.Beautify(num, frac); } } @@ -3516,8 +3494,8 @@ CM.Disp.lastAscendState = -1; CM.Disp.cookieTimes = [10, 15, 30, 60, 300, 600, 900, 1800]; CM.Disp.clickTimes = [1, 5, 10, 15, 30]; -CM.Disp.metric = ['M', 'G', 'T', 'P', 'E', 'Z', 'Y']; -CM.Disp.shortScale = ['M', 'B', 'Tr', 'Quadr', 'Quint', 'Sext', 'Sept', 'Oct', 'Non', 'Dec', 'Undec', 'Duodec', 'Tredec', 'Quattuordec', 'Quindec', 'Sexdec', 'Septendec', 'Octodec', 'Novemdec', 'Vigint', 'Unvigint', 'Duovigint', 'Trevigint', 'Quattuorvigint']; +CM.Disp.metric = ['', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y']; +CM.Disp.shortScale = ['', 'M', 'B', 'Tr', 'Quadr', 'Quint', 'Sext', 'Sept', 'Oct', 'Non', 'Dec', 'Undec', 'Duodec', 'Tredec', 'Quattuordec', 'Quindec', 'Sexdec', 'Septendec', 'Octodec', 'Novemdec', 'Vigint', 'Unvigint', 'Duovigint', 'Trevigint', 'Quattuorvigint']; CM.Disp.TooltipWrinklerArea = 0; CM.Disp.TooltipWrinkler = -1; diff --git a/src/Disp.js b/src/Disp.js index c1dd66d..221ab6c 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -318,14 +318,13 @@ CM.Disp.RefreshScale = function() { CM.Disp.UpdateUpgrades(); } /******** - * Section: General functions to format or beautify strings - * TODO: Annotate most functions */ + * Section: General functions to format or beautify strings */ /** * This function returns time as a string depending on TimeFormat setting - * @param {number} time Time as number + * @param {number} time Time to be formatted * @param {number} longFormat 1 or 0 - * @return {string} + * @return {string} Formatted time` */ CM.Disp.FormatTime = function(time, longFormat) { if (time == Infinity) return time; @@ -353,105 +352,83 @@ CM.Disp.FormatTime = function(time, longFormat) { return str; } -CM.Disp.Beautify = function(num, frac) { - if (CM.Config.Scale != 0 && isFinite(num)) { +/** + * This function returns formats number based on the Scale setting + * @param {number} num Number to be beautified + * @param {any} frac Used in some scenario's by CM.Backup.Beautify (Game's original function) + * @param {number} forced Used to force (type 3) in certains cases + * @return {string} Formatted number + * TODO: Add functionality to choose amount of decimals and separators + */ +CM.Disp.Beautify = function(num, frac, forced) { + var decimals = 3; // This can be used to implement function to let user choose amount of decimals + if (CM.Config.Scale == 0) { + return CM.Backup.Beautify(num, frac); + } + else if (isFinite(num)) { var answer = ''; - var negative = false; if (num < 0) { num = Math.abs(num); - negative = true; + var negative = true; } - - if (CM.Config.Scale == 3) { - if (num >= 999999) { - var count = 0; - while (num >= 10) { - count++; - num /= 10; - } - answer = +(Math.round(num + "e+2") + "e-2") + 'E+' + count; - } - else if (num < -999999 && num != 0) { - var count = 0; - while (num < 1) { - count++; - num *= 10; - } - answer = +(Math.round(num + "e+2") + "e-2") + 'E-' + count; - } - else { - answer = CM.Backup.Beautify(num, frac); - } + num = num.toString(); + var timesTenToPowerThree = Math.trunc(Math.log10(num) / 3) + if (timesTenToPowerThree < 2) { + answer = num; } - else if (CM.Config.Scale == 4) { - if (um >= 999999) { - var count = 0; - while (num >= 1000) { - count++; - num /= 1000; - } - answer = +(Math.round(num + "e+2") + "e-2") + 'E+' + (count * 3); - } - else if (num < -999999 && num != 0) { - var count = 0; - while (num < 1) { - count++; - num *= 1000; - } - answer = +(Math.round(num + "e+2") + "e-2") + 'E-' + (count * 3); - } - else { - answer = CM.Backup.Beautify(num, frac); + else if (CM.Config.Scale == 3 && !forced || forced == 3) { // Scientific notation, 123456789 => 1.235E+8 + answer = num[0] + '.' + i = 0; + while (i < decimals - 1) { + answer += num[i + 2]; // num has a 0-based index and [1] is a '.' + i++; } + answer += Math.round(num[i + 2] + '.' + num[i + 3]); + answer += 'E+' + Math.trunc(Math.log10(num)); } else { - for (var i = (CM.Disp.shortScale.length - 1); i >= 0; i--) { - if (i < CM.Disp.metric.length && CM.Config.Scale == 1) { - // Revert to Scientific Notation from e27 - if (Math.log10(num) > 27) { - if (num >= 999999) { - var count = 0; - while (num >= 10) { - count++; - num /= 10; - } - answer = +(Math.round(num + "e+2") + "e-2") + 'E+' + count; - } - else if (num < -999999 && num != 0) { - var count = 0; - while (num < 1) { - count++; - num *= 10; - } - answer = +(Math.round(num + "e+2") + "e-2") + 'E-' + count; - } - else { - answer = CM.Backup.Beautify(num, frac); - } - } - else if (num >= Math.pow(1000, i + 2)) { - answer = (Math.round(num / Math.pow(1000, i + 1)) / 1000).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',') + ' ' + CM.Disp.metric[i]; - break; - } + var restOfNumber = (num / Math.pow(10, (timesTenToPowerThree * 3))).toString(); + numbersToAdd = (restOfNumber.indexOf('.') > -1 ? restOfNumber.indexOf('.') + 1 + decimals : (restOfNumber.length)) + i = 0 + while (i < numbersToAdd - 1) { + answer += restOfNumber[i]; + i++ + } + answer += (i + 1 < restOfNumber.length ? Math.round(restOfNumber[i] + '.' + restOfNumber[i + 1]) : restOfNumber[i]); + + // answer is now "xxx.xx" (e.g., 123456789 would be 123.46) + if (CM.Config.Scale == 1 && !forced || forced == 1) { // Metric scale, 123456789 => 123.457 M + if (timesTenToPowerThree - 1 < CM.Disp.metric.length) { + answer += ' ' + CM.Disp.metric[timesTenToPowerThree - 1] } - else if (CM.Config.Scale == 2) { - if (num >= Math.pow(1000, i + 2)) { - answer = (Math.round(num / Math.pow(1000, i + 1)) / 1000) + ' ' + CM.Disp.shortScale[i]; - break; - } + else { // If number is too large, revert to scientific notation + return CM.Disp.Beautify(num, 0, 3); } } + else if (CM.Config.Scale == 2 && !forced || forced == 2) { // Short scale, 123456789 => 123.457 M + if (timesTenToPowerThree < CM.Disp.shortScale.length + 1) { + answer += ' ' + CM.Disp.shortScale[timesTenToPowerThree - 1]; + } + else { // If number is too large, revert to scientific notation + return CM.Disp.Beautify(num, 0, 3); + } + } + else if (CM.Config.Scale == 4 && !forced || forced == 4) { // Engineering notation, 123456789 => 123.457E+6 + answer += 'E+' + (timesTenToPowerThree * 3); + } } if (answer == '') { - answer = CM.Backup.Beautify(num, frac); - } - - if (negative) { - answer = '-' + answer; + console.log("Could not beautify number with CM.Disp.Beautify"); + answer = CM.Backup.Beautify(num, frac); } + if (negative) answer = '-' + answer; return answer; } + else if (num == Infinity) { + return "Infinity"; + } else { + console.log("Could not beautify number with CM.Disp.Beautify"); return CM.Backup.Beautify(num, frac); } } @@ -2674,8 +2651,8 @@ CM.Disp.lastAscendState = -1; CM.Disp.cookieTimes = [10, 15, 30, 60, 300, 600, 900, 1800]; CM.Disp.clickTimes = [1, 5, 10, 15, 30]; -CM.Disp.metric = ['M', 'G', 'T', 'P', 'E', 'Z', 'Y']; -CM.Disp.shortScale = ['M', 'B', 'Tr', 'Quadr', 'Quint', 'Sext', 'Sept', 'Oct', 'Non', 'Dec', 'Undec', 'Duodec', 'Tredec', 'Quattuordec', 'Quindec', 'Sexdec', 'Septendec', 'Octodec', 'Novemdec', 'Vigint', 'Unvigint', 'Duovigint', 'Trevigint', 'Quattuorvigint']; +CM.Disp.metric = ['', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y']; +CM.Disp.shortScale = ['', 'M', 'B', 'Tr', 'Quadr', 'Quint', 'Sext', 'Sept', 'Oct', 'Non', 'Dec', 'Undec', 'Duodec', 'Tredec', 'Quattuordec', 'Quindec', 'Sexdec', 'Septendec', 'Octodec', 'Novemdec', 'Vigint', 'Unvigint', 'Duovigint', 'Trevigint', 'Quattuorvigint']; CM.Disp.TooltipWrinklerArea = 0; CM.Disp.TooltipWrinkler = -1; From 243e43188facc15c91a9ace258802c06040635e3 Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Thu, 3 Dec 2020 11:40:05 +0100 Subject: [PATCH 005/106] Cleaned up bottom bar code --- CookieMonster.js | 207 +++++++++++++++++++++++------------------------ src/Disp.js | 197 ++++++++++++++++++++++---------------------- src/Main.js | 5 +- 3 files changed, 202 insertions(+), 207 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index ff2f2d7..f8e6678 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -1155,13 +1155,12 @@ CM.Disp.RefreshScale = function() { Game.RefreshStore(); Game.RebuildUpgrades(); - CM.Disp.UpdateBotBarOther(); + CM.Disp.UpdateBotBar(); CM.Disp.UpdateBuildings(); CM.Disp.UpdateUpgrades(); } /******** - * Section: General functions to format or beautify strings - * TODO: Annotate most functions */ + * Section: General functions to format or beautify strings */ /** * This function returns time as a string depending on TimeFormat setting @@ -1202,7 +1201,7 @@ CM.Disp.FormatTime = function(time, longFormat) { * @param {number} forced Used to force (type 3) in certains cases * @return {string} Formatted number * TODO: Add functionality to choose amount of decimals and separators - */ +*/ CM.Disp.Beautify = function(num, frac, forced) { var decimals = 3; // This can be used to implement function to let user choose amount of decimals if (CM.Config.Scale == 0) { @@ -1238,7 +1237,7 @@ CM.Disp.Beautify = function(num, frac, forced) { i++ } answer += (i + 1 < restOfNumber.length ? Math.round(restOfNumber[i] + '.' + restOfNumber[i + 1]) : restOfNumber[i]); - + // answer is now "xxx.xx" (e.g., 123456789 would be 123.46) if (CM.Config.Scale == 1 && !forced || forced == 1) { // Metric scale, 123456789 => 123.457 M if (timesTenToPowerThree - 1 < CM.Disp.metric.length) { @@ -1277,14 +1276,102 @@ CM.Disp.Beautify = function(num, frac, forced) { } /******** - * Section: Functions related to the Bottom Bar - * TODO: Annotate functions */ + * Section: Functions related to the Bottom Bar */ + + /** + * This function toggle the bottom bar + * It is called by CM.Disp.UpdateAscendState() and a change in CM.Config.BotBar + */ +CM.Disp.ToggleBotBar = function() { + if (CM.Config.BotBar == 1) { + CM.Disp.BotBar.style.display = ''; + CM.Disp.UpdateBotBar(); + } + else { + CM.Disp.BotBar.style.display = 'none'; + } + CM.Disp.UpdateBotTimerBarPosition(); +} + + /** + * This function creates the bottom bar and appends it to l('wrapper') + * It is called by CM.DelayInit and a change in CM.Config.BotBar + */ +CM.Disp.CreateBotBar = function() { + CM.Disp.BotBar = document.createElement('div'); + CM.Disp.BotBar.id = 'CMBotBar'; + CM.Disp.BotBar.style.height = '69px'; + CM.Disp.BotBar.style.width = '100%'; + CM.Disp.BotBar.style.position = 'absolute'; + CM.Disp.BotBar.style.display = 'none'; + CM.Disp.BotBar.style.backgroundColor = '#262224'; + // This is old code for very old browsersand should not be needed anymore + //CM.Disp.BotBar.style.backgroundImage = '-moz-linear-gradient(top, #4d4548, #000000)'; + //CM.Disp.BotBar.style.backgroundImage = '-o-linear-gradient(top, #4d4548, #000000)'; + //CM.Disp.BotBar.style.backgroundImage = '-webkit-linear-gradient(top, #4d4548, #000000)'; + CM.Disp.BotBar.style.backgroundImage = 'linear-gradient(to bottom, #4d4548, #000000)'; + CM.Disp.BotBar.style.borderTop = '1px solid black'; + CM.Disp.BotBar.style.overflow = 'auto'; + CM.Disp.BotBar.style.textShadow = '-1px 0 black, 0 1px black, 1px 0 black, 0 -1px black'; + + var table = CM.Disp.BotBar.appendChild(document.createElement('table')); + table.style.width = '100%'; + table.style.textAlign = 'center'; + table.style.whiteSpace = 'nowrap'; + var tbody = table.appendChild(document.createElement('tbody')); + + var firstCol = function(text, color) { + var td = document.createElement('td'); + td.style.textAlign = 'right'; + td.className = CM.Disp.colorTextPre + color; + td.textContent = text; + return td; + } + var type = tbody.appendChild(document.createElement('tr')); + type.style.fontWeight = 'bold'; + type.appendChild(firstCol(CM.VersionMajor + '.' + CM.VersionMinor, CM.Disp.colorYellow)); + var bonus = tbody.appendChild(document.createElement('tr')); + bonus.appendChild(firstCol('Bonus Income', CM.Disp.colorBlue)); + var pp = tbody.appendChild(document.createElement('tr')); + pp.appendChild(firstCol('Payback Period', CM.Disp.colorBlue)); + var time = tbody.appendChild(document.createElement('tr')); + time.appendChild(firstCol('Time Left', CM.Disp.colorBlue)); + + for (var i in Game.Objects) { + CM.Disp.CreateBotBarBuildingColumn(i); + } + + l('wrapper').appendChild(CM.Disp.BotBar); +} /** - * Extends the bottom bar (created by CM.Disp.CreateBotBar) with a column for the given building. - * + * This function updates the bonus-, pp-, and time-rows in the the bottom bar + * It is called by CM.Loop() + */ +CM.Disp.UpdateBotBar = function() { + if (CM.Config.BotBar == 1) { + var count = 0; + for (var i in CM.Cache.Objects) { + var target = 'Objects'; + if (Game.buyBulk == 10) {target = 'Objects10';} + if (Game.buyBulk == 100) {target = 'Objects100';} + count++; + CM.Disp.BotBar.firstChild.firstChild.childNodes[0].childNodes[count].childNodes[1].textContent = Game.Objects[i].amount; + CM.Disp.BotBar.firstChild.firstChild.childNodes[1].childNodes[count].textContent = Beautify(CM.Cache[target][i].bonus, 2); + CM.Disp.BotBar.firstChild.firstChild.childNodes[2].childNodes[count].className = CM.Disp.colorTextPre + CM.Cache[target][i].color; + CM.Disp.BotBar.firstChild.firstChild.childNodes[2].childNodes[count].textContent = Beautify(CM.Cache[target][i].pp, 2); + var timeColor = CM.Disp.GetTimeColor(Game.Objects[i].bulkPrice, (Game.cookies + CM.Disp.GetWrinkConfigBank()), CM.Disp.GetCPS()); + CM.Disp.BotBar.firstChild.firstChild.childNodes[3].childNodes[count].className = CM.Disp.colorTextPre + timeColor.color; + CM.Disp.BotBar.firstChild.firstChild.childNodes[3].childNodes[count].textContent = timeColor.text; + } + } +} + +/** + * This function extends the bottom bar (created by CM.Disp.CreateBotBar) with a column for the given building. * This function is called by CM.Disp.CreateBotBar on initialization of Cookie Monster, * and also in CM.Sim.CopyData if a new building (added by another mod) is discovered. + * @param {string} buildingName Objectname to be added (e.g., "Cursor") */ CM.Disp.CreateBotBarBuildingColumn = function(buildingName) { if(!CM.Disp.BotBar) { @@ -1310,97 +1397,6 @@ CM.Disp.CreateBotBarBuildingColumn = function(buildingName) { time.appendChild(document.createElement('td')); } -CM.Disp.CreateBotBar = function() { - CM.Disp.BotBar = document.createElement('div'); - CM.Disp.BotBar.id = 'CMBotBar'; - CM.Disp.BotBar.style.height = '69px'; - CM.Disp.BotBar.style.width = '100%'; - CM.Disp.BotBar.style.position = 'absolute'; - CM.Disp.BotBar.style.display = 'none'; - CM.Disp.BotBar.style.backgroundColor = '#262224'; - CM.Disp.BotBar.style.backgroundImage = '-moz-linear-gradient(top, #4d4548, #000000)'; - CM.Disp.BotBar.style.backgroundImage = '-o-linear-gradient(top, #4d4548, #000000)'; - CM.Disp.BotBar.style.backgroundImage = '-webkit-linear-gradient(top, #4d4548, #000000)'; - CM.Disp.BotBar.style.backgroundImage = 'linear-gradient(to bottom, #4d4548, #000000)'; - CM.Disp.BotBar.style.borderTop = '1px solid black'; - CM.Disp.BotBar.style.overflow = 'auto'; - CM.Disp.BotBar.style.textShadow = '-1px 0 black, 0 1px black, 1px 0 black, 0 -1px black'; - - var table = CM.Disp.BotBar.appendChild(document.createElement('table')); - table.style.width = '100%'; - table.style.textAlign = 'center'; - table.style.whiteSpace = 'nowrap'; - // TODO figure a better way - //table.style.tableLayout = 'fixed'; - //table.style.overflow = 'hidden'; - var tbody = table.appendChild(document.createElement('tbody')); - - var firstCol = function(text, color) { - var td = document.createElement('td'); - td.style.textAlign = 'right'; - td.className = CM.Disp.colorTextPre + color; - td.textContent = text; - return td; - } - - var type = tbody.appendChild(document.createElement('tr')); - type.style.fontWeight = 'bold'; - type.appendChild(firstCol(CM.VersionMajor + '.' + CM.VersionMinor, CM.Disp.colorYellow)); - var bonus = tbody.appendChild(document.createElement('tr')); - bonus.appendChild(firstCol('Bonus Income', CM.Disp.colorBlue)); - var pp = tbody.appendChild(document.createElement('tr')); - pp.appendChild(firstCol('Payback Period', CM.Disp.colorBlue)); - var time = tbody.appendChild(document.createElement('tr')); - time.appendChild(firstCol('Time Left', CM.Disp.colorBlue)); - - for (var i in Game.Objects) { - CM.Disp.CreateBotBarBuildingColumn(i); - } - - l('wrapper').appendChild(CM.Disp.BotBar); -} - -CM.Disp.ToggleBotBar = function() { - if (CM.Config.BotBar == 1) { - CM.Disp.BotBar.style.display = ''; - CM.Disp.UpdateBotBarOther(); - } - else { - CM.Disp.BotBar.style.display = 'none'; - } - CM.Disp.UpdateBotTimerBarDisplay(); -} - -CM.Disp.UpdateBotBarOther = function() { - if (CM.Config.BotBar == 1) { - var count = 0; - - for (var i in CM.Cache.Objects) { - var target = 'Objects'; - if (Game.buyBulk == 10) {target = 'Objects10';} - if (Game.buyBulk == 100) {target = 'Objects100';} - count++; - CM.Disp.BotBar.firstChild.firstChild.childNodes[0].childNodes[count].childNodes[1].textContent = Game.Objects[i].amount; - CM.Disp.BotBar.firstChild.firstChild.childNodes[1].childNodes[count].textContent = Beautify(CM.Cache[target][i].bonus, 2); - CM.Disp.BotBar.firstChild.firstChild.childNodes[2].childNodes[count].className = CM.Disp.colorTextPre + CM.Cache[target][i].color; - CM.Disp.BotBar.firstChild.firstChild.childNodes[2].childNodes[count].textContent = Beautify(CM.Cache[target][i].pp, 2); - } - } -} - -CM.Disp.UpdateBotBarTime = function() { - if (CM.Config.BotBar == 1) { - var count = 0; - - for (var i in CM.Cache.Objects) { - count++; - var timeColor = CM.Disp.GetTimeColor(Game.Objects[i].getPrice(), (Game.cookies + CM.Disp.GetWrinkConfigBank()), CM.Disp.GetCPS()); - CM.Disp.BotBar.firstChild.firstChild.childNodes[3].childNodes[count].className = CM.Disp.colorTextPre + timeColor.color; - CM.Disp.BotBar.firstChild.firstChild.childNodes[3].childNodes[count].textContent = timeColor.text; - } - } -} - /******** * Section: Functions related to the Timer Bar * TODO: Annotate functions */ @@ -1502,7 +1498,7 @@ CM.Disp.ToggleTimerBar = function() { else { CM.Disp.TimerBar.style.display = 'none'; } - CM.Disp.UpdateBotTimerBarDisplay(); + CM.Disp.UpdateBotTimerBarPosition(); } CM.Disp.ToggleTimerBarPos = function() { @@ -1516,7 +1512,7 @@ CM.Disp.ToggleTimerBarPos = function() { CM.Disp.TimerBar.style.bottom = '0px'; l('wrapper').appendChild(CM.Disp.TimerBar); } - CM.Disp.UpdateBotTimerBarDisplay(); + CM.Disp.UpdateBotTimerBarPosition(); } CM.Disp.UpdateTimerBar = function() { @@ -1638,7 +1634,7 @@ CM.Disp.UpdateTimerBar = function() { } } -CM.Disp.UpdateBotTimerBarDisplay = function() { +CM.Disp.UpdateBotTimerBarPosition = function() { if (CM.Config.BotBar == 1 && CM.Config.TimerBar == 1 && CM.Config.TimerBarPos == 1) { CM.Disp.BotBar.style.bottom = '48px'; l('game').style.bottom = '118px'; @@ -3680,14 +3676,15 @@ CM.Loop = function() { CM.Cache.RemakePP(); // Update colors - CM.Disp.UpdateBotBarOther(); CM.Disp.UpdateBuildings(); CM.Disp.UpdateUpgrades(); // Redraw timers - CM.Disp.UpdateBotBarTime(); CM.Disp.UpdateTimerBar(); + // Update Bottom Bar + CM.Disp.UpdateBotBar(); + // Update Tooltip CM.Disp.UpdateTooltip(); diff --git a/src/Disp.js b/src/Disp.js index 221ab6c..30b199c 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -313,7 +313,7 @@ CM.Disp.RefreshScale = function() { Game.RefreshStore(); Game.RebuildUpgrades(); - CM.Disp.UpdateBotBarOther(); + CM.Disp.UpdateBotBar(); CM.Disp.UpdateBuildings(); CM.Disp.UpdateUpgrades(); } @@ -359,7 +359,7 @@ CM.Disp.FormatTime = function(time, longFormat) { * @param {number} forced Used to force (type 3) in certains cases * @return {string} Formatted number * TODO: Add functionality to choose amount of decimals and separators - */ +*/ CM.Disp.Beautify = function(num, frac, forced) { var decimals = 3; // This can be used to implement function to let user choose amount of decimals if (CM.Config.Scale == 0) { @@ -434,14 +434,102 @@ CM.Disp.Beautify = function(num, frac, forced) { } /******** - * Section: Functions related to the Bottom Bar - * TODO: Annotate functions */ + * Section: Functions related to the Bottom Bar */ + + /** + * This function toggle the bottom bar + * It is called by CM.Disp.UpdateAscendState() and a change in CM.Config.BotBar + */ +CM.Disp.ToggleBotBar = function() { + if (CM.Config.BotBar == 1) { + CM.Disp.BotBar.style.display = ''; + CM.Disp.UpdateBotBar(); + } + else { + CM.Disp.BotBar.style.display = 'none'; + } + CM.Disp.UpdateBotTimerBarPosition(); +} + + /** + * This function creates the bottom bar and appends it to l('wrapper') + * It is called by CM.DelayInit and a change in CM.Config.BotBar + */ +CM.Disp.CreateBotBar = function() { + CM.Disp.BotBar = document.createElement('div'); + CM.Disp.BotBar.id = 'CMBotBar'; + CM.Disp.BotBar.style.height = '69px'; + CM.Disp.BotBar.style.width = '100%'; + CM.Disp.BotBar.style.position = 'absolute'; + CM.Disp.BotBar.style.display = 'none'; + CM.Disp.BotBar.style.backgroundColor = '#262224'; + // This is old code for very old browsersand should not be needed anymore + //CM.Disp.BotBar.style.backgroundImage = '-moz-linear-gradient(top, #4d4548, #000000)'; + //CM.Disp.BotBar.style.backgroundImage = '-o-linear-gradient(top, #4d4548, #000000)'; + //CM.Disp.BotBar.style.backgroundImage = '-webkit-linear-gradient(top, #4d4548, #000000)'; + CM.Disp.BotBar.style.backgroundImage = 'linear-gradient(to bottom, #4d4548, #000000)'; + CM.Disp.BotBar.style.borderTop = '1px solid black'; + CM.Disp.BotBar.style.overflow = 'auto'; + CM.Disp.BotBar.style.textShadow = '-1px 0 black, 0 1px black, 1px 0 black, 0 -1px black'; + + var table = CM.Disp.BotBar.appendChild(document.createElement('table')); + table.style.width = '100%'; + table.style.textAlign = 'center'; + table.style.whiteSpace = 'nowrap'; + var tbody = table.appendChild(document.createElement('tbody')); + + var firstCol = function(text, color) { + var td = document.createElement('td'); + td.style.textAlign = 'right'; + td.className = CM.Disp.colorTextPre + color; + td.textContent = text; + return td; + } + var type = tbody.appendChild(document.createElement('tr')); + type.style.fontWeight = 'bold'; + type.appendChild(firstCol(CM.VersionMajor + '.' + CM.VersionMinor, CM.Disp.colorYellow)); + var bonus = tbody.appendChild(document.createElement('tr')); + bonus.appendChild(firstCol('Bonus Income', CM.Disp.colorBlue)); + var pp = tbody.appendChild(document.createElement('tr')); + pp.appendChild(firstCol('Payback Period', CM.Disp.colorBlue)); + var time = tbody.appendChild(document.createElement('tr')); + time.appendChild(firstCol('Time Left', CM.Disp.colorBlue)); + + for (var i in Game.Objects) { + CM.Disp.CreateBotBarBuildingColumn(i); + } + + l('wrapper').appendChild(CM.Disp.BotBar); +} /** - * Extends the bottom bar (created by CM.Disp.CreateBotBar) with a column for the given building. - * + * This function updates the bonus-, pp-, and time-rows in the the bottom bar + * It is called by CM.Loop() + */ +CM.Disp.UpdateBotBar = function() { + if (CM.Config.BotBar == 1) { + var count = 0; + for (var i in CM.Cache.Objects) { + var target = 'Objects'; + if (Game.buyBulk == 10) {target = 'Objects10';} + if (Game.buyBulk == 100) {target = 'Objects100';} + count++; + CM.Disp.BotBar.firstChild.firstChild.childNodes[0].childNodes[count].childNodes[1].textContent = Game.Objects[i].amount; + CM.Disp.BotBar.firstChild.firstChild.childNodes[1].childNodes[count].textContent = Beautify(CM.Cache[target][i].bonus, 2); + CM.Disp.BotBar.firstChild.firstChild.childNodes[2].childNodes[count].className = CM.Disp.colorTextPre + CM.Cache[target][i].color; + CM.Disp.BotBar.firstChild.firstChild.childNodes[2].childNodes[count].textContent = Beautify(CM.Cache[target][i].pp, 2); + var timeColor = CM.Disp.GetTimeColor(Game.Objects[i].bulkPrice, (Game.cookies + CM.Disp.GetWrinkConfigBank()), CM.Disp.GetCPS()); + CM.Disp.BotBar.firstChild.firstChild.childNodes[3].childNodes[count].className = CM.Disp.colorTextPre + timeColor.color; + CM.Disp.BotBar.firstChild.firstChild.childNodes[3].childNodes[count].textContent = timeColor.text; + } + } +} + +/** + * This function extends the bottom bar (created by CM.Disp.CreateBotBar) with a column for the given building. * This function is called by CM.Disp.CreateBotBar on initialization of Cookie Monster, * and also in CM.Sim.CopyData if a new building (added by another mod) is discovered. + * @param {string} buildingName Objectname to be added (e.g., "Cursor") */ CM.Disp.CreateBotBarBuildingColumn = function(buildingName) { if(!CM.Disp.BotBar) { @@ -467,97 +555,6 @@ CM.Disp.CreateBotBarBuildingColumn = function(buildingName) { time.appendChild(document.createElement('td')); } -CM.Disp.CreateBotBar = function() { - CM.Disp.BotBar = document.createElement('div'); - CM.Disp.BotBar.id = 'CMBotBar'; - CM.Disp.BotBar.style.height = '69px'; - CM.Disp.BotBar.style.width = '100%'; - CM.Disp.BotBar.style.position = 'absolute'; - CM.Disp.BotBar.style.display = 'none'; - CM.Disp.BotBar.style.backgroundColor = '#262224'; - CM.Disp.BotBar.style.backgroundImage = '-moz-linear-gradient(top, #4d4548, #000000)'; - CM.Disp.BotBar.style.backgroundImage = '-o-linear-gradient(top, #4d4548, #000000)'; - CM.Disp.BotBar.style.backgroundImage = '-webkit-linear-gradient(top, #4d4548, #000000)'; - CM.Disp.BotBar.style.backgroundImage = 'linear-gradient(to bottom, #4d4548, #000000)'; - CM.Disp.BotBar.style.borderTop = '1px solid black'; - CM.Disp.BotBar.style.overflow = 'auto'; - CM.Disp.BotBar.style.textShadow = '-1px 0 black, 0 1px black, 1px 0 black, 0 -1px black'; - - var table = CM.Disp.BotBar.appendChild(document.createElement('table')); - table.style.width = '100%'; - table.style.textAlign = 'center'; - table.style.whiteSpace = 'nowrap'; - // TODO figure a better way - //table.style.tableLayout = 'fixed'; - //table.style.overflow = 'hidden'; - var tbody = table.appendChild(document.createElement('tbody')); - - var firstCol = function(text, color) { - var td = document.createElement('td'); - td.style.textAlign = 'right'; - td.className = CM.Disp.colorTextPre + color; - td.textContent = text; - return td; - } - - var type = tbody.appendChild(document.createElement('tr')); - type.style.fontWeight = 'bold'; - type.appendChild(firstCol(CM.VersionMajor + '.' + CM.VersionMinor, CM.Disp.colorYellow)); - var bonus = tbody.appendChild(document.createElement('tr')); - bonus.appendChild(firstCol('Bonus Income', CM.Disp.colorBlue)); - var pp = tbody.appendChild(document.createElement('tr')); - pp.appendChild(firstCol('Payback Period', CM.Disp.colorBlue)); - var time = tbody.appendChild(document.createElement('tr')); - time.appendChild(firstCol('Time Left', CM.Disp.colorBlue)); - - for (var i in Game.Objects) { - CM.Disp.CreateBotBarBuildingColumn(i); - } - - l('wrapper').appendChild(CM.Disp.BotBar); -} - -CM.Disp.ToggleBotBar = function() { - if (CM.Config.BotBar == 1) { - CM.Disp.BotBar.style.display = ''; - CM.Disp.UpdateBotBarOther(); - } - else { - CM.Disp.BotBar.style.display = 'none'; - } - CM.Disp.UpdateBotTimerBarDisplay(); -} - -CM.Disp.UpdateBotBarOther = function() { - if (CM.Config.BotBar == 1) { - var count = 0; - - for (var i in CM.Cache.Objects) { - var target = 'Objects'; - if (Game.buyBulk == 10) {target = 'Objects10';} - if (Game.buyBulk == 100) {target = 'Objects100';} - count++; - CM.Disp.BotBar.firstChild.firstChild.childNodes[0].childNodes[count].childNodes[1].textContent = Game.Objects[i].amount; - CM.Disp.BotBar.firstChild.firstChild.childNodes[1].childNodes[count].textContent = Beautify(CM.Cache[target][i].bonus, 2); - CM.Disp.BotBar.firstChild.firstChild.childNodes[2].childNodes[count].className = CM.Disp.colorTextPre + CM.Cache[target][i].color; - CM.Disp.BotBar.firstChild.firstChild.childNodes[2].childNodes[count].textContent = Beautify(CM.Cache[target][i].pp, 2); - } - } -} - -CM.Disp.UpdateBotBarTime = function() { - if (CM.Config.BotBar == 1) { - var count = 0; - - for (var i in CM.Cache.Objects) { - count++; - var timeColor = CM.Disp.GetTimeColor(Game.Objects[i].getPrice(), (Game.cookies + CM.Disp.GetWrinkConfigBank()), CM.Disp.GetCPS()); - CM.Disp.BotBar.firstChild.firstChild.childNodes[3].childNodes[count].className = CM.Disp.colorTextPre + timeColor.color; - CM.Disp.BotBar.firstChild.firstChild.childNodes[3].childNodes[count].textContent = timeColor.text; - } - } -} - /******** * Section: Functions related to the Timer Bar * TODO: Annotate functions */ @@ -659,7 +656,7 @@ CM.Disp.ToggleTimerBar = function() { else { CM.Disp.TimerBar.style.display = 'none'; } - CM.Disp.UpdateBotTimerBarDisplay(); + CM.Disp.UpdateBotTimerBarPosition(); } CM.Disp.ToggleTimerBarPos = function() { @@ -673,7 +670,7 @@ CM.Disp.ToggleTimerBarPos = function() { CM.Disp.TimerBar.style.bottom = '0px'; l('wrapper').appendChild(CM.Disp.TimerBar); } - CM.Disp.UpdateBotTimerBarDisplay(); + CM.Disp.UpdateBotTimerBarPosition(); } CM.Disp.UpdateTimerBar = function() { @@ -795,7 +792,7 @@ CM.Disp.UpdateTimerBar = function() { } } -CM.Disp.UpdateBotTimerBarDisplay = function() { +CM.Disp.UpdateBotTimerBarPosition = function() { if (CM.Config.BotBar == 1 && CM.Config.TimerBar == 1 && CM.Config.TimerBarPos == 1) { CM.Disp.BotBar.style.bottom = '48px'; l('game').style.bottom = '118px'; diff --git a/src/Main.js b/src/Main.js index 657bdd8..1ee0d57 100644 --- a/src/Main.js +++ b/src/Main.js @@ -165,14 +165,15 @@ CM.Loop = function() { CM.Cache.RemakePP(); // Update colors - CM.Disp.UpdateBotBarOther(); CM.Disp.UpdateBuildings(); CM.Disp.UpdateUpgrades(); // Redraw timers - CM.Disp.UpdateBotBarTime(); CM.Disp.UpdateTimerBar(); + // Update Bottom Bar + CM.Disp.UpdateBotBar(); + // Update Tooltip CM.Disp.UpdateTooltip(); From 854bec1519c1b377c2d9db817a54000428ea8098 Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Thu, 3 Dec 2020 12:17:00 +0100 Subject: [PATCH 006/106] Updated upgrade bar code --- CookieMonster.js | 130 +++++++++++++++++++++++++++-------------------- src/Config.js | 2 +- src/Disp.js | 128 ++++++++++++++++++++++++++-------------------- 3 files changed, 148 insertions(+), 112 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index f8e6678..2938bde 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -711,7 +711,7 @@ CM.ConfigData.TimerBarPos = {label: ['Timer Bar Position (Top Left)', 'Timer Bar CM.ConfigData.BuildColor = {label: ['Building Colors OFF', 'Building Colors ON'], desc: 'Color code buildings', toggle: true, func: function() {CM.Disp.UpdateBuildings();}}; CM.ConfigData.BulkBuildColor = {label: ['Bulk Building Colors (Single Building Color)', 'Bulk Building Colors (Calculated Bulk Color)'], desc: 'Color code bulk buildings based on single buildings color or calculated bulk value color', toggle: false, func: function() {CM.Disp.UpdateBuildings();}}; CM.ConfigData.ColorPPBulkMode = {label: ['Color of PP (Compared to Single)', 'Color of PP (Compared to Bulk)'], desc: 'Color PP-values based on comparison with single purchase or with selected bulk-buy mode', toggle: false}; -CM.ConfigData.UpBarColor = {label: ['Upgrade Colors/Bar OFF', 'Upgrade Colors with Bar ON', 'Upgrade Colors without Bar ON'], desc: 'Color code upgrades and optionally add a counter bar', toggle: false, func: function() {CM.Disp.ToggleUpBarColor();}}; +CM.ConfigData.UpBarColor = {label: ['Upgrade Colors/Bar OFF', 'Upgrade Colors with Bar ON', 'Upgrade Colors without Bar ON'], desc: 'Color code upgrades and optionally add a counter bar', toggle: false, func: function() {CM.Disp.ToggleUpgradeBarAndColor();}}; CM.ConfigData.Colors = { desc: { Blue: 'Color Blue. Used to show better than best PP building, for Click Frenzy bar, and for various labels', @@ -1164,9 +1164,9 @@ CM.Disp.RefreshScale = function() { /** * This function returns time as a string depending on TimeFormat setting - * @param {number} time Time to be formatted - * @param {number} longFormat 1 or 0 - * @return {string} Formatted time` + * @param {number} time Time to be formatted + * @param {number} longFormat 1 or 0 + * @returns {string} Formatted time` */ CM.Disp.FormatTime = function(time, longFormat) { if (time == Infinity) return time; @@ -1199,9 +1199,9 @@ CM.Disp.FormatTime = function(time, longFormat) { * @param {number} num Number to be beautified * @param {any} frac Used in some scenario's by CM.Backup.Beautify (Game's original function) * @param {number} forced Used to force (type 3) in certains cases - * @return {string} Formatted number + * @returns {string} Formatted number * TODO: Add functionality to choose amount of decimals and separators -*/ + */ CM.Disp.Beautify = function(num, frac, forced) { var decimals = 3; // This can be used to implement function to let user choose amount of decimals if (CM.Config.Scale == 0) { @@ -1278,7 +1278,7 @@ CM.Disp.Beautify = function(num, frac, forced) { /******** * Section: Functions related to the Bottom Bar */ - /** +/** * This function toggle the bottom bar * It is called by CM.Disp.UpdateAscendState() and a change in CM.Config.BotBar */ @@ -1293,7 +1293,7 @@ CM.Disp.ToggleBotBar = function() { CM.Disp.UpdateBotTimerBarPosition(); } - /** +/** * This function creates the bottom bar and appends it to l('wrapper') * It is called by CM.DelayInit and a change in CM.Config.BotBar */ @@ -1729,8 +1729,44 @@ CM.Disp.UpdateBuildings = function() { /******** * Section: Functions related to the Upgrade Bar - * TODO: Annotate functions */ +/** + * This function toggles the upgrade bar and the colours of upgrades + * It is called by a change in CM.Config.UpBarColor + */ +CM.Disp.ToggleUpgradeBarAndColor = function() { + if (CM.Config.UpBarColor == 1) { // Colours and bar on + CM.Disp.UpgradeBar.style.display = ''; + CM.Disp.UpdateUpgrades(); + } + else if (CM.Config.UpBarColor == 2) {// Colours on and bar off + CM.Disp.UpgradeBar.style.display = 'none'; + CM.Disp.UpdateUpgrades(); + } + else { // Colours and bar off + CM.Disp.UpgradeBar.style.display = 'none'; + Game.RebuildUpgrades(); + } +} + +/** + * This function toggles the position of the upgrade bar from fixed or non-fixed mode + * It is called by a change in CM.Config.UpgradeBarFixedPos + */ +CM.Disp.ToggleUpgradeBarFixedPos = function() { + if (CM.Config.UpgradeBarFixedPos == 1) { // Fix to top of screen when scrolling + CM.Disp.UpgradeBar.style.position = 'sticky'; + CM.Disp.UpgradeBar.style.top = '0px'; + } + else { + CM.Disp.UpgradeBar.style.position = ''; // Possible to scroll offscreen + } +} + +/** + * This function creates the upgrade bar above the upgrade-section in the right section of the screen + * The number (.textContent) of upgrades gets updated by CM.Disp.UpdateUpgrades() + */ CM.Disp.CreateUpgradeBar = function() { CM.Disp.UpgradeBar = document.createElement('div'); CM.Disp.UpgradeBar.id = 'CMUpgradeBar'; @@ -1743,6 +1779,34 @@ CM.Disp.CreateUpgradeBar = function() { CM.Disp.UpgradeBar.onmouseout = function() { Game.tooltip.hide(); }; var placeholder = document.createElement('div'); + placeholder.appendChild(CM.Disp.CreateUpgradeBarLegend()); + CM.Disp.UpgradeBar.onmouseover = function() {Game.tooltip.draw(this, escape(placeholder.innerHTML), 'store');}; + + var upgradeNumber = function(id, color) { + var span = document.createElement('span'); + span.id = id; + span.className = CM.Disp.colorTextPre + color; + span.style.width = '14.28571428571429%'; + span.style.display = 'inline-block'; + span.textContent = '0'; + return span; + } + CM.Disp.UpgradeBar.appendChild(upgradeNumber('CMUpgradeBarBlue', CM.Disp.colorBlue)); + CM.Disp.UpgradeBar.appendChild(upgradeNumber('CMUpgradeBarGreen', CM.Disp.colorGreen)); + CM.Disp.UpgradeBar.appendChild(upgradeNumber('CMUpgradeBarYellow', CM.Disp.colorYellow)); + CM.Disp.UpgradeBar.appendChild(upgradeNumber('CMUpgradeBarOrange', CM.Disp.colorOrange)); + CM.Disp.UpgradeBar.appendChild(upgradeNumber('CMUpgradeBarRed', CM.Disp.colorRed)); + CM.Disp.UpgradeBar.appendChild(upgradeNumber('CMUpgradeBarPurple', CM.Disp.colorPurple)); + CM.Disp.UpgradeBar.appendChild(upgradeNumber('CMUpgradeBarGray', CM.Disp.colorGray)); + + l('upgrades').parentNode.insertBefore(CM.Disp.UpgradeBar, l('upgrades').parentNode.childNodes[3]); +} + +/** + * This function creates the legend for the upgrade bar, it is called by CM.Disp.CreateUpgradeBar + * @returns {object} legend The legend-object to be added + */ +CM.Disp.CreateUpgradeBarLegend = function() { var legend = document.createElement('div'); legend.style.minWidth = '330px'; legend.style.marginBottom = '4px'; @@ -1773,53 +1837,7 @@ CM.Disp.CreateUpgradeBar = function() { legend.appendChild(legendLine(CM.Disp.colorRed, 'Same as worst PP building')); legend.appendChild(legendLine(CM.Disp.colorPurple, 'Worse than worst PP building')); legend.appendChild(legendLine(CM.Disp.colorGray, 'Negative or infinity PP')); - placeholder.appendChild(legend); - - CM.Disp.UpgradeBar.onmouseover = function() {Game.tooltip.draw(this, escape(placeholder.innerHTML), 'store');}; - - var upgradeNumber = function(id, color) { - var span = document.createElement('span'); - span.id = id; - span.className = CM.Disp.colorTextPre + color; - span.style.width = '14.28571428571429%'; - span.style.display = 'inline-block'; - span.textContent = '0'; - return span; - } - CM.Disp.UpgradeBar.appendChild(upgradeNumber('CMUpgradeBarBlue', CM.Disp.colorBlue)); - CM.Disp.UpgradeBar.appendChild(upgradeNumber('CMUpgradeBarGreen', CM.Disp.colorGreen)); - CM.Disp.UpgradeBar.appendChild(upgradeNumber('CMUpgradeBarYellow', CM.Disp.colorYellow)); - CM.Disp.UpgradeBar.appendChild(upgradeNumber('CMUpgradeBarOrange', CM.Disp.colorOrange)); - CM.Disp.UpgradeBar.appendChild(upgradeNumber('CMUpgradeBarRed', CM.Disp.colorRed)); - CM.Disp.UpgradeBar.appendChild(upgradeNumber('CMUpgradeBarPurple', CM.Disp.colorPurple)); - CM.Disp.UpgradeBar.appendChild(upgradeNumber('CMUpgradeBarGray', CM.Disp.colorGray)); - - l('upgrades').parentNode.insertBefore(CM.Disp.UpgradeBar, l('upgrades').parentNode.childNodes[3]); -} - -CM.Disp.ToggleUpBarColor = function() { - if (CM.Config.UpBarColor == 1) { - CM.Disp.UpgradeBar.style.display = ''; - CM.Disp.UpdateUpgrades(); - } - else if (CM.Config.UpBarColor == 2) { - CM.Disp.UpgradeBar.style.display = 'none'; - CM.Disp.UpdateUpgrades(); - } - else { - CM.Disp.UpgradeBar.style.display = 'none'; - Game.RebuildUpgrades(); - } -} - -CM.Disp.ToggleUpgradeBarFixedPos = function() { - if (CM.Config.UpgradeBarFixedPos == 1) { - CM.Disp.UpgradeBar.style.position = 'sticky'; - CM.Disp.UpgradeBar.style.top = '0px'; - } - else { - CM.Disp.UpgradeBar.style.position = ''; - } + return legend; } /******** diff --git a/src/Config.js b/src/Config.js index 5ff8665..a98742b 100644 --- a/src/Config.js +++ b/src/Config.js @@ -159,7 +159,7 @@ CM.ConfigData.TimerBarPos = {label: ['Timer Bar Position (Top Left)', 'Timer Bar CM.ConfigData.BuildColor = {label: ['Building Colors OFF', 'Building Colors ON'], desc: 'Color code buildings', toggle: true, func: function() {CM.Disp.UpdateBuildings();}}; CM.ConfigData.BulkBuildColor = {label: ['Bulk Building Colors (Single Building Color)', 'Bulk Building Colors (Calculated Bulk Color)'], desc: 'Color code bulk buildings based on single buildings color or calculated bulk value color', toggle: false, func: function() {CM.Disp.UpdateBuildings();}}; CM.ConfigData.ColorPPBulkMode = {label: ['Color of PP (Compared to Single)', 'Color of PP (Compared to Bulk)'], desc: 'Color PP-values based on comparison with single purchase or with selected bulk-buy mode', toggle: false}; -CM.ConfigData.UpBarColor = {label: ['Upgrade Colors/Bar OFF', 'Upgrade Colors with Bar ON', 'Upgrade Colors without Bar ON'], desc: 'Color code upgrades and optionally add a counter bar', toggle: false, func: function() {CM.Disp.ToggleUpBarColor();}}; +CM.ConfigData.UpBarColor = {label: ['Upgrade Colors/Bar OFF', 'Upgrade Colors with Bar ON', 'Upgrade Colors without Bar ON'], desc: 'Color code upgrades and optionally add a counter bar', toggle: false, func: function() {CM.Disp.ToggleUpgradeBarAndColor();}}; CM.ConfigData.Colors = { desc: { Blue: 'Color Blue. Used to show better than best PP building, for Click Frenzy bar, and for various labels', diff --git a/src/Disp.js b/src/Disp.js index 30b199c..5510420 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -322,9 +322,9 @@ CM.Disp.RefreshScale = function() { /** * This function returns time as a string depending on TimeFormat setting - * @param {number} time Time to be formatted - * @param {number} longFormat 1 or 0 - * @return {string} Formatted time` + * @param {number} time Time to be formatted + * @param {number} longFormat 1 or 0 + * @returns {string} Formatted time` */ CM.Disp.FormatTime = function(time, longFormat) { if (time == Infinity) return time; @@ -357,9 +357,9 @@ CM.Disp.FormatTime = function(time, longFormat) { * @param {number} num Number to be beautified * @param {any} frac Used in some scenario's by CM.Backup.Beautify (Game's original function) * @param {number} forced Used to force (type 3) in certains cases - * @return {string} Formatted number + * @returns {string} Formatted number * TODO: Add functionality to choose amount of decimals and separators -*/ + */ CM.Disp.Beautify = function(num, frac, forced) { var decimals = 3; // This can be used to implement function to let user choose amount of decimals if (CM.Config.Scale == 0) { @@ -436,7 +436,7 @@ CM.Disp.Beautify = function(num, frac, forced) { /******** * Section: Functions related to the Bottom Bar */ - /** +/** * This function toggle the bottom bar * It is called by CM.Disp.UpdateAscendState() and a change in CM.Config.BotBar */ @@ -451,7 +451,7 @@ CM.Disp.ToggleBotBar = function() { CM.Disp.UpdateBotTimerBarPosition(); } - /** +/** * This function creates the bottom bar and appends it to l('wrapper') * It is called by CM.DelayInit and a change in CM.Config.BotBar */ @@ -887,8 +887,44 @@ CM.Disp.UpdateBuildings = function() { /******** * Section: Functions related to the Upgrade Bar - * TODO: Annotate functions */ +/** + * This function toggles the upgrade bar and the colours of upgrades + * It is called by a change in CM.Config.UpBarColor + */ +CM.Disp.ToggleUpgradeBarAndColor = function() { + if (CM.Config.UpBarColor == 1) { // Colours and bar on + CM.Disp.UpgradeBar.style.display = ''; + CM.Disp.UpdateUpgrades(); + } + else if (CM.Config.UpBarColor == 2) {// Colours on and bar off + CM.Disp.UpgradeBar.style.display = 'none'; + CM.Disp.UpdateUpgrades(); + } + else { // Colours and bar off + CM.Disp.UpgradeBar.style.display = 'none'; + Game.RebuildUpgrades(); + } +} + +/** + * This function toggles the position of the upgrade bar from fixed or non-fixed mode + * It is called by a change in CM.Config.UpgradeBarFixedPos + */ +CM.Disp.ToggleUpgradeBarFixedPos = function() { + if (CM.Config.UpgradeBarFixedPos == 1) { // Fix to top of screen when scrolling + CM.Disp.UpgradeBar.style.position = 'sticky'; + CM.Disp.UpgradeBar.style.top = '0px'; + } + else { + CM.Disp.UpgradeBar.style.position = ''; // Possible to scroll offscreen + } +} + +/** + * This function creates the upgrade bar above the upgrade-section in the right section of the screen + * The number (.textContent) of upgrades gets updated by CM.Disp.UpdateUpgrades() + */ CM.Disp.CreateUpgradeBar = function() { CM.Disp.UpgradeBar = document.createElement('div'); CM.Disp.UpgradeBar.id = 'CMUpgradeBar'; @@ -901,6 +937,34 @@ CM.Disp.CreateUpgradeBar = function() { CM.Disp.UpgradeBar.onmouseout = function() { Game.tooltip.hide(); }; var placeholder = document.createElement('div'); + placeholder.appendChild(CM.Disp.CreateUpgradeBarLegend()); + CM.Disp.UpgradeBar.onmouseover = function() {Game.tooltip.draw(this, escape(placeholder.innerHTML), 'store');}; + + var upgradeNumber = function(id, color) { + var span = document.createElement('span'); + span.id = id; + span.className = CM.Disp.colorTextPre + color; + span.style.width = '14.28571428571429%'; + span.style.display = 'inline-block'; + span.textContent = '0'; + return span; + } + CM.Disp.UpgradeBar.appendChild(upgradeNumber('CMUpgradeBarBlue', CM.Disp.colorBlue)); + CM.Disp.UpgradeBar.appendChild(upgradeNumber('CMUpgradeBarGreen', CM.Disp.colorGreen)); + CM.Disp.UpgradeBar.appendChild(upgradeNumber('CMUpgradeBarYellow', CM.Disp.colorYellow)); + CM.Disp.UpgradeBar.appendChild(upgradeNumber('CMUpgradeBarOrange', CM.Disp.colorOrange)); + CM.Disp.UpgradeBar.appendChild(upgradeNumber('CMUpgradeBarRed', CM.Disp.colorRed)); + CM.Disp.UpgradeBar.appendChild(upgradeNumber('CMUpgradeBarPurple', CM.Disp.colorPurple)); + CM.Disp.UpgradeBar.appendChild(upgradeNumber('CMUpgradeBarGray', CM.Disp.colorGray)); + + l('upgrades').parentNode.insertBefore(CM.Disp.UpgradeBar, l('upgrades').parentNode.childNodes[3]); +} + +/** + * This function creates the legend for the upgrade bar, it is called by CM.Disp.CreateUpgradeBar + * @returns {object} legend The legend-object to be added + */ +CM.Disp.CreateUpgradeBarLegend = function() { var legend = document.createElement('div'); legend.style.minWidth = '330px'; legend.style.marginBottom = '4px'; @@ -931,53 +995,7 @@ CM.Disp.CreateUpgradeBar = function() { legend.appendChild(legendLine(CM.Disp.colorRed, 'Same as worst PP building')); legend.appendChild(legendLine(CM.Disp.colorPurple, 'Worse than worst PP building')); legend.appendChild(legendLine(CM.Disp.colorGray, 'Negative or infinity PP')); - placeholder.appendChild(legend); - - CM.Disp.UpgradeBar.onmouseover = function() {Game.tooltip.draw(this, escape(placeholder.innerHTML), 'store');}; - - var upgradeNumber = function(id, color) { - var span = document.createElement('span'); - span.id = id; - span.className = CM.Disp.colorTextPre + color; - span.style.width = '14.28571428571429%'; - span.style.display = 'inline-block'; - span.textContent = '0'; - return span; - } - CM.Disp.UpgradeBar.appendChild(upgradeNumber('CMUpgradeBarBlue', CM.Disp.colorBlue)); - CM.Disp.UpgradeBar.appendChild(upgradeNumber('CMUpgradeBarGreen', CM.Disp.colorGreen)); - CM.Disp.UpgradeBar.appendChild(upgradeNumber('CMUpgradeBarYellow', CM.Disp.colorYellow)); - CM.Disp.UpgradeBar.appendChild(upgradeNumber('CMUpgradeBarOrange', CM.Disp.colorOrange)); - CM.Disp.UpgradeBar.appendChild(upgradeNumber('CMUpgradeBarRed', CM.Disp.colorRed)); - CM.Disp.UpgradeBar.appendChild(upgradeNumber('CMUpgradeBarPurple', CM.Disp.colorPurple)); - CM.Disp.UpgradeBar.appendChild(upgradeNumber('CMUpgradeBarGray', CM.Disp.colorGray)); - - l('upgrades').parentNode.insertBefore(CM.Disp.UpgradeBar, l('upgrades').parentNode.childNodes[3]); -} - -CM.Disp.ToggleUpBarColor = function() { - if (CM.Config.UpBarColor == 1) { - CM.Disp.UpgradeBar.style.display = ''; - CM.Disp.UpdateUpgrades(); - } - else if (CM.Config.UpBarColor == 2) { - CM.Disp.UpgradeBar.style.display = 'none'; - CM.Disp.UpdateUpgrades(); - } - else { - CM.Disp.UpgradeBar.style.display = 'none'; - Game.RebuildUpgrades(); - } -} - -CM.Disp.ToggleUpgradeBarFixedPos = function() { - if (CM.Config.UpgradeBarFixedPos == 1) { - CM.Disp.UpgradeBar.style.position = 'sticky'; - CM.Disp.UpgradeBar.style.top = '0px'; - } - else { - CM.Disp.UpgradeBar.style.position = ''; - } + return legend; } /******** From 28ab2eab2208651224b7a32c44bbcbfc3453d3bd Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Thu, 3 Dec 2020 12:33:21 +0100 Subject: [PATCH 007/106] Annotated section on flashes/sound/notification --- CookieMonster.js | 57 +++++++++++++++++++++++++++++++++--------------- src/Disp.js | 57 +++++++++++++++++++++++++++++++++--------------- 2 files changed, 78 insertions(+), 36 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index 2938bde..a66ec70 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -1049,19 +1049,6 @@ CM.Disp.UpdateColors = function() { CM.Disp.UpdateBuildings(); // Class has been already set } -CM.Disp.CreateWhiteScreen = function() { - CM.Disp.WhiteScreen = document.createElement('div'); - CM.Disp.WhiteScreen.id = 'CMWhiteScreen'; - CM.Disp.WhiteScreen.style.width = '100%'; - CM.Disp.WhiteScreen.style.height = '100%'; - CM.Disp.WhiteScreen.style.backgroundColor = 'white'; - CM.Disp.WhiteScreen.style.display = 'none'; - CM.Disp.WhiteScreen.style.zIndex = '9999999999'; - CM.Disp.WhiteScreen.style.position = 'absolute'; - - l('wrapper').appendChild(CM.Disp.WhiteScreen); -} - CM.Disp.FindShimmer = function() { CM.Disp.currSpawnedGoldenCookieState = 0 CM.Disp.goldenShimmersByID = {} @@ -1842,8 +1829,30 @@ CM.Disp.CreateUpgradeBarLegend = function() { /******** * Section: Functions related to the flashes/sound/notifications - * TODO: Annotate functions */ +/** + * This function creates a white square over the full screen and appends it to l('wrapper') + * It is used (and called) by CM.Disp.Flash() to create the effect of a flash + */ +CM.Disp.CreateWhiteScreen = function() { + CM.Disp.WhiteScreen = document.createElement('div'); + CM.Disp.WhiteScreen.id = 'CMWhiteScreen'; + CM.Disp.WhiteScreen.style.width = '100%'; + CM.Disp.WhiteScreen.style.height = '100%'; + CM.Disp.WhiteScreen.style.backgroundColor = 'white'; + CM.Disp.WhiteScreen.style.display = 'none'; + CM.Disp.WhiteScreen.style.zIndex = '9999999999'; + CM.Disp.WhiteScreen.style.position = 'absolute'; + l('wrapper').appendChild(CM.Disp.WhiteScreen); +} + +/** + * This function creates a flash depending on configs. It is called by all functions + * that check game-events and which have settings for Flashes (e.g., Golden Cookies appearing, Magic meter being full) + * @param {number} mode Sets the intensity of the flash, used to recursively dim flash + * All calls of function have use mode == 3 + * @param {string} config The setting in CM.Config that is checked before creating the flash + */ CM.Disp.Flash = function(mode, config) { if ((CM.Config[config] == 1 && mode == 3) || mode == 1) { CM.Disp.WhiteScreen.style.opacity = '0.5'; @@ -1859,11 +1868,16 @@ CM.Disp.Flash = function(mode, config) { CM.Disp.WhiteScreen.style.opacity = '1'; setTimeout(function() {CM.Disp.Flash(1, config);}, 1000/Game.fps); } - else if (mode == 0) { - CM.Disp.WhiteScreen.style.display = 'none'; - } + else if (mode == 0) CM.Disp.WhiteScreen.style.display = 'none'; } +/** + * This function plays a sound depending on configs. It is called by all functions + * that check game-events and which have settings for sound (e.g., Golden Cookies appearing, Magic meter being full) + * @param {variable} url A variable that gives the url for the sound (e.g., CM.Config.GCSoundURL) + * @param {string} sndConfig The setting in CM.Config that is checked before creating the sound + * @param {string} volConfig The setting in CM.Config that is checked to determine volume + */ CM.Disp.PlaySound = function(url, sndConfig, volConfig) { if (CM.Config[sndConfig] == 1) { var sound = new realAudio(url); @@ -1872,10 +1886,17 @@ CM.Disp.PlaySound = function(url, sndConfig, volConfig) { } } +/** + * This function creates a notifcation depending on configs. It is called by all functions + * that check game-events and which have settings for notifications (e.g., Golden Cookies appearing, Magic meter being full) + * @param {string} notifyConfig The setting in CM.Config that is checked before creating the notification + * @param {string} title The title of the to-be created notifications + * @param {string} message The text of the to-be created notifications + */ CM.Disp.Notification = function(notifyConfig, title, message) { if (CM.Config[notifyConfig] == 1 && document.visibilityState == 'hidden') { var CookieIcon = 'https://orteil.dashnet.org/cookieclicker/favicon.ico' - var notification = new Notification(title, {body: message, badge: CookieIcon}); + notification = new Notification(title, {body: message, badge: CookieIcon}); } } diff --git a/src/Disp.js b/src/Disp.js index 5510420..e0d74ab 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -207,19 +207,6 @@ CM.Disp.UpdateColors = function() { CM.Disp.UpdateBuildings(); // Class has been already set } -CM.Disp.CreateWhiteScreen = function() { - CM.Disp.WhiteScreen = document.createElement('div'); - CM.Disp.WhiteScreen.id = 'CMWhiteScreen'; - CM.Disp.WhiteScreen.style.width = '100%'; - CM.Disp.WhiteScreen.style.height = '100%'; - CM.Disp.WhiteScreen.style.backgroundColor = 'white'; - CM.Disp.WhiteScreen.style.display = 'none'; - CM.Disp.WhiteScreen.style.zIndex = '9999999999'; - CM.Disp.WhiteScreen.style.position = 'absolute'; - - l('wrapper').appendChild(CM.Disp.WhiteScreen); -} - CM.Disp.FindShimmer = function() { CM.Disp.currSpawnedGoldenCookieState = 0 CM.Disp.goldenShimmersByID = {} @@ -1000,8 +987,30 @@ CM.Disp.CreateUpgradeBarLegend = function() { /******** * Section: Functions related to the flashes/sound/notifications - * TODO: Annotate functions */ +/** + * This function creates a white square over the full screen and appends it to l('wrapper') + * It is used (and called) by CM.Disp.Flash() to create the effect of a flash + */ +CM.Disp.CreateWhiteScreen = function() { + CM.Disp.WhiteScreen = document.createElement('div'); + CM.Disp.WhiteScreen.id = 'CMWhiteScreen'; + CM.Disp.WhiteScreen.style.width = '100%'; + CM.Disp.WhiteScreen.style.height = '100%'; + CM.Disp.WhiteScreen.style.backgroundColor = 'white'; + CM.Disp.WhiteScreen.style.display = 'none'; + CM.Disp.WhiteScreen.style.zIndex = '9999999999'; + CM.Disp.WhiteScreen.style.position = 'absolute'; + l('wrapper').appendChild(CM.Disp.WhiteScreen); +} + +/** + * This function creates a flash depending on configs. It is called by all functions + * that check game-events and which have settings for Flashes (e.g., Golden Cookies appearing, Magic meter being full) + * @param {number} mode Sets the intensity of the flash, used to recursively dim flash + * All calls of function have use mode == 3 + * @param {string} config The setting in CM.Config that is checked before creating the flash + */ CM.Disp.Flash = function(mode, config) { if ((CM.Config[config] == 1 && mode == 3) || mode == 1) { CM.Disp.WhiteScreen.style.opacity = '0.5'; @@ -1017,11 +1026,16 @@ CM.Disp.Flash = function(mode, config) { CM.Disp.WhiteScreen.style.opacity = '1'; setTimeout(function() {CM.Disp.Flash(1, config);}, 1000/Game.fps); } - else if (mode == 0) { - CM.Disp.WhiteScreen.style.display = 'none'; - } + else if (mode == 0) CM.Disp.WhiteScreen.style.display = 'none'; } +/** + * This function plays a sound depending on configs. It is called by all functions + * that check game-events and which have settings for sound (e.g., Golden Cookies appearing, Magic meter being full) + * @param {variable} url A variable that gives the url for the sound (e.g., CM.Config.GCSoundURL) + * @param {string} sndConfig The setting in CM.Config that is checked before creating the sound + * @param {string} volConfig The setting in CM.Config that is checked to determine volume + */ CM.Disp.PlaySound = function(url, sndConfig, volConfig) { if (CM.Config[sndConfig] == 1) { var sound = new realAudio(url); @@ -1030,10 +1044,17 @@ CM.Disp.PlaySound = function(url, sndConfig, volConfig) { } } +/** + * This function creates a notifcation depending on configs. It is called by all functions + * that check game-events and which have settings for notifications (e.g., Golden Cookies appearing, Magic meter being full) + * @param {string} notifyConfig The setting in CM.Config that is checked before creating the notification + * @param {string} title The title of the to-be created notifications + * @param {string} message The text of the to-be created notifications + */ CM.Disp.Notification = function(notifyConfig, title, message) { if (CM.Config[notifyConfig] == 1 && document.visibilityState == 'hidden') { var CookieIcon = 'https://orteil.dashnet.org/cookieclicker/favicon.ico' - var notification = new Notification(title, {body: message, badge: CookieIcon}); + notification = new Notification(title, {body: message, badge: CookieIcon}); } } From 06c7f59cd6d2c8d1e5d327ba0469f7e1a4f7bf2b Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Thu, 3 Dec 2020 13:05:22 +0100 Subject: [PATCH 008/106] Updated functions related to tab-bar --- CookieMonster.js | 58 ++++++++++++++++++++++-------------------------- src/Disp.js | 58 ++++++++++++++++++++++-------------------------- 2 files changed, 54 insertions(+), 62 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index a66ec70..1237255 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -1904,6 +1904,9 @@ CM.Disp.Notification = function(notifyConfig, title, message) { * Section: Functions related to updating the tab in the browser's tab-bar * TODO: Annotate functions */ +/** + * This function creates the Favicon, it is called by CM.DelayInit() + */ CM.Disp.CreateFavicon = function() { CM.Disp.Favicon = document.createElement('link'); CM.Disp.Favicon.id = 'CMFavicon'; @@ -1912,20 +1915,23 @@ CM.Disp.CreateFavicon = function() { document.getElementsByTagName('head')[0].appendChild(CM.Disp.Favicon); } +/** + * This function updates the Favicon depending on whether a Golden Cookie has spawned + * It is called on every loop by CM.Disp.CheckGoldenCookie() or by a change in CM.Config.Favicon + * By relying on CM.Disp.spawnedGoldenShimmer it only changes for non-user spawned cookie + */ CM.Disp.UpdateFavicon = function() { if (CM.Config.Favicon == 1) { - if (CM.Disp.spawnedGoldenShimmer.wrath) { - CM.Disp.Favicon.href = 'https://aktanusa.github.io/CookieMonster/favicon/wrathCookie.ico'; - } - else { - CM.Disp.Favicon.href = 'https://aktanusa.github.io/CookieMonster/favicon/goldenCookie.ico'; - } - } - else { - CM.Disp.Favicon.href = 'https://orteil.dashnet.org/cookieclicker/favicon.ico'; + if (CM.Disp.spawnedGoldenShimmer.wrath) CM.Disp.Favicon.href = 'https://aktanusa.github.io/CookieMonster/favicon/wrathCookie.ico'; + else CM.Disp.Favicon.href = 'https://aktanusa.github.io/CookieMonster/favicon/goldenCookie.ico'; } + else CM.Disp.Favicon.href = 'https://orteil.dashnet.org/cookieclicker/favicon.ico'; } +/** + * This function updates the tab title + * It is called on every loop by Game.Logic() which also sets CM.Cache.Title to Game.cookies + */ CM.Disp.UpdateTitle = function() { if (Game.OnAscend || CM.Config.Title == 0) { document.title = CM.Cache.Title; @@ -1933,56 +1939,46 @@ CM.Disp.UpdateTitle = function() { else if (CM.Config.Title == 1) { var addFC = false; var addSP = false; - var titleGC; var titleFC; var titleSP; - if (CM.Disp.lastGoldenCookieState) { - if (CM.Disp.spawnedGoldenShimmer.wrath) { - titleGC = '[W ' + Math.ceil(CM.Disp.spawnedGoldenShimmer.life / Game.fps) + ']'; - } - else { - titleGC = '[G ' + Math.ceil(CM.Disp.spawnedGoldenShimmer.life / Game.fps) + ']'; - } + + if (CM.Disp.spawnedGoldenShimmer) { + if (CM.Disp.spawnedGoldenShimmer.wrath) titleGC = '[W ' + Math.ceil(CM.Disp.spawnedGoldenShimmer.life / Game.fps) + ']'; + else titleGC = '[G ' + Math.ceil(CM.Disp.spawnedGoldenShimmer.life / Game.fps) + ']'; } else if (!Game.Has('Golden switch [off]')) { titleGC = '[' + Math.ceil((Game.shimmerTypes['golden'].maxTime - Game.shimmerTypes['golden'].time) / Game.fps) + ']'; } - else { - titleGC = '[GS]' - } + else titleGC = '[GS]' + if (CM.Disp.lastTickerFortuneState) { addFC = true; titleFC = '[F]'; } + if (Game.season == 'christmas') { addSP = true; - if (CM.Disp.lastSeasonPopupState) { - titleSP = '[R ' + Math.ceil(CM.Disp.seasonPopShimmer.life / Game.fps) + ']'; - } + if (CM.Disp.lastSeasonPopupState) titleSP = '[R ' + Math.ceil(CM.Disp.seasonPopShimmer.life / Game.fps) + ']'; else { titleSP = '[' + Math.ceil((Game.shimmerTypes['reindeer'].maxTime - Game.shimmerTypes['reindeer'].time) / Game.fps) + ']'; } } + // Remove previous timers and add current cookies var str = CM.Cache.Title; if (str.charAt(0) == '[') { str = str.substring(str.lastIndexOf(']') + 1); } - document.title = titleGC + (addFC ? titleFC : '') + (addSP ? titleSP : '') + ' ' + str; } else if (CM.Config.Title == 2) { var str = ''; var spawn = false; - if (CM.Disp.lastGoldenCookieState) { + if (CM.Disp.spawnedGoldenShimmer) { spawn = true; - if (CM.Disp.spawnedGoldenShimmer.wrath) { - str += '[W ' + Math.ceil(CM.Disp.spawnedGoldenShimmer.life / Game.fps) + ']'; - } - else { - str += '[G ' + Math.ceil(CM.Disp.spawnedGoldenShimmer.life / Game.fps) + ']'; - } + if (CM.Disp.spawnedGoldenShimmer.wrath) str += '[W ' + Math.ceil(CM.Disp.spawnedGoldenShimmer.life / Game.fps) + ']'; + else str += '[G ' + Math.ceil(CM.Disp.spawnedGoldenShimmer.life / Game.fps) + ']'; } if (CM.Disp.lastTickerFortuneState) { spawn = true; diff --git a/src/Disp.js b/src/Disp.js index e0d74ab..115e97c 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -1062,6 +1062,9 @@ CM.Disp.Notification = function(notifyConfig, title, message) { * Section: Functions related to updating the tab in the browser's tab-bar * TODO: Annotate functions */ +/** + * This function creates the Favicon, it is called by CM.DelayInit() + */ CM.Disp.CreateFavicon = function() { CM.Disp.Favicon = document.createElement('link'); CM.Disp.Favicon.id = 'CMFavicon'; @@ -1070,20 +1073,23 @@ CM.Disp.CreateFavicon = function() { document.getElementsByTagName('head')[0].appendChild(CM.Disp.Favicon); } +/** + * This function updates the Favicon depending on whether a Golden Cookie has spawned + * It is called on every loop by CM.Disp.CheckGoldenCookie() or by a change in CM.Config.Favicon + * By relying on CM.Disp.spawnedGoldenShimmer it only changes for non-user spawned cookie + */ CM.Disp.UpdateFavicon = function() { if (CM.Config.Favicon == 1) { - if (CM.Disp.spawnedGoldenShimmer.wrath) { - CM.Disp.Favicon.href = 'https://aktanusa.github.io/CookieMonster/favicon/wrathCookie.ico'; - } - else { - CM.Disp.Favicon.href = 'https://aktanusa.github.io/CookieMonster/favicon/goldenCookie.ico'; - } - } - else { - CM.Disp.Favicon.href = 'https://orteil.dashnet.org/cookieclicker/favicon.ico'; + if (CM.Disp.spawnedGoldenShimmer.wrath) CM.Disp.Favicon.href = 'https://aktanusa.github.io/CookieMonster/favicon/wrathCookie.ico'; + else CM.Disp.Favicon.href = 'https://aktanusa.github.io/CookieMonster/favicon/goldenCookie.ico'; } + else CM.Disp.Favicon.href = 'https://orteil.dashnet.org/cookieclicker/favicon.ico'; } +/** + * This function updates the tab title + * It is called on every loop by Game.Logic() which also sets CM.Cache.Title to Game.cookies + */ CM.Disp.UpdateTitle = function() { if (Game.OnAscend || CM.Config.Title == 0) { document.title = CM.Cache.Title; @@ -1091,56 +1097,46 @@ CM.Disp.UpdateTitle = function() { else if (CM.Config.Title == 1) { var addFC = false; var addSP = false; - var titleGC; var titleFC; var titleSP; - if (CM.Disp.lastGoldenCookieState) { - if (CM.Disp.spawnedGoldenShimmer.wrath) { - titleGC = '[W ' + Math.ceil(CM.Disp.spawnedGoldenShimmer.life / Game.fps) + ']'; - } - else { - titleGC = '[G ' + Math.ceil(CM.Disp.spawnedGoldenShimmer.life / Game.fps) + ']'; - } + + if (CM.Disp.spawnedGoldenShimmer) { + if (CM.Disp.spawnedGoldenShimmer.wrath) titleGC = '[W ' + Math.ceil(CM.Disp.spawnedGoldenShimmer.life / Game.fps) + ']'; + else titleGC = '[G ' + Math.ceil(CM.Disp.spawnedGoldenShimmer.life / Game.fps) + ']'; } else if (!Game.Has('Golden switch [off]')) { titleGC = '[' + Math.ceil((Game.shimmerTypes['golden'].maxTime - Game.shimmerTypes['golden'].time) / Game.fps) + ']'; } - else { - titleGC = '[GS]' - } + else titleGC = '[GS]' + if (CM.Disp.lastTickerFortuneState) { addFC = true; titleFC = '[F]'; } + if (Game.season == 'christmas') { addSP = true; - if (CM.Disp.lastSeasonPopupState) { - titleSP = '[R ' + Math.ceil(CM.Disp.seasonPopShimmer.life / Game.fps) + ']'; - } + if (CM.Disp.lastSeasonPopupState) titleSP = '[R ' + Math.ceil(CM.Disp.seasonPopShimmer.life / Game.fps) + ']'; else { titleSP = '[' + Math.ceil((Game.shimmerTypes['reindeer'].maxTime - Game.shimmerTypes['reindeer'].time) / Game.fps) + ']'; } } + // Remove previous timers and add current cookies var str = CM.Cache.Title; if (str.charAt(0) == '[') { str = str.substring(str.lastIndexOf(']') + 1); } - document.title = titleGC + (addFC ? titleFC : '') + (addSP ? titleSP : '') + ' ' + str; } else if (CM.Config.Title == 2) { var str = ''; var spawn = false; - if (CM.Disp.lastGoldenCookieState) { + if (CM.Disp.spawnedGoldenShimmer) { spawn = true; - if (CM.Disp.spawnedGoldenShimmer.wrath) { - str += '[W ' + Math.ceil(CM.Disp.spawnedGoldenShimmer.life / Game.fps) + ']'; - } - else { - str += '[G ' + Math.ceil(CM.Disp.spawnedGoldenShimmer.life / Game.fps) + ']'; - } + if (CM.Disp.spawnedGoldenShimmer.wrath) str += '[W ' + Math.ceil(CM.Disp.spawnedGoldenShimmer.life / Game.fps) + ']'; + else str += '[G ' + Math.ceil(CM.Disp.spawnedGoldenShimmer.life / Game.fps) + ']'; } if (CM.Disp.lastTickerFortuneState) { spawn = true; From 44f75247cda08d0ed9c76cda418c2ce0cecb387f Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Thu, 3 Dec 2020 13:05:43 +0100 Subject: [PATCH 009/106] Updated functions related to tab-bar v2 --- CookieMonster.js | 1 - src/Disp.js | 1 - 2 files changed, 2 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index 1237255..ae420b7 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -1902,7 +1902,6 @@ CM.Disp.Notification = function(notifyConfig, title, message) { /******** * Section: Functions related to updating the tab in the browser's tab-bar - * TODO: Annotate functions */ /** * This function creates the Favicon, it is called by CM.DelayInit() diff --git a/src/Disp.js b/src/Disp.js index 115e97c..34d4ca2 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -1060,7 +1060,6 @@ CM.Disp.Notification = function(notifyConfig, title, message) { /******** * Section: Functions related to updating the tab in the browser's tab-bar - * TODO: Annotate functions */ /** * This function creates the Favicon, it is called by CM.DelayInit() From 5b9d171bf4b66e1095bc35034cf921b92e4c7255 Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Thu, 3 Dec 2020 13:23:36 +0100 Subject: [PATCH 010/106] Updated CM.Disp.GetTimeColor --- CookieMonster.js | 57 ++++++++++++++++-------------------------------- src/Disp.js | 57 ++++++++++++++++-------------------------------- 2 files changed, 38 insertions(+), 76 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index ae420b7..104836e 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -849,39 +849,6 @@ CM.Data.ValCookies = ['Pure heart biscuits', 'Ardent heart biscuits', 'Sour hear * TODO: Annotate most functions * TODO: Sort functionsn in relevant (new) sections or files */ -CM.Disp.GetTimeColor = function(price, bank, cps, time) { - var color; - var text; - if (bank >= price) { - color = CM.Disp.colorGreen; - if (CM.Config.TimeFormat) { - text = '00:00:00:00:00'; - } - else { - text = 'Done!'; - } - } - else { - if (typeof time !== 'undefined') { - var time = time; - } - else { - var time = (price - bank) / cps; - } - text = CM.Disp.FormatTime(time); - if (time > 300) { - color = CM.Disp.colorRed; - } - else if (time > 60) { - color = CM.Disp.colorOrange; - } - else { - color = CM.Disp.colorYellow; - } - } - return {text: text, color: color}; -} - /** * This function returns Name and Color as object for sugar lump type that is given as input param. * @param type Sugar Lump Type. @@ -1181,6 +1148,20 @@ CM.Disp.FormatTime = function(time, longFormat) { return str; } +/** + * This function returns returns the color to be used for time-strings + * @param {number} time Time to be coloured + * @returns {{string, string}} {text, color} Both the formatted time and color as strings in an array + */ +CM.Disp.GetTimeColor = function(time) { + var color; + var text = CM.Disp.FormatTime(time); + if (time > 300) color = CM.Disp.colorRed; + else if (time > 60) color = CM.Disp.colorOrange; + else color = CM.Disp.colorYellow; + return {text: text, color: color}; +} + /** * This function returns formats number based on the Scale setting * @param {number} num Number to be beautified @@ -1347,7 +1328,7 @@ CM.Disp.UpdateBotBar = function() { CM.Disp.BotBar.firstChild.firstChild.childNodes[1].childNodes[count].textContent = Beautify(CM.Cache[target][i].bonus, 2); CM.Disp.BotBar.firstChild.firstChild.childNodes[2].childNodes[count].className = CM.Disp.colorTextPre + CM.Cache[target][i].color; CM.Disp.BotBar.firstChild.firstChild.childNodes[2].childNodes[count].textContent = Beautify(CM.Cache[target][i].pp, 2); - var timeColor = CM.Disp.GetTimeColor(Game.Objects[i].bulkPrice, (Game.cookies + CM.Disp.GetWrinkConfigBank()), CM.Disp.GetCPS()); + var timeColor = CM.Disp.GetTimeColor((Game.Objects[i].bulkPrice - (Game.cookies + CM.Disp.GetWrinkConfigBank())) / CM.Disp.GetCPS()); CM.Disp.BotBar.firstChild.firstChild.childNodes[3].childNodes[count].className = CM.Disp.colorTextPre + timeColor.color; CM.Disp.BotBar.firstChild.firstChild.childNodes[3].childNodes[count].textContent = timeColor.text; } @@ -2311,7 +2292,7 @@ CM.Disp.Tooltip = function(type, name) { if (amortizeAmount > 0) { l('tooltip').innerHTML = l('tooltip').innerHTML .split('so far') - .join('so far
' + Beautify(amortizeAmount) + ' ' + (Math.floor(amortizeAmount) == 1 ? 'cookie' : 'cookies') + ' left to amortize (' + CM.Disp.GetTimeColor(buildPrice, Game.Objects[name].totalCookies, (Game.Objects[name].storedTotalCps * Game.globalCpsMult)).text + ')'); + .join('so far
' + Beautify(amortizeAmount) + ' ' + (Math.floor(amortizeAmount) == 1 ? 'cookie' : 'cookies') + ' left to amortize (' + CM.Disp.GetTimeColor((buildPrice - Game.Objects[name].totalCookies) / (Game.Objects[name].storedTotalCps * Game.globalCpsMult)).text + ')'); } } if (Game.buyMode == 1) { @@ -2475,7 +2456,7 @@ CM.Disp.UpdateTooltip = function() { l('CMTooltipIncome').textContent += ' (' + (increase / 100) + '% of income)'; } - var timeColor = CM.Disp.GetTimeColor(price, (Game.cookies + CM.Disp.GetWrinkConfigBank()), CM.Disp.GetCPS()); + var timeColor = CM.Disp.GetTimeColor((price - (Game.cookies + CM.Disp.GetWrinkConfigBank())) / CM.Disp.GetCPS()); l('CMTooltipTime').textContent = timeColor.text; l('CMTooltipTime').className = CM.Disp.colorTextPre + timeColor.color; } @@ -2609,7 +2590,7 @@ CM.Disp.UpdateTooltip = function() { var time = document.createElement('div'); time.id = 'CMTooltipTime'; tooltip.appendChild(time); - var timeColor = CM.Disp.GetTimeColor(spellCost, minigame.magic, undefined, CM.Disp.CalculateGrimoireRefillTime(minigame.magic, minigame.magicM, spellCost)); + var timeColor = CM.Disp.GetTimeColor(CM.Disp.CalculateGrimoireRefillTime(minigame.magic, minigame.magicM, spellCost)); time.textContent = timeColor.text; time.className = CM.Disp.colorTextPre + timeColor.color; @@ -2618,7 +2599,7 @@ CM.Disp.UpdateTooltip = function() { var recover = document.createElement('div'); recover.id = 'CMTooltipRecover'; tooltip.appendChild(recover); - var recoverColor = CM.Disp.GetTimeColor(minigame.magic, Math.max(0, minigame.magic - spellCost), undefined, CM.Disp.CalculateGrimoireRefillTime(Math.max(0, minigame.magic - spellCost), minigame.magicM, minigame.magic)); + var recoverColor = CM.Disp.GetTimeColor(CM.Disp.CalculateGrimoireRefillTime(Math.max(0, minigame.magic - spellCost), minigame.magicM, minigame.magic)); recover.textContent = recoverColor.text; recover.className = CM.Disp.colorTextPre + recoverColor.color; } diff --git a/src/Disp.js b/src/Disp.js index 34d4ca2..bd414f9 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -7,39 +7,6 @@ * TODO: Annotate most functions * TODO: Sort functionsn in relevant (new) sections or files */ -CM.Disp.GetTimeColor = function(price, bank, cps, time) { - var color; - var text; - if (bank >= price) { - color = CM.Disp.colorGreen; - if (CM.Config.TimeFormat) { - text = '00:00:00:00:00'; - } - else { - text = 'Done!'; - } - } - else { - if (typeof time !== 'undefined') { - var time = time; - } - else { - var time = (price - bank) / cps; - } - text = CM.Disp.FormatTime(time); - if (time > 300) { - color = CM.Disp.colorRed; - } - else if (time > 60) { - color = CM.Disp.colorOrange; - } - else { - color = CM.Disp.colorYellow; - } - } - return {text: text, color: color}; -} - /** * This function returns Name and Color as object for sugar lump type that is given as input param. * @param type Sugar Lump Type. @@ -339,6 +306,20 @@ CM.Disp.FormatTime = function(time, longFormat) { return str; } +/** + * This function returns returns the color to be used for time-strings + * @param {number} time Time to be coloured + * @returns {{string, string}} {text, color} Both the formatted time and color as strings in an array + */ +CM.Disp.GetTimeColor = function(time) { + var color; + var text = CM.Disp.FormatTime(time); + if (time > 300) color = CM.Disp.colorRed; + else if (time > 60) color = CM.Disp.colorOrange; + else color = CM.Disp.colorYellow; + return {text: text, color: color}; +} + /** * This function returns formats number based on the Scale setting * @param {number} num Number to be beautified @@ -505,7 +486,7 @@ CM.Disp.UpdateBotBar = function() { CM.Disp.BotBar.firstChild.firstChild.childNodes[1].childNodes[count].textContent = Beautify(CM.Cache[target][i].bonus, 2); CM.Disp.BotBar.firstChild.firstChild.childNodes[2].childNodes[count].className = CM.Disp.colorTextPre + CM.Cache[target][i].color; CM.Disp.BotBar.firstChild.firstChild.childNodes[2].childNodes[count].textContent = Beautify(CM.Cache[target][i].pp, 2); - var timeColor = CM.Disp.GetTimeColor(Game.Objects[i].bulkPrice, (Game.cookies + CM.Disp.GetWrinkConfigBank()), CM.Disp.GetCPS()); + var timeColor = CM.Disp.GetTimeColor((Game.Objects[i].bulkPrice - (Game.cookies + CM.Disp.GetWrinkConfigBank())) / CM.Disp.GetCPS()); CM.Disp.BotBar.firstChild.firstChild.childNodes[3].childNodes[count].className = CM.Disp.colorTextPre + timeColor.color; CM.Disp.BotBar.firstChild.firstChild.childNodes[3].childNodes[count].textContent = timeColor.text; } @@ -1469,7 +1450,7 @@ CM.Disp.Tooltip = function(type, name) { if (amortizeAmount > 0) { l('tooltip').innerHTML = l('tooltip').innerHTML .split('so far') - .join('so far
' + Beautify(amortizeAmount) + ' ' + (Math.floor(amortizeAmount) == 1 ? 'cookie' : 'cookies') + ' left to amortize (' + CM.Disp.GetTimeColor(buildPrice, Game.Objects[name].totalCookies, (Game.Objects[name].storedTotalCps * Game.globalCpsMult)).text + ')'); + .join('so far
' + Beautify(amortizeAmount) + ' ' + (Math.floor(amortizeAmount) == 1 ? 'cookie' : 'cookies') + ' left to amortize (' + CM.Disp.GetTimeColor((buildPrice - Game.Objects[name].totalCookies) / (Game.Objects[name].storedTotalCps * Game.globalCpsMult)).text + ')'); } } if (Game.buyMode == 1) { @@ -1633,7 +1614,7 @@ CM.Disp.UpdateTooltip = function() { l('CMTooltipIncome').textContent += ' (' + (increase / 100) + '% of income)'; } - var timeColor = CM.Disp.GetTimeColor(price, (Game.cookies + CM.Disp.GetWrinkConfigBank()), CM.Disp.GetCPS()); + var timeColor = CM.Disp.GetTimeColor((price - (Game.cookies + CM.Disp.GetWrinkConfigBank())) / CM.Disp.GetCPS()); l('CMTooltipTime').textContent = timeColor.text; l('CMTooltipTime').className = CM.Disp.colorTextPre + timeColor.color; } @@ -1767,7 +1748,7 @@ CM.Disp.UpdateTooltip = function() { var time = document.createElement('div'); time.id = 'CMTooltipTime'; tooltip.appendChild(time); - var timeColor = CM.Disp.GetTimeColor(spellCost, minigame.magic, undefined, CM.Disp.CalculateGrimoireRefillTime(minigame.magic, minigame.magicM, spellCost)); + var timeColor = CM.Disp.GetTimeColor(CM.Disp.CalculateGrimoireRefillTime(minigame.magic, minigame.magicM, spellCost)); time.textContent = timeColor.text; time.className = CM.Disp.colorTextPre + timeColor.color; @@ -1776,7 +1757,7 @@ CM.Disp.UpdateTooltip = function() { var recover = document.createElement('div'); recover.id = 'CMTooltipRecover'; tooltip.appendChild(recover); - var recoverColor = CM.Disp.GetTimeColor(minigame.magic, Math.max(0, minigame.magic - spellCost), undefined, CM.Disp.CalculateGrimoireRefillTime(Math.max(0, minigame.magic - spellCost), minigame.magicM, minigame.magic)); + var recoverColor = CM.Disp.GetTimeColor(CM.Disp.CalculateGrimoireRefillTime(Math.max(0, minigame.magic - spellCost), minigame.magicM, minigame.magic)); recover.textContent = recoverColor.text; recover.className = CM.Disp.colorTextPre + recoverColor.color; } From 9cad31da3e4fdd9974a09c5e9677714ff2b4e574 Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Thu, 3 Dec 2020 13:24:34 +0100 Subject: [PATCH 011/106] Updated CM.Disp.GetTimeColor v2 --- CookieMonster.js | 2 +- src/Disp.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index 104836e..e908d08 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -1149,7 +1149,7 @@ CM.Disp.FormatTime = function(time, longFormat) { } /** - * This function returns returns the color to be used for time-strings + * This function returns the color to be used for time-strings * @param {number} time Time to be coloured * @returns {{string, string}} {text, color} Both the formatted time and color as strings in an array */ diff --git a/src/Disp.js b/src/Disp.js index bd414f9..9fa5c00 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -307,7 +307,7 @@ CM.Disp.FormatTime = function(time, longFormat) { } /** - * This function returns returns the color to be used for time-strings + * This function returns the color to be used for time-strings * @param {number} time Time to be coloured * @returns {{string, string}} {text, color} Both the formatted time and color as strings in an array */ From 63c3a493fa2dd50175ad728563feba5f0d901f24 Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Thu, 3 Dec 2020 15:23:12 +0100 Subject: [PATCH 012/106] Rewrote the code and data for the options-page --- CookieMonster.js | 474 ++++++++++++++++++++++------------------------- src/Config.js | 115 +----------- src/Data.js | 138 ++++++++++++++ src/Disp.js | 219 ++++++++-------------- src/Main.js | 2 +- 5 files changed, 447 insertions(+), 501 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index e908d08..92dc614 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -603,7 +603,7 @@ CM.LoadConfig = function() { if (mod) CM.SaveConfig(CM.Config); CM.Loop(); // Do loop once for (var i in CM.ConfigDefault) { - if (i != 'StatsPref' && i != 'MenuPref' && typeof CM.ConfigData[i].func !== 'undefined') { + if (i != 'StatsPref' && i != 'OptionsPref' && typeof CM.ConfigData[i].func !== 'undefined') { CM.ConfigData[i].func(); } } @@ -666,12 +666,12 @@ CM.ToggleStatsConfig = function(config) { CM.SaveConfig(CM.Config); } -CM.ToggleMenuConfig = function(config) { - if (CM.Config.MenuPref[config] == 0) { - CM.Config.MenuPref[config]++; +CM.ToggleOptionsConfig = function(config) { + if (CM.Config.OptionsPref[config] == 0) { + CM.Config.OptionsPref[config]++; } else { - CM.Config.MenuPref[config]--; + CM.Config.OptionsPref[config]--; } CM.SaveConfig(CM.Config); } @@ -703,111 +703,7 @@ CM.CheckNotificationPermissions = function(ToggleOnOff) { } } } -} - -CM.ConfigData.BotBar = {label: ['Bottom Bar OFF', 'Bottom Bar ON'], desc: 'Building Information', toggle: true, func: function() {CM.Disp.ToggleBotBar();}}; -CM.ConfigData.TimerBar = {label: ['Timer Bar OFF', 'Timer Bar ON'], desc: 'Timers of Golden Cookie, Season Popup, Frenzy (Normal, Clot, Elder), Click Frenzy', toggle: true, func: function() {CM.Disp.ToggleTimerBar();}}; -CM.ConfigData.TimerBarPos = {label: ['Timer Bar Position (Top Left)', 'Timer Bar Position (Bottom)'], desc: 'Placement of the Timer Bar', toggle: false, func: function() {CM.Disp.ToggleTimerBarPos();}}; -CM.ConfigData.BuildColor = {label: ['Building Colors OFF', 'Building Colors ON'], desc: 'Color code buildings', toggle: true, func: function() {CM.Disp.UpdateBuildings();}}; -CM.ConfigData.BulkBuildColor = {label: ['Bulk Building Colors (Single Building Color)', 'Bulk Building Colors (Calculated Bulk Color)'], desc: 'Color code bulk buildings based on single buildings color or calculated bulk value color', toggle: false, func: function() {CM.Disp.UpdateBuildings();}}; -CM.ConfigData.ColorPPBulkMode = {label: ['Color of PP (Compared to Single)', 'Color of PP (Compared to Bulk)'], desc: 'Color PP-values based on comparison with single purchase or with selected bulk-buy mode', toggle: false}; -CM.ConfigData.UpBarColor = {label: ['Upgrade Colors/Bar OFF', 'Upgrade Colors with Bar ON', 'Upgrade Colors without Bar ON'], desc: 'Color code upgrades and optionally add a counter bar', toggle: false, func: function() {CM.Disp.ToggleUpgradeBarAndColor();}}; -CM.ConfigData.Colors = { - desc: { - Blue: 'Color Blue. Used to show better than best PP building, for Click Frenzy bar, and for various labels', - Green: 'Color Green. Used to show best PP building, for Blood Frenzy bar, and for various labels', - Yellow: 'Color Yellow. Used to show between best and worst PP buildings closer to best, for Frenzy bar, and for various labels', - Orange: 'Color Orange. Used to show between best and worst PP buildings closer to worst, for Next Reindeer bar, and for various labels', - Red: 'Color Red. Used to show worst PP building, for Clot bar, and for various labels', - Purple: 'Color Purple. Used to show worse than worst PP building, for Next Cookie bar, and for various labels', - Gray: 'Color Gray. Used to show negative or infinity PP, and for Next Cookie/Next Reindeer bar', - Pink: 'Color Pink. Used for Dragonflight bar', - Brown: 'Color Brown. Used for Dragon Harvest bar' - }, - func: function() {CM.Disp.UpdateColors();} -}; -CM.ConfigData.UpgradeBarFixedPos = {label: ['Upgrade Bar Fixed Position OFF', 'Upgrade Bar Fixed Position ON'], desc: 'Lock the upgrade bar at top of the screen to prevent it from moving ofscreen when scrolling', toggle: true, func: function() {CM.Disp.ToggleUpgradeBarFixedPos();}}; -CM.ConfigData.CalcWrink = {label: ['Calculate with Wrinklers OFF', 'Calculate with Wrinklers ON'], desc: 'Calculate times and average Cookies Per Second with Wrinklers', toggle: true}; -CM.ConfigData.CPSMode = {label: ['Current Cookies Per Second', 'Average Cookies Per Second'], desc: 'Calculate times using current Cookies Per Second or average Cookies Per Second', toggle: false}; -CM.ConfigData.AvgCPSHist = {label: ['Average CPS for past 10s', 'Average CPS for past 15s', 'Average CPS for past 30s', 'Average CPS for past 1m', 'Average CPS for past 5m', 'Average CPS for past 10m', 'Average CPS for past 15m', 'Average CPS for past 30m'], desc: 'How much time average Cookies Per Second should consider', toggle: false}; -CM.ConfigData.AvgClicksHist = {label: ['Average Cookie Clicks for past 1s', 'Average Cookie Clicks for past 5s', 'Average Cookie Clicks for past 10s', 'Average Cookie Clicks for past 15s', 'Average Cookie Clicks for past 30s'], desc: 'How much time average Cookie Clicks should consider', toggle: false}; -CM.ConfigData.ToolWarnBon = {label: ['Calculate Tooltip Warning With Bonus CPS OFF', 'Calculate Tooltip Warning With Bonus CPS ON'], desc: 'Calculate the warning with or without the bonus CPS you get from buying', toggle: true}; -CM.ConfigData.GCNotification = {label: ['Golden Cookie Notification OFF', 'Golden Cookie Notification ON'], desc: 'Create a notification when Golden Cookie spawns', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Config.GCNotification);}}; -CM.ConfigData.GCFlash = {label: ['Golden Cookie Flash OFF', 'Golden Cookie Flash ON'], desc: 'Flash screen on Golden Cookie', toggle: true}; -CM.ConfigData.GCSound = {label: ['Golden Cookie Sound OFF', 'Golden Cookie Sound ON'], desc: 'Play a sound on Golden Cookie', toggle: true}; -CM.ConfigData.GCVolume = {label: [], desc: 'Volume of the Golden Cookie sound'}; -for (var i = 0; i < 101; i++) { - CM.ConfigData.GCVolume.label[i] = i + '%'; -} -CM.ConfigData.GCSoundURL = {label: 'Golden Cookie Sound URL:', desc: 'URL of the sound to be played when a Golden Cookie spawns'}; -CM.ConfigData.GCTimer = {label: ['Golden Cookie Timer OFF', 'Golden Cookie Timer ON'], desc: 'A timer on the Golden Cookie when it has been spawned', toggle: true, func: function() {CM.Disp.ToggleGCTimer();}}; -CM.ConfigData.Favicon = {label: ['Favicon OFF', 'Favicon ON'], desc: 'Update favicon with Golden/Wrath Cookie', toggle: true, func: function() {CM.Disp.UpdateFavicon();}}; -CM.ConfigData.FortuneNotification = {label: ['Fortune Cookie Notification OFF', 'Fortune Cookie Notification ON'], desc: 'Create a notification when Fortune Cookie is on the Ticker', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Config.FortuneNotification);}}; -CM.ConfigData.FortuneFlash = {label: ['Fortune Cookie Flash OFF', 'Fortune Cookie Flash ON'], desc: 'Flash screen on Fortune Cookie', toggle: true}; -CM.ConfigData.FortuneSound = {label: ['Fortune Cookie Sound OFF', 'Fortune Cookie Sound ON'], desc: 'Play a sound on Fortune Cookie', toggle: true}; -CM.ConfigData.FortuneVolume = {label: [], desc: 'Volume of the Fortune Cookie sound'}; -for (var i = 0; i < 101; i++) { - CM.ConfigData.FortuneVolume.label[i] = i + '%'; -} -CM.ConfigData.FortuneSoundURL = {label: 'Fortune Cookie Sound URL:', desc: 'URL of the sound to be played when the Ticker has a Fortune Cookie'}; -CM.ConfigData.SeaNotification = {label: ['Season Special Notification OFF', 'Season Special Notification ON'], desc: 'Create a notification on Season Popup', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Config.SeaNotification);}}; -CM.ConfigData.SeaFlash = {label: ['Season Special Flash OFF', 'Season Special Flash ON'], desc: 'Flash screen on Season Popup', toggle: true}; -CM.ConfigData.SeaSound = {label: ['Season Special Sound OFF', 'Season Special Sound ON'], desc: 'Play a sound on Season Popup', toggle: true}; -CM.ConfigData.SeaVolume = {label: [], desc: 'Volume of the Season Special sound'}; -for (var i = 0; i < 101; i++) { - CM.ConfigData.SeaVolume.label[i] = i + '%'; -} -CM.ConfigData.SeaSoundURL = {label: 'Season Special Sound URL:', desc: 'URL of the sound to be played when a Season Special spawns'}; -CM.ConfigData.GardFlash = {label: ['Garden Tick Flash OFF', 'Garden Tick Flash ON'], desc: 'Flash screen on Garden Tick', toggle: true}; -CM.ConfigData.GardSound = {label: ['Garden Tick Sound OFF', 'Garden Tick Sound ON'], desc: 'Play a sound on Garden Tick', toggle: true}; -CM.ConfigData.GardVolume = {label: [], desc: 'Volume of the Garden Tick sound'}; -for (var i = 0; i < 101; i++) { - CM.ConfigData.GardVolume.label[i] = i + '%'; -} -CM.ConfigData.GardSoundURL = {label: 'Garden Tick Sound URL:', desc: 'URL of the sound to be played when the garden ticks'}; -CM.ConfigData.MagicNotification = {label: ['Magic Max Notification OFF', 'Magic Max Notification ON'], desc: 'Create a notification when magic reaches maximum', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Config.MagicNotification);}}; -CM.ConfigData.MagicFlash = {label: ['Magic Max Flash OFF', 'Magic Max Flash ON'], desc: 'Flash screen when magic reaches maximum', toggle: true}; -CM.ConfigData.MagicSound = {label: ['Magic Max Sound OFF', 'Magic Max Sound ON'], desc: 'Play a sound when magic reaches maximum', toggle: true}; -CM.ConfigData.MagicVolume = {label: [], desc: 'Volume of the Max Magic sound'}; -for (var i = 0; i < 101; i++) { - CM.ConfigData.MagicVolume.label[i] = i + '%'; -} -CM.ConfigData.MagicSoundURL = {label: 'Magic Max Sound URL:', desc: 'URL of the sound to be played when magic reaches maxium'}; -CM.ConfigData.WrinklerNotification = {label: ['Wrinkler Notification OFF', 'Wrinkler Notification ON'], desc: 'Create a notification when a Wrinkler appears', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Config.WrinklerNotification);}}; -CM.ConfigData.WrinklerFlash = {label: ['Wrinkler Flash OFF', 'Wrinkler Flash ON'], desc: 'Flash screen when a Wrinkler appears', toggle: true}; -CM.ConfigData.WrinklerSound = {label: ['Wrinkler Sound OFF', 'Wrinkler Sound ON'], desc: 'Play a sound when a Wrinkler appears', toggle: true}; -CM.ConfigData.WrinklerVolume = {label: [], desc: 'Volume of the Wrinkler sound'}; -for (var i = 0; i < 101; i++) { - CM.ConfigData.WrinklerVolume.label[i] = i + '%'; -} -CM.ConfigData.WrinklerSoundURL = {label: 'Wrinkler Sound URL:', desc: 'URL of the sound to be played when a Wrinkler appears'}; -CM.ConfigData.WrinklerMaxNotification = {label: ['Wrinkler Max Notification OFF', 'Wrinkler Max Notification ON'], desc: 'Create a notification when the maximum amount of Wrinklers has appeared', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Config.WrinklerMaxNotification);}}; -CM.ConfigData.WrinklerMaxFlash = {label: ['Wrinkler Max Flash OFF', 'Wrinkler Max Flash ON'], desc: 'Flash screen when the maximum amount of Wrinklers has appeared', toggle: true}; -CM.ConfigData.WrinklerMaxSound = {label: ['Wrinkler Max Sound OFF', 'Wrinkler Max Sound ON'], desc: 'Play a sound when the maximum amount of Wrinklers has appeared', toggle: true}; -CM.ConfigData.WrinklerMaxVolume = {label: [], desc: 'Volume of the Wrinkler Max sound'}; -for (var i = 0; i < 101; i++) { - CM.ConfigData.WrinklerMaxVolume.label[i] = i + '%'; -} -CM.ConfigData.WrinklerMaxSoundURL = {label: 'Wrinkler Max Sound URL:', desc: 'URL of the sound to be played when the maximum amount of Wrinklers has appeared'}; -CM.ConfigData.Title = {label: ['Title OFF', 'Title ON', 'Title Pinned Tab Highlight'], desc: 'Update title with Golden Cookie/Season Popup timers; pinned tab highlight only changes the title when a Golden Cookie/Season Popup spawns', toggle: true}; -CM.ConfigData.TooltipBuildUp = {label: ['Buildings/Upgrades Tooltip Information OFF', 'Buildings/Upgrades Tooltip Information ON'], desc: 'Extra information in tooltip for buildings/upgrades', toggle: true}; -CM.ConfigData.TooltipAmor = {label: ['Buildings Tooltip Amortization Information OFF', 'Buildings Tooltip Amortization Information ON'], desc: 'Add amortization information to buildings tooltip', toggle: true}; -CM.ConfigData.ToolWarnLucky = {label: ['Tooltip Lucky Warning OFF', 'Tooltip Lucky Warning ON'], desc: 'A warning when buying if it will put the bank under the amount needed for max "Lucky!"/"Lucky!" (Frenzy) rewards', toggle: true}; -CM.ConfigData.ToolWarnConjure = {label: ['Tooltip Conjure Warning OFF', 'Tooltip Conjure Warning ON'], desc: 'A warning when buying if it will put the bank under the amount needed for max "Conjure Baked Goods" rewards', toggle: true}; -CM.ConfigData.ToolWarnPos = {label: ['Tooltip Warning Position (Left)', 'Tooltip Warning Position (Bottom)'], desc: 'Placement of the warning boxes', toggle: false, func: function() {CM.Disp.ToggleToolWarnPos();}}; -CM.ConfigData.TooltipGrim = {label: ['Grimoire Tooltip Information OFF', 'Grimoire Tooltip Information ON'], desc: 'Extra information in tooltip for grimoire', toggle: true}; -CM.ConfigData.ToolWrink = {label: ['Wrinkler Tooltip OFF', 'Wrinkler Tooltip ON'], desc: 'Shows the amount of cookies a wrinkler will give when popping it', toggle: true}; -CM.ConfigData.TooltipLump = {label: ['Sugar Lump Tooltip OFF', 'Sugar Lump Tooltip ON'], desc: 'Shows the current Sugar Lump type in Sugar lump tooltip.', toggle: true}; -CM.ConfigData.Stats = {label: ['Statistics OFF', 'Statistics ON'], desc: 'Extra Cookie Monster statistics!', toggle: true}; -CM.ConfigData.MissingUpgrades = {label: ['Missing Upgrades OFF', 'Missing Upgrades ON'], desc: 'Shows Missing upgrades in Stats Menu. This feature can be laggy for users with a low amount of unlocked achievements.', toggle: true}; -CM.ConfigData.UpStats = {label: ['Statistics Update Rate (Default)', 'Statistics Update Rate (1s)'], desc: 'Default Game rate is once every 5 seconds', toggle: false}; -CM.ConfigData.TimeFormat = {label: ['Time XXd, XXh, XXm, XXs', 'Time XX:XX:XX:XX:XX'], desc: 'Change the time format', toggle: false}; -CM.ConfigData.SayTime = {label: ['Format Time OFF', 'Format Time ON'], desc: 'Change how time is displayed in statistics', toggle: true, func: function() {CM.Disp.ToggleSayTime();}}; -CM.ConfigData.GrimoireBar = {label: ['Grimoire Magic Meter Timer OFF', 'Grimoire Magic Meter Timer ON'], desc: 'A timer on how long before the Grimoire magic meter is full', toggle: true}; -CM.ConfigData.Scale = {label: ['Game\'s Setting Scale', 'Metric', 'Short Scale', 'Scientific Notation', 'Engineering Notation'], desc: 'Change how long numbers are handled', toggle: false, func: function() {CM.Disp.RefreshScale();}}; -CM.ConfigData.SortBuildings = {label: ['Sort Buildings: Default', 'Sort Buildings: PP'], desc: 'Sort the display of buildings in either default order or by PP', toggle: false, func: function () { CM.Disp.UpdateBuildings();}}; -CM.ConfigData.SortUpgrades = {label: ['Sort Upgrades: Default', 'Sort Upgrades: PP'], desc: 'Sort the display of upgrades in either default order or by PP', toggle: false, func: function () { CM.Disp.UpdateUpgrades();}}; -/******** +}/******** * Data * ********/ @@ -840,7 +736,144 @@ CM.Data.HalloCookies = ['Skull cookies', 'Ghost cookies', 'Bat cookies', 'Slime CM.Data.ChristCookies = ['Christmas tree biscuits', 'Snowflake biscuits', 'Snowman biscuits', 'Holly biscuits', 'Candy cane biscuits', 'Bell biscuits', 'Present biscuits']; CM.Data.ValCookies = ['Pure heart biscuits', 'Ardent heart biscuits', 'Sour heart biscuits', 'Weeping heart biscuits', 'Golden heart biscuits', 'Eternal heart biscuits', 'Prism heart biscuits']; + + /******** + * Section: An array containing all Config groups and their to-be displayed title */ + +CM.ConfigGroups = { + BarsColors: "Bars/Colors", + Calculation: "Calculation", + Notification: "Notification", + Tooltip: "Tooltips", + Statistics: "Statitics", + Other: "Other"}, + +/******** + * Section: An array (CM.ConfigData) containing all Config options + * + * Each array has the following items + * @item {string} type The type of option (bool(ean), vol(ume), url or color) + * @item {string} group The options-group the option belongs to + * @item {[string, ...]} label A list of the various configurations of the option + * @item {string} desc Description to be used in options menu + * @item {boolean} toggle Whether it should be displayed as a grey/white toggle in the options menu + * @item {function} func A function to be called when the option is toggled + */ + +// Barscolors +CM.ConfigData.BotBar = {type: 'bool', group: 'BarsColors', label: ['Bottom Bar OFF', 'Bottom Bar ON'], desc: 'Building Information', toggle: true, func: function() {CM.Disp.ToggleBotBar();}}; +CM.ConfigData.TimerBar = {type: 'bool', group: 'BarsColors', label: ['Timer Bar OFF', 'Timer Bar ON'], desc: 'Timers of Golden Cookie, Season Popup, Frenzy (Normal, Clot, Elder), Click Frenzy', toggle: true, func: function() {CM.Disp.ToggleTimerBar();}}; +CM.ConfigData.TimerBarPos = {type: 'bool', group: 'BarsColors', label: ['Timer Bar Position (Top Left)', 'Timer Bar Position (Bottom)'], desc: 'Placement of the Timer Bar', toggle: false, func: function() {CM.Disp.ToggleTimerBarPos();}}; +CM.ConfigData.SortBuildings = {type: 'bool', group: 'BarsColors', label: ['Sort Buildings: Default', 'Sort Buildings: PP'], desc: 'Sort the display of buildings in either default order or by PP', toggle: false, func: function () { CM.Disp.UpdateBuildings();}}; +CM.ConfigData.SortUpgrades = {type: 'bool', group: 'BarsColors', label: ['Sort Upgrades: Default', 'Sort Upgrades: PP'], desc: 'Sort the display of upgrades in either default order or by PP', toggle: false, func: function () { CM.Disp.UpdateUpgrades();}}; +CM.ConfigData.BuildColor = {type: 'bool', group: 'BarsColors', label: ['Building Colors OFF', 'Building Colors ON'], desc: 'Color code buildings', toggle: true, func: function() {CM.Disp.UpdateBuildings();}}; +CM.ConfigData.BulkBuildColor = {type: 'bool', group: 'BarsColors', label: ['Bulk Building Colors (Single Building Color)', 'Bulk Building Colors (Calculated Bulk Color)'], desc: 'Color code bulk buildings based on single buildings color or calculated bulk value color', toggle: false, func: function() {CM.Disp.UpdateBuildings();}}; +CM.ConfigData.ColorPPBulkMode = {type: 'bool', group: 'BarsColors', label: ['Color of PP (Compared to Single)', 'Color of PP (Compared to Bulk)'], desc: 'Color PP-values based on comparison with single purchase or with selected bulk-buy mode', toggle: false}; +CM.ConfigData.UpBarColor = {type: 'bool', group: 'BarsColors', label: ['Upgrade Colors/Bar OFF', 'Upgrade Colors with Bar ON', 'Upgrade Colors without Bar ON'], desc: 'Color code upgrades and optionally add a counter bar', toggle: false, func: function() {CM.Disp.ToggleUpgradeBarAndColor();}}; +CM.ConfigData.Colors = { type: 'color', group: 'BarsColors', + desc: { + Blue: 'Color Blue. Used to show better than best PP building, for Click Frenzy bar, and for various labels', + Green: 'Color Green. Used to show best PP building, for Blood Frenzy bar, and for various labels', + Yellow: 'Color Yellow. Used to show between best and worst PP buildings closer to best, for Frenzy bar, and for various labels', + Orange: 'Color Orange. Used to show between best and worst PP buildings closer to worst, for Next Reindeer bar, and for various labels', + Red: 'Color Red. Used to show worst PP building, for Clot bar, and for various labels', + Purple: 'Color Purple. Used to show worse than worst PP building, for Next Cookie bar, and for various labels', + Gray: 'Color Gray. Used to show negative or infinity PP, and for Next Cookie/Next Reindeer bar', + Pink: 'Color Pink. Used for Dragonflight bar', + Brown: 'Color Brown. Used for Dragon Harvest bar' + }, + func: function() {CM.Disp.UpdateColors();} +}; +CM.ConfigData.UpgradeBarFixedPos = {type: 'bool', group: 'BarsColors', label: ['Upgrade Bar Fixed Position OFF', 'Upgrade Bar Fixed Position ON'], desc: 'Lock the upgrade bar at top of the screen to prevent it from moving ofscreen when scrolling', toggle: true, func: function() {CM.Disp.ToggleUpgradeBarFixedPos();}}; + +// Calculation +CM.ConfigData.CalcWrink = {type: 'bool', group: 'Calculation', label: ['Calculate with Wrinklers OFF', 'Calculate with Wrinklers ON'], desc: 'Calculate times and average Cookies Per Second with Wrinklers', toggle: true}; +CM.ConfigData.CPSMode = {type: 'bool', group: 'Calculation', label: ['Current Cookies Per Second', 'Average Cookies Per Second'], desc: 'Calculate times using current Cookies Per Second or average Cookies Per Second', toggle: false}; +CM.ConfigData.AvgCPSHist = {type: 'bool', group: 'Calculation', label: ['Average CPS for past 10s', 'Average CPS for past 15s', 'Average CPS for past 30s', 'Average CPS for past 1m', 'Average CPS for past 5m', 'Average CPS for past 10m', 'Average CPS for past 15m', 'Average CPS for past 30m'], desc: 'How much time average Cookies Per Second should consider', toggle: false}; +CM.ConfigData.AvgClicksHist = {type: 'bool', group: 'Calculation', label: ['Average Cookie Clicks for past 1s', 'Average Cookie Clicks for past 5s', 'Average Cookie Clicks for past 10s', 'Average Cookie Clicks for past 15s', 'Average Cookie Clicks for past 30s'], desc: 'How much time average Cookie Clicks should consider', toggle: false}; +CM.ConfigData.ToolWarnBon = {type: 'bool', group: 'Calculation', label: ['Calculate Tooltip Warning With Bonus CPS OFF', 'Calculate Tooltip Warning With Bonus CPS ON'], desc: 'Calculate the warning with or without the bonus CPS you get from buying', toggle: true}; + +// Notification +CM.ConfigData.GCNotification = {type: 'bool', group: 'Notification', label: ['Golden Cookie Notification OFF', 'Golden Cookie Notification ON'], desc: 'Create a notification when Golden Cookie spawns', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Config.GCNotification);}}; +CM.ConfigData.GCFlash = {type: 'bool', group: 'Notification', label: ['Golden Cookie Flash OFF', 'Golden Cookie Flash ON'], desc: 'Flash screen on Golden Cookie', toggle: true}; +CM.ConfigData.GCSound = {type: 'bool', group: 'Notification', label: ['Golden Cookie Sound OFF', 'Golden Cookie Sound ON'], desc: 'Play a sound on Golden Cookie', toggle: true}; +CM.ConfigData.GCVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of the Golden Cookie sound'}; +for (var i = 0; i < 101; i++) { + CM.ConfigData.GCVolume.label[i] = i + '%'; +} +CM.ConfigData.GCSoundURL = {type: 'url', group: 'Notification', label: 'Golden Cookie Sound URL:', desc: 'URL of the sound to be played when a Golden Cookie spawns'}; +CM.ConfigData.GCTimer = {type: 'bool', group: 'Notification', label: ['Golden Cookie Timer OFF', 'Golden Cookie Timer ON'], desc: 'A timer on the Golden Cookie when it has been spawned', toggle: true, func: function() {CM.Disp.ToggleGCTimer();}}; +CM.ConfigData.Favicon = {type: 'bool', group: 'Notification', label: ['Favicon OFF', 'Favicon ON'], desc: 'Update favicon with Golden/Wrath Cookie', toggle: true, func: function() {CM.Disp.UpdateFavicon();}}; +CM.ConfigData.FortuneNotification = {type: 'bool', group: 'Notification', label: ['Fortune Cookie Notification OFF', 'Fortune Cookie Notification ON'], desc: 'Create a notification when Fortune Cookie is on the Ticker', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Config.FortuneNotification);}}; +CM.ConfigData.FortuneFlash = {type: 'bool', group: 'Notification', label: ['Fortune Cookie Flash OFF', 'Fortune Cookie Flash ON'], desc: 'Flash screen on Fortune Cookie', toggle: true}; +CM.ConfigData.FortuneSound = {type: 'bool', group: 'Notification', label: ['Fortune Cookie Sound OFF', 'Fortune Cookie Sound ON'], desc: 'Play a sound on Fortune Cookie', toggle: true}; +CM.ConfigData.FortuneVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of the Fortune Cookie sound'}; +for (var i = 0; i < 101; i++) { + CM.ConfigData.FortuneVolume.label[i] = i + '%'; +} +CM.ConfigData.FortuneSoundURL = {type: 'url', group: 'Notification', label: 'Fortune Cookie Sound URL:', desc: 'URL of the sound to be played when the Ticker has a Fortune Cookie'}; +CM.ConfigData.SeaNotification = {type: 'bool', group: 'Notification', label: ['Season Special Notification OFF', 'Season Special Notification ON'], desc: 'Create a notification on Season Popup', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Config.SeaNotification);}}; +CM.ConfigData.SeaFlash = {type: 'bool', group: 'Notification', label: ['Season Special Flash OFF', 'Season Special Flash ON'], desc: 'Flash screen on Season Popup', toggle: true}; +CM.ConfigData.SeaSound = {type: 'bool', group: 'Notification', label: ['Season Special Sound OFF', 'Season Special Sound ON'], desc: 'Play a sound on Season Popup', toggle: true}; +CM.ConfigData.SeaVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of the Season Special sound'}; +for (var i = 0; i < 101; i++) { + CM.ConfigData.SeaVolume.label[i] = i + '%'; +} +CM.ConfigData.SeaSoundURL = {type: 'url', group: 'Notification', label: 'Season Special Sound URL:', desc: 'URL of the sound to be played when a Season Special spawns'}; +CM.ConfigData.GardFlash = {type: 'bool', group: 'Notification', label: ['Garden Tick Flash OFF', 'Garden Tick Flash ON'], desc: 'Flash screen on Garden Tick', toggle: true}; +CM.ConfigData.GardSound = {type: 'bool', group: 'Notification', label: ['Garden Tick Sound OFF', 'Garden Tick Sound ON'], desc: 'Play a sound on Garden Tick', toggle: true}; +CM.ConfigData.GardVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of the Garden Tick sound'}; +for (var i = 0; i < 101; i++) { + CM.ConfigData.GardVolume.label[i] = i + '%'; +} +CM.ConfigData.GardSoundURL = {type: 'url', group: 'Notification', label: 'Garden Tick Sound URL:', desc: 'URL of the sound to be played when the garden ticks'}; +CM.ConfigData.MagicNotification = {type: 'bool', group: 'Notification', label: ['Magic Max Notification OFF', 'Magic Max Notification ON'], desc: 'Create a notification when magic reaches maximum', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Config.MagicNotification);}}; +CM.ConfigData.MagicFlash = {type: 'bool', group: 'Notification', label: ['Magic Max Flash OFF', 'Magic Max Flash ON'], desc: 'Flash screen when magic reaches maximum', toggle: true}; +CM.ConfigData.MagicSound = {type: 'bool', group: 'Notification', label: ['Magic Max Sound OFF', 'Magic Max Sound ON'], desc: 'Play a sound when magic reaches maximum', toggle: true}; +CM.ConfigData.MagicVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of the Max Magic sound'}; +for (var i = 0; i < 101; i++) { + CM.ConfigData.MagicVolume.label[i] = i + '%'; +} +CM.ConfigData.MagicSoundURL = {type: 'url', group: 'Notification', label: 'Magic Max Sound URL:', desc: 'URL of the sound to be played when magic reaches maxium'}; +CM.ConfigData.WrinklerNotification = {type: 'bool', group: 'Notification', label: ['Wrinkler Notification OFF', 'Wrinkler Notification ON'], desc: 'Create a notification when a Wrinkler appears', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Config.WrinklerNotification);}}; +CM.ConfigData.WrinklerFlash = {type: 'bool', group: 'Notification', label: ['Wrinkler Flash OFF', 'Wrinkler Flash ON'], desc: 'Flash screen when a Wrinkler appears', toggle: true}; +CM.ConfigData.WrinklerSound = {type: 'bool', group: 'Notification', label: ['Wrinkler Sound OFF', 'Wrinkler Sound ON'], desc: 'Play a sound when a Wrinkler appears', toggle: true}; +CM.ConfigData.WrinklerVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of the Wrinkler sound'}; +for (var i = 0; i < 101; i++) { + CM.ConfigData.WrinklerVolume.label[i] = i + '%'; +} +CM.ConfigData.WrinklerSoundURL = {type: 'url', group: 'Notification', label: 'Wrinkler Sound URL:', desc: 'URL of the sound to be played when a Wrinkler appears'}; +CM.ConfigData.WrinklerMaxNotification = {type: 'bool', group: 'Notification', label: ['Wrinkler Max Notification OFF', 'Wrinkler Max Notification ON'], desc: 'Create a notification when the maximum amount of Wrinklers has appeared', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Config.WrinklerMaxNotification);}}; +CM.ConfigData.WrinklerMaxFlash = {type: 'bool', group: 'Notification', label: ['Wrinkler Max Flash OFF', 'Wrinkler Max Flash ON'], desc: 'Flash screen when the maximum amount of Wrinklers has appeared', toggle: true}; +CM.ConfigData.WrinklerMaxSound = {type: 'bool', group: 'Notification', label: ['Wrinkler Max Sound OFF', 'Wrinkler Max Sound ON'], desc: 'Play a sound when the maximum amount of Wrinklers has appeared', toggle: true}; +CM.ConfigData.WrinklerMaxVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of the Wrinkler Max sound'}; +for (var i = 0; i < 101; i++) { + CM.ConfigData.WrinklerMaxVolume.label[i] = i + '%'; +} +CM.ConfigData.WrinklerMaxSoundURL = {type: 'url', group: 'Notification', label: 'Wrinkler Max Sound URL:', desc: 'URL of the sound to be played when the maximum amount of Wrinklers has appeared'}; +CM.ConfigData.Title = {type: 'bool', group: 'Notification', label: ['Title OFF', 'Title ON', 'Title Pinned Tab Highlight'], desc: 'Update title with Golden Cookie/Season Popup timers; pinned tab highlight only changes the title when a Golden Cookie/Season Popup spawns', toggle: true}; + +// Tooltip +CM.ConfigData.TooltipBuildUp = {type: 'bool', group: 'Tooltip', label: ['Buildings/Upgrades Tooltip Information OFF', 'Buildings/Upgrades Tooltip Information ON'], desc: 'Extra information in tooltip for buildings/upgrades', toggle: true}; +CM.ConfigData.TooltipAmor = {type: 'bool', group: 'Tooltip', label: ['Buildings Tooltip Amortization Information OFF', 'Buildings Tooltip Amortization Information ON'], desc: 'Add amortization information to buildings tooltip', toggle: true}; +CM.ConfigData.ToolWarnLucky = {type: 'bool', group: 'Tooltip', label: ['Tooltip Lucky Warning OFF', 'Tooltip Lucky Warning ON'], desc: 'A warning when buying if it will put the bank under the amount needed for max "Lucky!"/"Lucky!" (Frenzy) rewards', toggle: true}; +CM.ConfigData.ToolWarnConjure = {type: 'bool', group: 'Tooltip', label: ['Tooltip Conjure Warning OFF', 'Tooltip Conjure Warning ON'], desc: 'A warning when buying if it will put the bank under the amount needed for max "Conjure Baked Goods" rewards', toggle: true}; +CM.ConfigData.ToolWarnPos = {type: 'bool', group: 'Tooltip', label: ['Tooltip Warning Position (Left)', 'Tooltip Warning Position (Bottom)'], desc: 'Placement of the warning boxes', toggle: false, func: function() {CM.Disp.ToggleToolWarnPos();}}; +CM.ConfigData.TooltipGrim = {type: 'bool', group: 'Tooltip', label: ['Grimoire Tooltip Information OFF', 'Grimoire Tooltip Information ON'], desc: 'Extra information in tooltip for grimoire', toggle: true}; +CM.ConfigData.ToolWrink = {type: 'bool', group: 'Tooltip', label: ['Wrinkler Tooltip OFF', 'Wrinkler Tooltip ON'], desc: 'Shows the amount of cookies a wrinkler will give when popping it', toggle: true}; +CM.ConfigData.TooltipLump = {type: 'bool', group: 'Tooltip', label: ['Sugar Lump Tooltip OFF', 'Sugar Lump Tooltip ON'], desc: 'Shows the current Sugar Lump type in Sugar lump tooltip.', toggle: true}; + +// Statistics +CM.ConfigData.Stats = {type: 'bool', group: 'Statistics', label: ['Statistics OFF', 'Statistics ON'], desc: 'Extra Cookie Monster statistics!', toggle: true}; +CM.ConfigData.MissingUpgrades = {type: 'bool', group: 'Statistics', label: ['Missing Upgrades OFF', 'Missing Upgrades ON'], desc: 'Shows Missing upgrades in Stats Menu. This feature can be laggy for users with a low amount of unlocked achievements.', toggle: true}; +CM.ConfigData.UpStats = {type: 'bool', group: 'Statistics', label: ['Statistics Update Rate (Default)', 'Statistics Update Rate (1s)'], desc: 'Default Game rate is once every 5 seconds', toggle: false}; +CM.ConfigData.TimeFormat = {type: 'bool', group: 'Statistics', label: ['Time XXd, XXh, XXm, XXs', 'Time XX:XX:XX:XX:XX'], desc: 'Change the time format', toggle: false}; +CM.ConfigData.SayTime = {type: 'bool', group: 'Statistics', label: ['Format Time OFF', 'Format Time ON'], desc: 'Change how time is displayed in statistics', toggle: true, func: function() {CM.Disp.ToggleSayTime();}}; +CM.ConfigData.GrimoireBar = {type: 'bool', group: 'Statistics', label: ['Grimoire Magic Meter Timer OFF', 'Grimoire Magic Meter Timer ON'], desc: 'A timer on how long before the Grimoire magic meter is full', toggle: true}; + +// Statistics +CM.ConfigData.Scale = {type: 'bool', group: 'Other', label: ['Game\'s Setting Scale', 'Metric', 'Short Scale', 'Scientific Notation', 'Engineering Notation'], desc: 'Change how long numbers are handled', toggle: false, func: function() {CM.Disp.RefreshScale();}};/******** * Disp * ********/ @@ -1813,7 +1846,7 @@ CM.Disp.CreateUpgradeBarLegend = function() { /** * This function creates a white square over the full screen and appends it to l('wrapper') - * It is used (and called) by CM.Disp.Flash() to create the effect of a flash + * It is used by CM.Disp.Flash() to create the effect of a flash and called by CM.DelayInit() */ CM.Disp.CreateWhiteScreen = function() { CM.Disp.WhiteScreen = document.createElement('div'); @@ -2735,40 +2768,84 @@ CM.Disp.RefreshMenu = function() { } /******** - * Section: Functions related to the Options page - * TODO: Annotate functions */ - -CM.Disp.AddMenuPref = function(title) { - var header = function(text, config) { - var div = document.createElement('div'); - div.className = 'listing'; - div.style.padding = '5px 16px'; - div.style.opacity = '0.7'; - div.style.fontSize = '17px'; - div.style.fontFamily = '\"Kavoon\", Georgia, serif'; - div.appendChild(document.createTextNode(text + ' ')); - var span = document.createElement('span'); - span.style.cursor = 'pointer'; - span.style.display = 'inline-block'; - span.style.height = '14px'; - span.style.width = '14px'; - span.style.borderRadius = '7px'; - span.style.textAlign = 'center'; - span.style.backgroundColor = '#C0C0C0'; - span.style.color = 'black'; - span.style.fontSize = '13px'; - span.style.verticalAlign = 'middle'; - span.textContent = CM.Config.MenuPref[config] ? '-' : '+'; - span.onclick = function() {CM.ToggleMenuConfig(config); Game.UpdateMenu();}; - div.appendChild(span); - return div; - } + * Section: Functions related to the Options/Preferences page +/** + * This function adds the options/settings of CookieMonster to the options page + * It is called by CM.Disp.AddMenu + * @param {function} title A function that returns the title of CookieMonster pre-styled + */ +CM.Disp.AddMenuPref = function(title) { var frag = document.createDocumentFragment(); - frag.appendChild(title()); - var listing = function(config) { + for (var group in CM.ConfigGroups) { + groupObject = CM.Disp.CreatePrefHeader(group, CM.ConfigGroups[group]) // (group, display-name of group) + frag.appendChild(groupObject) + if (CM.Config.OptionsPref[group]) { // 0 is show, 1 is collapsed + for (var option in CM.ConfigData) { + if (CM.ConfigData[option].group == group) frag.appendChild(CM.Disp.CreatePrefOption(option)) + } + } + } + + var resDef = document.createElement('div'); + resDef.className = 'listing'; + var resDefBut = document.createElement('a'); + resDefBut.className = 'option'; + resDefBut.onclick = function() {CM.RestoreDefault();}; + resDefBut.textContent = 'Restore Default'; + resDef.appendChild(resDefBut); + frag.appendChild(resDef); + + l('menu').childNodes[2].insertBefore(frag, l('menu').childNodes[2].childNodes[l('menu').childNodes[2].childNodes.length - 1]); + + // TODO: What does this do? @DanielNoord + CM.Disp.FormatButtonOnClickBak = l('formatButton').onclick; + eval('l(\'formatButton\').onclick = ' + l('formatButton').onclick.toString().split('mp3\');').join('mp3\'); CM.Disp.RefreshScale();')); + //l('formatButton').onclick = function() {Game.Toggle('format', 'formatButton', 'Short numbers OFF', 'Short numbers ON', '1'); PlaySound('snd/tick.mp3'); CM.Disp.RefreshScale();}; +} + +/** + * This function creates a header-object for the options page + * It is called by CM.Disp.AddMenuPref() + * @param {string} config The name of the Config-group + * @param {string} text The to-be displayed name of the header + * @returns {object} div The header object + */ +CM.Disp.CreatePrefHeader = function(config, text) { + var div = document.createElement('div'); + div.className = 'listing'; + div.style.padding = '5px 16px'; + div.style.opacity = '0.7'; + div.style.fontSize = '17px'; + div.style.fontFamily = '\"Kavoon\", Georgia, serif'; + div.appendChild(document.createTextNode(text + ' ')); + var span = document.createElement('span'); // Creates the +/- button + span.style.cursor = 'pointer'; + span.style.display = 'inline-block'; + span.style.height = '14px'; + span.style.width = '14px'; + span.style.borderRadius = '7px'; + span.style.textAlign = 'center'; + span.style.backgroundColor = '#C0C0C0'; + span.style.color = 'black'; + span.style.fontSize = '13px'; + span.style.verticalAlign = 'middle'; + span.textContent = CM.Config.OptionsPref[config] ? '-' : '+'; + span.onclick = function() {CM.ToggleOptionsConfig(config); Game.UpdateMenu();}; + div.appendChild(span); + return div; +} + +/** + * This function creates an option-object for the options page + * It is called by CM.Disp.AddMenuPref() + * @param {string} config The name of the option + * @returns {object} div The option object + */ +CM.Disp.CreatePrefOption = function(config) { + if (CM.ConfigData[config].type == "bool") { var div = document.createElement('div'); div.className = 'listing'; var a = document.createElement('a'); @@ -2787,8 +2864,7 @@ CM.Disp.AddMenuPref = function(title) { div.appendChild(label); return div; } - - var vol = function(config) { + else if (CM.ConfigData[config].type == "vol") { var volConfig = config; var volume = document.createElement('div'); volume.className = 'listing'; @@ -2811,8 +2887,7 @@ CM.Disp.AddMenuPref = function(title) { volume.appendChild(volLabel); return volume; } - - var url = function(config) { + else if (CM.ConfigData[config].type == "url") { var div = document.createElement('div'); div.className = 'listing'; var span = document.createElement('span'); @@ -2843,18 +2918,7 @@ CM.Disp.AddMenuPref = function(title) { div.appendChild(label); return div; } - - frag.appendChild(header('Bars/Colors', 'BarsColors')); - if (CM.Config.MenuPref.BarsColors) { - frag.appendChild(listing('BotBar')); - frag.appendChild(listing('TimerBar')); - frag.appendChild(listing('TimerBarPos')); - frag.appendChild(listing('SortBuildings')); - frag.appendChild(listing('SortUpgrades')); - frag.appendChild(listing('BuildColor')); - frag.appendChild(listing('BulkBuildColor')); - frag.appendChild(listing('ColorPPBulkMode')); - frag.appendChild(listing('UpBarColor')); + else if (CM.ConfigData[config].type == "color") { for (var i = 0; i < CM.Disp.colors.length; i++) { var div = document.createElement('div'); div.className = 'listing'; @@ -2869,101 +2933,9 @@ CM.Disp.AddMenuPref = function(title) { var label = document.createElement('label'); label.textContent = CM.ConfigData.Colors.desc[CM.Disp.colors[i]]; div.appendChild(label); - frag.appendChild(div); + return div; } - frag.appendChild(listing('UpgradeBarFixedPos')); } - - frag.appendChild(header('Calculation', 'Calculation')); - if (CM.Config.MenuPref.Calculation) { - frag.appendChild(listing('CalcWrink')); - frag.appendChild(listing('CPSMode')); - frag.appendChild(listing('AvgCPSHist')); - frag.appendChild(listing('AvgClicksHist')); - frag.appendChild(listing('ToolWarnBon')); - } - - frag.appendChild(header('Notification', 'Notification')); - if (CM.Config.MenuPref.Notification) { - frag.appendChild(listing('GCNotification')); - frag.appendChild(listing('GCFlash')); - frag.appendChild(listing('GCSound')); - frag.appendChild(vol('GCVolume')); - frag.appendChild(url('GCSoundURL')); - frag.appendChild(listing('GCTimer')); - frag.appendChild(listing('Favicon')); - frag.appendChild(listing('FortuneNotification')); - frag.appendChild(listing('FortuneFlash')); - frag.appendChild(listing('FortuneSound')); - frag.appendChild(vol('FortuneVolume')); - frag.appendChild(url('FortuneSoundURL')); - frag.appendChild(listing('SeaNotification')); - frag.appendChild(listing('SeaFlash')); - frag.appendChild(listing('SeaSound')); - frag.appendChild(vol('SeaVolume')); - frag.appendChild(url('SeaSoundURL')); - frag.appendChild(listing('GardFlash')); - frag.appendChild(listing('GardSound')); - frag.appendChild(vol('GardVolume')); - frag.appendChild(url('GardSoundURL')); - frag.appendChild(listing('MagicNotification')); - frag.appendChild(listing('MagicFlash')); - frag.appendChild(listing('MagicSound')); - frag.appendChild(vol('MagicVolume')); - frag.appendChild(url('MagicSoundURL')); - frag.appendChild(listing('WrinklerNotification')); - frag.appendChild(listing('WrinklerFlash')); - frag.appendChild(listing('WrinklerSound')); - frag.appendChild(vol('WrinklerVolume')); - frag.appendChild(url('WrinklerSoundURL')); - frag.appendChild(listing('WrinklerMaxNotification')); - frag.appendChild(listing('WrinklerMaxFlash')); - frag.appendChild(listing('WrinklerMaxSound')); - frag.appendChild(vol('WrinklerMaxVolume')); - frag.appendChild(url('WrinklerMaxSoundURL')); - frag.appendChild(listing('Title')); - } - - frag.appendChild(header('Tooltip', 'Tooltip')); - if (CM.Config.MenuPref.Tooltip) { - frag.appendChild(listing('TooltipBuildUp')); - frag.appendChild(listing('TooltipAmor')); - frag.appendChild(listing('ToolWarnLucky')); - frag.appendChild(listing('ToolWarnConjure')); - frag.appendChild(listing('ToolWarnPos')); - frag.appendChild(listing('TooltipGrim')); - frag.appendChild(listing('ToolWrink')); - frag.appendChild(listing('TooltipLump')); - } - - frag.appendChild(header('Statistics', 'Statistics')); - if (CM.Config.MenuPref.Statistics) { - frag.appendChild(listing('Stats')); - frag.appendChild(listing('MissingUpgrades')); - frag.appendChild(listing('UpStats')); - frag.appendChild(listing('TimeFormat')); - frag.appendChild(listing('SayTime')); - frag.appendChild(listing('GrimoireBar')); - } - - frag.appendChild(header('Other', 'Other')); - if (CM.Config.MenuPref.Other) { - frag.appendChild(listing('Scale')); - var resDef = document.createElement('div'); - resDef.className = 'listing'; - var resDefBut = document.createElement('a'); - resDefBut.className = 'option'; - resDefBut.onclick = function() {CM.RestoreDefault();}; - resDefBut.textContent = 'Restore Default'; - resDef.appendChild(resDefBut); - frag.appendChild(resDef); - } - - l('menu').childNodes[2].insertBefore(frag, l('menu').childNodes[2].childNodes[l('menu').childNodes[2].childNodes.length - 1]); - - CM.Disp.FormatButtonOnClickBak = l('formatButton').onclick; - eval('l(\'formatButton\').onclick = ' + l('formatButton').onclick.toString().split('mp3\');').join('mp3\'); CM.Disp.RefreshScale();')); - //l('formatButton').onclick = function() {Game.Toggle('format', 'formatButton', 'Short numbers OFF', 'Short numbers ON', '1'); PlaySound('snd/tick.mp3'); CM.Disp.RefreshScale();}; } /******** @@ -3852,7 +3824,7 @@ CM.ConfigDefault = { SayTime: 1, GrimoireBar: 1, Scale: 2, - MenuPref: {BarsColors: 1, Calculation: 1, Notification: 1, Tooltip: 1, Statistics: 1, Other: 1}, + OptionsPref: {BarsColors: 1, Calculation: 1, Notification: 1, Tooltip: 1, Statistics: 1, Other: 1}, StatsPref: {Lucky: 1, Conjure: 1, Chain: 1, Prestige: 1, Wrink: 1, Sea: 1, Misc: 1}, Colors : {Blue: '#4bb8f0', Green: '#00ff00', Yellow: '#ffff00', Orange: '#ff7f00', Red: '#ff0000', Purple: '#ff00ff', Gray: '#b3b3b3', Pink: '#ff1493', Brown: '#8b4513'}, SortBuildings: 0, diff --git a/src/Config.js b/src/Config.js index a98742b..8a00a3e 100644 --- a/src/Config.js +++ b/src/Config.js @@ -51,7 +51,7 @@ CM.LoadConfig = function() { if (mod) CM.SaveConfig(CM.Config); CM.Loop(); // Do loop once for (var i in CM.ConfigDefault) { - if (i != 'StatsPref' && i != 'MenuPref' && typeof CM.ConfigData[i].func !== 'undefined') { + if (i != 'StatsPref' && i != 'OptionsPref' && typeof CM.ConfigData[i].func !== 'undefined') { CM.ConfigData[i].func(); } } @@ -114,12 +114,12 @@ CM.ToggleStatsConfig = function(config) { CM.SaveConfig(CM.Config); } -CM.ToggleMenuConfig = function(config) { - if (CM.Config.MenuPref[config] == 0) { - CM.Config.MenuPref[config]++; +CM.ToggleOptionsConfig = function(config) { + if (CM.Config.OptionsPref[config] == 0) { + CM.Config.OptionsPref[config]++; } else { - CM.Config.MenuPref[config]--; + CM.Config.OptionsPref[config]--; } CM.SaveConfig(CM.Config); } @@ -151,107 +151,4 @@ CM.CheckNotificationPermissions = function(ToggleOnOff) { } } } -} - -CM.ConfigData.BotBar = {label: ['Bottom Bar OFF', 'Bottom Bar ON'], desc: 'Building Information', toggle: true, func: function() {CM.Disp.ToggleBotBar();}}; -CM.ConfigData.TimerBar = {label: ['Timer Bar OFF', 'Timer Bar ON'], desc: 'Timers of Golden Cookie, Season Popup, Frenzy (Normal, Clot, Elder), Click Frenzy', toggle: true, func: function() {CM.Disp.ToggleTimerBar();}}; -CM.ConfigData.TimerBarPos = {label: ['Timer Bar Position (Top Left)', 'Timer Bar Position (Bottom)'], desc: 'Placement of the Timer Bar', toggle: false, func: function() {CM.Disp.ToggleTimerBarPos();}}; -CM.ConfigData.BuildColor = {label: ['Building Colors OFF', 'Building Colors ON'], desc: 'Color code buildings', toggle: true, func: function() {CM.Disp.UpdateBuildings();}}; -CM.ConfigData.BulkBuildColor = {label: ['Bulk Building Colors (Single Building Color)', 'Bulk Building Colors (Calculated Bulk Color)'], desc: 'Color code bulk buildings based on single buildings color or calculated bulk value color', toggle: false, func: function() {CM.Disp.UpdateBuildings();}}; -CM.ConfigData.ColorPPBulkMode = {label: ['Color of PP (Compared to Single)', 'Color of PP (Compared to Bulk)'], desc: 'Color PP-values based on comparison with single purchase or with selected bulk-buy mode', toggle: false}; -CM.ConfigData.UpBarColor = {label: ['Upgrade Colors/Bar OFF', 'Upgrade Colors with Bar ON', 'Upgrade Colors without Bar ON'], desc: 'Color code upgrades and optionally add a counter bar', toggle: false, func: function() {CM.Disp.ToggleUpgradeBarAndColor();}}; -CM.ConfigData.Colors = { - desc: { - Blue: 'Color Blue. Used to show better than best PP building, for Click Frenzy bar, and for various labels', - Green: 'Color Green. Used to show best PP building, for Blood Frenzy bar, and for various labels', - Yellow: 'Color Yellow. Used to show between best and worst PP buildings closer to best, for Frenzy bar, and for various labels', - Orange: 'Color Orange. Used to show between best and worst PP buildings closer to worst, for Next Reindeer bar, and for various labels', - Red: 'Color Red. Used to show worst PP building, for Clot bar, and for various labels', - Purple: 'Color Purple. Used to show worse than worst PP building, for Next Cookie bar, and for various labels', - Gray: 'Color Gray. Used to show negative or infinity PP, and for Next Cookie/Next Reindeer bar', - Pink: 'Color Pink. Used for Dragonflight bar', - Brown: 'Color Brown. Used for Dragon Harvest bar' - }, - func: function() {CM.Disp.UpdateColors();} -}; -CM.ConfigData.UpgradeBarFixedPos = {label: ['Upgrade Bar Fixed Position OFF', 'Upgrade Bar Fixed Position ON'], desc: 'Lock the upgrade bar at top of the screen to prevent it from moving ofscreen when scrolling', toggle: true, func: function() {CM.Disp.ToggleUpgradeBarFixedPos();}}; -CM.ConfigData.CalcWrink = {label: ['Calculate with Wrinklers OFF', 'Calculate with Wrinklers ON'], desc: 'Calculate times and average Cookies Per Second with Wrinklers', toggle: true}; -CM.ConfigData.CPSMode = {label: ['Current Cookies Per Second', 'Average Cookies Per Second'], desc: 'Calculate times using current Cookies Per Second or average Cookies Per Second', toggle: false}; -CM.ConfigData.AvgCPSHist = {label: ['Average CPS for past 10s', 'Average CPS for past 15s', 'Average CPS for past 30s', 'Average CPS for past 1m', 'Average CPS for past 5m', 'Average CPS for past 10m', 'Average CPS for past 15m', 'Average CPS for past 30m'], desc: 'How much time average Cookies Per Second should consider', toggle: false}; -CM.ConfigData.AvgClicksHist = {label: ['Average Cookie Clicks for past 1s', 'Average Cookie Clicks for past 5s', 'Average Cookie Clicks for past 10s', 'Average Cookie Clicks for past 15s', 'Average Cookie Clicks for past 30s'], desc: 'How much time average Cookie Clicks should consider', toggle: false}; -CM.ConfigData.ToolWarnBon = {label: ['Calculate Tooltip Warning With Bonus CPS OFF', 'Calculate Tooltip Warning With Bonus CPS ON'], desc: 'Calculate the warning with or without the bonus CPS you get from buying', toggle: true}; -CM.ConfigData.GCNotification = {label: ['Golden Cookie Notification OFF', 'Golden Cookie Notification ON'], desc: 'Create a notification when Golden Cookie spawns', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Config.GCNotification);}}; -CM.ConfigData.GCFlash = {label: ['Golden Cookie Flash OFF', 'Golden Cookie Flash ON'], desc: 'Flash screen on Golden Cookie', toggle: true}; -CM.ConfigData.GCSound = {label: ['Golden Cookie Sound OFF', 'Golden Cookie Sound ON'], desc: 'Play a sound on Golden Cookie', toggle: true}; -CM.ConfigData.GCVolume = {label: [], desc: 'Volume of the Golden Cookie sound'}; -for (var i = 0; i < 101; i++) { - CM.ConfigData.GCVolume.label[i] = i + '%'; -} -CM.ConfigData.GCSoundURL = {label: 'Golden Cookie Sound URL:', desc: 'URL of the sound to be played when a Golden Cookie spawns'}; -CM.ConfigData.GCTimer = {label: ['Golden Cookie Timer OFF', 'Golden Cookie Timer ON'], desc: 'A timer on the Golden Cookie when it has been spawned', toggle: true, func: function() {CM.Disp.ToggleGCTimer();}}; -CM.ConfigData.Favicon = {label: ['Favicon OFF', 'Favicon ON'], desc: 'Update favicon with Golden/Wrath Cookie', toggle: true, func: function() {CM.Disp.UpdateFavicon();}}; -CM.ConfigData.FortuneNotification = {label: ['Fortune Cookie Notification OFF', 'Fortune Cookie Notification ON'], desc: 'Create a notification when Fortune Cookie is on the Ticker', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Config.FortuneNotification);}}; -CM.ConfigData.FortuneFlash = {label: ['Fortune Cookie Flash OFF', 'Fortune Cookie Flash ON'], desc: 'Flash screen on Fortune Cookie', toggle: true}; -CM.ConfigData.FortuneSound = {label: ['Fortune Cookie Sound OFF', 'Fortune Cookie Sound ON'], desc: 'Play a sound on Fortune Cookie', toggle: true}; -CM.ConfigData.FortuneVolume = {label: [], desc: 'Volume of the Fortune Cookie sound'}; -for (var i = 0; i < 101; i++) { - CM.ConfigData.FortuneVolume.label[i] = i + '%'; -} -CM.ConfigData.FortuneSoundURL = {label: 'Fortune Cookie Sound URL:', desc: 'URL of the sound to be played when the Ticker has a Fortune Cookie'}; -CM.ConfigData.SeaNotification = {label: ['Season Special Notification OFF', 'Season Special Notification ON'], desc: 'Create a notification on Season Popup', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Config.SeaNotification);}}; -CM.ConfigData.SeaFlash = {label: ['Season Special Flash OFF', 'Season Special Flash ON'], desc: 'Flash screen on Season Popup', toggle: true}; -CM.ConfigData.SeaSound = {label: ['Season Special Sound OFF', 'Season Special Sound ON'], desc: 'Play a sound on Season Popup', toggle: true}; -CM.ConfigData.SeaVolume = {label: [], desc: 'Volume of the Season Special sound'}; -for (var i = 0; i < 101; i++) { - CM.ConfigData.SeaVolume.label[i] = i + '%'; -} -CM.ConfigData.SeaSoundURL = {label: 'Season Special Sound URL:', desc: 'URL of the sound to be played when a Season Special spawns'}; -CM.ConfigData.GardFlash = {label: ['Garden Tick Flash OFF', 'Garden Tick Flash ON'], desc: 'Flash screen on Garden Tick', toggle: true}; -CM.ConfigData.GardSound = {label: ['Garden Tick Sound OFF', 'Garden Tick Sound ON'], desc: 'Play a sound on Garden Tick', toggle: true}; -CM.ConfigData.GardVolume = {label: [], desc: 'Volume of the Garden Tick sound'}; -for (var i = 0; i < 101; i++) { - CM.ConfigData.GardVolume.label[i] = i + '%'; -} -CM.ConfigData.GardSoundURL = {label: 'Garden Tick Sound URL:', desc: 'URL of the sound to be played when the garden ticks'}; -CM.ConfigData.MagicNotification = {label: ['Magic Max Notification OFF', 'Magic Max Notification ON'], desc: 'Create a notification when magic reaches maximum', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Config.MagicNotification);}}; -CM.ConfigData.MagicFlash = {label: ['Magic Max Flash OFF', 'Magic Max Flash ON'], desc: 'Flash screen when magic reaches maximum', toggle: true}; -CM.ConfigData.MagicSound = {label: ['Magic Max Sound OFF', 'Magic Max Sound ON'], desc: 'Play a sound when magic reaches maximum', toggle: true}; -CM.ConfigData.MagicVolume = {label: [], desc: 'Volume of the Max Magic sound'}; -for (var i = 0; i < 101; i++) { - CM.ConfigData.MagicVolume.label[i] = i + '%'; -} -CM.ConfigData.MagicSoundURL = {label: 'Magic Max Sound URL:', desc: 'URL of the sound to be played when magic reaches maxium'}; -CM.ConfigData.WrinklerNotification = {label: ['Wrinkler Notification OFF', 'Wrinkler Notification ON'], desc: 'Create a notification when a Wrinkler appears', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Config.WrinklerNotification);}}; -CM.ConfigData.WrinklerFlash = {label: ['Wrinkler Flash OFF', 'Wrinkler Flash ON'], desc: 'Flash screen when a Wrinkler appears', toggle: true}; -CM.ConfigData.WrinklerSound = {label: ['Wrinkler Sound OFF', 'Wrinkler Sound ON'], desc: 'Play a sound when a Wrinkler appears', toggle: true}; -CM.ConfigData.WrinklerVolume = {label: [], desc: 'Volume of the Wrinkler sound'}; -for (var i = 0; i < 101; i++) { - CM.ConfigData.WrinklerVolume.label[i] = i + '%'; -} -CM.ConfigData.WrinklerSoundURL = {label: 'Wrinkler Sound URL:', desc: 'URL of the sound to be played when a Wrinkler appears'}; -CM.ConfigData.WrinklerMaxNotification = {label: ['Wrinkler Max Notification OFF', 'Wrinkler Max Notification ON'], desc: 'Create a notification when the maximum amount of Wrinklers has appeared', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Config.WrinklerMaxNotification);}}; -CM.ConfigData.WrinklerMaxFlash = {label: ['Wrinkler Max Flash OFF', 'Wrinkler Max Flash ON'], desc: 'Flash screen when the maximum amount of Wrinklers has appeared', toggle: true}; -CM.ConfigData.WrinklerMaxSound = {label: ['Wrinkler Max Sound OFF', 'Wrinkler Max Sound ON'], desc: 'Play a sound when the maximum amount of Wrinklers has appeared', toggle: true}; -CM.ConfigData.WrinklerMaxVolume = {label: [], desc: 'Volume of the Wrinkler Max sound'}; -for (var i = 0; i < 101; i++) { - CM.ConfigData.WrinklerMaxVolume.label[i] = i + '%'; -} -CM.ConfigData.WrinklerMaxSoundURL = {label: 'Wrinkler Max Sound URL:', desc: 'URL of the sound to be played when the maximum amount of Wrinklers has appeared'}; -CM.ConfigData.Title = {label: ['Title OFF', 'Title ON', 'Title Pinned Tab Highlight'], desc: 'Update title with Golden Cookie/Season Popup timers; pinned tab highlight only changes the title when a Golden Cookie/Season Popup spawns', toggle: true}; -CM.ConfigData.TooltipBuildUp = {label: ['Buildings/Upgrades Tooltip Information OFF', 'Buildings/Upgrades Tooltip Information ON'], desc: 'Extra information in tooltip for buildings/upgrades', toggle: true}; -CM.ConfigData.TooltipAmor = {label: ['Buildings Tooltip Amortization Information OFF', 'Buildings Tooltip Amortization Information ON'], desc: 'Add amortization information to buildings tooltip', toggle: true}; -CM.ConfigData.ToolWarnLucky = {label: ['Tooltip Lucky Warning OFF', 'Tooltip Lucky Warning ON'], desc: 'A warning when buying if it will put the bank under the amount needed for max "Lucky!"/"Lucky!" (Frenzy) rewards', toggle: true}; -CM.ConfigData.ToolWarnConjure = {label: ['Tooltip Conjure Warning OFF', 'Tooltip Conjure Warning ON'], desc: 'A warning when buying if it will put the bank under the amount needed for max "Conjure Baked Goods" rewards', toggle: true}; -CM.ConfigData.ToolWarnPos = {label: ['Tooltip Warning Position (Left)', 'Tooltip Warning Position (Bottom)'], desc: 'Placement of the warning boxes', toggle: false, func: function() {CM.Disp.ToggleToolWarnPos();}}; -CM.ConfigData.TooltipGrim = {label: ['Grimoire Tooltip Information OFF', 'Grimoire Tooltip Information ON'], desc: 'Extra information in tooltip for grimoire', toggle: true}; -CM.ConfigData.ToolWrink = {label: ['Wrinkler Tooltip OFF', 'Wrinkler Tooltip ON'], desc: 'Shows the amount of cookies a wrinkler will give when popping it', toggle: true}; -CM.ConfigData.TooltipLump = {label: ['Sugar Lump Tooltip OFF', 'Sugar Lump Tooltip ON'], desc: 'Shows the current Sugar Lump type in Sugar lump tooltip.', toggle: true}; -CM.ConfigData.Stats = {label: ['Statistics OFF', 'Statistics ON'], desc: 'Extra Cookie Monster statistics!', toggle: true}; -CM.ConfigData.MissingUpgrades = {label: ['Missing Upgrades OFF', 'Missing Upgrades ON'], desc: 'Shows Missing upgrades in Stats Menu. This feature can be laggy for users with a low amount of unlocked achievements.', toggle: true}; -CM.ConfigData.UpStats = {label: ['Statistics Update Rate (Default)', 'Statistics Update Rate (1s)'], desc: 'Default Game rate is once every 5 seconds', toggle: false}; -CM.ConfigData.TimeFormat = {label: ['Time XXd, XXh, XXm, XXs', 'Time XX:XX:XX:XX:XX'], desc: 'Change the time format', toggle: false}; -CM.ConfigData.SayTime = {label: ['Format Time OFF', 'Format Time ON'], desc: 'Change how time is displayed in statistics', toggle: true, func: function() {CM.Disp.ToggleSayTime();}}; -CM.ConfigData.GrimoireBar = {label: ['Grimoire Magic Meter Timer OFF', 'Grimoire Magic Meter Timer ON'], desc: 'A timer on how long before the Grimoire magic meter is full', toggle: true}; -CM.ConfigData.Scale = {label: ['Game\'s Setting Scale', 'Metric', 'Short Scale', 'Scientific Notation', 'Engineering Notation'], desc: 'Change how long numbers are handled', toggle: false, func: function() {CM.Disp.RefreshScale();}}; -CM.ConfigData.SortBuildings = {label: ['Sort Buildings: Default', 'Sort Buildings: PP'], desc: 'Sort the display of buildings in either default order or by PP', toggle: false, func: function () { CM.Disp.UpdateBuildings();}}; -CM.ConfigData.SortUpgrades = {label: ['Sort Upgrades: Default', 'Sort Upgrades: PP'], desc: 'Sort the display of upgrades in either default order or by PP', toggle: false, func: function () { CM.Disp.UpdateUpgrades();}}; +} \ No newline at end of file diff --git a/src/Data.js b/src/Data.js index f5a8bde..e50b3ba 100644 --- a/src/Data.js +++ b/src/Data.js @@ -31,3 +31,141 @@ CM.Data.HalloCookies = ['Skull cookies', 'Ghost cookies', 'Bat cookies', 'Slime CM.Data.ChristCookies = ['Christmas tree biscuits', 'Snowflake biscuits', 'Snowman biscuits', 'Holly biscuits', 'Candy cane biscuits', 'Bell biscuits', 'Present biscuits']; CM.Data.ValCookies = ['Pure heart biscuits', 'Ardent heart biscuits', 'Sour heart biscuits', 'Weeping heart biscuits', 'Golden heart biscuits', 'Eternal heart biscuits', 'Prism heart biscuits']; + + +/******** + * Section: An array containing all Config groups and their to-be displayed title */ + +CM.ConfigGroups = { + BarsColors: "Bars/Colors", + Calculation: "Calculation", + Notification: "Notification", + Tooltip: "Tooltips", + Statistics: "Statitics", + Other: "Other"}, + +/******** + * Section: An array (CM.ConfigData) containing all Config options + * + * Each array has the following items + * @item {string} type The type of option (bool(ean), vol(ume), url or color) + * @item {string} group The options-group the option belongs to + * @item {[string, ...]} label A list of the various configurations of the option + * @item {string} desc Description to be used in options menu + * @item {boolean} toggle Whether it should be displayed as a grey/white toggle in the options menu + * @item {function} func A function to be called when the option is toggled + */ + +// Barscolors +CM.ConfigData.BotBar = {type: 'bool', group: 'BarsColors', label: ['Bottom Bar OFF', 'Bottom Bar ON'], desc: 'Building Information', toggle: true, func: function() {CM.Disp.ToggleBotBar();}}; +CM.ConfigData.TimerBar = {type: 'bool', group: 'BarsColors', label: ['Timer Bar OFF', 'Timer Bar ON'], desc: 'Timers of Golden Cookie, Season Popup, Frenzy (Normal, Clot, Elder), Click Frenzy', toggle: true, func: function() {CM.Disp.ToggleTimerBar();}}; +CM.ConfigData.TimerBarPos = {type: 'bool', group: 'BarsColors', label: ['Timer Bar Position (Top Left)', 'Timer Bar Position (Bottom)'], desc: 'Placement of the Timer Bar', toggle: false, func: function() {CM.Disp.ToggleTimerBarPos();}}; +CM.ConfigData.SortBuildings = {type: 'bool', group: 'BarsColors', label: ['Sort Buildings: Default', 'Sort Buildings: PP'], desc: 'Sort the display of buildings in either default order or by PP', toggle: false, func: function () { CM.Disp.UpdateBuildings();}}; +CM.ConfigData.SortUpgrades = {type: 'bool', group: 'BarsColors', label: ['Sort Upgrades: Default', 'Sort Upgrades: PP'], desc: 'Sort the display of upgrades in either default order or by PP', toggle: false, func: function () { CM.Disp.UpdateUpgrades();}}; +CM.ConfigData.BuildColor = {type: 'bool', group: 'BarsColors', label: ['Building Colors OFF', 'Building Colors ON'], desc: 'Color code buildings', toggle: true, func: function() {CM.Disp.UpdateBuildings();}}; +CM.ConfigData.BulkBuildColor = {type: 'bool', group: 'BarsColors', label: ['Bulk Building Colors (Single Building Color)', 'Bulk Building Colors (Calculated Bulk Color)'], desc: 'Color code bulk buildings based on single buildings color or calculated bulk value color', toggle: false, func: function() {CM.Disp.UpdateBuildings();}}; +CM.ConfigData.ColorPPBulkMode = {type: 'bool', group: 'BarsColors', label: ['Color of PP (Compared to Single)', 'Color of PP (Compared to Bulk)'], desc: 'Color PP-values based on comparison with single purchase or with selected bulk-buy mode', toggle: false}; +CM.ConfigData.UpBarColor = {type: 'bool', group: 'BarsColors', label: ['Upgrade Colors/Bar OFF', 'Upgrade Colors with Bar ON', 'Upgrade Colors without Bar ON'], desc: 'Color code upgrades and optionally add a counter bar', toggle: false, func: function() {CM.Disp.ToggleUpgradeBarAndColor();}}; +CM.ConfigData.Colors = { type: 'color', group: 'BarsColors', + desc: { + Blue: 'Color Blue. Used to show better than best PP building, for Click Frenzy bar, and for various labels', + Green: 'Color Green. Used to show best PP building, for Blood Frenzy bar, and for various labels', + Yellow: 'Color Yellow. Used to show between best and worst PP buildings closer to best, for Frenzy bar, and for various labels', + Orange: 'Color Orange. Used to show between best and worst PP buildings closer to worst, for Next Reindeer bar, and for various labels', + Red: 'Color Red. Used to show worst PP building, for Clot bar, and for various labels', + Purple: 'Color Purple. Used to show worse than worst PP building, for Next Cookie bar, and for various labels', + Gray: 'Color Gray. Used to show negative or infinity PP, and for Next Cookie/Next Reindeer bar', + Pink: 'Color Pink. Used for Dragonflight bar', + Brown: 'Color Brown. Used for Dragon Harvest bar' + }, + func: function() {CM.Disp.UpdateColors();} +}; +CM.ConfigData.UpgradeBarFixedPos = {type: 'bool', group: 'BarsColors', label: ['Upgrade Bar Fixed Position OFF', 'Upgrade Bar Fixed Position ON'], desc: 'Lock the upgrade bar at top of the screen to prevent it from moving ofscreen when scrolling', toggle: true, func: function() {CM.Disp.ToggleUpgradeBarFixedPos();}}; + +// Calculation +CM.ConfigData.CalcWrink = {type: 'bool', group: 'Calculation', label: ['Calculate with Wrinklers OFF', 'Calculate with Wrinklers ON'], desc: 'Calculate times and average Cookies Per Second with Wrinklers', toggle: true}; +CM.ConfigData.CPSMode = {type: 'bool', group: 'Calculation', label: ['Current Cookies Per Second', 'Average Cookies Per Second'], desc: 'Calculate times using current Cookies Per Second or average Cookies Per Second', toggle: false}; +CM.ConfigData.AvgCPSHist = {type: 'bool', group: 'Calculation', label: ['Average CPS for past 10s', 'Average CPS for past 15s', 'Average CPS for past 30s', 'Average CPS for past 1m', 'Average CPS for past 5m', 'Average CPS for past 10m', 'Average CPS for past 15m', 'Average CPS for past 30m'], desc: 'How much time average Cookies Per Second should consider', toggle: false}; +CM.ConfigData.AvgClicksHist = {type: 'bool', group: 'Calculation', label: ['Average Cookie Clicks for past 1s', 'Average Cookie Clicks for past 5s', 'Average Cookie Clicks for past 10s', 'Average Cookie Clicks for past 15s', 'Average Cookie Clicks for past 30s'], desc: 'How much time average Cookie Clicks should consider', toggle: false}; +CM.ConfigData.ToolWarnBon = {type: 'bool', group: 'Calculation', label: ['Calculate Tooltip Warning With Bonus CPS OFF', 'Calculate Tooltip Warning With Bonus CPS ON'], desc: 'Calculate the warning with or without the bonus CPS you get from buying', toggle: true}; + +// Notification +CM.ConfigData.GCNotification = {type: 'bool', group: 'Notification', label: ['Golden Cookie Notification OFF', 'Golden Cookie Notification ON'], desc: 'Create a notification when Golden Cookie spawns', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Config.GCNotification);}}; +CM.ConfigData.GCFlash = {type: 'bool', group: 'Notification', label: ['Golden Cookie Flash OFF', 'Golden Cookie Flash ON'], desc: 'Flash screen on Golden Cookie', toggle: true}; +CM.ConfigData.GCSound = {type: 'bool', group: 'Notification', label: ['Golden Cookie Sound OFF', 'Golden Cookie Sound ON'], desc: 'Play a sound on Golden Cookie', toggle: true}; +CM.ConfigData.GCVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of the Golden Cookie sound'}; +for (var i = 0; i < 101; i++) { + CM.ConfigData.GCVolume.label[i] = i + '%'; +} +CM.ConfigData.GCSoundURL = {type: 'url', group: 'Notification', label: 'Golden Cookie Sound URL:', desc: 'URL of the sound to be played when a Golden Cookie spawns'}; +CM.ConfigData.GCTimer = {type: 'bool', group: 'Notification', label: ['Golden Cookie Timer OFF', 'Golden Cookie Timer ON'], desc: 'A timer on the Golden Cookie when it has been spawned', toggle: true, func: function() {CM.Disp.ToggleGCTimer();}}; +CM.ConfigData.Favicon = {type: 'bool', group: 'Notification', label: ['Favicon OFF', 'Favicon ON'], desc: 'Update favicon with Golden/Wrath Cookie', toggle: true, func: function() {CM.Disp.UpdateFavicon();}}; +CM.ConfigData.FortuneNotification = {type: 'bool', group: 'Notification', label: ['Fortune Cookie Notification OFF', 'Fortune Cookie Notification ON'], desc: 'Create a notification when Fortune Cookie is on the Ticker', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Config.FortuneNotification);}}; +CM.ConfigData.FortuneFlash = {type: 'bool', group: 'Notification', label: ['Fortune Cookie Flash OFF', 'Fortune Cookie Flash ON'], desc: 'Flash screen on Fortune Cookie', toggle: true}; +CM.ConfigData.FortuneSound = {type: 'bool', group: 'Notification', label: ['Fortune Cookie Sound OFF', 'Fortune Cookie Sound ON'], desc: 'Play a sound on Fortune Cookie', toggle: true}; +CM.ConfigData.FortuneVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of the Fortune Cookie sound'}; +for (var i = 0; i < 101; i++) { + CM.ConfigData.FortuneVolume.label[i] = i + '%'; +} +CM.ConfigData.FortuneSoundURL = {type: 'url', group: 'Notification', label: 'Fortune Cookie Sound URL:', desc: 'URL of the sound to be played when the Ticker has a Fortune Cookie'}; +CM.ConfigData.SeaNotification = {type: 'bool', group: 'Notification', label: ['Season Special Notification OFF', 'Season Special Notification ON'], desc: 'Create a notification on Season Popup', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Config.SeaNotification);}}; +CM.ConfigData.SeaFlash = {type: 'bool', group: 'Notification', label: ['Season Special Flash OFF', 'Season Special Flash ON'], desc: 'Flash screen on Season Popup', toggle: true}; +CM.ConfigData.SeaSound = {type: 'bool', group: 'Notification', label: ['Season Special Sound OFF', 'Season Special Sound ON'], desc: 'Play a sound on Season Popup', toggle: true}; +CM.ConfigData.SeaVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of the Season Special sound'}; +for (var i = 0; i < 101; i++) { + CM.ConfigData.SeaVolume.label[i] = i + '%'; +} +CM.ConfigData.SeaSoundURL = {type: 'url', group: 'Notification', label: 'Season Special Sound URL:', desc: 'URL of the sound to be played when a Season Special spawns'}; +CM.ConfigData.GardFlash = {type: 'bool', group: 'Notification', label: ['Garden Tick Flash OFF', 'Garden Tick Flash ON'], desc: 'Flash screen on Garden Tick', toggle: true}; +CM.ConfigData.GardSound = {type: 'bool', group: 'Notification', label: ['Garden Tick Sound OFF', 'Garden Tick Sound ON'], desc: 'Play a sound on Garden Tick', toggle: true}; +CM.ConfigData.GardVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of the Garden Tick sound'}; +for (var i = 0; i < 101; i++) { + CM.ConfigData.GardVolume.label[i] = i + '%'; +} +CM.ConfigData.GardSoundURL = {type: 'url', group: 'Notification', label: 'Garden Tick Sound URL:', desc: 'URL of the sound to be played when the garden ticks'}; +CM.ConfigData.MagicNotification = {type: 'bool', group: 'Notification', label: ['Magic Max Notification OFF', 'Magic Max Notification ON'], desc: 'Create a notification when magic reaches maximum', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Config.MagicNotification);}}; +CM.ConfigData.MagicFlash = {type: 'bool', group: 'Notification', label: ['Magic Max Flash OFF', 'Magic Max Flash ON'], desc: 'Flash screen when magic reaches maximum', toggle: true}; +CM.ConfigData.MagicSound = {type: 'bool', group: 'Notification', label: ['Magic Max Sound OFF', 'Magic Max Sound ON'], desc: 'Play a sound when magic reaches maximum', toggle: true}; +CM.ConfigData.MagicVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of the Max Magic sound'}; +for (var i = 0; i < 101; i++) { + CM.ConfigData.MagicVolume.label[i] = i + '%'; +} +CM.ConfigData.MagicSoundURL = {type: 'url', group: 'Notification', label: 'Magic Max Sound URL:', desc: 'URL of the sound to be played when magic reaches maxium'}; +CM.ConfigData.WrinklerNotification = {type: 'bool', group: 'Notification', label: ['Wrinkler Notification OFF', 'Wrinkler Notification ON'], desc: 'Create a notification when a Wrinkler appears', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Config.WrinklerNotification);}}; +CM.ConfigData.WrinklerFlash = {type: 'bool', group: 'Notification', label: ['Wrinkler Flash OFF', 'Wrinkler Flash ON'], desc: 'Flash screen when a Wrinkler appears', toggle: true}; +CM.ConfigData.WrinklerSound = {type: 'bool', group: 'Notification', label: ['Wrinkler Sound OFF', 'Wrinkler Sound ON'], desc: 'Play a sound when a Wrinkler appears', toggle: true}; +CM.ConfigData.WrinklerVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of the Wrinkler sound'}; +for (var i = 0; i < 101; i++) { + CM.ConfigData.WrinklerVolume.label[i] = i + '%'; +} +CM.ConfigData.WrinklerSoundURL = {type: 'url', group: 'Notification', label: 'Wrinkler Sound URL:', desc: 'URL of the sound to be played when a Wrinkler appears'}; +CM.ConfigData.WrinklerMaxNotification = {type: 'bool', group: 'Notification', label: ['Wrinkler Max Notification OFF', 'Wrinkler Max Notification ON'], desc: 'Create a notification when the maximum amount of Wrinklers has appeared', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Config.WrinklerMaxNotification);}}; +CM.ConfigData.WrinklerMaxFlash = {type: 'bool', group: 'Notification', label: ['Wrinkler Max Flash OFF', 'Wrinkler Max Flash ON'], desc: 'Flash screen when the maximum amount of Wrinklers has appeared', toggle: true}; +CM.ConfigData.WrinklerMaxSound = {type: 'bool', group: 'Notification', label: ['Wrinkler Max Sound OFF', 'Wrinkler Max Sound ON'], desc: 'Play a sound when the maximum amount of Wrinklers has appeared', toggle: true}; +CM.ConfigData.WrinklerMaxVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of the Wrinkler Max sound'}; +for (var i = 0; i < 101; i++) { + CM.ConfigData.WrinklerMaxVolume.label[i] = i + '%'; +} +CM.ConfigData.WrinklerMaxSoundURL = {type: 'url', group: 'Notification', label: 'Wrinkler Max Sound URL:', desc: 'URL of the sound to be played when the maximum amount of Wrinklers has appeared'}; +CM.ConfigData.Title = {type: 'bool', group: 'Notification', label: ['Title OFF', 'Title ON', 'Title Pinned Tab Highlight'], desc: 'Update title with Golden Cookie/Season Popup timers; pinned tab highlight only changes the title when a Golden Cookie/Season Popup spawns', toggle: true}; + +// Tooltip +CM.ConfigData.TooltipBuildUp = {type: 'bool', group: 'Tooltip', label: ['Buildings/Upgrades Tooltip Information OFF', 'Buildings/Upgrades Tooltip Information ON'], desc: 'Extra information in tooltip for buildings/upgrades', toggle: true}; +CM.ConfigData.TooltipAmor = {type: 'bool', group: 'Tooltip', label: ['Buildings Tooltip Amortization Information OFF', 'Buildings Tooltip Amortization Information ON'], desc: 'Add amortization information to buildings tooltip', toggle: true}; +CM.ConfigData.ToolWarnLucky = {type: 'bool', group: 'Tooltip', label: ['Tooltip Lucky Warning OFF', 'Tooltip Lucky Warning ON'], desc: 'A warning when buying if it will put the bank under the amount needed for max "Lucky!"/"Lucky!" (Frenzy) rewards', toggle: true}; +CM.ConfigData.ToolWarnConjure = {type: 'bool', group: 'Tooltip', label: ['Tooltip Conjure Warning OFF', 'Tooltip Conjure Warning ON'], desc: 'A warning when buying if it will put the bank under the amount needed for max "Conjure Baked Goods" rewards', toggle: true}; +CM.ConfigData.ToolWarnPos = {type: 'bool', group: 'Tooltip', label: ['Tooltip Warning Position (Left)', 'Tooltip Warning Position (Bottom)'], desc: 'Placement of the warning boxes', toggle: false, func: function() {CM.Disp.ToggleToolWarnPos();}}; +CM.ConfigData.TooltipGrim = {type: 'bool', group: 'Tooltip', label: ['Grimoire Tooltip Information OFF', 'Grimoire Tooltip Information ON'], desc: 'Extra information in tooltip for grimoire', toggle: true}; +CM.ConfigData.ToolWrink = {type: 'bool', group: 'Tooltip', label: ['Wrinkler Tooltip OFF', 'Wrinkler Tooltip ON'], desc: 'Shows the amount of cookies a wrinkler will give when popping it', toggle: true}; +CM.ConfigData.TooltipLump = {type: 'bool', group: 'Tooltip', label: ['Sugar Lump Tooltip OFF', 'Sugar Lump Tooltip ON'], desc: 'Shows the current Sugar Lump type in Sugar lump tooltip.', toggle: true}; + +// Statistics +CM.ConfigData.Stats = {type: 'bool', group: 'Statistics', label: ['Statistics OFF', 'Statistics ON'], desc: 'Extra Cookie Monster statistics!', toggle: true}; +CM.ConfigData.MissingUpgrades = {type: 'bool', group: 'Statistics', label: ['Missing Upgrades OFF', 'Missing Upgrades ON'], desc: 'Shows Missing upgrades in Stats Menu. This feature can be laggy for users with a low amount of unlocked achievements.', toggle: true}; +CM.ConfigData.UpStats = {type: 'bool', group: 'Statistics', label: ['Statistics Update Rate (Default)', 'Statistics Update Rate (1s)'], desc: 'Default Game rate is once every 5 seconds', toggle: false}; +CM.ConfigData.TimeFormat = {type: 'bool', group: 'Statistics', label: ['Time XXd, XXh, XXm, XXs', 'Time XX:XX:XX:XX:XX'], desc: 'Change the time format', toggle: false}; +CM.ConfigData.SayTime = {type: 'bool', group: 'Statistics', label: ['Format Time OFF', 'Format Time ON'], desc: 'Change how time is displayed in statistics', toggle: true, func: function() {CM.Disp.ToggleSayTime();}}; +CM.ConfigData.GrimoireBar = {type: 'bool', group: 'Statistics', label: ['Grimoire Magic Meter Timer OFF', 'Grimoire Magic Meter Timer ON'], desc: 'A timer on how long before the Grimoire magic meter is full', toggle: true}; + +// Statistics +CM.ConfigData.Scale = {type: 'bool', group: 'Other', label: ['Game\'s Setting Scale', 'Metric', 'Short Scale', 'Scientific Notation', 'Engineering Notation'], desc: 'Change how long numbers are handled', toggle: false, func: function() {CM.Disp.RefreshScale();}}; \ No newline at end of file diff --git a/src/Disp.js b/src/Disp.js index 9fa5c00..280417d 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -971,7 +971,7 @@ CM.Disp.CreateUpgradeBarLegend = function() { /** * This function creates a white square over the full screen and appends it to l('wrapper') - * It is used (and called) by CM.Disp.Flash() to create the effect of a flash + * It is used by CM.Disp.Flash() to create the effect of a flash and called by CM.DelayInit() */ CM.Disp.CreateWhiteScreen = function() { CM.Disp.WhiteScreen = document.createElement('div'); @@ -1893,40 +1893,84 @@ CM.Disp.RefreshMenu = function() { } /******** - * Section: Functions related to the Options page - * TODO: Annotate functions */ - -CM.Disp.AddMenuPref = function(title) { - var header = function(text, config) { - var div = document.createElement('div'); - div.className = 'listing'; - div.style.padding = '5px 16px'; - div.style.opacity = '0.7'; - div.style.fontSize = '17px'; - div.style.fontFamily = '\"Kavoon\", Georgia, serif'; - div.appendChild(document.createTextNode(text + ' ')); - var span = document.createElement('span'); - span.style.cursor = 'pointer'; - span.style.display = 'inline-block'; - span.style.height = '14px'; - span.style.width = '14px'; - span.style.borderRadius = '7px'; - span.style.textAlign = 'center'; - span.style.backgroundColor = '#C0C0C0'; - span.style.color = 'black'; - span.style.fontSize = '13px'; - span.style.verticalAlign = 'middle'; - span.textContent = CM.Config.MenuPref[config] ? '-' : '+'; - span.onclick = function() {CM.ToggleMenuConfig(config); Game.UpdateMenu();}; - div.appendChild(span); - return div; - } + * Section: Functions related to the Options/Preferences page +/** + * This function adds the options/settings of CookieMonster to the options page + * It is called by CM.Disp.AddMenu + * @param {function} title A function that returns the title of CookieMonster pre-styled + */ +CM.Disp.AddMenuPref = function(title) { var frag = document.createDocumentFragment(); - frag.appendChild(title()); - var listing = function(config) { + for (var group in CM.ConfigGroups) { + groupObject = CM.Disp.CreatePrefHeader(group, CM.ConfigGroups[group]) // (group, display-name of group) + frag.appendChild(groupObject) + if (CM.Config.OptionsPref[group]) { // 0 is show, 1 is collapsed + for (var option in CM.ConfigData) { + if (CM.ConfigData[option].group == group) frag.appendChild(CM.Disp.CreatePrefOption(option)) + } + } + } + + var resDef = document.createElement('div'); + resDef.className = 'listing'; + var resDefBut = document.createElement('a'); + resDefBut.className = 'option'; + resDefBut.onclick = function() {CM.RestoreDefault();}; + resDefBut.textContent = 'Restore Default'; + resDef.appendChild(resDefBut); + frag.appendChild(resDef); + + l('menu').childNodes[2].insertBefore(frag, l('menu').childNodes[2].childNodes[l('menu').childNodes[2].childNodes.length - 1]); + + // TODO: What does this do? @DanielNoord + CM.Disp.FormatButtonOnClickBak = l('formatButton').onclick; + eval('l(\'formatButton\').onclick = ' + l('formatButton').onclick.toString().split('mp3\');').join('mp3\'); CM.Disp.RefreshScale();')); + //l('formatButton').onclick = function() {Game.Toggle('format', 'formatButton', 'Short numbers OFF', 'Short numbers ON', '1'); PlaySound('snd/tick.mp3'); CM.Disp.RefreshScale();}; +} + +/** + * This function creates a header-object for the options page + * It is called by CM.Disp.AddMenuPref() + * @param {string} config The name of the Config-group + * @param {string} text The to-be displayed name of the header + * @returns {object} div The header object + */ +CM.Disp.CreatePrefHeader = function(config, text) { + var div = document.createElement('div'); + div.className = 'listing'; + div.style.padding = '5px 16px'; + div.style.opacity = '0.7'; + div.style.fontSize = '17px'; + div.style.fontFamily = '\"Kavoon\", Georgia, serif'; + div.appendChild(document.createTextNode(text + ' ')); + var span = document.createElement('span'); // Creates the +/- button + span.style.cursor = 'pointer'; + span.style.display = 'inline-block'; + span.style.height = '14px'; + span.style.width = '14px'; + span.style.borderRadius = '7px'; + span.style.textAlign = 'center'; + span.style.backgroundColor = '#C0C0C0'; + span.style.color = 'black'; + span.style.fontSize = '13px'; + span.style.verticalAlign = 'middle'; + span.textContent = CM.Config.OptionsPref[config] ? '-' : '+'; + span.onclick = function() {CM.ToggleOptionsConfig(config); Game.UpdateMenu();}; + div.appendChild(span); + return div; +} + +/** + * This function creates an option-object for the options page + * It is called by CM.Disp.AddMenuPref() + * @param {string} config The name of the option + * @returns {object} div The option object + */ +CM.Disp.CreatePrefOption = function(config) { + if (CM.ConfigData[config].type == "bool") { var div = document.createElement('div'); div.className = 'listing'; var a = document.createElement('a'); @@ -1945,8 +1989,7 @@ CM.Disp.AddMenuPref = function(title) { div.appendChild(label); return div; } - - var vol = function(config) { + else if (CM.ConfigData[config].type == "vol") { var volConfig = config; var volume = document.createElement('div'); volume.className = 'listing'; @@ -1969,8 +2012,7 @@ CM.Disp.AddMenuPref = function(title) { volume.appendChild(volLabel); return volume; } - - var url = function(config) { + else if (CM.ConfigData[config].type == "url") { var div = document.createElement('div'); div.className = 'listing'; var span = document.createElement('span'); @@ -2001,18 +2043,7 @@ CM.Disp.AddMenuPref = function(title) { div.appendChild(label); return div; } - - frag.appendChild(header('Bars/Colors', 'BarsColors')); - if (CM.Config.MenuPref.BarsColors) { - frag.appendChild(listing('BotBar')); - frag.appendChild(listing('TimerBar')); - frag.appendChild(listing('TimerBarPos')); - frag.appendChild(listing('SortBuildings')); - frag.appendChild(listing('SortUpgrades')); - frag.appendChild(listing('BuildColor')); - frag.appendChild(listing('BulkBuildColor')); - frag.appendChild(listing('ColorPPBulkMode')); - frag.appendChild(listing('UpBarColor')); + else if (CM.ConfigData[config].type == "color") { for (var i = 0; i < CM.Disp.colors.length; i++) { var div = document.createElement('div'); div.className = 'listing'; @@ -2027,101 +2058,9 @@ CM.Disp.AddMenuPref = function(title) { var label = document.createElement('label'); label.textContent = CM.ConfigData.Colors.desc[CM.Disp.colors[i]]; div.appendChild(label); - frag.appendChild(div); + return div; } - frag.appendChild(listing('UpgradeBarFixedPos')); } - - frag.appendChild(header('Calculation', 'Calculation')); - if (CM.Config.MenuPref.Calculation) { - frag.appendChild(listing('CalcWrink')); - frag.appendChild(listing('CPSMode')); - frag.appendChild(listing('AvgCPSHist')); - frag.appendChild(listing('AvgClicksHist')); - frag.appendChild(listing('ToolWarnBon')); - } - - frag.appendChild(header('Notification', 'Notification')); - if (CM.Config.MenuPref.Notification) { - frag.appendChild(listing('GCNotification')); - frag.appendChild(listing('GCFlash')); - frag.appendChild(listing('GCSound')); - frag.appendChild(vol('GCVolume')); - frag.appendChild(url('GCSoundURL')); - frag.appendChild(listing('GCTimer')); - frag.appendChild(listing('Favicon')); - frag.appendChild(listing('FortuneNotification')); - frag.appendChild(listing('FortuneFlash')); - frag.appendChild(listing('FortuneSound')); - frag.appendChild(vol('FortuneVolume')); - frag.appendChild(url('FortuneSoundURL')); - frag.appendChild(listing('SeaNotification')); - frag.appendChild(listing('SeaFlash')); - frag.appendChild(listing('SeaSound')); - frag.appendChild(vol('SeaVolume')); - frag.appendChild(url('SeaSoundURL')); - frag.appendChild(listing('GardFlash')); - frag.appendChild(listing('GardSound')); - frag.appendChild(vol('GardVolume')); - frag.appendChild(url('GardSoundURL')); - frag.appendChild(listing('MagicNotification')); - frag.appendChild(listing('MagicFlash')); - frag.appendChild(listing('MagicSound')); - frag.appendChild(vol('MagicVolume')); - frag.appendChild(url('MagicSoundURL')); - frag.appendChild(listing('WrinklerNotification')); - frag.appendChild(listing('WrinklerFlash')); - frag.appendChild(listing('WrinklerSound')); - frag.appendChild(vol('WrinklerVolume')); - frag.appendChild(url('WrinklerSoundURL')); - frag.appendChild(listing('WrinklerMaxNotification')); - frag.appendChild(listing('WrinklerMaxFlash')); - frag.appendChild(listing('WrinklerMaxSound')); - frag.appendChild(vol('WrinklerMaxVolume')); - frag.appendChild(url('WrinklerMaxSoundURL')); - frag.appendChild(listing('Title')); - } - - frag.appendChild(header('Tooltip', 'Tooltip')); - if (CM.Config.MenuPref.Tooltip) { - frag.appendChild(listing('TooltipBuildUp')); - frag.appendChild(listing('TooltipAmor')); - frag.appendChild(listing('ToolWarnLucky')); - frag.appendChild(listing('ToolWarnConjure')); - frag.appendChild(listing('ToolWarnPos')); - frag.appendChild(listing('TooltipGrim')); - frag.appendChild(listing('ToolWrink')); - frag.appendChild(listing('TooltipLump')); - } - - frag.appendChild(header('Statistics', 'Statistics')); - if (CM.Config.MenuPref.Statistics) { - frag.appendChild(listing('Stats')); - frag.appendChild(listing('MissingUpgrades')); - frag.appendChild(listing('UpStats')); - frag.appendChild(listing('TimeFormat')); - frag.appendChild(listing('SayTime')); - frag.appendChild(listing('GrimoireBar')); - } - - frag.appendChild(header('Other', 'Other')); - if (CM.Config.MenuPref.Other) { - frag.appendChild(listing('Scale')); - var resDef = document.createElement('div'); - resDef.className = 'listing'; - var resDefBut = document.createElement('a'); - resDefBut.className = 'option'; - resDefBut.onclick = function() {CM.RestoreDefault();}; - resDefBut.textContent = 'Restore Default'; - resDef.appendChild(resDefBut); - frag.appendChild(resDef); - } - - l('menu').childNodes[2].insertBefore(frag, l('menu').childNodes[2].childNodes[l('menu').childNodes[2].childNodes.length - 1]); - - CM.Disp.FormatButtonOnClickBak = l('formatButton').onclick; - eval('l(\'formatButton\').onclick = ' + l('formatButton').onclick.toString().split('mp3\');').join('mp3\'); CM.Disp.RefreshScale();')); - //l('formatButton').onclick = function() {Game.Toggle('format', 'formatButton', 'Short numbers OFF', 'Short numbers ON', '1'); PlaySound('snd/tick.mp3'); CM.Disp.RefreshScale();}; } /******** diff --git a/src/Main.js b/src/Main.js index 1ee0d57..4c168ac 100644 --- a/src/Main.js +++ b/src/Main.js @@ -326,7 +326,7 @@ CM.ConfigDefault = { SayTime: 1, GrimoireBar: 1, Scale: 2, - MenuPref: {BarsColors: 1, Calculation: 1, Notification: 1, Tooltip: 1, Statistics: 1, Other: 1}, + OptionsPref: {BarsColors: 1, Calculation: 1, Notification: 1, Tooltip: 1, Statistics: 1, Other: 1}, StatsPref: {Lucky: 1, Conjure: 1, Chain: 1, Prestige: 1, Wrink: 1, Sea: 1, Misc: 1}, Colors : {Blue: '#4bb8f0', Green: '#00ff00', Yellow: '#ffff00', Orange: '#ff7f00', Red: '#ff0000', Purple: '#ff00ff', Gray: '#b3b3b3', Pink: '#ff1493', Brown: '#8b4513'}, SortBuildings: 0, From 95f19fbfd73923e6a396579904ee529bd2f0df1b Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Thu, 3 Dec 2020 15:28:38 +0100 Subject: [PATCH 013/106] Fixded CM.Disp.GetTimeColor --- CookieMonster.js | 16 ++++++++++++---- src/Disp.js | 16 ++++++++++++---- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index 92dc614..55c23a6 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -1188,10 +1188,18 @@ CM.Disp.FormatTime = function(time, longFormat) { */ CM.Disp.GetTimeColor = function(time) { var color; - var text = CM.Disp.FormatTime(time); - if (time > 300) color = CM.Disp.colorRed; - else if (time > 60) color = CM.Disp.colorOrange; - else color = CM.Disp.colorYellow; + var text; + if (time < 0) { + if (CM.Config.TimeFormat) text = '00:00:00:00:00'; + else text = 'Done!'; + color = CM.Disp.colorGreen; + } + else { + text = CM.Disp.FormatTime(time); + if (time > 300) color = CM.Disp.colorRed; + else if (time > 60) color = CM.Disp.colorOrange; + else color = CM.Disp.colorYellow; + } return {text: text, color: color}; } diff --git a/src/Disp.js b/src/Disp.js index 280417d..67fae59 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -313,10 +313,18 @@ CM.Disp.FormatTime = function(time, longFormat) { */ CM.Disp.GetTimeColor = function(time) { var color; - var text = CM.Disp.FormatTime(time); - if (time > 300) color = CM.Disp.colorRed; - else if (time > 60) color = CM.Disp.colorOrange; - else color = CM.Disp.colorYellow; + var text; + if (time < 0) { + if (CM.Config.TimeFormat) text = '00:00:00:00:00'; + else text = 'Done!'; + color = CM.Disp.colorGreen; + } + else { + text = CM.Disp.FormatTime(time); + if (time > 300) color = CM.Disp.colorRed; + else if (time > 60) color = CM.Disp.colorOrange; + else color = CM.Disp.colorYellow; + } return {text: text, color: color}; } From e3861f1ffe3e74450f1f32dbcb22538ced047e78 Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Wed, 2 Dec 2020 21:53:19 +0100 Subject: [PATCH 014/106] Cleaned CM.Disp.FormatTime --- CookieMonster.js | 65 +++++++++++++++--------------------------------- src/Disp.js | 65 +++++++++++++++--------------------------------- 2 files changed, 40 insertions(+), 90 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index 9c9b1cf..b244f19 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -844,55 +844,30 @@ CM.Data.ValCookies = ['Pure heart biscuits', 'Ardent heart biscuits', 'Sour hear * Disp * ********/ -CM.Disp.FormatTime = function(time, format) { +// General functions to format or beautify strings + +CM.Disp.FormatTime = function(time, longFormat) { if (time == Infinity) return time; + time = Math.ceil(time); + var y = Math.floor(time / 31557600); + var d = Math.floor(time % 31557600 / 86400); + var h = Math.floor(time % 86400 / 3600); + var m = Math.floor(time % 3600 / 60); + var s = Math.floor(time % 60); + var str = ''; if (CM.Config.TimeFormat) { if (time > 3155760000) return 'XX:XX:XX:XX:XX'; - time = Math.ceil(time); - var y = Math.floor(time / 31557600); - var d = Math.floor(time % 31557600 / 86400); - var h = Math.floor(time % 86400 / 3600); - var m = Math.floor(time % 3600 / 60); - var s = Math.floor(time % 60); - var str = ''; - if (y < 10) { - str += '0'; - } - str += y + ':'; - if (d < 10) { - str += '0'; - } - str += d + ':'; - if (h < 10) { - str += '0'; - } - str += h + ':'; - if (m < 10) { - str += '0'; - } - str += m + ':'; - if (s < 10) { - str += '0'; - } - str += s; + str += (y < 10 ? '0' : '') + y + ':'; + str += (d < 10 ? '0' : '') + d + ':'; + str += (h < 10 ? '0' : '') + h + ':'; + str += (m < 10 ? '0' : '') + m + ':'; + str += (s < 10 ? '0' : '') + s + ':'; } else { - if (time > 777600000) return format ? 'Over 9000 days!' : '>9000d'; - time = Math.ceil(time); - var d = Math.floor(time / 86400); - var h = Math.floor(time % 86400 / 3600); - var m = Math.floor(time % 3600 / 60); - var s = Math.floor(time % 60); - var str = ''; - if (d > 0) { - str += d + (format ? (d == 1 ? ' day' : ' days') : 'd') + ', '; - } - if (str.length > 0 || h > 0) { - str += h + (format ? (h == 1 ? ' hour' : ' hours') : 'h') + ', '; - } - if (str.length > 0 || m > 0) { - str += m + (format ? (m == 1 ? ' minute' : ' minutes') : 'm') + ', '; - } - str += s + (format ? (s == 1 ? ' second' : ' seconds') : 's'); + if (time > 777600000) return longFormat ? 'Over 9000 days!' : '>9000d'; + str += (d > 0 ? d + (longFormat ? (d == 1 ? ' day' : ' days') : 'd') + ', ': ""); + if (str.length > 0 || h > 0) str += h + (longFormat ? (h == 1 ? ' hour' : ' hours') : 'h') + ', '; + if (str.length > 0 || m > 0) str += m + (longFormat ? (m == 1 ? ' minute' : ' minutes') : 'm') + ', '; + str += s + (longFormat ? (s == 1 ? ' second' : ' seconds') : 's'); } return str; } diff --git a/src/Disp.js b/src/Disp.js index b5667dd..1845216 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -2,55 +2,30 @@ * Disp * ********/ -CM.Disp.FormatTime = function(time, format) { +// General functions to format or beautify strings + +CM.Disp.FormatTime = function(time, longFormat) { if (time == Infinity) return time; + time = Math.ceil(time); + var y = Math.floor(time / 31557600); + var d = Math.floor(time % 31557600 / 86400); + var h = Math.floor(time % 86400 / 3600); + var m = Math.floor(time % 3600 / 60); + var s = Math.floor(time % 60); + var str = ''; if (CM.Config.TimeFormat) { if (time > 3155760000) return 'XX:XX:XX:XX:XX'; - time = Math.ceil(time); - var y = Math.floor(time / 31557600); - var d = Math.floor(time % 31557600 / 86400); - var h = Math.floor(time % 86400 / 3600); - var m = Math.floor(time % 3600 / 60); - var s = Math.floor(time % 60); - var str = ''; - if (y < 10) { - str += '0'; - } - str += y + ':'; - if (d < 10) { - str += '0'; - } - str += d + ':'; - if (h < 10) { - str += '0'; - } - str += h + ':'; - if (m < 10) { - str += '0'; - } - str += m + ':'; - if (s < 10) { - str += '0'; - } - str += s; + str += (y < 10 ? '0' : '') + y + ':'; + str += (d < 10 ? '0' : '') + d + ':'; + str += (h < 10 ? '0' : '') + h + ':'; + str += (m < 10 ? '0' : '') + m + ':'; + str += (s < 10 ? '0' : '') + s + ':'; } else { - if (time > 777600000) return format ? 'Over 9000 days!' : '>9000d'; - time = Math.ceil(time); - var d = Math.floor(time / 86400); - var h = Math.floor(time % 86400 / 3600); - var m = Math.floor(time % 3600 / 60); - var s = Math.floor(time % 60); - var str = ''; - if (d > 0) { - str += d + (format ? (d == 1 ? ' day' : ' days') : 'd') + ', '; - } - if (str.length > 0 || h > 0) { - str += h + (format ? (h == 1 ? ' hour' : ' hours') : 'h') + ', '; - } - if (str.length > 0 || m > 0) { - str += m + (format ? (m == 1 ? ' minute' : ' minutes') : 'm') + ', '; - } - str += s + (format ? (s == 1 ? ' second' : ' seconds') : 's'); + if (time > 777600000) return longFormat ? 'Over 9000 days!' : '>9000d'; + str += (d > 0 ? d + (longFormat ? (d == 1 ? ' day' : ' days') : 'd') + ', ': ""); + if (str.length > 0 || h > 0) str += h + (longFormat ? (h == 1 ? ' hour' : ' hours') : 'h') + ', '; + if (str.length > 0 || m > 0) str += m + (longFormat ? (m == 1 ? ' minute' : ' minutes') : 'm') + ', '; + str += s + (longFormat ? (s == 1 ? ' second' : ' seconds') : 's'); } return str; } From 406741039735f7af025595f1ec53d79733c96541 Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Wed, 2 Dec 2020 21:55:57 +0100 Subject: [PATCH 015/106] Added annotations to CM.Disp.FormatTime --- CookieMonster.js | 4 ++++ src/Disp.js | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/CookieMonster.js b/CookieMonster.js index b244f19..7544678 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -846,6 +846,10 @@ CM.Data.ValCookies = ['Pure heart biscuits', 'Ardent heart biscuits', 'Sour hear // General functions to format or beautify strings +/** + * This function returns time as a string depending on TimeFormat setting + * @param type Time as number, longFormat 1 or 0. + */ CM.Disp.FormatTime = function(time, longFormat) { if (time == Infinity) return time; time = Math.ceil(time); diff --git a/src/Disp.js b/src/Disp.js index 1845216..1263661 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -4,6 +4,10 @@ // General functions to format or beautify strings +/** + * This function returns time as a string depending on TimeFormat setting + * @param type Time as number, longFormat 1 or 0. + */ CM.Disp.FormatTime = function(time, longFormat) { if (time == Infinity) return time; time = Math.ceil(time); From 08e005b9db3238507388e5534418def242e56bb2 Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Wed, 2 Dec 2020 22:23:17 +0100 Subject: [PATCH 016/106] Reorgainzed src/Disp.js --- CookieMonster.js | 1865 ++++++++++++++++++++++++---------------------- src/Disp.js | 1865 ++++++++++++++++++++++++---------------------- 2 files changed, 1924 insertions(+), 1806 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index 7544678..3a3b3e9 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -844,37 +844,10 @@ CM.Data.ValCookies = ['Pure heart biscuits', 'Ardent heart biscuits', 'Sour hear * Disp * ********/ -// General functions to format or beautify strings - -/** - * This function returns time as a string depending on TimeFormat setting - * @param type Time as number, longFormat 1 or 0. - */ -CM.Disp.FormatTime = function(time, longFormat) { - if (time == Infinity) return time; - time = Math.ceil(time); - var y = Math.floor(time / 31557600); - var d = Math.floor(time % 31557600 / 86400); - var h = Math.floor(time % 86400 / 3600); - var m = Math.floor(time % 3600 / 60); - var s = Math.floor(time % 60); - var str = ''; - if (CM.Config.TimeFormat) { - if (time > 3155760000) return 'XX:XX:XX:XX:XX'; - str += (y < 10 ? '0' : '') + y + ':'; - str += (d < 10 ? '0' : '') + d + ':'; - str += (h < 10 ? '0' : '') + h + ':'; - str += (m < 10 ? '0' : '') + m + ':'; - str += (s < 10 ? '0' : '') + s + ':'; - } else { - if (time > 777600000) return longFormat ? 'Over 9000 days!' : '>9000d'; - str += (d > 0 ? d + (longFormat ? (d == 1 ? ' day' : ' days') : 'd') + ', ': ""); - if (str.length > 0 || h > 0) str += h + (longFormat ? (h == 1 ? ' hour' : ' hours') : 'h') + ', '; - if (str.length > 0 || m > 0) str += m + (longFormat ? (m == 1 ? ' minute' : ' minutes') : 'm') + ', '; - str += s + (longFormat ? (s == 1 ? ' second' : ' seconds') : 's'); - } - return str; -} +/******** + * Section: Unsorted functions + * TODO: Annotate most functions + * TODO: Sort functionsn in relevant (new) sections or files */ CM.Disp.GetTimeColor = function(price, bank, cps, time) { var color; @@ -949,6 +922,279 @@ CM.Disp.GetLumpColor = function(type) { return {text: name, color: color}; }; +CM.Disp.GetWrinkConfigBank = function() { + if (CM.Config.CalcWrink) + return CM.Cache.WrinkBank; + else + return 0; +} + +CM.Disp.GetCPS = function() { + if (CM.Config.CPSMode) + return CM.Cache.AvgCPS; + else + return (Game.cookiesPs * (1 - Game.cpsSucked)); +} + +CM.Disp.UpdateBackground = function() { + Game.Background.canvas.width = Game.Background.canvas.parentNode.offsetWidth; + Game.Background.canvas.height = Game.Background.canvas.parentNode.offsetHeight; + Game.LeftBackground.canvas.width = Game.LeftBackground.canvas.parentNode.offsetWidth; + Game.LeftBackground.canvas.height = Game.LeftBackground.canvas.parentNode.offsetHeight; +} + +CM.Disp.GetConfigDisplay = function(config) { + return CM.ConfigData[config].label[CM.Config[config]]; +} + +CM.Disp.AddJscolor = function() { + CM.Disp.Jscolor = document.createElement('script'); + CM.Disp.Jscolor.type = 'text/javascript'; + CM.Disp.Jscolor.setAttribute('src', 'https://aktanusa.github.io/CookieMonster/jscolor/jscolor.js'); + document.head.appendChild(CM.Disp.Jscolor); +} + +CM.Disp.CreateCssArea = function() { + CM.Disp.Css = document.createElement('style'); + CM.Disp.Css.type = 'text/css'; + + document.head.appendChild(CM.Disp.Css); + + // given the architecture of your code, you probably want these lines somewhere else, + // but I stuck them here for convenience + l("products").style.display = "grid"; + l("storeBulk").style.gridRow = "1/1"; + + l("upgrades").style.display = "flex"; + l("upgrades").style["flex-wrap"] = "wrap"; +} + +CM.Disp.UpdateUpgrades = function() { + if (CM.Config.UpBarColor > 0) { + var blue = 0; + var green = 0; + var yellow = 0; + var orange = 0; + var red = 0; + var purple = 0; + var gray = 0; + + for (var i in Game.UpgradesInStore) { + var me = Game.UpgradesInStore[i]; + var addedColor = false; + for (var j = 0; j < l('upgrade' + i).childNodes.length; j++) { + if (l('upgrade' + i).childNodes[j].className.indexOf(CM.Disp.colorBackPre) != -1) { + l('upgrade' + i).childNodes[j].className = CM.Disp.colorBackPre + CM.Cache.Upgrades[me.name].color; + addedColor = true; + break; + } + } + if (!addedColor) { + var div = document.createElement('div'); + div.style.width = '10px'; + div.style.height = '10px'; + div.className = CM.Disp.colorBackPre + CM.Cache.Upgrades[me.name].color; + l('upgrade' + i).appendChild(div); + } + if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorBlue) blue++; + else if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorGreen) green++; + else if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorYellow) yellow++; + else if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorOrange) orange++; + else if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorRed) red++; + else if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorPurple) purple++; + else if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorGray) gray++; + } + + l('CMUpgradeBarBlue').textContent = blue; + l('CMUpgradeBarGreen').textContent = green; + l('CMUpgradeBarYellow').textContent = yellow; + l('CMUpgradeBarOrange').textContent = orange; + l('CMUpgradeBarRed').textContent = red; + l('CMUpgradeBarPurple').textContent = purple; + l('CMUpgradeBarGray').textContent = gray; + } + + // Build array of pointers, sort by pp, set flex positions + var arr = []; + for (var x = 0; x < Game.UpgradesInStore.length; x++){ + var o = {}; + o.name = Game.UpgradesInStore[x].name; + o.price = Game.UpgradesInStore[x].basePrice; + o.pp = CM.Cache.Upgrades[o.name].pp; + arr.push(o); + } + + if (CM.Config.SortUpgrades) + arr.sort((a, b) => a.pp - b.pp); + else + arr.sort((a, b) => a.price - b.price); + + for (var x = 0; x < Game.UpgradesInStore.length; x++){ + l("upgrade" + x).style.order = arr.findIndex(e => e.name === Game.UpgradesInStore[x].name) + 1 + } +} + +CM.Disp.UpdateColors = function() { + var str = ''; + for (var i = 0; i < CM.Disp.colors.length; i++) { + str += '.' + CM.Disp.colorTextPre + CM.Disp.colors[i] + ' { color: ' + CM.Config.Colors[CM.Disp.colors[i]] + '; }\n'; + } + for (var i = 0; i < CM.Disp.colors.length; i++) { + str += '.' + CM.Disp.colorBackPre + CM.Disp.colors[i] + ' { background-color: ' + CM.Config.Colors[CM.Disp.colors[i]] + '; }\n'; + } + for (var i = 0; i < CM.Disp.colors.length; i++) { + str += '.' + CM.Disp.colorBorderPre + CM.Disp.colors[i] + ' { border: 1px solid ' + CM.Config.Colors[CM.Disp.colors[i]] + '; }\n'; + } + CM.Disp.Css.textContent = str; + CM.Disp.UpdateBuildings(); // Class has been already set +} + +CM.Disp.CreateWhiteScreen = function() { + CM.Disp.WhiteScreen = document.createElement('div'); + CM.Disp.WhiteScreen.id = 'CMWhiteScreen'; + CM.Disp.WhiteScreen.style.width = '100%'; + CM.Disp.WhiteScreen.style.height = '100%'; + CM.Disp.WhiteScreen.style.backgroundColor = 'white'; + CM.Disp.WhiteScreen.style.display = 'none'; + CM.Disp.WhiteScreen.style.zIndex = '9999999999'; + CM.Disp.WhiteScreen.style.position = 'absolute'; + + l('wrapper').appendChild(CM.Disp.WhiteScreen); +} + +CM.Disp.FindShimmer = function() { + CM.Disp.currSpawnedGoldenCookieState = 0 + CM.Disp.goldenShimmersByID = {} + for (var i in Game.shimmers) { + CM.Disp.goldenShimmersByID[Game.shimmers[i].id] = Game.shimmers[i] + if (Game.shimmers[i].spawnLead && Game.shimmers[i].type == 'golden') { + CM.Disp.spawnedGoldenShimmer = Game.shimmers[i]; + CM.Disp.currSpawnedGoldenCookieState += 1; + } + } +} + +CM.Disp.CollectWrinklers = function() { + for (var i in Game.wrinklers) { + if (Game.wrinklers[i].sucked > 0 && Game.wrinklers[i].type == 0) { + Game.wrinklers[i].hp = 0; + } + } +} + +CM.Disp.FixMouseY = function(target) { + if (CM.Config.TimerBar == 1 && CM.Config.TimerBarPos == 0) { + var timerBarHeight = parseInt(CM.Disp.TimerBar.style.height); + Game.mouseY -= timerBarHeight; + target(); + Game.mouseY += timerBarHeight; + } + else { + target(); + } +} + +CM.Disp.CalculateGrimoireRefillTime = function(currentMagic, maxMagic, targetMagic) { + var count = 0; + while (currentMagic < targetMagic) { + currentMagic += Math.max(0.002, Math.pow(currentMagic / Math.max(maxMagic, 100), 0.5)) * 0.002; + count++; + } + return count / Game.fps; +} + +CM.Disp.AddWrinklerAreaDetect = function() { + l('backgroundLeftCanvas').onmouseover = function() {CM.Disp.TooltipWrinklerArea = 1;}; + l('backgroundLeftCanvas').onmouseout = function() { + CM.Disp.TooltipWrinklerArea = 0; + Game.tooltip.hide(); + for (var i in Game.wrinklers) { + CM.Disp.TooltipWrinklerCache[i] = 0; + } + }; +} + +CM.Disp.UpdateAscendState = function() { + if (Game.OnAscend) { + l('game').style.bottom = '0px'; + if (CM.Config.BotBar == 1) CM.Disp.BotBar.style.display = 'none'; + if (CM.Config.TimerBar == 1) CM.Disp.TimerBar.style.display = 'none'; + } + else { + CM.Disp.ToggleBotBar(); + CM.Disp.ToggleTimerBar(); + } + + CM.Disp.UpdateBackground(); +} + +CM.Disp.UpdateAuraDescription = function() { + return "function(aura)\ + {\ + l('dragonAuraInfo').innerHTML=\ + '

'+Game.dragonAuras[aura].name+'

'+\ + '
'+\ + Game.dragonAuras[aura].desc+\ + '
'+\ + CM.\ + '
';\ + }" +} + +CM.Disp.ToggleSayTime = function() { + if (CM.Config.SayTime == 1) { + Game.sayTime = CM.Disp.sayTime; + } + else { + Game.sayTime = CM.Backup.sayTime; + } +} + +CM.Disp.RefreshScale = function() { + BeautifyAll(); + Game.RefreshStore(); + Game.RebuildUpgrades(); + + CM.Disp.UpdateBotBarOther(); + CM.Disp.UpdateBuildings(); + CM.Disp.UpdateUpgrades(); +} +/******** + * Section: General functions to format or beautify strings + * TODO: Annotate most functions */ + +/** + * This function returns time as a string depending on TimeFormat setting + * @param {number} time Time as number + * @param {number} longFormat 1 or 0 + * @return {string} + */ +CM.Disp.FormatTime = function(time, longFormat) { + if (time == Infinity) return time; + time = Math.ceil(time); + var y = Math.floor(time / 31557600); + var d = Math.floor(time % 31557600 / 86400); + var h = Math.floor(time % 86400 / 3600); + var m = Math.floor(time % 3600 / 60); + var s = Math.floor(time % 60); + var str = ''; + if (CM.Config.TimeFormat) { + if (time > 3155760000) return 'XX:XX:XX:XX:XX'; + str += (y < 10 ? '0' : '') + y + ':'; + str += (d < 10 ? '0' : '') + d + ':'; + str += (h < 10 ? '0' : '') + h + ':'; + str += (m < 10 ? '0' : '') + m + ':'; + str += (s < 10 ? '0' : '') + s + ':'; + } else { + if (time > 777600000) return longFormat ? 'Over 9000 days!' : '>9000d'; + str += (d > 0 ? d + (longFormat ? (d == 1 ? ' day' : ' days') : 'd') + ', ': ""); + if (str.length > 0 || h > 0) str += h + (longFormat ? (h == 1 ? ' hour' : ' hours') : 'h') + ', '; + if (str.length > 0 || m > 0) str += m + (longFormat ? (m == 1 ? ' minute' : ' minutes') : 'm') + ', '; + str += s + (longFormat ? (s == 1 ? ' second' : ' seconds') : 's'); + } + return str; +} + CM.Disp.Beautify = function(num, frac) { if (CM.Config.Scale != 0 && isFinite(num)) { var answer = ''; @@ -980,7 +1226,7 @@ CM.Disp.Beautify = function(num, frac) { } } else if (CM.Config.Scale == 4) { - if (num >= 999999) { + if (um >= 999999) { var count = 0; while (num >= 1000) { count++; @@ -1052,52 +1298,9 @@ CM.Disp.Beautify = function(num, frac) { } } -CM.Disp.GetWrinkConfigBank = function() { - if (CM.Config.CalcWrink) - return CM.Cache.WrinkBank; - else - return 0; -} - -CM.Disp.GetCPS = function() { - if (CM.Config.CPSMode) - return CM.Cache.AvgCPS; - else - return (Game.cookiesPs * (1 - Game.cpsSucked)); -} - -CM.Disp.UpdateBackground = function() { - Game.Background.canvas.width = Game.Background.canvas.parentNode.offsetWidth; - Game.Background.canvas.height = Game.Background.canvas.parentNode.offsetHeight; - Game.LeftBackground.canvas.width = Game.LeftBackground.canvas.parentNode.offsetWidth; - Game.LeftBackground.canvas.height = Game.LeftBackground.canvas.parentNode.offsetHeight; -} - -CM.Disp.GetConfigDisplay = function(config) { - return CM.ConfigData[config].label[CM.Config[config]]; -} - -CM.Disp.AddJscolor = function() { - CM.Disp.Jscolor = document.createElement('script'); - CM.Disp.Jscolor.type = 'text/javascript'; - CM.Disp.Jscolor.setAttribute('src', 'https://aktanusa.github.io/CookieMonster/jscolor/jscolor.js'); - document.head.appendChild(CM.Disp.Jscolor); -} - -CM.Disp.CreateCssArea = function() { - CM.Disp.Css = document.createElement('style'); - CM.Disp.Css.type = 'text/css'; - - document.head.appendChild(CM.Disp.Css); - - // given the architecture of your code, you probably want these lines somewhere else, - // but I stuck them here for convenience - l("products").style.display = "grid"; - l("storeBulk").style.gridRow = "1/1"; - - l("upgrades").style.display = "flex"; - l("upgrades").style["flex-wrap"] = "wrap"; -} +/******** + * Section: Functions related to the Bottom Bar + * TODO: Annotate functions */ /** * Extends the bottom bar (created by CM.Disp.CreateBotBar) with a column for the given building. @@ -1220,6 +1423,10 @@ CM.Disp.UpdateBotBarTime = function() { } } +/******** + * Section: Functions related to the Timer Bar + * TODO: Annotate functions */ + CM.Disp.CreateTimerBar = function() { CM.Disp.TimerBar = document.createElement('div'); CM.Disp.TimerBar.id = 'CMTimerBar'; @@ -1479,6 +1686,10 @@ CM.Disp.UpdateBotTimerBarDisplay = function() { CM.Disp.UpdateBackground(); } +/******** + * Section: Functions related to column of buildings/objects + * TODO: Annotate functions */ + CM.Disp.UpdateBuildings = function() { if (CM.Config.BuildColor == 1 && Game.buyMode == 1) { var target = ''; @@ -1542,6 +1753,10 @@ CM.Disp.UpdateBuildings = function() { } } +/******** + * Section: Functions related to the Upgrade Bar + * TODO: Annotate functions */ + CM.Disp.CreateUpgradeBar = function() { CM.Disp.UpgradeBar = document.createElement('div'); CM.Disp.UpgradeBar.id = 'CMUpgradeBar'; @@ -1623,86 +1838,6 @@ CM.Disp.ToggleUpBarColor = function() { } } -CM.Disp.UpdateUpgrades = function() { - if (CM.Config.UpBarColor > 0) { - var blue = 0; - var green = 0; - var yellow = 0; - var orange = 0; - var red = 0; - var purple = 0; - var gray = 0; - - for (var i in Game.UpgradesInStore) { - var me = Game.UpgradesInStore[i]; - var addedColor = false; - for (var j = 0; j < l('upgrade' + i).childNodes.length; j++) { - if (l('upgrade' + i).childNodes[j].className.indexOf(CM.Disp.colorBackPre) != -1) { - l('upgrade' + i).childNodes[j].className = CM.Disp.colorBackPre + CM.Cache.Upgrades[me.name].color; - addedColor = true; - break; - } - } - if (!addedColor) { - var div = document.createElement('div'); - div.style.width = '10px'; - div.style.height = '10px'; - div.className = CM.Disp.colorBackPre + CM.Cache.Upgrades[me.name].color; - l('upgrade' + i).appendChild(div); - } - if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorBlue) blue++; - else if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorGreen) green++; - else if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorYellow) yellow++; - else if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorOrange) orange++; - else if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorRed) red++; - else if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorPurple) purple++; - else if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorGray) gray++; - } - - l('CMUpgradeBarBlue').textContent = blue; - l('CMUpgradeBarGreen').textContent = green; - l('CMUpgradeBarYellow').textContent = yellow; - l('CMUpgradeBarOrange').textContent = orange; - l('CMUpgradeBarRed').textContent = red; - l('CMUpgradeBarPurple').textContent = purple; - l('CMUpgradeBarGray').textContent = gray; - } - - // Build array of pointers, sort by pp, set flex positions - var arr = []; - for (var x = 0; x < Game.UpgradesInStore.length; x++){ - var o = {}; - o.name = Game.UpgradesInStore[x].name; - o.price = Game.UpgradesInStore[x].basePrice; - o.pp = CM.Cache.Upgrades[o.name].pp; - arr.push(o); - } - - if (CM.Config.SortUpgrades) - arr.sort((a, b) => a.pp - b.pp); - else - arr.sort((a, b) => a.price - b.price); - - for (var x = 0; x < Game.UpgradesInStore.length; x++){ - l("upgrade" + x).style.order = arr.findIndex(e => e.name === Game.UpgradesInStore[x].name) + 1 - } -} - -CM.Disp.UpdateColors = function() { - var str = ''; - for (var i = 0; i < CM.Disp.colors.length; i++) { - str += '.' + CM.Disp.colorTextPre + CM.Disp.colors[i] + ' { color: ' + CM.Config.Colors[CM.Disp.colors[i]] + '; }\n'; - } - for (var i = 0; i < CM.Disp.colors.length; i++) { - str += '.' + CM.Disp.colorBackPre + CM.Disp.colors[i] + ' { background-color: ' + CM.Config.Colors[CM.Disp.colors[i]] + '; }\n'; - } - for (var i = 0; i < CM.Disp.colors.length; i++) { - str += '.' + CM.Disp.colorBorderPre + CM.Disp.colors[i] + ' { border: 1px solid ' + CM.Config.Colors[CM.Disp.colors[i]] + '; }\n'; - } - CM.Disp.Css.textContent = str; - CM.Disp.UpdateBuildings(); // Class has been already set -} - CM.Disp.ToggleUpgradeBarFixedPos = function() { if (CM.Config.UpgradeBarFixedPos == 1) { CM.Disp.UpgradeBar.style.position = 'sticky'; @@ -1713,18 +1848,9 @@ CM.Disp.ToggleUpgradeBarFixedPos = function() { } } -CM.Disp.CreateWhiteScreen = function() { - CM.Disp.WhiteScreen = document.createElement('div'); - CM.Disp.WhiteScreen.id = 'CMWhiteScreen'; - CM.Disp.WhiteScreen.style.width = '100%'; - CM.Disp.WhiteScreen.style.height = '100%'; - CM.Disp.WhiteScreen.style.backgroundColor = 'white'; - CM.Disp.WhiteScreen.style.display = 'none'; - CM.Disp.WhiteScreen.style.zIndex = '9999999999'; - CM.Disp.WhiteScreen.style.position = 'absolute'; - - l('wrapper').appendChild(CM.Disp.WhiteScreen); -} +/******** + * Section: Functions related to the flashes/sound/notifications + * TODO: Annotate functions */ CM.Disp.Flash = function(mode, config) { if ((CM.Config[config] == 1 && mode == 3) || mode == 1) { @@ -1761,19 +1887,9 @@ CM.Disp.Notification = function(notifyConfig, title, message) { } } - -CM.Disp.FindShimmer = function() { - CM.Disp.currSpawnedGoldenCookieState = 0 - CM.Disp.goldenShimmersByID = {} - for (var i in Game.shimmers) { - CM.Disp.goldenShimmersByID[Game.shimmers[i].id] = Game.shimmers[i] - if (Game.shimmers[i].spawnLead && Game.shimmers[i].type == 'golden') { - CM.Disp.spawnedGoldenShimmer = Game.shimmers[i]; - CM.Disp.currSpawnedGoldenCookieState += 1; - } - } - -} +/******** + * Section: Functions related to updating the tab in the browser's tab-bar + * TODO: Annotate functions */ CM.Disp.CreateFavicon = function() { CM.Disp.Favicon = document.createElement('link'); @@ -1797,6 +1913,84 @@ CM.Disp.UpdateFavicon = function() { } } +CM.Disp.UpdateTitle = function() { + if (Game.OnAscend || CM.Config.Title == 0) { + document.title = CM.Cache.Title; + } + else if (CM.Config.Title == 1) { + var addFC = false; + var addSP = false; + + var titleGC; + var titleFC; + var titleSP; + if (CM.Disp.lastGoldenCookieState) { + if (CM.Disp.spawnedGoldenShimmer.wrath) { + titleGC = '[W ' + Math.ceil(CM.Disp.spawnedGoldenShimmer.life / Game.fps) + ']'; + } + else { + titleGC = '[G ' + Math.ceil(CM.Disp.spawnedGoldenShimmer.life / Game.fps) + ']'; + } + } + else if (!Game.Has('Golden switch [off]')) { + titleGC = '[' + Math.ceil((Game.shimmerTypes['golden'].maxTime - Game.shimmerTypes['golden'].time) / Game.fps) + ']'; + } + else { + titleGC = '[GS]' + } + if (CM.Disp.lastTickerFortuneState) { + addFC = true; + titleFC = '[F]'; + } + if (Game.season == 'christmas') { + addSP = true; + if (CM.Disp.lastSeasonPopupState) { + titleSP = '[R ' + Math.ceil(CM.Disp.seasonPopShimmer.life / Game.fps) + ']'; + } + else { + titleSP = '[' + Math.ceil((Game.shimmerTypes['reindeer'].maxTime - Game.shimmerTypes['reindeer'].time) / Game.fps) + ']'; + } + } + + var str = CM.Cache.Title; + if (str.charAt(0) == '[') { + str = str.substring(str.lastIndexOf(']') + 1); + } + + document.title = titleGC + (addFC ? titleFC : '') + (addSP ? titleSP : '') + ' ' + str; + } + else if (CM.Config.Title == 2) { + var str = ''; + var spawn = false; + if (CM.Disp.lastGoldenCookieState) { + spawn = true; + if (CM.Disp.spawnedGoldenShimmer.wrath) { + str += '[W ' + Math.ceil(CM.Disp.spawnedGoldenShimmer.life / Game.fps) + ']'; + } + else { + str += '[G ' + Math.ceil(CM.Disp.spawnedGoldenShimmer.life / Game.fps) + ']'; + } + } + if (CM.Disp.lastTickerFortuneState) { + spawn = true; + str += '[F]'; + } + if (Game.season == 'christmas' && CM.Disp.lastSeasonPopupState) { + str += '[R ' + Math.ceil(CM.Disp.seasonPopShimmer.life / Game.fps) + ']'; + spawn = true; + } + if (spawn) str += ' - '; + var title = 'Cookie Clicker'; + if (Game.season == 'fools') title = 'Cookie Baker'; + str += title; + document.title = str; + } +} + +/******** + * Section: Functions related to the Golden Cookie Timers + * TODO: Annotate functions */ + CM.Disp.CreateGCTimer = function(cookie) { GCTimer = document.createElement('div'); GCTimer.id = 'GCTimer' + cookie.id @@ -1837,6 +2031,11 @@ CM.Disp.ToggleGCTimer = function() { } } +/******** + * Section: Functions related to checking for changes in Minigames/GC's/Ticker + * TODO: Annotate functions + * TODO: Possibly move this section */ + CM.Disp.CheckGoldenCookie = function() { CM.Disp.FindShimmer(); for (var i in CM.Disp.GCTimers) { @@ -1964,87 +2163,9 @@ CM.Disp.CheckWrinklerCount = function() { } } -CM.Disp.UpdateTitle = function() { - if (Game.OnAscend || CM.Config.Title == 0) { - document.title = CM.Cache.Title; - } - else if (CM.Config.Title == 1) { - var addFC = false; - var addSP = false; - - var titleGC; - var titleFC; - var titleSP; - if (CM.Disp.lastGoldenCookieState) { - if (CM.Disp.spawnedGoldenShimmer.wrath) { - titleGC = '[W ' + Math.ceil(CM.Disp.spawnedGoldenShimmer.life / Game.fps) + ']'; - } - else { - titleGC = '[G ' + Math.ceil(CM.Disp.spawnedGoldenShimmer.life / Game.fps) + ']'; - } - } - else if (!Game.Has('Golden switch [off]')) { - titleGC = '[' + Math.ceil((Game.shimmerTypes['golden'].maxTime - Game.shimmerTypes['golden'].time) / Game.fps) + ']'; - } - else { - titleGC = '[GS]' - } - if (CM.Disp.lastTickerFortuneState) { - addFC = true; - titleFC = '[F]'; - } - if (Game.season == 'christmas') { - addSP = true; - if (CM.Disp.lastSeasonPopupState) { - titleSP = '[R ' + Math.ceil(CM.Disp.seasonPopShimmer.life / Game.fps) + ']'; - } - else { - titleSP = '[' + Math.ceil((Game.shimmerTypes['reindeer'].maxTime - Game.shimmerTypes['reindeer'].time) / Game.fps) + ']'; - } - } - - var str = CM.Cache.Title; - if (str.charAt(0) == '[') { - str = str.substring(str.lastIndexOf(']') + 1); - } - - document.title = titleGC + (addFC ? titleFC : '') + (addSP ? titleSP : '') + ' ' + str; - } - else if (CM.Config.Title == 2) { - var str = ''; - var spawn = false; - if (CM.Disp.lastGoldenCookieState) { - spawn = true; - if (CM.Disp.spawnedGoldenShimmer.wrath) { - str += '[W ' + Math.ceil(CM.Disp.spawnedGoldenShimmer.life / Game.fps) + ']'; - } - else { - str += '[G ' + Math.ceil(CM.Disp.spawnedGoldenShimmer.life / Game.fps) + ']'; - } - } - if (CM.Disp.lastTickerFortuneState) { - spawn = true; - str += '[F]'; - } - if (Game.season == 'christmas' && CM.Disp.lastSeasonPopupState) { - str += '[R ' + Math.ceil(CM.Disp.seasonPopShimmer.life / Game.fps) + ']'; - spawn = true; - } - if (spawn) str += ' - '; - var title = 'Cookie Clicker'; - if (Game.season == 'fools') title = 'Cookie Baker'; - str += title; - document.title = str; - } -} - -CM.Disp.CollectWrinklers = function() { - for (var i in Game.wrinklers) { - if (Game.wrinklers[i].sucked > 0 && Game.wrinklers[i].type == 0) { - Game.wrinklers[i].hp = 0; - } - } -} +/******** + * Section: Functions related to Tooltips + * TODO: Annotate functions */ CM.Disp.CreateTooltip = function(placeholder, text, minWidth) { CM.Disp[placeholder] = document.createElement('div'); @@ -2058,6 +2179,576 @@ CM.Disp.CreateTooltip = function(placeholder, text, minWidth) { CM.Disp[placeholder].appendChild(desc); } +CM.Disp.UpdateTooltipLocation = function() { + if (Game.tooltip.origin == 'store') { + var warnOffset = 0; + if (CM.Config.ToolWarnLucky == 1 && CM.Config.ToolWarnPos == 1) warnOffset = CM.Disp.TooltipWarn.clientHeight - 4; + Game.tooltip.tta.style.top = Math.min(parseInt(Game.tooltip.tta.style.top), (l('game').clientHeight + l('topBar').clientHeight) - Game.tooltip.tt.clientHeight - warnOffset - 46) + 'px'; + } + // Kept for future possible use if the code changes again + /*else if (!Game.onCrate && !Game.OnAscend && CM.Config.TimerBar == 1 && CM.Config.TimerBarPos == 0) { + Game.tooltip.tta.style.top = (parseInt(Game.tooltip.tta.style.top) + parseInt(CM.Disp.TimerBar.style.height)) + 'px'; + }*/ +} + +CM.Disp.CreateTooltipWarn = function() { + CM.Disp.TooltipWarn = document.createElement('div'); + CM.Disp.TooltipWarn.style.position = 'absolute'; + CM.Disp.TooltipWarn.style.display = 'none'; + CM.Disp.TooltipWarn.style.left = 'auto'; + CM.Disp.TooltipWarn.style.bottom = 'auto'; + + var create = function(boxId, color, labelTextFront, labelTextBack, deficitId) { + var box = document.createElement('div'); + box.id = boxId; + box.style.display = 'none'; + box.style.WebkitTransition = 'opacity 0.1s ease-out'; + box.style.MozTransition = 'opacity 0.1s ease-out'; + box.style.MsTransition = 'opacity 0.1s ease-out'; + box.style.OTransition = 'opacity 0.1s ease-out'; + box.style.transition = 'opacity 0.1s ease-out'; + box.className = CM.Disp.colorBorderPre + color; + box.style.padding = '2px'; + box.style.background = '#000 url(img/darkNoise.png)'; + var labelDiv = document.createElement('div'); + box.appendChild(labelDiv); + var labelSpan = document.createElement('span'); + labelSpan.className = CM.Disp.colorTextPre + color; + labelSpan.style.fontWeight = 'bold'; + labelSpan.textContent = labelTextFront; + labelDiv.appendChild(labelSpan); + labelDiv.appendChild(document.createTextNode(labelTextBack)); + var deficitDiv = document.createElement('div'); + box.appendChild(deficitDiv); + var deficitSpan = document.createElement('span'); + deficitSpan.id = deficitId; + deficitDiv.appendChild(document.createTextNode('Deficit: ')); + deficitDiv.appendChild(deficitSpan); + return box; + } + CM.Disp.TooltipWarn.appendChild(create('CMDispTooltipWarnLucky', CM.Disp.colorRed, 'Warning: ', 'Purchase of this item will put you under the number of Cookies required for "Lucky!"', 'CMDispTooltipWarnLuckyText')); + CM.Disp.TooltipWarn.firstChild.style.marginBottom = '4px'; + CM.Disp.TooltipWarn.appendChild(create('CMDispTooltipWarnLuckyFrenzy', CM.Disp.colorYellow, 'Warning: ', 'Purchase of this item will put you under the number of Cookies required for "Lucky!" (Frenzy)', 'CMDispTooltipWarnLuckyFrenzyText')); + CM.Disp.TooltipWarn.lastChild.style.marginBottom = '4px'; + CM.Disp.TooltipWarn.appendChild(create('CMDispTooltipWarnConjure', CM.Disp.colorPurple, 'Warning: ', 'Purchase of this item will put you under the number of Cookies required for "Conjure Baked Goods"', 'CMDispTooltipWarnConjureText')); + + + l('tooltipAnchor').appendChild(CM.Disp.TooltipWarn); +} + +CM.Disp.ToggleToolWarnPos = function() { + if (CM.Config.ToolWarnPos == 0) { + CM.Disp.TooltipWarn.style.top = 'auto'; + CM.Disp.TooltipWarn.style.margin = '4px -4px'; + CM.Disp.TooltipWarn.style.padding = '3px 4px'; + } + else { + CM.Disp.TooltipWarn.style.right = 'auto'; + CM.Disp.TooltipWarn.style.margin = '4px'; + CM.Disp.TooltipWarn.style.padding = '4px 3px'; + } +} + +CM.Disp.AddTooltipBuild = function() { + CM.Disp.TooltipBuildBack = []; + for (var i in Game.Objects) { + var me = Game.Objects[i]; + if (l('product' + me.id).onmouseover != null) { + CM.Disp.TooltipBuildBack[i] = l('product' + me.id).onmouseover; + eval('l(\'product\' + me.id).onmouseover = function() {Game.tooltip.dynamic = 1; Game.tooltip.draw(this, function() {return CM.Disp.Tooltip(\'b\', \'' + i + '\');}, \'store\'); Game.tooltip.wobble();}'); + } + } +} + +CM.Disp.AddTooltipUpgrade = function() { + CM.Disp.TooltipUpgradeBack = []; + for (var i in Game.UpgradesInStore) { + var me = Game.UpgradesInStore[i]; + if (l('upgrade' + i).onmouseover != null) { + CM.Disp.TooltipUpgradeBack[i] = l('upgrade' + i).onmouseover; + eval('l(\'upgrade\' + i).onmouseover = function() {if (!Game.mouseDown) {Game.setOnCrate(this); Game.tooltip.dynamic = 1; Game.tooltip.draw(this, function() {return CM.Disp.Tooltip(\'u\', \'' + i + '\');}, \'store\'); Game.tooltip.wobble();}}'); + } + } +} + +CM.Disp.AddTooltipGrimoire = function() { + if (Game.Objects['Wizard tower'].minigameLoaded) { + CM.Disp.TooltipGrimoireBack = []; + for (var i in Game.Objects['Wizard tower'].minigame.spellsById) { + if (l('grimoireSpell' + i).onmouseover != null) { + CM.Disp.TooltipGrimoireBack[i] = l('grimoireSpell' + i).onmouseover; + eval('l(\'grimoireSpell\' + i).onmouseover = function() {Game.tooltip.dynamic = 1; Game.tooltip.draw(this, function() {return CM.Disp.Tooltip(\'g\', \'' + i + '\');}, \'this\'); Game.tooltip.wobble();}'); + } + } + } +} + +/** + * This function improves Sugar Lump tooltip by adding extra infromation. + * @constructor + */ +CM.Disp.AddTooltipLump = function() { + if (Game.canLumps()) { + CM.Disp.TooltipLumpBack = l('lumps').onmouseover; + eval('l(\'lumps\').onmouseover = function() {Game.tooltip.dynamic = 1; Game.tooltip.draw(this, function() {return CM.Disp.Tooltip(\'s\', \'Lump\');}, \'this\'); Game.tooltip.wobble();}'); + } +}; + +CM.Disp.Tooltip = function(type, name) { + if (type == 'b') { + l('tooltip').innerHTML = Game.Objects[name].tooltip(); + if (CM.Config.TooltipAmor == 1) { + var buildPrice = CM.Sim.BuildingGetPrice(Game.Objects[name], Game.Objects[name].basePrice, 0, Game.Objects[name].free, Game.Objects[name].amount); + var amortizeAmount = buildPrice - Game.Objects[name].totalCookies; + if (amortizeAmount > 0) { + l('tooltip').innerHTML = l('tooltip').innerHTML + .split('so far') + .join('so far
' + Beautify(amortizeAmount) + ' ' + (Math.floor(amortizeAmount) == 1 ? 'cookie' : 'cookies') + ' left to amortize (' + CM.Disp.GetTimeColor(buildPrice, Game.Objects[name].totalCookies, (Game.Objects[name].storedTotalCps * Game.globalCpsMult)).text + ')'); + } + } + if (Game.buyMode == 1) { + var target = ''; + var change = false; + if (Game.buyBulk == 10) { + target = 'Objects10'; + change = true; + } + else if (Game.buyBulk == 100) { + target = 'Objects100'; + change = true; + } + if (change) { + l('tooltip').innerHTML = l('tooltip').innerHTML.split(Beautify(Game.Objects[name].getPrice())).join(Beautify(CM.Cache[target][name].price)); + } + } + else if (Game.buyMode == -1) { + /* + * Fix sell price displayed in the object tooltip. + * + * The buildings sell price displayed by the game itself (without any mod) is incorrect. + * The following line of code fixes this issue, and can be safely removed when the game gets fixed. + * + * This issue is extensively detailed here: https://github.com/Aktanusa/CookieMonster/issues/359#issuecomment-735658262 + */ + l('tooltip').innerHTML = l('tooltip').innerHTML.split(Beautify(Game.Objects[name].bulkPrice)).join(Beautify(CM.Sim.BuildingSell(Game.Objects[name], Game.Objects[name].basePrice, Game.Objects[name].amount, Game.Objects[name].free, Game.buyBulk, 1))); + } + } + else if (type == 'u') { + if (!Game.UpgradesInStore[name]) return ''; + l('tooltip').innerHTML = Game.crateTooltip(Game.UpgradesInStore[name], 'store'); + } + else if (type === 's') { + // Sugar Lump + l('tooltip').innerHTML = Game.lumpTooltip(); + } + else { // Grimoire + l('tooltip').innerHTML = Game.Objects['Wizard tower'].minigame.spellTooltip(name)(); + } + + var area = document.createElement('div'); + area.id = 'CMTooltipArea'; + l('tooltip').appendChild(area); + + if (CM.Config.TooltipBuildUp == 1 && (type == 'u' || (type == 'b' && Game.buyMode == 1))) { + l('tooltip').firstChild.style.paddingBottom = '4px'; + var tooltip = document.createElement('div'); + tooltip.style.border = '1px solid'; + tooltip.style.padding = '4px'; + tooltip.style.margin = '0px -4px'; + tooltip.id = 'CMTooltipBorder'; + + var header = function(text) { + var div = document.createElement('div'); + div.style.fontWeight = 'bold'; + div.className = CM.Disp.colorTextPre + CM.Disp.colorBlue; + div.textContent = text; + return div; + } + + tooltip.appendChild(header('Bonus Income')); + var income = document.createElement('div'); + income.style.marginBottom = '4px'; + income.style.color = 'white'; + income.id = 'CMTooltipIncome'; + tooltip.appendChild(income); + tooltip.appendChild(header('Payback Period')); + var pp = document.createElement('div'); + pp.style.marginBottom = '4px'; + pp.id = 'CMTooltipPP'; + tooltip.appendChild(pp); + tooltip.appendChild(header('Time Left')); + var time = document.createElement('div'); + time.id = 'CMTooltipTime'; + tooltip.appendChild(time); + if (type == 'b') { + tooltip.appendChild(header('Production left till next achievement')); + tooltip.lastChild.id = 'CMTooltipProductionHeader'; + var production = document.createElement('div'); + production.id = 'CMTooltipProduction'; + tooltip.appendChild(production); + } + + area.appendChild(tooltip); + } + + CM.Disp.tooltipType = type; + CM.Disp.tooltipName = name; + + CM.Disp.UpdateTooltip(); + + return l('tooltip').innerHTML; +} + +CM.Disp.UpdateTooltip = function() { + CM.Sim.CopyData(); + if (l('tooltipAnchor').style.display != 'none') { + + if (l('CMTooltipArea') != null) { + if (CM.Disp.tooltipType == 'b' || CM.Disp.tooltipType == 'u') { + // Error checking + if (CM.Disp.tooltipType == 'u' && (typeof Game.UpgradesInStore[CM.Disp.tooltipName] === 'undefined' || typeof CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name] === 'undefined')) { + return; + } + var price; + var bonus; + if (CM.Disp.tooltipType == 'b') { + var target = ''; + if (Game.buyMode == 1 && Game.buyBulk == 10) { + target = 'Objects10'; + price = CM.Cache[target][CM.Disp.tooltipName].price; + } + else if (Game.buyMode == 1 && Game.buyBulk == 100) { + target = 'Objects100'; + price = CM.Cache[target][CM.Disp.tooltipName].price; + } + else { + target = 'Objects'; + price = Game.Objects[CM.Disp.tooltipName].getPrice(); + } + bonus = CM.Cache[target][CM.Disp.tooltipName].bonus; + if (CM.Config.TooltipBuildUp == 1 && Game.buyMode == 1) { + l('CMTooltipBorder').className = CM.Disp.colorTextPre + CM.Cache[target][CM.Disp.tooltipName].color; + l('CMTooltipPP').textContent = Beautify(CM.Cache[target][CM.Disp.tooltipName].pp, 2); + l('CMTooltipPP').className = CM.Disp.colorTextPre + CM.Cache[target][CM.Disp.tooltipName].color; + } + if (CM.Config.TooltipBuildUp) { + for (var i in Game.Objects[CM.Disp.tooltipName].productionAchievs) { + if (!CM.Sim.HasAchiev(Game.Objects[CM.Disp.tooltipName].productionAchievs[i].achiev.name)) { + var nextProductionAchiev = Game.Objects[CM.Disp.tooltipName].productionAchievs[i] + break + } + } + if (typeof nextProductionAchiev != "undefined") { + l('CMTooltipTime').style.marginBottom = '4px'; + l('CMTooltipProductionHeader').style.display = ""; + l('CMTooltipProduction').className = "ProdAchievement" + CM.Disp.tooltipName; + l('CMTooltipProduction').textContent = Beautify(nextProductionAchiev.pow - CM.Sim.Objects[CM.Disp.tooltipName].totalCookies, 15); + l('CMTooltipProduction').style.color = "white"; + } else { + l('CMTooltipProductionHeader').style.display = "none"; + l('CMTooltipTime').style.marginBottom = '0px'; + } + } + } + else { // Upgrades + bonus = CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].bonus; + price = Game.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].getPrice(); + if (CM.Config.TooltipBuildUp == 1) { + l('CMTooltipBorder').className = CM.Disp.colorTextPre + CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].color; + l('CMTooltipPP').textContent = Beautify(CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].pp, 2); + l('CMTooltipPP').className = CM.Disp.colorTextPre + CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].color; + } + } + if (CM.Config.TooltipBuildUp == 1 && (CM.Disp.tooltipType != 'b' || Game.buyMode == 1)) { + l('CMTooltipIncome').textContent = Beautify(bonus, 2); + + var increase = Math.round(bonus / Game.cookiesPs * 10000); + if (isFinite(increase) && increase != 0) { + l('CMTooltipIncome').textContent += ' (' + (increase / 100) + '% of income)'; + } + + var timeColor = CM.Disp.GetTimeColor(price, (Game.cookies + CM.Disp.GetWrinkConfigBank()), CM.Disp.GetCPS()); + l('CMTooltipTime').textContent = timeColor.text; + l('CMTooltipTime').className = CM.Disp.colorTextPre + timeColor.color; + } + + if (CM.Config.ToolWarnPos == 0) { + CM.Disp.TooltipWarn.style.right = '0px'; + } + else { + CM.Disp.TooltipWarn.style.top = (l('tooltip').offsetHeight) + 'px'; + } + CM.Disp.TooltipWarn.style.width = (l('tooltip').offsetWidth - 6) + 'px'; + + if (CM.Config.ToolWarnLucky == 1) { + CM.Disp.TooltipWarn.style.display = 'block'; + var limitLucky = CM.Cache.Lucky; + if (CM.Config.ToolWarnBon == 1) { + var bonusNoFren = bonus; + bonusNoFren /= CM.Sim.getCPSBuffMult(); + limitLucky += ((bonusNoFren * 60 * 15) / 0.15); + } + var limitLuckyFrenzy = limitLucky * 7; + var amount = (Game.cookies + CM.Disp.GetWrinkConfigBank()) - price; + if ((amount < limitLucky || amount < limitLuckyFrenzy) && (CM.Disp.tooltipType != 'b' || Game.buyMode == 1)) { + if (amount < limitLucky) { + l('CMDispTooltipWarnLucky').style.display = ''; + l('CMDispTooltipWarnLuckyText').textContent = Beautify(limitLucky - amount) + ' (' + CM.Disp.FormatTime((limitLucky - amount) / CM.Disp.GetCPS()) + ')'; + l('CMDispTooltipWarnLuckyFrenzy').style.display = ''; + l('CMDispTooltipWarnLuckyFrenzyText').textContent = Beautify(limitLuckyFrenzy - amount) + ' (' + CM.Disp.FormatTime((limitLuckyFrenzy - amount) / CM.Disp.GetCPS()) + ')'; + } + else if (amount < limitLuckyFrenzy) { + l('CMDispTooltipWarnLuckyFrenzy').style.display = ''; + l('CMDispTooltipWarnLuckyFrenzyText').textContent = Beautify(limitLuckyFrenzy - amount) + ' (' + CM.Disp.FormatTime((limitLuckyFrenzy - amount) / CM.Disp.GetCPS()) + ')'; + l('CMDispTooltipWarnLucky').style.display = 'none'; + } + } else { + l('CMDispTooltipWarnLucky').style.display = 'none'; + l('CMDispTooltipWarnLuckyFrenzy').style.display = 'none'; + } + } + else { + l('CMDispTooltipWarnLucky').style.display = 'none'; + l('CMDispTooltipWarnLuckyFrenzy').style.display = 'none'; + } + + if (CM.Config.ToolWarnConjure == 1) { + CM.Disp.TooltipWarn.style.display = 'block'; + var limitLucky = CM.Cache.Lucky; + if (CM.Config.ToolWarnBon == 1) { + var bonusNoFren = bonus; + bonusNoFren /= CM.Sim.getCPSBuffMult(); + limitLucky += ((bonusNoFren * 60 * 15) / 0.15); + } + var limitConjure = limitLucky * 2; + var amount = (Game.cookies + CM.Disp.GetWrinkConfigBank()) - price; + if ((amount < limitConjure) && (CM.Disp.tooltipType != 'b' || Game.buyMode == 1)) { + l('CMDispTooltipWarnConjure').style.display = ''; + l('CMDispTooltipWarnConjureText').textContent = Beautify(limitConjure - amount) + ' (' + CM.Disp.FormatTime((limitConjure - amount) / CM.Disp.GetCPS()) + ')'; + } else { + l('CMDispTooltipWarnConjure').style.display = 'none'; + } + } + else { + l('CMDispTooltipWarnConjure').style.display = 'none'; + } + } + else if (CM.Disp.tooltipType === 's') { + // Adding information about Sugar Lumps. + + CM.Disp.TooltipWarn.style.display = 'none'; + l('CMDispTooltipWarnLucky').style.display = 'none'; + l('CMDispTooltipWarnLuckyFrenzy').style.display = 'none'; + l('CMDispTooltipWarnConjure').style.display = 'none'; + + if (CM.Config.TooltipLump === 1) { + l('CMTooltipArea').innerHTML = ''; + + l('tooltip').firstChild.style.paddingBottom = '4px'; + var lumpTooltip = document.createElement('div'); + lumpTooltip.style.border = '1px solid'; + lumpTooltip.style.padding = '4px'; + lumpTooltip.style.margin = '0px -4px'; + lumpTooltip.id = 'CMTooltipBorder'; + lumpTooltip.className = CM.Disp.colorTextPre + CM.Disp.colorGray; + + var lumpHeader = document.createElement('div'); + lumpHeader.style.fontWeight = 'bold'; + lumpHeader.className = CM.Disp.colorTextPre + CM.Disp.colorBlue; + lumpHeader.textContent = 'Current Sugar Lump'; + + lumpTooltip.appendChild(lumpHeader); + var lumpType = document.createElement('div'); + lumpType.id = 'CMTooltipTime'; + lumpTooltip.appendChild(lumpType); + var lumpColor = CM.Disp.GetLumpColor(Game.lumpCurrentType); + lumpType.textContent = lumpColor.text; + lumpType.className = CM.Disp.colorTextPre + lumpColor.color; + + l('CMTooltipArea').appendChild(lumpTooltip); + } + } + else if (CM.Disp.tooltipType === 'g') { + // Grimoire + CM.Disp.TooltipWarn.style.display = 'none'; + l('CMDispTooltipWarnLucky').style.display = 'none'; + l('CMDispTooltipWarnLuckyFrenzy').style.display = 'none'; + l('CMDispTooltipWarnConjure').style.display = 'none'; + + var minigame = Game.Objects['Wizard tower'].minigame; + var spellCost = minigame.getSpellCost(minigame.spellsById[CM.Disp.tooltipName]); + + if (CM.Config.TooltipGrim == 1 && spellCost <= minigame.magicM) { + l('CMTooltipArea').innerHTML = ''; + + l('tooltip').firstChild.style.paddingBottom = '4px'; + var tooltip = document.createElement('div'); + tooltip.style.border = '1px solid'; + tooltip.style.padding = '4px'; + tooltip.style.margin = '0px -4px'; + tooltip.id = 'CMTooltipBorder'; + tooltip.className = CM.Disp.colorTextPre + CM.Disp.colorGray; + + var header = function(text) { + var div = document.createElement('div'); + div.style.fontWeight = 'bold'; + div.className = CM.Disp.colorTextPre + CM.Disp.colorBlue; + div.textContent = text; + return div; + } + + tooltip.appendChild(header('Time Left')); + var time = document.createElement('div'); + time.id = 'CMTooltipTime'; + tooltip.appendChild(time); + var timeColor = CM.Disp.GetTimeColor(spellCost, minigame.magic, undefined, CM.Disp.CalculateGrimoireRefillTime(minigame.magic, minigame.magicM, spellCost)); + time.textContent = timeColor.text; + time.className = CM.Disp.colorTextPre + timeColor.color; + + if (spellCost <= minigame.magic) { + tooltip.appendChild(header('Recover Time')); + var recover = document.createElement('div'); + recover.id = 'CMTooltipRecover'; + tooltip.appendChild(recover); + var recoverColor = CM.Disp.GetTimeColor(minigame.magic, Math.max(0, minigame.magic - spellCost), undefined, CM.Disp.CalculateGrimoireRefillTime(Math.max(0, minigame.magic - spellCost), minigame.magicM, minigame.magic)); + recover.textContent = recoverColor.text; + recover.className = CM.Disp.colorTextPre + recoverColor.color; + } + + // Extra information when spell is Conjure Baked Goods (Name == 0) + if (CM.Disp.tooltipName == 0) { + tooltip.appendChild(header('Cookies to be gained/lost')); + var conjure = document.createElement('div'); + conjure.id = 'CMTooltipConjure'; + tooltip.appendChild(conjure); + var reward = document.createElement('span'); + reward.style.color = "#33FF00" + reward.textContent = Beautify(Math.min((Game.cookies + CM.Disp.GetWrinkConfigBank()) * 0.15, CM.Cache.NoGoldSwitchCookiesPS * 60 * 30), 2) + conjure.appendChild(reward) + var seperator = document.createElement('span'); + seperator.textContent = ' / ' + conjure.appendChild(seperator) + var loss = document.createElement('span'); + loss.style.color = "red" + loss.textContent = Beautify((CM.Cache.NoGoldSwitchCookiesPS * 60 * 15), 2); + conjure.appendChild(loss) + } + + l('CMTooltipArea').appendChild(tooltip); + } + } + } + else { + CM.Disp.TooltipWarn.style.display = 'none'; + } + } +} + +CM.Disp.DrawTooltipWarn = function() { + if (CM.Config.ToolWarnLucky == 1) { + l('CMDispTooltipWarnLucky').style.opacity = '0'; + l('CMDispTooltipWarnLuckyFrenzy').style.opacity = '0'; + } + if (CM.Config.ToolWarnConjure == 1) { + l('CMDispTooltipWarnConjure').style.opacity = '0'; + } +} + +CM.Disp.UpdateTooltipWarn = function() { + if (CM.Config.ToolWarnLucky == 1 && l('tooltipAnchor').style.display != 'none' && l('CMTooltipArea') != null) { + l('CMDispTooltipWarnLucky').style.opacity = '1'; + l('CMDispTooltipWarnLuckyFrenzy').style.opacity = '1'; + } + if (CM.Config.ToolWarnConjure == 1 && l('tooltipAnchor').style.display != 'none' && l('CMTooltipArea') != null) { + l('CMDispTooltipWarnConjure').style.opacity = '1'; + } +} + +CM.Disp.CheckWrinklerTooltip = function() { + if (CM.Config.ToolWrink == 1 && CM.Disp.TooltipWrinklerArea == 1) { + var showingTooltip = false; + for (var i in Game.wrinklers) { + var me = Game.wrinklers[i]; + if (me.phase > 0 && me.selected) { + showingTooltip = true; + if (CM.Disp.TooltipWrinklerCache[i] == 0) { + var placeholder = document.createElement('div'); + var wrinkler = document.createElement('div'); + wrinkler.style.minWidth = '120px'; + wrinkler.style.marginBottom = '4px'; + var div = document.createElement('div'); + div.style.textAlign = 'center'; + div.id = 'CMTooltipWrinkler'; + wrinkler.appendChild(div); + placeholder.appendChild(wrinkler); + Game.tooltip.draw(this, escape(placeholder.innerHTML)); + CM.Disp.TooltipWrinkler = i; + CM.Disp.TooltipWrinklerCache[i] = 1; + } + else break; + } + else { + CM.Disp.TooltipWrinklerCache[i] = 0; + } + } + if (!showingTooltip) { + Game.tooltip.hide(); + } + } +} + +CM.Disp.UpdateWrinklerTooltip = function() { + if (CM.Config.ToolWrink == 1 && l('CMTooltipWrinkler') != null) { + var sucked = Game.wrinklers[CM.Disp.TooltipWrinkler].sucked; + var toSuck = 1.1; + if (Game.Has('Sacrilegious corruption')) toSuck *= 1.05; + if (Game.wrinklers[CM.Disp.TooltipWrinkler].type == 1) toSuck *= 3; // Shiny wrinklers + sucked *= toSuck; + if (Game.Has('Wrinklerspawn')) sucked *= 1.05; + if (CM.Sim.Objects.Temple.minigameLoaded) { + var godLvl = CM.Sim.hasGod('scorn'); + if (godLvl == 1) sucked *= 1.15; + else if (godLvl == 2) sucked *= 1.1; + else if (godLvl == 3) sucked *= 1.05; + } + l('CMTooltipWrinkler').textContent = Beautify(sucked); + } +} + +/******** + * Section: General functions related to the Options/Stats pages + * TODO: Annotate functions */ + +CM.Disp.AddMenu = function() { + var title = function() { + var div = document.createElement('div'); + div.className = 'title ' + CM.Disp.colorTextPre + CM.Disp.colorBlue; + div.textContent = 'Cookie Monster Goodies'; + return div; + } + + if (Game.onMenu == 'prefs') { + CM.Disp.AddMenuPref(title); + } + else if (Game.onMenu == 'stats') { + if (CM.Config.Stats) { + CM.Disp.AddMenuStats(title); + } + + if (CM.Config.MissingUpgrades) { + CM.Disp.AddMissingUpgrades(); + } + } +} + +CM.Disp.RefreshMenu = function() { + if (CM.Config.UpStats && Game.onMenu == 'stats' && (Game.drawT - 1) % (Game.fps * 5) != 0 && (Game.drawT - 1) % Game.fps == 0) Game.UpdateMenu(); +} + +/******** + * Section: Functions related to the Options page + * TODO: Annotate functions */ + CM.Disp.AddMenuPref = function(title) { var header = function(text, config) { var div = document.createElement('div'); @@ -2286,6 +2977,10 @@ CM.Disp.AddMenuPref = function(title) { //l('formatButton').onclick = function() {Game.Toggle('format', 'formatButton', 'Short numbers OFF', 'Short numbers ON', '1'); PlaySound('snd/tick.mp3'); CM.Disp.RefreshScale();}; } +/******** + * Section: Functions related to the Stats page + * TODO: Annotate functions */ + CM.Disp.AddMenuStats = function(title) { var header = function(text, config) { var div = document.createElement('div'); @@ -2786,645 +3481,9 @@ CM.Disp.AddMissingUpgrades = function() { } } -CM.Disp.AddMenu = function() { - var title = function() { - var div = document.createElement('div'); - div.className = 'title ' + CM.Disp.colorTextPre + CM.Disp.colorBlue; - div.textContent = 'Cookie Monster Goodies'; - return div; - } - - if (Game.onMenu == 'prefs') { - CM.Disp.AddMenuPref(title); - } - else if (Game.onMenu == 'stats') { - if (CM.Config.Stats) { - CM.Disp.AddMenuStats(title); - } - - if (CM.Config.MissingUpgrades) { - CM.Disp.AddMissingUpgrades(); - } - } -} - -CM.Disp.RefreshMenu = function() { - if (CM.Config.UpStats && Game.onMenu == 'stats' && (Game.drawT - 1) % (Game.fps * 5) != 0 && (Game.drawT - 1) % Game.fps == 0) Game.UpdateMenu(); -} - -CM.Disp.FixMouseY = function(target) { - if (CM.Config.TimerBar == 1 && CM.Config.TimerBarPos == 0) { - var timerBarHeight = parseInt(CM.Disp.TimerBar.style.height); - Game.mouseY -= timerBarHeight; - target(); - Game.mouseY += timerBarHeight; - } - else { - target(); - } -} - -CM.Disp.UpdateTooltipLocation = function() { - if (Game.tooltip.origin == 'store') { - var warnOffset = 0; - if (CM.Config.ToolWarnLucky == 1 && CM.Config.ToolWarnPos == 1) warnOffset = CM.Disp.TooltipWarn.clientHeight - 4; - Game.tooltip.tta.style.top = Math.min(parseInt(Game.tooltip.tta.style.top), (l('game').clientHeight + l('topBar').clientHeight) - Game.tooltip.tt.clientHeight - warnOffset - 46) + 'px'; - } - // Kept for future possible use if the code changes again - /*else if (!Game.onCrate && !Game.OnAscend && CM.Config.TimerBar == 1 && CM.Config.TimerBarPos == 0) { - Game.tooltip.tta.style.top = (parseInt(Game.tooltip.tta.style.top) + parseInt(CM.Disp.TimerBar.style.height)) + 'px'; - }*/ -} - -CM.Disp.CreateTooltipWarn = function() { - CM.Disp.TooltipWarn = document.createElement('div'); - CM.Disp.TooltipWarn.style.position = 'absolute'; - CM.Disp.TooltipWarn.style.display = 'none'; - CM.Disp.TooltipWarn.style.left = 'auto'; - CM.Disp.TooltipWarn.style.bottom = 'auto'; - - var create = function(boxId, color, labelTextFront, labelTextBack, deficitId) { - var box = document.createElement('div'); - box.id = boxId; - box.style.display = 'none'; - box.style.WebkitTransition = 'opacity 0.1s ease-out'; - box.style.MozTransition = 'opacity 0.1s ease-out'; - box.style.MsTransition = 'opacity 0.1s ease-out'; - box.style.OTransition = 'opacity 0.1s ease-out'; - box.style.transition = 'opacity 0.1s ease-out'; - box.className = CM.Disp.colorBorderPre + color; - box.style.padding = '2px'; - box.style.background = '#000 url(img/darkNoise.png)'; - var labelDiv = document.createElement('div'); - box.appendChild(labelDiv); - var labelSpan = document.createElement('span'); - labelSpan.className = CM.Disp.colorTextPre + color; - labelSpan.style.fontWeight = 'bold'; - labelSpan.textContent = labelTextFront; - labelDiv.appendChild(labelSpan); - labelDiv.appendChild(document.createTextNode(labelTextBack)); - var deficitDiv = document.createElement('div'); - box.appendChild(deficitDiv); - var deficitSpan = document.createElement('span'); - deficitSpan.id = deficitId; - deficitDiv.appendChild(document.createTextNode('Deficit: ')); - deficitDiv.appendChild(deficitSpan); - return box; - } - CM.Disp.TooltipWarn.appendChild(create('CMDispTooltipWarnLucky', CM.Disp.colorRed, 'Warning: ', 'Purchase of this item will put you under the number of Cookies required for "Lucky!"', 'CMDispTooltipWarnLuckyText')); - CM.Disp.TooltipWarn.firstChild.style.marginBottom = '4px'; - CM.Disp.TooltipWarn.appendChild(create('CMDispTooltipWarnLuckyFrenzy', CM.Disp.colorYellow, 'Warning: ', 'Purchase of this item will put you under the number of Cookies required for "Lucky!" (Frenzy)', 'CMDispTooltipWarnLuckyFrenzyText')); - CM.Disp.TooltipWarn.lastChild.style.marginBottom = '4px'; - CM.Disp.TooltipWarn.appendChild(create('CMDispTooltipWarnConjure', CM.Disp.colorPurple, 'Warning: ', 'Purchase of this item will put you under the number of Cookies required for "Conjure Baked Goods"', 'CMDispTooltipWarnConjureText')); - - - l('tooltipAnchor').appendChild(CM.Disp.TooltipWarn); -} - -CM.Disp.ToggleToolWarnPos = function() { - if (CM.Config.ToolWarnPos == 0) { - CM.Disp.TooltipWarn.style.top = 'auto'; - CM.Disp.TooltipWarn.style.margin = '4px -4px'; - CM.Disp.TooltipWarn.style.padding = '3px 4px'; - } - else { - CM.Disp.TooltipWarn.style.right = 'auto'; - CM.Disp.TooltipWarn.style.margin = '4px'; - CM.Disp.TooltipWarn.style.padding = '4px 3px'; - } -} - -CM.Disp.CalculateGrimoireRefillTime = function(currentMagic, maxMagic, targetMagic) { - var count = 0; - while (currentMagic < targetMagic) { - currentMagic += Math.max(0.002, Math.pow(currentMagic / Math.max(maxMagic, 100), 0.5)) * 0.002; - count++; - } - return count / Game.fps; -} - -CM.Disp.AddTooltipBuild = function() { - CM.Disp.TooltipBuildBack = []; - for (var i in Game.Objects) { - var me = Game.Objects[i]; - if (l('product' + me.id).onmouseover != null) { - CM.Disp.TooltipBuildBack[i] = l('product' + me.id).onmouseover; - eval('l(\'product\' + me.id).onmouseover = function() {Game.tooltip.dynamic = 1; Game.tooltip.draw(this, function() {return CM.Disp.Tooltip(\'b\', \'' + i + '\');}, \'store\'); Game.tooltip.wobble();}'); - } - } -} - -CM.Disp.AddTooltipUpgrade = function() { - CM.Disp.TooltipUpgradeBack = []; - for (var i in Game.UpgradesInStore) { - var me = Game.UpgradesInStore[i]; - if (l('upgrade' + i).onmouseover != null) { - CM.Disp.TooltipUpgradeBack[i] = l('upgrade' + i).onmouseover; - eval('l(\'upgrade\' + i).onmouseover = function() {if (!Game.mouseDown) {Game.setOnCrate(this); Game.tooltip.dynamic = 1; Game.tooltip.draw(this, function() {return CM.Disp.Tooltip(\'u\', \'' + i + '\');}, \'store\'); Game.tooltip.wobble();}}'); - } - } -} - -CM.Disp.AddTooltipGrimoire = function() { - if (Game.Objects['Wizard tower'].minigameLoaded) { - CM.Disp.TooltipGrimoireBack = []; - for (var i in Game.Objects['Wizard tower'].minigame.spellsById) { - if (l('grimoireSpell' + i).onmouseover != null) { - CM.Disp.TooltipGrimoireBack[i] = l('grimoireSpell' + i).onmouseover; - eval('l(\'grimoireSpell\' + i).onmouseover = function() {Game.tooltip.dynamic = 1; Game.tooltip.draw(this, function() {return CM.Disp.Tooltip(\'g\', \'' + i + '\');}, \'this\'); Game.tooltip.wobble();}'); - } - } - } -} - -/** - * This function improves Sugar Lump tooltip by adding extra infromation. - * @constructor - */ -CM.Disp.AddTooltipLump = function() { - if (Game.canLumps()) { - CM.Disp.TooltipLumpBack = l('lumps').onmouseover; - eval('l(\'lumps\').onmouseover = function() {Game.tooltip.dynamic = 1; Game.tooltip.draw(this, function() {return CM.Disp.Tooltip(\'s\', \'Lump\');}, \'this\'); Game.tooltip.wobble();}'); - } -}; - -CM.Disp.Tooltip = function(type, name) { - if (type == 'b') { - l('tooltip').innerHTML = Game.Objects[name].tooltip(); - if (CM.Config.TooltipAmor == 1) { - var buildPrice = CM.Sim.BuildingGetPrice(Game.Objects[name], Game.Objects[name].basePrice, 0, Game.Objects[name].free, Game.Objects[name].amount); - var amortizeAmount = buildPrice - Game.Objects[name].totalCookies; - if (amortizeAmount > 0) { - l('tooltip').innerHTML = l('tooltip').innerHTML - .split('so far') - .join('so far
' + Beautify(amortizeAmount) + ' ' + (Math.floor(amortizeAmount) == 1 ? 'cookie' : 'cookies') + ' left to amortize (' + CM.Disp.GetTimeColor(buildPrice, Game.Objects[name].totalCookies, (Game.Objects[name].storedTotalCps * Game.globalCpsMult)).text + ')'); - } - } - if (Game.buyMode == 1) { - var target = ''; - var change = false; - if (Game.buyBulk == 10) { - target = 'Objects10'; - change = true; - } - else if (Game.buyBulk == 100) { - target = 'Objects100'; - change = true; - } - if (change) { - l('tooltip').innerHTML = l('tooltip').innerHTML.split(Beautify(Game.Objects[name].getPrice())).join(Beautify(CM.Cache[target][name].price)); - } - } - else if (Game.buyMode == -1) { - /* - * Fix sell price displayed in the object tooltip. - * - * The buildings sell price displayed by the game itself (without any mod) is incorrect. - * The following line of code fixes this issue, and can be safely removed when the game gets fixed. - * - * This issue is extensively detailed here: https://github.com/Aktanusa/CookieMonster/issues/359#issuecomment-735658262 - */ - l('tooltip').innerHTML = l('tooltip').innerHTML.split(Beautify(Game.Objects[name].bulkPrice)).join(Beautify(CM.Sim.BuildingSell(Game.Objects[name], Game.Objects[name].basePrice, Game.Objects[name].amount, Game.Objects[name].free, Game.buyBulk, 1))); - } - } - else if (type == 'u') { - if (!Game.UpgradesInStore[name]) return ''; - l('tooltip').innerHTML = Game.crateTooltip(Game.UpgradesInStore[name], 'store'); - } - else if (type === 's') { - // Sugar Lump - l('tooltip').innerHTML = Game.lumpTooltip(); - } - else { // Grimoire - l('tooltip').innerHTML = Game.Objects['Wizard tower'].minigame.spellTooltip(name)(); - } - - var area = document.createElement('div'); - area.id = 'CMTooltipArea'; - l('tooltip').appendChild(area); - - if (CM.Config.TooltipBuildUp == 1 && (type == 'u' || (type == 'b' && Game.buyMode == 1))) { - l('tooltip').firstChild.style.paddingBottom = '4px'; - var tooltip = document.createElement('div'); - tooltip.style.border = '1px solid'; - tooltip.style.padding = '4px'; - tooltip.style.margin = '0px -4px'; - tooltip.id = 'CMTooltipBorder'; - - var header = function(text) { - var div = document.createElement('div'); - div.style.fontWeight = 'bold'; - div.className = CM.Disp.colorTextPre + CM.Disp.colorBlue; - div.textContent = text; - return div; - } - - tooltip.appendChild(header('Bonus Income')); - var income = document.createElement('div'); - income.style.marginBottom = '4px'; - income.style.color = 'white'; - income.id = 'CMTooltipIncome'; - tooltip.appendChild(income); - tooltip.appendChild(header('Payback Period')); - var pp = document.createElement('div'); - pp.style.marginBottom = '4px'; - pp.id = 'CMTooltipPP'; - tooltip.appendChild(pp); - tooltip.appendChild(header('Time Left')); - var time = document.createElement('div'); - time.id = 'CMTooltipTime'; - tooltip.appendChild(time); - if (type == 'b') { - tooltip.appendChild(header('Production left till next achievement')); - tooltip.lastChild.id = 'CMTooltipProductionHeader'; - var production = document.createElement('div'); - production.id = 'CMTooltipProduction'; - tooltip.appendChild(production); - } - - area.appendChild(tooltip); - } - - CM.Disp.tooltipType = type; - CM.Disp.tooltipName = name; - - CM.Disp.UpdateTooltip(); - - return l('tooltip').innerHTML; -} - -CM.Disp.UpdateTooltip = function() { - CM.Sim.CopyData(); - if (l('tooltipAnchor').style.display != 'none') { - - if (l('CMTooltipArea') != null) { - if (CM.Disp.tooltipType == 'b' || CM.Disp.tooltipType == 'u') { - // Error checking - if (CM.Disp.tooltipType == 'u' && (typeof Game.UpgradesInStore[CM.Disp.tooltipName] === 'undefined' || typeof CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name] === 'undefined')) { - return; - } - var price; - var bonus; - if (CM.Disp.tooltipType == 'b') { - var target = ''; - if (Game.buyMode == 1 && Game.buyBulk == 10) { - target = 'Objects10'; - price = CM.Cache[target][CM.Disp.tooltipName].price; - } - else if (Game.buyMode == 1 && Game.buyBulk == 100) { - target = 'Objects100'; - price = CM.Cache[target][CM.Disp.tooltipName].price; - } - else { - target = 'Objects'; - price = Game.Objects[CM.Disp.tooltipName].getPrice(); - } - bonus = CM.Cache[target][CM.Disp.tooltipName].bonus; - if (CM.Config.TooltipBuildUp == 1 && Game.buyMode == 1) { - l('CMTooltipBorder').className = CM.Disp.colorTextPre + CM.Cache[target][CM.Disp.tooltipName].color; - l('CMTooltipPP').textContent = Beautify(CM.Cache[target][CM.Disp.tooltipName].pp, 2); - l('CMTooltipPP').className = CM.Disp.colorTextPre + CM.Cache[target][CM.Disp.tooltipName].color; - } - if (CM.Config.TooltipBuildUp) { - for (var i in Game.Objects[CM.Disp.tooltipName].productionAchievs) { - if (!CM.Sim.HasAchiev(Game.Objects[CM.Disp.tooltipName].productionAchievs[i].achiev.name)) { - var nextProductionAchiev = Game.Objects[CM.Disp.tooltipName].productionAchievs[i] - break - } - } - if (typeof nextProductionAchiev != "undefined") { - l('CMTooltipTime').style.marginBottom = '4px'; - l('CMTooltipProductionHeader').style.display = ""; - l('CMTooltipProduction').className = "ProdAchievement" + CM.Disp.tooltipName; - l('CMTooltipProduction').textContent = Beautify(nextProductionAchiev.pow - CM.Sim.Objects[CM.Disp.tooltipName].totalCookies, 15); - l('CMTooltipProduction').style.color = "white"; - } else { - l('CMTooltipProductionHeader').style.display = "none"; - l('CMTooltipTime').style.marginBottom = '0px'; - } - } - } - else { // Upgrades - bonus = CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].bonus; - price = Game.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].getPrice(); - if (CM.Config.TooltipBuildUp == 1) { - l('CMTooltipBorder').className = CM.Disp.colorTextPre + CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].color; - l('CMTooltipPP').textContent = Beautify(CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].pp, 2); - l('CMTooltipPP').className = CM.Disp.colorTextPre + CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].color; - } - } - if (CM.Config.TooltipBuildUp == 1 && (CM.Disp.tooltipType != 'b' || Game.buyMode == 1)) { - l('CMTooltipIncome').textContent = Beautify(bonus, 2); - - var increase = Math.round(bonus / Game.cookiesPs * 10000); - if (isFinite(increase) && increase != 0) { - l('CMTooltipIncome').textContent += ' (' + (increase / 100) + '% of income)'; - } - - var timeColor = CM.Disp.GetTimeColor(price, (Game.cookies + CM.Disp.GetWrinkConfigBank()), CM.Disp.GetCPS()); - l('CMTooltipTime').textContent = timeColor.text; - l('CMTooltipTime').className = CM.Disp.colorTextPre + timeColor.color; - } - - if (CM.Config.ToolWarnPos == 0) { - CM.Disp.TooltipWarn.style.right = '0px'; - } - else { - CM.Disp.TooltipWarn.style.top = (l('tooltip').offsetHeight) + 'px'; - } - CM.Disp.TooltipWarn.style.width = (l('tooltip').offsetWidth - 6) + 'px'; - - if (CM.Config.ToolWarnLucky == 1) { - CM.Disp.TooltipWarn.style.display = 'block'; - var limitLucky = CM.Cache.Lucky; - if (CM.Config.ToolWarnBon == 1) { - var bonusNoFren = bonus; - bonusNoFren /= CM.Sim.getCPSBuffMult(); - limitLucky += ((bonusNoFren * 60 * 15) / 0.15); - } - var limitLuckyFrenzy = limitLucky * 7; - var amount = (Game.cookies + CM.Disp.GetWrinkConfigBank()) - price; - if ((amount < limitLucky || amount < limitLuckyFrenzy) && (CM.Disp.tooltipType != 'b' || Game.buyMode == 1)) { - if (amount < limitLucky) { - l('CMDispTooltipWarnLucky').style.display = ''; - l('CMDispTooltipWarnLuckyText').textContent = Beautify(limitLucky - amount) + ' (' + CM.Disp.FormatTime((limitLucky - amount) / CM.Disp.GetCPS()) + ')'; - l('CMDispTooltipWarnLuckyFrenzy').style.display = ''; - l('CMDispTooltipWarnLuckyFrenzyText').textContent = Beautify(limitLuckyFrenzy - amount) + ' (' + CM.Disp.FormatTime((limitLuckyFrenzy - amount) / CM.Disp.GetCPS()) + ')'; - } - else if (amount < limitLuckyFrenzy) { - l('CMDispTooltipWarnLuckyFrenzy').style.display = ''; - l('CMDispTooltipWarnLuckyFrenzyText').textContent = Beautify(limitLuckyFrenzy - amount) + ' (' + CM.Disp.FormatTime((limitLuckyFrenzy - amount) / CM.Disp.GetCPS()) + ')'; - l('CMDispTooltipWarnLucky').style.display = 'none'; - } - } else { - l('CMDispTooltipWarnLucky').style.display = 'none'; - l('CMDispTooltipWarnLuckyFrenzy').style.display = 'none'; - } - } - else { - l('CMDispTooltipWarnLucky').style.display = 'none'; - l('CMDispTooltipWarnLuckyFrenzy').style.display = 'none'; - } - - if (CM.Config.ToolWarnConjure == 1) { - CM.Disp.TooltipWarn.style.display = 'block'; - var limitLucky = CM.Cache.Lucky; - if (CM.Config.ToolWarnBon == 1) { - var bonusNoFren = bonus; - bonusNoFren /= CM.Sim.getCPSBuffMult(); - limitLucky += ((bonusNoFren * 60 * 15) / 0.15); - } - var limitConjure = limitLucky * 2; - var amount = (Game.cookies + CM.Disp.GetWrinkConfigBank()) - price; - if ((amount < limitConjure) && (CM.Disp.tooltipType != 'b' || Game.buyMode == 1)) { - l('CMDispTooltipWarnConjure').style.display = ''; - l('CMDispTooltipWarnConjureText').textContent = Beautify(limitConjure - amount) + ' (' + CM.Disp.FormatTime((limitConjure - amount) / CM.Disp.GetCPS()) + ')'; - } else { - l('CMDispTooltipWarnConjure').style.display = 'none'; - } - } - else { - l('CMDispTooltipWarnConjure').style.display = 'none'; - } - } - else if (CM.Disp.tooltipType === 's') { - // Adding information about Sugar Lumps. - - CM.Disp.TooltipWarn.style.display = 'none'; - l('CMDispTooltipWarnLucky').style.display = 'none'; - l('CMDispTooltipWarnLuckyFrenzy').style.display = 'none'; - l('CMDispTooltipWarnConjure').style.display = 'none'; - - if (CM.Config.TooltipLump === 1) { - l('CMTooltipArea').innerHTML = ''; - - l('tooltip').firstChild.style.paddingBottom = '4px'; - var lumpTooltip = document.createElement('div'); - lumpTooltip.style.border = '1px solid'; - lumpTooltip.style.padding = '4px'; - lumpTooltip.style.margin = '0px -4px'; - lumpTooltip.id = 'CMTooltipBorder'; - lumpTooltip.className = CM.Disp.colorTextPre + CM.Disp.colorGray; - - var lumpHeader = document.createElement('div'); - lumpHeader.style.fontWeight = 'bold'; - lumpHeader.className = CM.Disp.colorTextPre + CM.Disp.colorBlue; - lumpHeader.textContent = 'Current Sugar Lump'; - - lumpTooltip.appendChild(lumpHeader); - var lumpType = document.createElement('div'); - lumpType.id = 'CMTooltipTime'; - lumpTooltip.appendChild(lumpType); - var lumpColor = CM.Disp.GetLumpColor(Game.lumpCurrentType); - lumpType.textContent = lumpColor.text; - lumpType.className = CM.Disp.colorTextPre + lumpColor.color; - - l('CMTooltipArea').appendChild(lumpTooltip); - } - } - else if (CM.Disp.tooltipType === 'g') { - // Grimoire - CM.Disp.TooltipWarn.style.display = 'none'; - l('CMDispTooltipWarnLucky').style.display = 'none'; - l('CMDispTooltipWarnLuckyFrenzy').style.display = 'none'; - l('CMDispTooltipWarnConjure').style.display = 'none'; - - var minigame = Game.Objects['Wizard tower'].minigame; - var spellCost = minigame.getSpellCost(minigame.spellsById[CM.Disp.tooltipName]); - - if (CM.Config.TooltipGrim == 1 && spellCost <= minigame.magicM) { - l('CMTooltipArea').innerHTML = ''; - - l('tooltip').firstChild.style.paddingBottom = '4px'; - var tooltip = document.createElement('div'); - tooltip.style.border = '1px solid'; - tooltip.style.padding = '4px'; - tooltip.style.margin = '0px -4px'; - tooltip.id = 'CMTooltipBorder'; - tooltip.className = CM.Disp.colorTextPre + CM.Disp.colorGray; - - var header = function(text) { - var div = document.createElement('div'); - div.style.fontWeight = 'bold'; - div.className = CM.Disp.colorTextPre + CM.Disp.colorBlue; - div.textContent = text; - return div; - } - - tooltip.appendChild(header('Time Left')); - var time = document.createElement('div'); - time.id = 'CMTooltipTime'; - tooltip.appendChild(time); - var timeColor = CM.Disp.GetTimeColor(spellCost, minigame.magic, undefined, CM.Disp.CalculateGrimoireRefillTime(minigame.magic, minigame.magicM, spellCost)); - time.textContent = timeColor.text; - time.className = CM.Disp.colorTextPre + timeColor.color; - - if (spellCost <= minigame.magic) { - tooltip.appendChild(header('Recover Time')); - var recover = document.createElement('div'); - recover.id = 'CMTooltipRecover'; - tooltip.appendChild(recover); - var recoverColor = CM.Disp.GetTimeColor(minigame.magic, Math.max(0, minigame.magic - spellCost), undefined, CM.Disp.CalculateGrimoireRefillTime(Math.max(0, minigame.magic - spellCost), minigame.magicM, minigame.magic)); - recover.textContent = recoverColor.text; - recover.className = CM.Disp.colorTextPre + recoverColor.color; - } - - // Extra information when spell is Conjure Baked Goods (Name == 0) - if (CM.Disp.tooltipName == 0) { - tooltip.appendChild(header('Cookies to be gained/lost')); - var conjure = document.createElement('div'); - conjure.id = 'CMTooltipConjure'; - tooltip.appendChild(conjure); - var reward = document.createElement('span'); - reward.style.color = "#33FF00" - reward.textContent = Beautify(Math.min((Game.cookies + CM.Disp.GetWrinkConfigBank()) * 0.15, CM.Cache.NoGoldSwitchCookiesPS * 60 * 30), 2) - conjure.appendChild(reward) - var seperator = document.createElement('span'); - seperator.textContent = ' / ' - conjure.appendChild(seperator) - var loss = document.createElement('span'); - loss.style.color = "red" - loss.textContent = Beautify((CM.Cache.NoGoldSwitchCookiesPS * 60 * 15), 2); - conjure.appendChild(loss) - } - - l('CMTooltipArea').appendChild(tooltip); - } - } - } - else { - CM.Disp.TooltipWarn.style.display = 'none'; - } - } -} - -CM.Disp.DrawTooltipWarn = function() { - if (CM.Config.ToolWarnLucky == 1) { - l('CMDispTooltipWarnLucky').style.opacity = '0'; - l('CMDispTooltipWarnLuckyFrenzy').style.opacity = '0'; - } - if (CM.Config.ToolWarnConjure == 1) { - l('CMDispTooltipWarnConjure').style.opacity = '0'; - } -} - -CM.Disp.UpdateTooltipWarn = function() { - if (CM.Config.ToolWarnLucky == 1 && l('tooltipAnchor').style.display != 'none' && l('CMTooltipArea') != null) { - l('CMDispTooltipWarnLucky').style.opacity = '1'; - l('CMDispTooltipWarnLuckyFrenzy').style.opacity = '1'; - } - if (CM.Config.ToolWarnConjure == 1 && l('tooltipAnchor').style.display != 'none' && l('CMTooltipArea') != null) { - l('CMDispTooltipWarnConjure').style.opacity = '1'; - } -} - -CM.Disp.AddWrinklerAreaDetect = function() { - l('backgroundLeftCanvas').onmouseover = function() {CM.Disp.TooltipWrinklerArea = 1;}; - l('backgroundLeftCanvas').onmouseout = function() { - CM.Disp.TooltipWrinklerArea = 0; - Game.tooltip.hide(); - for (var i in Game.wrinklers) { - CM.Disp.TooltipWrinklerCache[i] = 0; - } - }; -} - -CM.Disp.CheckWrinklerTooltip = function() { - if (CM.Config.ToolWrink == 1 && CM.Disp.TooltipWrinklerArea == 1) { - var showingTooltip = false; - for (var i in Game.wrinklers) { - var me = Game.wrinklers[i]; - if (me.phase > 0 && me.selected) { - showingTooltip = true; - if (CM.Disp.TooltipWrinklerCache[i] == 0) { - var placeholder = document.createElement('div'); - var wrinkler = document.createElement('div'); - wrinkler.style.minWidth = '120px'; - wrinkler.style.marginBottom = '4px'; - var div = document.createElement('div'); - div.style.textAlign = 'center'; - div.id = 'CMTooltipWrinkler'; - wrinkler.appendChild(div); - placeholder.appendChild(wrinkler); - Game.tooltip.draw(this, escape(placeholder.innerHTML)); - CM.Disp.TooltipWrinkler = i; - CM.Disp.TooltipWrinklerCache[i] = 1; - } - else break; - } - else { - CM.Disp.TooltipWrinklerCache[i] = 0; - } - } - if (!showingTooltip) { - Game.tooltip.hide(); - } - } -} - -CM.Disp.UpdateWrinklerTooltip = function() { - if (CM.Config.ToolWrink == 1 && l('CMTooltipWrinkler') != null) { - var sucked = Game.wrinklers[CM.Disp.TooltipWrinkler].sucked; - var toSuck = 1.1; - if (Game.Has('Sacrilegious corruption')) toSuck *= 1.05; - if (Game.wrinklers[CM.Disp.TooltipWrinkler].type == 1) toSuck *= 3; // Shiny wrinklers - sucked *= toSuck; - if (Game.Has('Wrinklerspawn')) sucked *= 1.05; - if (CM.Sim.Objects.Temple.minigameLoaded) { - var godLvl = CM.Sim.hasGod('scorn'); - if (godLvl == 1) sucked *= 1.15; - else if (godLvl == 2) sucked *= 1.1; - else if (godLvl == 3) sucked *= 1.05; - } - l('CMTooltipWrinkler').textContent = Beautify(sucked); - } -} - -CM.Disp.UpdateAscendState = function() { - if (Game.OnAscend) { - l('game').style.bottom = '0px'; - if (CM.Config.BotBar == 1) CM.Disp.BotBar.style.display = 'none'; - if (CM.Config.TimerBar == 1) CM.Disp.TimerBar.style.display = 'none'; - } - else { - CM.Disp.ToggleBotBar(); - CM.Disp.ToggleTimerBar(); - } - - CM.Disp.UpdateBackground(); -} - -CM.Disp.UpdateAuraDescription = function() { - return "function(aura)\ - {\ - l('dragonAuraInfo').innerHTML=\ - '

'+Game.dragonAuras[aura].name+'

'+\ - '
'+\ - Game.dragonAuras[aura].desc+\ - '
'+\ - CM.\ - '
';\ - }" -} - -CM.Disp.ToggleSayTime = function() { - if (CM.Config.SayTime == 1) { - Game.sayTime = CM.Disp.sayTime; - } - else { - Game.sayTime = CM.Backup.sayTime; - } -} - -CM.Disp.RefreshScale = function() { - BeautifyAll(); - Game.RefreshStore(); - Game.RebuildUpgrades(); - - CM.Disp.UpdateBotBarOther(); - CM.Disp.UpdateBuildings(); - CM.Disp.UpdateUpgrades(); -} +/******** + * Section: Variables used in Disp functions + * TODO: Move certain variables to src/Data.js (e.g., CM.Disp.metric & CM.Disp.shortScale) */ CM.Disp.colorTextPre = 'CMText'; CM.Disp.colorBackPre = 'CMBack'; diff --git a/src/Disp.js b/src/Disp.js index 1263661..c1dd66d 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -2,37 +2,10 @@ * Disp * ********/ -// General functions to format or beautify strings - -/** - * This function returns time as a string depending on TimeFormat setting - * @param type Time as number, longFormat 1 or 0. - */ -CM.Disp.FormatTime = function(time, longFormat) { - if (time == Infinity) return time; - time = Math.ceil(time); - var y = Math.floor(time / 31557600); - var d = Math.floor(time % 31557600 / 86400); - var h = Math.floor(time % 86400 / 3600); - var m = Math.floor(time % 3600 / 60); - var s = Math.floor(time % 60); - var str = ''; - if (CM.Config.TimeFormat) { - if (time > 3155760000) return 'XX:XX:XX:XX:XX'; - str += (y < 10 ? '0' : '') + y + ':'; - str += (d < 10 ? '0' : '') + d + ':'; - str += (h < 10 ? '0' : '') + h + ':'; - str += (m < 10 ? '0' : '') + m + ':'; - str += (s < 10 ? '0' : '') + s + ':'; - } else { - if (time > 777600000) return longFormat ? 'Over 9000 days!' : '>9000d'; - str += (d > 0 ? d + (longFormat ? (d == 1 ? ' day' : ' days') : 'd') + ', ': ""); - if (str.length > 0 || h > 0) str += h + (longFormat ? (h == 1 ? ' hour' : ' hours') : 'h') + ', '; - if (str.length > 0 || m > 0) str += m + (longFormat ? (m == 1 ? ' minute' : ' minutes') : 'm') + ', '; - str += s + (longFormat ? (s == 1 ? ' second' : ' seconds') : 's'); - } - return str; -} +/******** + * Section: Unsorted functions + * TODO: Annotate most functions + * TODO: Sort functionsn in relevant (new) sections or files */ CM.Disp.GetTimeColor = function(price, bank, cps, time) { var color; @@ -107,6 +80,279 @@ CM.Disp.GetLumpColor = function(type) { return {text: name, color: color}; }; +CM.Disp.GetWrinkConfigBank = function() { + if (CM.Config.CalcWrink) + return CM.Cache.WrinkBank; + else + return 0; +} + +CM.Disp.GetCPS = function() { + if (CM.Config.CPSMode) + return CM.Cache.AvgCPS; + else + return (Game.cookiesPs * (1 - Game.cpsSucked)); +} + +CM.Disp.UpdateBackground = function() { + Game.Background.canvas.width = Game.Background.canvas.parentNode.offsetWidth; + Game.Background.canvas.height = Game.Background.canvas.parentNode.offsetHeight; + Game.LeftBackground.canvas.width = Game.LeftBackground.canvas.parentNode.offsetWidth; + Game.LeftBackground.canvas.height = Game.LeftBackground.canvas.parentNode.offsetHeight; +} + +CM.Disp.GetConfigDisplay = function(config) { + return CM.ConfigData[config].label[CM.Config[config]]; +} + +CM.Disp.AddJscolor = function() { + CM.Disp.Jscolor = document.createElement('script'); + CM.Disp.Jscolor.type = 'text/javascript'; + CM.Disp.Jscolor.setAttribute('src', 'https://aktanusa.github.io/CookieMonster/jscolor/jscolor.js'); + document.head.appendChild(CM.Disp.Jscolor); +} + +CM.Disp.CreateCssArea = function() { + CM.Disp.Css = document.createElement('style'); + CM.Disp.Css.type = 'text/css'; + + document.head.appendChild(CM.Disp.Css); + + // given the architecture of your code, you probably want these lines somewhere else, + // but I stuck them here for convenience + l("products").style.display = "grid"; + l("storeBulk").style.gridRow = "1/1"; + + l("upgrades").style.display = "flex"; + l("upgrades").style["flex-wrap"] = "wrap"; +} + +CM.Disp.UpdateUpgrades = function() { + if (CM.Config.UpBarColor > 0) { + var blue = 0; + var green = 0; + var yellow = 0; + var orange = 0; + var red = 0; + var purple = 0; + var gray = 0; + + for (var i in Game.UpgradesInStore) { + var me = Game.UpgradesInStore[i]; + var addedColor = false; + for (var j = 0; j < l('upgrade' + i).childNodes.length; j++) { + if (l('upgrade' + i).childNodes[j].className.indexOf(CM.Disp.colorBackPre) != -1) { + l('upgrade' + i).childNodes[j].className = CM.Disp.colorBackPre + CM.Cache.Upgrades[me.name].color; + addedColor = true; + break; + } + } + if (!addedColor) { + var div = document.createElement('div'); + div.style.width = '10px'; + div.style.height = '10px'; + div.className = CM.Disp.colorBackPre + CM.Cache.Upgrades[me.name].color; + l('upgrade' + i).appendChild(div); + } + if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorBlue) blue++; + else if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorGreen) green++; + else if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorYellow) yellow++; + else if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorOrange) orange++; + else if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorRed) red++; + else if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorPurple) purple++; + else if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorGray) gray++; + } + + l('CMUpgradeBarBlue').textContent = blue; + l('CMUpgradeBarGreen').textContent = green; + l('CMUpgradeBarYellow').textContent = yellow; + l('CMUpgradeBarOrange').textContent = orange; + l('CMUpgradeBarRed').textContent = red; + l('CMUpgradeBarPurple').textContent = purple; + l('CMUpgradeBarGray').textContent = gray; + } + + // Build array of pointers, sort by pp, set flex positions + var arr = []; + for (var x = 0; x < Game.UpgradesInStore.length; x++){ + var o = {}; + o.name = Game.UpgradesInStore[x].name; + o.price = Game.UpgradesInStore[x].basePrice; + o.pp = CM.Cache.Upgrades[o.name].pp; + arr.push(o); + } + + if (CM.Config.SortUpgrades) + arr.sort((a, b) => a.pp - b.pp); + else + arr.sort((a, b) => a.price - b.price); + + for (var x = 0; x < Game.UpgradesInStore.length; x++){ + l("upgrade" + x).style.order = arr.findIndex(e => e.name === Game.UpgradesInStore[x].name) + 1 + } +} + +CM.Disp.UpdateColors = function() { + var str = ''; + for (var i = 0; i < CM.Disp.colors.length; i++) { + str += '.' + CM.Disp.colorTextPre + CM.Disp.colors[i] + ' { color: ' + CM.Config.Colors[CM.Disp.colors[i]] + '; }\n'; + } + for (var i = 0; i < CM.Disp.colors.length; i++) { + str += '.' + CM.Disp.colorBackPre + CM.Disp.colors[i] + ' { background-color: ' + CM.Config.Colors[CM.Disp.colors[i]] + '; }\n'; + } + for (var i = 0; i < CM.Disp.colors.length; i++) { + str += '.' + CM.Disp.colorBorderPre + CM.Disp.colors[i] + ' { border: 1px solid ' + CM.Config.Colors[CM.Disp.colors[i]] + '; }\n'; + } + CM.Disp.Css.textContent = str; + CM.Disp.UpdateBuildings(); // Class has been already set +} + +CM.Disp.CreateWhiteScreen = function() { + CM.Disp.WhiteScreen = document.createElement('div'); + CM.Disp.WhiteScreen.id = 'CMWhiteScreen'; + CM.Disp.WhiteScreen.style.width = '100%'; + CM.Disp.WhiteScreen.style.height = '100%'; + CM.Disp.WhiteScreen.style.backgroundColor = 'white'; + CM.Disp.WhiteScreen.style.display = 'none'; + CM.Disp.WhiteScreen.style.zIndex = '9999999999'; + CM.Disp.WhiteScreen.style.position = 'absolute'; + + l('wrapper').appendChild(CM.Disp.WhiteScreen); +} + +CM.Disp.FindShimmer = function() { + CM.Disp.currSpawnedGoldenCookieState = 0 + CM.Disp.goldenShimmersByID = {} + for (var i in Game.shimmers) { + CM.Disp.goldenShimmersByID[Game.shimmers[i].id] = Game.shimmers[i] + if (Game.shimmers[i].spawnLead && Game.shimmers[i].type == 'golden') { + CM.Disp.spawnedGoldenShimmer = Game.shimmers[i]; + CM.Disp.currSpawnedGoldenCookieState += 1; + } + } +} + +CM.Disp.CollectWrinklers = function() { + for (var i in Game.wrinklers) { + if (Game.wrinklers[i].sucked > 0 && Game.wrinklers[i].type == 0) { + Game.wrinklers[i].hp = 0; + } + } +} + +CM.Disp.FixMouseY = function(target) { + if (CM.Config.TimerBar == 1 && CM.Config.TimerBarPos == 0) { + var timerBarHeight = parseInt(CM.Disp.TimerBar.style.height); + Game.mouseY -= timerBarHeight; + target(); + Game.mouseY += timerBarHeight; + } + else { + target(); + } +} + +CM.Disp.CalculateGrimoireRefillTime = function(currentMagic, maxMagic, targetMagic) { + var count = 0; + while (currentMagic < targetMagic) { + currentMagic += Math.max(0.002, Math.pow(currentMagic / Math.max(maxMagic, 100), 0.5)) * 0.002; + count++; + } + return count / Game.fps; +} + +CM.Disp.AddWrinklerAreaDetect = function() { + l('backgroundLeftCanvas').onmouseover = function() {CM.Disp.TooltipWrinklerArea = 1;}; + l('backgroundLeftCanvas').onmouseout = function() { + CM.Disp.TooltipWrinklerArea = 0; + Game.tooltip.hide(); + for (var i in Game.wrinklers) { + CM.Disp.TooltipWrinklerCache[i] = 0; + } + }; +} + +CM.Disp.UpdateAscendState = function() { + if (Game.OnAscend) { + l('game').style.bottom = '0px'; + if (CM.Config.BotBar == 1) CM.Disp.BotBar.style.display = 'none'; + if (CM.Config.TimerBar == 1) CM.Disp.TimerBar.style.display = 'none'; + } + else { + CM.Disp.ToggleBotBar(); + CM.Disp.ToggleTimerBar(); + } + + CM.Disp.UpdateBackground(); +} + +CM.Disp.UpdateAuraDescription = function() { + return "function(aura)\ + {\ + l('dragonAuraInfo').innerHTML=\ + '

'+Game.dragonAuras[aura].name+'

'+\ + '
'+\ + Game.dragonAuras[aura].desc+\ + '
'+\ + CM.\ + '
';\ + }" +} + +CM.Disp.ToggleSayTime = function() { + if (CM.Config.SayTime == 1) { + Game.sayTime = CM.Disp.sayTime; + } + else { + Game.sayTime = CM.Backup.sayTime; + } +} + +CM.Disp.RefreshScale = function() { + BeautifyAll(); + Game.RefreshStore(); + Game.RebuildUpgrades(); + + CM.Disp.UpdateBotBarOther(); + CM.Disp.UpdateBuildings(); + CM.Disp.UpdateUpgrades(); +} +/******** + * Section: General functions to format or beautify strings + * TODO: Annotate most functions */ + +/** + * This function returns time as a string depending on TimeFormat setting + * @param {number} time Time as number + * @param {number} longFormat 1 or 0 + * @return {string} + */ +CM.Disp.FormatTime = function(time, longFormat) { + if (time == Infinity) return time; + time = Math.ceil(time); + var y = Math.floor(time / 31557600); + var d = Math.floor(time % 31557600 / 86400); + var h = Math.floor(time % 86400 / 3600); + var m = Math.floor(time % 3600 / 60); + var s = Math.floor(time % 60); + var str = ''; + if (CM.Config.TimeFormat) { + if (time > 3155760000) return 'XX:XX:XX:XX:XX'; + str += (y < 10 ? '0' : '') + y + ':'; + str += (d < 10 ? '0' : '') + d + ':'; + str += (h < 10 ? '0' : '') + h + ':'; + str += (m < 10 ? '0' : '') + m + ':'; + str += (s < 10 ? '0' : '') + s + ':'; + } else { + if (time > 777600000) return longFormat ? 'Over 9000 days!' : '>9000d'; + str += (d > 0 ? d + (longFormat ? (d == 1 ? ' day' : ' days') : 'd') + ', ': ""); + if (str.length > 0 || h > 0) str += h + (longFormat ? (h == 1 ? ' hour' : ' hours') : 'h') + ', '; + if (str.length > 0 || m > 0) str += m + (longFormat ? (m == 1 ? ' minute' : ' minutes') : 'm') + ', '; + str += s + (longFormat ? (s == 1 ? ' second' : ' seconds') : 's'); + } + return str; +} + CM.Disp.Beautify = function(num, frac) { if (CM.Config.Scale != 0 && isFinite(num)) { var answer = ''; @@ -138,7 +384,7 @@ CM.Disp.Beautify = function(num, frac) { } } else if (CM.Config.Scale == 4) { - if (num >= 999999) { + if (um >= 999999) { var count = 0; while (num >= 1000) { count++; @@ -210,52 +456,9 @@ CM.Disp.Beautify = function(num, frac) { } } -CM.Disp.GetWrinkConfigBank = function() { - if (CM.Config.CalcWrink) - return CM.Cache.WrinkBank; - else - return 0; -} - -CM.Disp.GetCPS = function() { - if (CM.Config.CPSMode) - return CM.Cache.AvgCPS; - else - return (Game.cookiesPs * (1 - Game.cpsSucked)); -} - -CM.Disp.UpdateBackground = function() { - Game.Background.canvas.width = Game.Background.canvas.parentNode.offsetWidth; - Game.Background.canvas.height = Game.Background.canvas.parentNode.offsetHeight; - Game.LeftBackground.canvas.width = Game.LeftBackground.canvas.parentNode.offsetWidth; - Game.LeftBackground.canvas.height = Game.LeftBackground.canvas.parentNode.offsetHeight; -} - -CM.Disp.GetConfigDisplay = function(config) { - return CM.ConfigData[config].label[CM.Config[config]]; -} - -CM.Disp.AddJscolor = function() { - CM.Disp.Jscolor = document.createElement('script'); - CM.Disp.Jscolor.type = 'text/javascript'; - CM.Disp.Jscolor.setAttribute('src', 'https://aktanusa.github.io/CookieMonster/jscolor/jscolor.js'); - document.head.appendChild(CM.Disp.Jscolor); -} - -CM.Disp.CreateCssArea = function() { - CM.Disp.Css = document.createElement('style'); - CM.Disp.Css.type = 'text/css'; - - document.head.appendChild(CM.Disp.Css); - - // given the architecture of your code, you probably want these lines somewhere else, - // but I stuck them here for convenience - l("products").style.display = "grid"; - l("storeBulk").style.gridRow = "1/1"; - - l("upgrades").style.display = "flex"; - l("upgrades").style["flex-wrap"] = "wrap"; -} +/******** + * Section: Functions related to the Bottom Bar + * TODO: Annotate functions */ /** * Extends the bottom bar (created by CM.Disp.CreateBotBar) with a column for the given building. @@ -378,6 +581,10 @@ CM.Disp.UpdateBotBarTime = function() { } } +/******** + * Section: Functions related to the Timer Bar + * TODO: Annotate functions */ + CM.Disp.CreateTimerBar = function() { CM.Disp.TimerBar = document.createElement('div'); CM.Disp.TimerBar.id = 'CMTimerBar'; @@ -637,6 +844,10 @@ CM.Disp.UpdateBotTimerBarDisplay = function() { CM.Disp.UpdateBackground(); } +/******** + * Section: Functions related to column of buildings/objects + * TODO: Annotate functions */ + CM.Disp.UpdateBuildings = function() { if (CM.Config.BuildColor == 1 && Game.buyMode == 1) { var target = ''; @@ -700,6 +911,10 @@ CM.Disp.UpdateBuildings = function() { } } +/******** + * Section: Functions related to the Upgrade Bar + * TODO: Annotate functions */ + CM.Disp.CreateUpgradeBar = function() { CM.Disp.UpgradeBar = document.createElement('div'); CM.Disp.UpgradeBar.id = 'CMUpgradeBar'; @@ -781,86 +996,6 @@ CM.Disp.ToggleUpBarColor = function() { } } -CM.Disp.UpdateUpgrades = function() { - if (CM.Config.UpBarColor > 0) { - var blue = 0; - var green = 0; - var yellow = 0; - var orange = 0; - var red = 0; - var purple = 0; - var gray = 0; - - for (var i in Game.UpgradesInStore) { - var me = Game.UpgradesInStore[i]; - var addedColor = false; - for (var j = 0; j < l('upgrade' + i).childNodes.length; j++) { - if (l('upgrade' + i).childNodes[j].className.indexOf(CM.Disp.colorBackPre) != -1) { - l('upgrade' + i).childNodes[j].className = CM.Disp.colorBackPre + CM.Cache.Upgrades[me.name].color; - addedColor = true; - break; - } - } - if (!addedColor) { - var div = document.createElement('div'); - div.style.width = '10px'; - div.style.height = '10px'; - div.className = CM.Disp.colorBackPre + CM.Cache.Upgrades[me.name].color; - l('upgrade' + i).appendChild(div); - } - if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorBlue) blue++; - else if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorGreen) green++; - else if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorYellow) yellow++; - else if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorOrange) orange++; - else if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorRed) red++; - else if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorPurple) purple++; - else if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorGray) gray++; - } - - l('CMUpgradeBarBlue').textContent = blue; - l('CMUpgradeBarGreen').textContent = green; - l('CMUpgradeBarYellow').textContent = yellow; - l('CMUpgradeBarOrange').textContent = orange; - l('CMUpgradeBarRed').textContent = red; - l('CMUpgradeBarPurple').textContent = purple; - l('CMUpgradeBarGray').textContent = gray; - } - - // Build array of pointers, sort by pp, set flex positions - var arr = []; - for (var x = 0; x < Game.UpgradesInStore.length; x++){ - var o = {}; - o.name = Game.UpgradesInStore[x].name; - o.price = Game.UpgradesInStore[x].basePrice; - o.pp = CM.Cache.Upgrades[o.name].pp; - arr.push(o); - } - - if (CM.Config.SortUpgrades) - arr.sort((a, b) => a.pp - b.pp); - else - arr.sort((a, b) => a.price - b.price); - - for (var x = 0; x < Game.UpgradesInStore.length; x++){ - l("upgrade" + x).style.order = arr.findIndex(e => e.name === Game.UpgradesInStore[x].name) + 1 - } -} - -CM.Disp.UpdateColors = function() { - var str = ''; - for (var i = 0; i < CM.Disp.colors.length; i++) { - str += '.' + CM.Disp.colorTextPre + CM.Disp.colors[i] + ' { color: ' + CM.Config.Colors[CM.Disp.colors[i]] + '; }\n'; - } - for (var i = 0; i < CM.Disp.colors.length; i++) { - str += '.' + CM.Disp.colorBackPre + CM.Disp.colors[i] + ' { background-color: ' + CM.Config.Colors[CM.Disp.colors[i]] + '; }\n'; - } - for (var i = 0; i < CM.Disp.colors.length; i++) { - str += '.' + CM.Disp.colorBorderPre + CM.Disp.colors[i] + ' { border: 1px solid ' + CM.Config.Colors[CM.Disp.colors[i]] + '; }\n'; - } - CM.Disp.Css.textContent = str; - CM.Disp.UpdateBuildings(); // Class has been already set -} - CM.Disp.ToggleUpgradeBarFixedPos = function() { if (CM.Config.UpgradeBarFixedPos == 1) { CM.Disp.UpgradeBar.style.position = 'sticky'; @@ -871,18 +1006,9 @@ CM.Disp.ToggleUpgradeBarFixedPos = function() { } } -CM.Disp.CreateWhiteScreen = function() { - CM.Disp.WhiteScreen = document.createElement('div'); - CM.Disp.WhiteScreen.id = 'CMWhiteScreen'; - CM.Disp.WhiteScreen.style.width = '100%'; - CM.Disp.WhiteScreen.style.height = '100%'; - CM.Disp.WhiteScreen.style.backgroundColor = 'white'; - CM.Disp.WhiteScreen.style.display = 'none'; - CM.Disp.WhiteScreen.style.zIndex = '9999999999'; - CM.Disp.WhiteScreen.style.position = 'absolute'; - - l('wrapper').appendChild(CM.Disp.WhiteScreen); -} +/******** + * Section: Functions related to the flashes/sound/notifications + * TODO: Annotate functions */ CM.Disp.Flash = function(mode, config) { if ((CM.Config[config] == 1 && mode == 3) || mode == 1) { @@ -919,19 +1045,9 @@ CM.Disp.Notification = function(notifyConfig, title, message) { } } - -CM.Disp.FindShimmer = function() { - CM.Disp.currSpawnedGoldenCookieState = 0 - CM.Disp.goldenShimmersByID = {} - for (var i in Game.shimmers) { - CM.Disp.goldenShimmersByID[Game.shimmers[i].id] = Game.shimmers[i] - if (Game.shimmers[i].spawnLead && Game.shimmers[i].type == 'golden') { - CM.Disp.spawnedGoldenShimmer = Game.shimmers[i]; - CM.Disp.currSpawnedGoldenCookieState += 1; - } - } - -} +/******** + * Section: Functions related to updating the tab in the browser's tab-bar + * TODO: Annotate functions */ CM.Disp.CreateFavicon = function() { CM.Disp.Favicon = document.createElement('link'); @@ -955,6 +1071,84 @@ CM.Disp.UpdateFavicon = function() { } } +CM.Disp.UpdateTitle = function() { + if (Game.OnAscend || CM.Config.Title == 0) { + document.title = CM.Cache.Title; + } + else if (CM.Config.Title == 1) { + var addFC = false; + var addSP = false; + + var titleGC; + var titleFC; + var titleSP; + if (CM.Disp.lastGoldenCookieState) { + if (CM.Disp.spawnedGoldenShimmer.wrath) { + titleGC = '[W ' + Math.ceil(CM.Disp.spawnedGoldenShimmer.life / Game.fps) + ']'; + } + else { + titleGC = '[G ' + Math.ceil(CM.Disp.spawnedGoldenShimmer.life / Game.fps) + ']'; + } + } + else if (!Game.Has('Golden switch [off]')) { + titleGC = '[' + Math.ceil((Game.shimmerTypes['golden'].maxTime - Game.shimmerTypes['golden'].time) / Game.fps) + ']'; + } + else { + titleGC = '[GS]' + } + if (CM.Disp.lastTickerFortuneState) { + addFC = true; + titleFC = '[F]'; + } + if (Game.season == 'christmas') { + addSP = true; + if (CM.Disp.lastSeasonPopupState) { + titleSP = '[R ' + Math.ceil(CM.Disp.seasonPopShimmer.life / Game.fps) + ']'; + } + else { + titleSP = '[' + Math.ceil((Game.shimmerTypes['reindeer'].maxTime - Game.shimmerTypes['reindeer'].time) / Game.fps) + ']'; + } + } + + var str = CM.Cache.Title; + if (str.charAt(0) == '[') { + str = str.substring(str.lastIndexOf(']') + 1); + } + + document.title = titleGC + (addFC ? titleFC : '') + (addSP ? titleSP : '') + ' ' + str; + } + else if (CM.Config.Title == 2) { + var str = ''; + var spawn = false; + if (CM.Disp.lastGoldenCookieState) { + spawn = true; + if (CM.Disp.spawnedGoldenShimmer.wrath) { + str += '[W ' + Math.ceil(CM.Disp.spawnedGoldenShimmer.life / Game.fps) + ']'; + } + else { + str += '[G ' + Math.ceil(CM.Disp.spawnedGoldenShimmer.life / Game.fps) + ']'; + } + } + if (CM.Disp.lastTickerFortuneState) { + spawn = true; + str += '[F]'; + } + if (Game.season == 'christmas' && CM.Disp.lastSeasonPopupState) { + str += '[R ' + Math.ceil(CM.Disp.seasonPopShimmer.life / Game.fps) + ']'; + spawn = true; + } + if (spawn) str += ' - '; + var title = 'Cookie Clicker'; + if (Game.season == 'fools') title = 'Cookie Baker'; + str += title; + document.title = str; + } +} + +/******** + * Section: Functions related to the Golden Cookie Timers + * TODO: Annotate functions */ + CM.Disp.CreateGCTimer = function(cookie) { GCTimer = document.createElement('div'); GCTimer.id = 'GCTimer' + cookie.id @@ -995,6 +1189,11 @@ CM.Disp.ToggleGCTimer = function() { } } +/******** + * Section: Functions related to checking for changes in Minigames/GC's/Ticker + * TODO: Annotate functions + * TODO: Possibly move this section */ + CM.Disp.CheckGoldenCookie = function() { CM.Disp.FindShimmer(); for (var i in CM.Disp.GCTimers) { @@ -1122,87 +1321,9 @@ CM.Disp.CheckWrinklerCount = function() { } } -CM.Disp.UpdateTitle = function() { - if (Game.OnAscend || CM.Config.Title == 0) { - document.title = CM.Cache.Title; - } - else if (CM.Config.Title == 1) { - var addFC = false; - var addSP = false; - - var titleGC; - var titleFC; - var titleSP; - if (CM.Disp.lastGoldenCookieState) { - if (CM.Disp.spawnedGoldenShimmer.wrath) { - titleGC = '[W ' + Math.ceil(CM.Disp.spawnedGoldenShimmer.life / Game.fps) + ']'; - } - else { - titleGC = '[G ' + Math.ceil(CM.Disp.spawnedGoldenShimmer.life / Game.fps) + ']'; - } - } - else if (!Game.Has('Golden switch [off]')) { - titleGC = '[' + Math.ceil((Game.shimmerTypes['golden'].maxTime - Game.shimmerTypes['golden'].time) / Game.fps) + ']'; - } - else { - titleGC = '[GS]' - } - if (CM.Disp.lastTickerFortuneState) { - addFC = true; - titleFC = '[F]'; - } - if (Game.season == 'christmas') { - addSP = true; - if (CM.Disp.lastSeasonPopupState) { - titleSP = '[R ' + Math.ceil(CM.Disp.seasonPopShimmer.life / Game.fps) + ']'; - } - else { - titleSP = '[' + Math.ceil((Game.shimmerTypes['reindeer'].maxTime - Game.shimmerTypes['reindeer'].time) / Game.fps) + ']'; - } - } - - var str = CM.Cache.Title; - if (str.charAt(0) == '[') { - str = str.substring(str.lastIndexOf(']') + 1); - } - - document.title = titleGC + (addFC ? titleFC : '') + (addSP ? titleSP : '') + ' ' + str; - } - else if (CM.Config.Title == 2) { - var str = ''; - var spawn = false; - if (CM.Disp.lastGoldenCookieState) { - spawn = true; - if (CM.Disp.spawnedGoldenShimmer.wrath) { - str += '[W ' + Math.ceil(CM.Disp.spawnedGoldenShimmer.life / Game.fps) + ']'; - } - else { - str += '[G ' + Math.ceil(CM.Disp.spawnedGoldenShimmer.life / Game.fps) + ']'; - } - } - if (CM.Disp.lastTickerFortuneState) { - spawn = true; - str += '[F]'; - } - if (Game.season == 'christmas' && CM.Disp.lastSeasonPopupState) { - str += '[R ' + Math.ceil(CM.Disp.seasonPopShimmer.life / Game.fps) + ']'; - spawn = true; - } - if (spawn) str += ' - '; - var title = 'Cookie Clicker'; - if (Game.season == 'fools') title = 'Cookie Baker'; - str += title; - document.title = str; - } -} - -CM.Disp.CollectWrinklers = function() { - for (var i in Game.wrinklers) { - if (Game.wrinklers[i].sucked > 0 && Game.wrinklers[i].type == 0) { - Game.wrinklers[i].hp = 0; - } - } -} +/******** + * Section: Functions related to Tooltips + * TODO: Annotate functions */ CM.Disp.CreateTooltip = function(placeholder, text, minWidth) { CM.Disp[placeholder] = document.createElement('div'); @@ -1216,6 +1337,576 @@ CM.Disp.CreateTooltip = function(placeholder, text, minWidth) { CM.Disp[placeholder].appendChild(desc); } +CM.Disp.UpdateTooltipLocation = function() { + if (Game.tooltip.origin == 'store') { + var warnOffset = 0; + if (CM.Config.ToolWarnLucky == 1 && CM.Config.ToolWarnPos == 1) warnOffset = CM.Disp.TooltipWarn.clientHeight - 4; + Game.tooltip.tta.style.top = Math.min(parseInt(Game.tooltip.tta.style.top), (l('game').clientHeight + l('topBar').clientHeight) - Game.tooltip.tt.clientHeight - warnOffset - 46) + 'px'; + } + // Kept for future possible use if the code changes again + /*else if (!Game.onCrate && !Game.OnAscend && CM.Config.TimerBar == 1 && CM.Config.TimerBarPos == 0) { + Game.tooltip.tta.style.top = (parseInt(Game.tooltip.tta.style.top) + parseInt(CM.Disp.TimerBar.style.height)) + 'px'; + }*/ +} + +CM.Disp.CreateTooltipWarn = function() { + CM.Disp.TooltipWarn = document.createElement('div'); + CM.Disp.TooltipWarn.style.position = 'absolute'; + CM.Disp.TooltipWarn.style.display = 'none'; + CM.Disp.TooltipWarn.style.left = 'auto'; + CM.Disp.TooltipWarn.style.bottom = 'auto'; + + var create = function(boxId, color, labelTextFront, labelTextBack, deficitId) { + var box = document.createElement('div'); + box.id = boxId; + box.style.display = 'none'; + box.style.WebkitTransition = 'opacity 0.1s ease-out'; + box.style.MozTransition = 'opacity 0.1s ease-out'; + box.style.MsTransition = 'opacity 0.1s ease-out'; + box.style.OTransition = 'opacity 0.1s ease-out'; + box.style.transition = 'opacity 0.1s ease-out'; + box.className = CM.Disp.colorBorderPre + color; + box.style.padding = '2px'; + box.style.background = '#000 url(img/darkNoise.png)'; + var labelDiv = document.createElement('div'); + box.appendChild(labelDiv); + var labelSpan = document.createElement('span'); + labelSpan.className = CM.Disp.colorTextPre + color; + labelSpan.style.fontWeight = 'bold'; + labelSpan.textContent = labelTextFront; + labelDiv.appendChild(labelSpan); + labelDiv.appendChild(document.createTextNode(labelTextBack)); + var deficitDiv = document.createElement('div'); + box.appendChild(deficitDiv); + var deficitSpan = document.createElement('span'); + deficitSpan.id = deficitId; + deficitDiv.appendChild(document.createTextNode('Deficit: ')); + deficitDiv.appendChild(deficitSpan); + return box; + } + CM.Disp.TooltipWarn.appendChild(create('CMDispTooltipWarnLucky', CM.Disp.colorRed, 'Warning: ', 'Purchase of this item will put you under the number of Cookies required for "Lucky!"', 'CMDispTooltipWarnLuckyText')); + CM.Disp.TooltipWarn.firstChild.style.marginBottom = '4px'; + CM.Disp.TooltipWarn.appendChild(create('CMDispTooltipWarnLuckyFrenzy', CM.Disp.colorYellow, 'Warning: ', 'Purchase of this item will put you under the number of Cookies required for "Lucky!" (Frenzy)', 'CMDispTooltipWarnLuckyFrenzyText')); + CM.Disp.TooltipWarn.lastChild.style.marginBottom = '4px'; + CM.Disp.TooltipWarn.appendChild(create('CMDispTooltipWarnConjure', CM.Disp.colorPurple, 'Warning: ', 'Purchase of this item will put you under the number of Cookies required for "Conjure Baked Goods"', 'CMDispTooltipWarnConjureText')); + + + l('tooltipAnchor').appendChild(CM.Disp.TooltipWarn); +} + +CM.Disp.ToggleToolWarnPos = function() { + if (CM.Config.ToolWarnPos == 0) { + CM.Disp.TooltipWarn.style.top = 'auto'; + CM.Disp.TooltipWarn.style.margin = '4px -4px'; + CM.Disp.TooltipWarn.style.padding = '3px 4px'; + } + else { + CM.Disp.TooltipWarn.style.right = 'auto'; + CM.Disp.TooltipWarn.style.margin = '4px'; + CM.Disp.TooltipWarn.style.padding = '4px 3px'; + } +} + +CM.Disp.AddTooltipBuild = function() { + CM.Disp.TooltipBuildBack = []; + for (var i in Game.Objects) { + var me = Game.Objects[i]; + if (l('product' + me.id).onmouseover != null) { + CM.Disp.TooltipBuildBack[i] = l('product' + me.id).onmouseover; + eval('l(\'product\' + me.id).onmouseover = function() {Game.tooltip.dynamic = 1; Game.tooltip.draw(this, function() {return CM.Disp.Tooltip(\'b\', \'' + i + '\');}, \'store\'); Game.tooltip.wobble();}'); + } + } +} + +CM.Disp.AddTooltipUpgrade = function() { + CM.Disp.TooltipUpgradeBack = []; + for (var i in Game.UpgradesInStore) { + var me = Game.UpgradesInStore[i]; + if (l('upgrade' + i).onmouseover != null) { + CM.Disp.TooltipUpgradeBack[i] = l('upgrade' + i).onmouseover; + eval('l(\'upgrade\' + i).onmouseover = function() {if (!Game.mouseDown) {Game.setOnCrate(this); Game.tooltip.dynamic = 1; Game.tooltip.draw(this, function() {return CM.Disp.Tooltip(\'u\', \'' + i + '\');}, \'store\'); Game.tooltip.wobble();}}'); + } + } +} + +CM.Disp.AddTooltipGrimoire = function() { + if (Game.Objects['Wizard tower'].minigameLoaded) { + CM.Disp.TooltipGrimoireBack = []; + for (var i in Game.Objects['Wizard tower'].minigame.spellsById) { + if (l('grimoireSpell' + i).onmouseover != null) { + CM.Disp.TooltipGrimoireBack[i] = l('grimoireSpell' + i).onmouseover; + eval('l(\'grimoireSpell\' + i).onmouseover = function() {Game.tooltip.dynamic = 1; Game.tooltip.draw(this, function() {return CM.Disp.Tooltip(\'g\', \'' + i + '\');}, \'this\'); Game.tooltip.wobble();}'); + } + } + } +} + +/** + * This function improves Sugar Lump tooltip by adding extra infromation. + * @constructor + */ +CM.Disp.AddTooltipLump = function() { + if (Game.canLumps()) { + CM.Disp.TooltipLumpBack = l('lumps').onmouseover; + eval('l(\'lumps\').onmouseover = function() {Game.tooltip.dynamic = 1; Game.tooltip.draw(this, function() {return CM.Disp.Tooltip(\'s\', \'Lump\');}, \'this\'); Game.tooltip.wobble();}'); + } +}; + +CM.Disp.Tooltip = function(type, name) { + if (type == 'b') { + l('tooltip').innerHTML = Game.Objects[name].tooltip(); + if (CM.Config.TooltipAmor == 1) { + var buildPrice = CM.Sim.BuildingGetPrice(Game.Objects[name], Game.Objects[name].basePrice, 0, Game.Objects[name].free, Game.Objects[name].amount); + var amortizeAmount = buildPrice - Game.Objects[name].totalCookies; + if (amortizeAmount > 0) { + l('tooltip').innerHTML = l('tooltip').innerHTML + .split('so far') + .join('so far
' + Beautify(amortizeAmount) + ' ' + (Math.floor(amortizeAmount) == 1 ? 'cookie' : 'cookies') + ' left to amortize (' + CM.Disp.GetTimeColor(buildPrice, Game.Objects[name].totalCookies, (Game.Objects[name].storedTotalCps * Game.globalCpsMult)).text + ')'); + } + } + if (Game.buyMode == 1) { + var target = ''; + var change = false; + if (Game.buyBulk == 10) { + target = 'Objects10'; + change = true; + } + else if (Game.buyBulk == 100) { + target = 'Objects100'; + change = true; + } + if (change) { + l('tooltip').innerHTML = l('tooltip').innerHTML.split(Beautify(Game.Objects[name].getPrice())).join(Beautify(CM.Cache[target][name].price)); + } + } + else if (Game.buyMode == -1) { + /* + * Fix sell price displayed in the object tooltip. + * + * The buildings sell price displayed by the game itself (without any mod) is incorrect. + * The following line of code fixes this issue, and can be safely removed when the game gets fixed. + * + * This issue is extensively detailed here: https://github.com/Aktanusa/CookieMonster/issues/359#issuecomment-735658262 + */ + l('tooltip').innerHTML = l('tooltip').innerHTML.split(Beautify(Game.Objects[name].bulkPrice)).join(Beautify(CM.Sim.BuildingSell(Game.Objects[name], Game.Objects[name].basePrice, Game.Objects[name].amount, Game.Objects[name].free, Game.buyBulk, 1))); + } + } + else if (type == 'u') { + if (!Game.UpgradesInStore[name]) return ''; + l('tooltip').innerHTML = Game.crateTooltip(Game.UpgradesInStore[name], 'store'); + } + else if (type === 's') { + // Sugar Lump + l('tooltip').innerHTML = Game.lumpTooltip(); + } + else { // Grimoire + l('tooltip').innerHTML = Game.Objects['Wizard tower'].minigame.spellTooltip(name)(); + } + + var area = document.createElement('div'); + area.id = 'CMTooltipArea'; + l('tooltip').appendChild(area); + + if (CM.Config.TooltipBuildUp == 1 && (type == 'u' || (type == 'b' && Game.buyMode == 1))) { + l('tooltip').firstChild.style.paddingBottom = '4px'; + var tooltip = document.createElement('div'); + tooltip.style.border = '1px solid'; + tooltip.style.padding = '4px'; + tooltip.style.margin = '0px -4px'; + tooltip.id = 'CMTooltipBorder'; + + var header = function(text) { + var div = document.createElement('div'); + div.style.fontWeight = 'bold'; + div.className = CM.Disp.colorTextPre + CM.Disp.colorBlue; + div.textContent = text; + return div; + } + + tooltip.appendChild(header('Bonus Income')); + var income = document.createElement('div'); + income.style.marginBottom = '4px'; + income.style.color = 'white'; + income.id = 'CMTooltipIncome'; + tooltip.appendChild(income); + tooltip.appendChild(header('Payback Period')); + var pp = document.createElement('div'); + pp.style.marginBottom = '4px'; + pp.id = 'CMTooltipPP'; + tooltip.appendChild(pp); + tooltip.appendChild(header('Time Left')); + var time = document.createElement('div'); + time.id = 'CMTooltipTime'; + tooltip.appendChild(time); + if (type == 'b') { + tooltip.appendChild(header('Production left till next achievement')); + tooltip.lastChild.id = 'CMTooltipProductionHeader'; + var production = document.createElement('div'); + production.id = 'CMTooltipProduction'; + tooltip.appendChild(production); + } + + area.appendChild(tooltip); + } + + CM.Disp.tooltipType = type; + CM.Disp.tooltipName = name; + + CM.Disp.UpdateTooltip(); + + return l('tooltip').innerHTML; +} + +CM.Disp.UpdateTooltip = function() { + CM.Sim.CopyData(); + if (l('tooltipAnchor').style.display != 'none') { + + if (l('CMTooltipArea') != null) { + if (CM.Disp.tooltipType == 'b' || CM.Disp.tooltipType == 'u') { + // Error checking + if (CM.Disp.tooltipType == 'u' && (typeof Game.UpgradesInStore[CM.Disp.tooltipName] === 'undefined' || typeof CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name] === 'undefined')) { + return; + } + var price; + var bonus; + if (CM.Disp.tooltipType == 'b') { + var target = ''; + if (Game.buyMode == 1 && Game.buyBulk == 10) { + target = 'Objects10'; + price = CM.Cache[target][CM.Disp.tooltipName].price; + } + else if (Game.buyMode == 1 && Game.buyBulk == 100) { + target = 'Objects100'; + price = CM.Cache[target][CM.Disp.tooltipName].price; + } + else { + target = 'Objects'; + price = Game.Objects[CM.Disp.tooltipName].getPrice(); + } + bonus = CM.Cache[target][CM.Disp.tooltipName].bonus; + if (CM.Config.TooltipBuildUp == 1 && Game.buyMode == 1) { + l('CMTooltipBorder').className = CM.Disp.colorTextPre + CM.Cache[target][CM.Disp.tooltipName].color; + l('CMTooltipPP').textContent = Beautify(CM.Cache[target][CM.Disp.tooltipName].pp, 2); + l('CMTooltipPP').className = CM.Disp.colorTextPre + CM.Cache[target][CM.Disp.tooltipName].color; + } + if (CM.Config.TooltipBuildUp) { + for (var i in Game.Objects[CM.Disp.tooltipName].productionAchievs) { + if (!CM.Sim.HasAchiev(Game.Objects[CM.Disp.tooltipName].productionAchievs[i].achiev.name)) { + var nextProductionAchiev = Game.Objects[CM.Disp.tooltipName].productionAchievs[i] + break + } + } + if (typeof nextProductionAchiev != "undefined") { + l('CMTooltipTime').style.marginBottom = '4px'; + l('CMTooltipProductionHeader').style.display = ""; + l('CMTooltipProduction').className = "ProdAchievement" + CM.Disp.tooltipName; + l('CMTooltipProduction').textContent = Beautify(nextProductionAchiev.pow - CM.Sim.Objects[CM.Disp.tooltipName].totalCookies, 15); + l('CMTooltipProduction').style.color = "white"; + } else { + l('CMTooltipProductionHeader').style.display = "none"; + l('CMTooltipTime').style.marginBottom = '0px'; + } + } + } + else { // Upgrades + bonus = CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].bonus; + price = Game.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].getPrice(); + if (CM.Config.TooltipBuildUp == 1) { + l('CMTooltipBorder').className = CM.Disp.colorTextPre + CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].color; + l('CMTooltipPP').textContent = Beautify(CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].pp, 2); + l('CMTooltipPP').className = CM.Disp.colorTextPre + CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].color; + } + } + if (CM.Config.TooltipBuildUp == 1 && (CM.Disp.tooltipType != 'b' || Game.buyMode == 1)) { + l('CMTooltipIncome').textContent = Beautify(bonus, 2); + + var increase = Math.round(bonus / Game.cookiesPs * 10000); + if (isFinite(increase) && increase != 0) { + l('CMTooltipIncome').textContent += ' (' + (increase / 100) + '% of income)'; + } + + var timeColor = CM.Disp.GetTimeColor(price, (Game.cookies + CM.Disp.GetWrinkConfigBank()), CM.Disp.GetCPS()); + l('CMTooltipTime').textContent = timeColor.text; + l('CMTooltipTime').className = CM.Disp.colorTextPre + timeColor.color; + } + + if (CM.Config.ToolWarnPos == 0) { + CM.Disp.TooltipWarn.style.right = '0px'; + } + else { + CM.Disp.TooltipWarn.style.top = (l('tooltip').offsetHeight) + 'px'; + } + CM.Disp.TooltipWarn.style.width = (l('tooltip').offsetWidth - 6) + 'px'; + + if (CM.Config.ToolWarnLucky == 1) { + CM.Disp.TooltipWarn.style.display = 'block'; + var limitLucky = CM.Cache.Lucky; + if (CM.Config.ToolWarnBon == 1) { + var bonusNoFren = bonus; + bonusNoFren /= CM.Sim.getCPSBuffMult(); + limitLucky += ((bonusNoFren * 60 * 15) / 0.15); + } + var limitLuckyFrenzy = limitLucky * 7; + var amount = (Game.cookies + CM.Disp.GetWrinkConfigBank()) - price; + if ((amount < limitLucky || amount < limitLuckyFrenzy) && (CM.Disp.tooltipType != 'b' || Game.buyMode == 1)) { + if (amount < limitLucky) { + l('CMDispTooltipWarnLucky').style.display = ''; + l('CMDispTooltipWarnLuckyText').textContent = Beautify(limitLucky - amount) + ' (' + CM.Disp.FormatTime((limitLucky - amount) / CM.Disp.GetCPS()) + ')'; + l('CMDispTooltipWarnLuckyFrenzy').style.display = ''; + l('CMDispTooltipWarnLuckyFrenzyText').textContent = Beautify(limitLuckyFrenzy - amount) + ' (' + CM.Disp.FormatTime((limitLuckyFrenzy - amount) / CM.Disp.GetCPS()) + ')'; + } + else if (amount < limitLuckyFrenzy) { + l('CMDispTooltipWarnLuckyFrenzy').style.display = ''; + l('CMDispTooltipWarnLuckyFrenzyText').textContent = Beautify(limitLuckyFrenzy - amount) + ' (' + CM.Disp.FormatTime((limitLuckyFrenzy - amount) / CM.Disp.GetCPS()) + ')'; + l('CMDispTooltipWarnLucky').style.display = 'none'; + } + } else { + l('CMDispTooltipWarnLucky').style.display = 'none'; + l('CMDispTooltipWarnLuckyFrenzy').style.display = 'none'; + } + } + else { + l('CMDispTooltipWarnLucky').style.display = 'none'; + l('CMDispTooltipWarnLuckyFrenzy').style.display = 'none'; + } + + if (CM.Config.ToolWarnConjure == 1) { + CM.Disp.TooltipWarn.style.display = 'block'; + var limitLucky = CM.Cache.Lucky; + if (CM.Config.ToolWarnBon == 1) { + var bonusNoFren = bonus; + bonusNoFren /= CM.Sim.getCPSBuffMult(); + limitLucky += ((bonusNoFren * 60 * 15) / 0.15); + } + var limitConjure = limitLucky * 2; + var amount = (Game.cookies + CM.Disp.GetWrinkConfigBank()) - price; + if ((amount < limitConjure) && (CM.Disp.tooltipType != 'b' || Game.buyMode == 1)) { + l('CMDispTooltipWarnConjure').style.display = ''; + l('CMDispTooltipWarnConjureText').textContent = Beautify(limitConjure - amount) + ' (' + CM.Disp.FormatTime((limitConjure - amount) / CM.Disp.GetCPS()) + ')'; + } else { + l('CMDispTooltipWarnConjure').style.display = 'none'; + } + } + else { + l('CMDispTooltipWarnConjure').style.display = 'none'; + } + } + else if (CM.Disp.tooltipType === 's') { + // Adding information about Sugar Lumps. + + CM.Disp.TooltipWarn.style.display = 'none'; + l('CMDispTooltipWarnLucky').style.display = 'none'; + l('CMDispTooltipWarnLuckyFrenzy').style.display = 'none'; + l('CMDispTooltipWarnConjure').style.display = 'none'; + + if (CM.Config.TooltipLump === 1) { + l('CMTooltipArea').innerHTML = ''; + + l('tooltip').firstChild.style.paddingBottom = '4px'; + var lumpTooltip = document.createElement('div'); + lumpTooltip.style.border = '1px solid'; + lumpTooltip.style.padding = '4px'; + lumpTooltip.style.margin = '0px -4px'; + lumpTooltip.id = 'CMTooltipBorder'; + lumpTooltip.className = CM.Disp.colorTextPre + CM.Disp.colorGray; + + var lumpHeader = document.createElement('div'); + lumpHeader.style.fontWeight = 'bold'; + lumpHeader.className = CM.Disp.colorTextPre + CM.Disp.colorBlue; + lumpHeader.textContent = 'Current Sugar Lump'; + + lumpTooltip.appendChild(lumpHeader); + var lumpType = document.createElement('div'); + lumpType.id = 'CMTooltipTime'; + lumpTooltip.appendChild(lumpType); + var lumpColor = CM.Disp.GetLumpColor(Game.lumpCurrentType); + lumpType.textContent = lumpColor.text; + lumpType.className = CM.Disp.colorTextPre + lumpColor.color; + + l('CMTooltipArea').appendChild(lumpTooltip); + } + } + else if (CM.Disp.tooltipType === 'g') { + // Grimoire + CM.Disp.TooltipWarn.style.display = 'none'; + l('CMDispTooltipWarnLucky').style.display = 'none'; + l('CMDispTooltipWarnLuckyFrenzy').style.display = 'none'; + l('CMDispTooltipWarnConjure').style.display = 'none'; + + var minigame = Game.Objects['Wizard tower'].minigame; + var spellCost = minigame.getSpellCost(minigame.spellsById[CM.Disp.tooltipName]); + + if (CM.Config.TooltipGrim == 1 && spellCost <= minigame.magicM) { + l('CMTooltipArea').innerHTML = ''; + + l('tooltip').firstChild.style.paddingBottom = '4px'; + var tooltip = document.createElement('div'); + tooltip.style.border = '1px solid'; + tooltip.style.padding = '4px'; + tooltip.style.margin = '0px -4px'; + tooltip.id = 'CMTooltipBorder'; + tooltip.className = CM.Disp.colorTextPre + CM.Disp.colorGray; + + var header = function(text) { + var div = document.createElement('div'); + div.style.fontWeight = 'bold'; + div.className = CM.Disp.colorTextPre + CM.Disp.colorBlue; + div.textContent = text; + return div; + } + + tooltip.appendChild(header('Time Left')); + var time = document.createElement('div'); + time.id = 'CMTooltipTime'; + tooltip.appendChild(time); + var timeColor = CM.Disp.GetTimeColor(spellCost, minigame.magic, undefined, CM.Disp.CalculateGrimoireRefillTime(minigame.magic, minigame.magicM, spellCost)); + time.textContent = timeColor.text; + time.className = CM.Disp.colorTextPre + timeColor.color; + + if (spellCost <= minigame.magic) { + tooltip.appendChild(header('Recover Time')); + var recover = document.createElement('div'); + recover.id = 'CMTooltipRecover'; + tooltip.appendChild(recover); + var recoverColor = CM.Disp.GetTimeColor(minigame.magic, Math.max(0, minigame.magic - spellCost), undefined, CM.Disp.CalculateGrimoireRefillTime(Math.max(0, minigame.magic - spellCost), minigame.magicM, minigame.magic)); + recover.textContent = recoverColor.text; + recover.className = CM.Disp.colorTextPre + recoverColor.color; + } + + // Extra information when spell is Conjure Baked Goods (Name == 0) + if (CM.Disp.tooltipName == 0) { + tooltip.appendChild(header('Cookies to be gained/lost')); + var conjure = document.createElement('div'); + conjure.id = 'CMTooltipConjure'; + tooltip.appendChild(conjure); + var reward = document.createElement('span'); + reward.style.color = "#33FF00" + reward.textContent = Beautify(Math.min((Game.cookies + CM.Disp.GetWrinkConfigBank()) * 0.15, CM.Cache.NoGoldSwitchCookiesPS * 60 * 30), 2) + conjure.appendChild(reward) + var seperator = document.createElement('span'); + seperator.textContent = ' / ' + conjure.appendChild(seperator) + var loss = document.createElement('span'); + loss.style.color = "red" + loss.textContent = Beautify((CM.Cache.NoGoldSwitchCookiesPS * 60 * 15), 2); + conjure.appendChild(loss) + } + + l('CMTooltipArea').appendChild(tooltip); + } + } + } + else { + CM.Disp.TooltipWarn.style.display = 'none'; + } + } +} + +CM.Disp.DrawTooltipWarn = function() { + if (CM.Config.ToolWarnLucky == 1) { + l('CMDispTooltipWarnLucky').style.opacity = '0'; + l('CMDispTooltipWarnLuckyFrenzy').style.opacity = '0'; + } + if (CM.Config.ToolWarnConjure == 1) { + l('CMDispTooltipWarnConjure').style.opacity = '0'; + } +} + +CM.Disp.UpdateTooltipWarn = function() { + if (CM.Config.ToolWarnLucky == 1 && l('tooltipAnchor').style.display != 'none' && l('CMTooltipArea') != null) { + l('CMDispTooltipWarnLucky').style.opacity = '1'; + l('CMDispTooltipWarnLuckyFrenzy').style.opacity = '1'; + } + if (CM.Config.ToolWarnConjure == 1 && l('tooltipAnchor').style.display != 'none' && l('CMTooltipArea') != null) { + l('CMDispTooltipWarnConjure').style.opacity = '1'; + } +} + +CM.Disp.CheckWrinklerTooltip = function() { + if (CM.Config.ToolWrink == 1 && CM.Disp.TooltipWrinklerArea == 1) { + var showingTooltip = false; + for (var i in Game.wrinklers) { + var me = Game.wrinklers[i]; + if (me.phase > 0 && me.selected) { + showingTooltip = true; + if (CM.Disp.TooltipWrinklerCache[i] == 0) { + var placeholder = document.createElement('div'); + var wrinkler = document.createElement('div'); + wrinkler.style.minWidth = '120px'; + wrinkler.style.marginBottom = '4px'; + var div = document.createElement('div'); + div.style.textAlign = 'center'; + div.id = 'CMTooltipWrinkler'; + wrinkler.appendChild(div); + placeholder.appendChild(wrinkler); + Game.tooltip.draw(this, escape(placeholder.innerHTML)); + CM.Disp.TooltipWrinkler = i; + CM.Disp.TooltipWrinklerCache[i] = 1; + } + else break; + } + else { + CM.Disp.TooltipWrinklerCache[i] = 0; + } + } + if (!showingTooltip) { + Game.tooltip.hide(); + } + } +} + +CM.Disp.UpdateWrinklerTooltip = function() { + if (CM.Config.ToolWrink == 1 && l('CMTooltipWrinkler') != null) { + var sucked = Game.wrinklers[CM.Disp.TooltipWrinkler].sucked; + var toSuck = 1.1; + if (Game.Has('Sacrilegious corruption')) toSuck *= 1.05; + if (Game.wrinklers[CM.Disp.TooltipWrinkler].type == 1) toSuck *= 3; // Shiny wrinklers + sucked *= toSuck; + if (Game.Has('Wrinklerspawn')) sucked *= 1.05; + if (CM.Sim.Objects.Temple.minigameLoaded) { + var godLvl = CM.Sim.hasGod('scorn'); + if (godLvl == 1) sucked *= 1.15; + else if (godLvl == 2) sucked *= 1.1; + else if (godLvl == 3) sucked *= 1.05; + } + l('CMTooltipWrinkler').textContent = Beautify(sucked); + } +} + +/******** + * Section: General functions related to the Options/Stats pages + * TODO: Annotate functions */ + +CM.Disp.AddMenu = function() { + var title = function() { + var div = document.createElement('div'); + div.className = 'title ' + CM.Disp.colorTextPre + CM.Disp.colorBlue; + div.textContent = 'Cookie Monster Goodies'; + return div; + } + + if (Game.onMenu == 'prefs') { + CM.Disp.AddMenuPref(title); + } + else if (Game.onMenu == 'stats') { + if (CM.Config.Stats) { + CM.Disp.AddMenuStats(title); + } + + if (CM.Config.MissingUpgrades) { + CM.Disp.AddMissingUpgrades(); + } + } +} + +CM.Disp.RefreshMenu = function() { + if (CM.Config.UpStats && Game.onMenu == 'stats' && (Game.drawT - 1) % (Game.fps * 5) != 0 && (Game.drawT - 1) % Game.fps == 0) Game.UpdateMenu(); +} + +/******** + * Section: Functions related to the Options page + * TODO: Annotate functions */ + CM.Disp.AddMenuPref = function(title) { var header = function(text, config) { var div = document.createElement('div'); @@ -1444,6 +2135,10 @@ CM.Disp.AddMenuPref = function(title) { //l('formatButton').onclick = function() {Game.Toggle('format', 'formatButton', 'Short numbers OFF', 'Short numbers ON', '1'); PlaySound('snd/tick.mp3'); CM.Disp.RefreshScale();}; } +/******** + * Section: Functions related to the Stats page + * TODO: Annotate functions */ + CM.Disp.AddMenuStats = function(title) { var header = function(text, config) { var div = document.createElement('div'); @@ -1944,645 +2639,9 @@ CM.Disp.AddMissingUpgrades = function() { } } -CM.Disp.AddMenu = function() { - var title = function() { - var div = document.createElement('div'); - div.className = 'title ' + CM.Disp.colorTextPre + CM.Disp.colorBlue; - div.textContent = 'Cookie Monster Goodies'; - return div; - } - - if (Game.onMenu == 'prefs') { - CM.Disp.AddMenuPref(title); - } - else if (Game.onMenu == 'stats') { - if (CM.Config.Stats) { - CM.Disp.AddMenuStats(title); - } - - if (CM.Config.MissingUpgrades) { - CM.Disp.AddMissingUpgrades(); - } - } -} - -CM.Disp.RefreshMenu = function() { - if (CM.Config.UpStats && Game.onMenu == 'stats' && (Game.drawT - 1) % (Game.fps * 5) != 0 && (Game.drawT - 1) % Game.fps == 0) Game.UpdateMenu(); -} - -CM.Disp.FixMouseY = function(target) { - if (CM.Config.TimerBar == 1 && CM.Config.TimerBarPos == 0) { - var timerBarHeight = parseInt(CM.Disp.TimerBar.style.height); - Game.mouseY -= timerBarHeight; - target(); - Game.mouseY += timerBarHeight; - } - else { - target(); - } -} - -CM.Disp.UpdateTooltipLocation = function() { - if (Game.tooltip.origin == 'store') { - var warnOffset = 0; - if (CM.Config.ToolWarnLucky == 1 && CM.Config.ToolWarnPos == 1) warnOffset = CM.Disp.TooltipWarn.clientHeight - 4; - Game.tooltip.tta.style.top = Math.min(parseInt(Game.tooltip.tta.style.top), (l('game').clientHeight + l('topBar').clientHeight) - Game.tooltip.tt.clientHeight - warnOffset - 46) + 'px'; - } - // Kept for future possible use if the code changes again - /*else if (!Game.onCrate && !Game.OnAscend && CM.Config.TimerBar == 1 && CM.Config.TimerBarPos == 0) { - Game.tooltip.tta.style.top = (parseInt(Game.tooltip.tta.style.top) + parseInt(CM.Disp.TimerBar.style.height)) + 'px'; - }*/ -} - -CM.Disp.CreateTooltipWarn = function() { - CM.Disp.TooltipWarn = document.createElement('div'); - CM.Disp.TooltipWarn.style.position = 'absolute'; - CM.Disp.TooltipWarn.style.display = 'none'; - CM.Disp.TooltipWarn.style.left = 'auto'; - CM.Disp.TooltipWarn.style.bottom = 'auto'; - - var create = function(boxId, color, labelTextFront, labelTextBack, deficitId) { - var box = document.createElement('div'); - box.id = boxId; - box.style.display = 'none'; - box.style.WebkitTransition = 'opacity 0.1s ease-out'; - box.style.MozTransition = 'opacity 0.1s ease-out'; - box.style.MsTransition = 'opacity 0.1s ease-out'; - box.style.OTransition = 'opacity 0.1s ease-out'; - box.style.transition = 'opacity 0.1s ease-out'; - box.className = CM.Disp.colorBorderPre + color; - box.style.padding = '2px'; - box.style.background = '#000 url(img/darkNoise.png)'; - var labelDiv = document.createElement('div'); - box.appendChild(labelDiv); - var labelSpan = document.createElement('span'); - labelSpan.className = CM.Disp.colorTextPre + color; - labelSpan.style.fontWeight = 'bold'; - labelSpan.textContent = labelTextFront; - labelDiv.appendChild(labelSpan); - labelDiv.appendChild(document.createTextNode(labelTextBack)); - var deficitDiv = document.createElement('div'); - box.appendChild(deficitDiv); - var deficitSpan = document.createElement('span'); - deficitSpan.id = deficitId; - deficitDiv.appendChild(document.createTextNode('Deficit: ')); - deficitDiv.appendChild(deficitSpan); - return box; - } - CM.Disp.TooltipWarn.appendChild(create('CMDispTooltipWarnLucky', CM.Disp.colorRed, 'Warning: ', 'Purchase of this item will put you under the number of Cookies required for "Lucky!"', 'CMDispTooltipWarnLuckyText')); - CM.Disp.TooltipWarn.firstChild.style.marginBottom = '4px'; - CM.Disp.TooltipWarn.appendChild(create('CMDispTooltipWarnLuckyFrenzy', CM.Disp.colorYellow, 'Warning: ', 'Purchase of this item will put you under the number of Cookies required for "Lucky!" (Frenzy)', 'CMDispTooltipWarnLuckyFrenzyText')); - CM.Disp.TooltipWarn.lastChild.style.marginBottom = '4px'; - CM.Disp.TooltipWarn.appendChild(create('CMDispTooltipWarnConjure', CM.Disp.colorPurple, 'Warning: ', 'Purchase of this item will put you under the number of Cookies required for "Conjure Baked Goods"', 'CMDispTooltipWarnConjureText')); - - - l('tooltipAnchor').appendChild(CM.Disp.TooltipWarn); -} - -CM.Disp.ToggleToolWarnPos = function() { - if (CM.Config.ToolWarnPos == 0) { - CM.Disp.TooltipWarn.style.top = 'auto'; - CM.Disp.TooltipWarn.style.margin = '4px -4px'; - CM.Disp.TooltipWarn.style.padding = '3px 4px'; - } - else { - CM.Disp.TooltipWarn.style.right = 'auto'; - CM.Disp.TooltipWarn.style.margin = '4px'; - CM.Disp.TooltipWarn.style.padding = '4px 3px'; - } -} - -CM.Disp.CalculateGrimoireRefillTime = function(currentMagic, maxMagic, targetMagic) { - var count = 0; - while (currentMagic < targetMagic) { - currentMagic += Math.max(0.002, Math.pow(currentMagic / Math.max(maxMagic, 100), 0.5)) * 0.002; - count++; - } - return count / Game.fps; -} - -CM.Disp.AddTooltipBuild = function() { - CM.Disp.TooltipBuildBack = []; - for (var i in Game.Objects) { - var me = Game.Objects[i]; - if (l('product' + me.id).onmouseover != null) { - CM.Disp.TooltipBuildBack[i] = l('product' + me.id).onmouseover; - eval('l(\'product\' + me.id).onmouseover = function() {Game.tooltip.dynamic = 1; Game.tooltip.draw(this, function() {return CM.Disp.Tooltip(\'b\', \'' + i + '\');}, \'store\'); Game.tooltip.wobble();}'); - } - } -} - -CM.Disp.AddTooltipUpgrade = function() { - CM.Disp.TooltipUpgradeBack = []; - for (var i in Game.UpgradesInStore) { - var me = Game.UpgradesInStore[i]; - if (l('upgrade' + i).onmouseover != null) { - CM.Disp.TooltipUpgradeBack[i] = l('upgrade' + i).onmouseover; - eval('l(\'upgrade\' + i).onmouseover = function() {if (!Game.mouseDown) {Game.setOnCrate(this); Game.tooltip.dynamic = 1; Game.tooltip.draw(this, function() {return CM.Disp.Tooltip(\'u\', \'' + i + '\');}, \'store\'); Game.tooltip.wobble();}}'); - } - } -} - -CM.Disp.AddTooltipGrimoire = function() { - if (Game.Objects['Wizard tower'].minigameLoaded) { - CM.Disp.TooltipGrimoireBack = []; - for (var i in Game.Objects['Wizard tower'].minigame.spellsById) { - if (l('grimoireSpell' + i).onmouseover != null) { - CM.Disp.TooltipGrimoireBack[i] = l('grimoireSpell' + i).onmouseover; - eval('l(\'grimoireSpell\' + i).onmouseover = function() {Game.tooltip.dynamic = 1; Game.tooltip.draw(this, function() {return CM.Disp.Tooltip(\'g\', \'' + i + '\');}, \'this\'); Game.tooltip.wobble();}'); - } - } - } -} - -/** - * This function improves Sugar Lump tooltip by adding extra infromation. - * @constructor - */ -CM.Disp.AddTooltipLump = function() { - if (Game.canLumps()) { - CM.Disp.TooltipLumpBack = l('lumps').onmouseover; - eval('l(\'lumps\').onmouseover = function() {Game.tooltip.dynamic = 1; Game.tooltip.draw(this, function() {return CM.Disp.Tooltip(\'s\', \'Lump\');}, \'this\'); Game.tooltip.wobble();}'); - } -}; - -CM.Disp.Tooltip = function(type, name) { - if (type == 'b') { - l('tooltip').innerHTML = Game.Objects[name].tooltip(); - if (CM.Config.TooltipAmor == 1) { - var buildPrice = CM.Sim.BuildingGetPrice(Game.Objects[name], Game.Objects[name].basePrice, 0, Game.Objects[name].free, Game.Objects[name].amount); - var amortizeAmount = buildPrice - Game.Objects[name].totalCookies; - if (amortizeAmount > 0) { - l('tooltip').innerHTML = l('tooltip').innerHTML - .split('so far') - .join('so far
' + Beautify(amortizeAmount) + ' ' + (Math.floor(amortizeAmount) == 1 ? 'cookie' : 'cookies') + ' left to amortize (' + CM.Disp.GetTimeColor(buildPrice, Game.Objects[name].totalCookies, (Game.Objects[name].storedTotalCps * Game.globalCpsMult)).text + ')'); - } - } - if (Game.buyMode == 1) { - var target = ''; - var change = false; - if (Game.buyBulk == 10) { - target = 'Objects10'; - change = true; - } - else if (Game.buyBulk == 100) { - target = 'Objects100'; - change = true; - } - if (change) { - l('tooltip').innerHTML = l('tooltip').innerHTML.split(Beautify(Game.Objects[name].getPrice())).join(Beautify(CM.Cache[target][name].price)); - } - } - else if (Game.buyMode == -1) { - /* - * Fix sell price displayed in the object tooltip. - * - * The buildings sell price displayed by the game itself (without any mod) is incorrect. - * The following line of code fixes this issue, and can be safely removed when the game gets fixed. - * - * This issue is extensively detailed here: https://github.com/Aktanusa/CookieMonster/issues/359#issuecomment-735658262 - */ - l('tooltip').innerHTML = l('tooltip').innerHTML.split(Beautify(Game.Objects[name].bulkPrice)).join(Beautify(CM.Sim.BuildingSell(Game.Objects[name], Game.Objects[name].basePrice, Game.Objects[name].amount, Game.Objects[name].free, Game.buyBulk, 1))); - } - } - else if (type == 'u') { - if (!Game.UpgradesInStore[name]) return ''; - l('tooltip').innerHTML = Game.crateTooltip(Game.UpgradesInStore[name], 'store'); - } - else if (type === 's') { - // Sugar Lump - l('tooltip').innerHTML = Game.lumpTooltip(); - } - else { // Grimoire - l('tooltip').innerHTML = Game.Objects['Wizard tower'].minigame.spellTooltip(name)(); - } - - var area = document.createElement('div'); - area.id = 'CMTooltipArea'; - l('tooltip').appendChild(area); - - if (CM.Config.TooltipBuildUp == 1 && (type == 'u' || (type == 'b' && Game.buyMode == 1))) { - l('tooltip').firstChild.style.paddingBottom = '4px'; - var tooltip = document.createElement('div'); - tooltip.style.border = '1px solid'; - tooltip.style.padding = '4px'; - tooltip.style.margin = '0px -4px'; - tooltip.id = 'CMTooltipBorder'; - - var header = function(text) { - var div = document.createElement('div'); - div.style.fontWeight = 'bold'; - div.className = CM.Disp.colorTextPre + CM.Disp.colorBlue; - div.textContent = text; - return div; - } - - tooltip.appendChild(header('Bonus Income')); - var income = document.createElement('div'); - income.style.marginBottom = '4px'; - income.style.color = 'white'; - income.id = 'CMTooltipIncome'; - tooltip.appendChild(income); - tooltip.appendChild(header('Payback Period')); - var pp = document.createElement('div'); - pp.style.marginBottom = '4px'; - pp.id = 'CMTooltipPP'; - tooltip.appendChild(pp); - tooltip.appendChild(header('Time Left')); - var time = document.createElement('div'); - time.id = 'CMTooltipTime'; - tooltip.appendChild(time); - if (type == 'b') { - tooltip.appendChild(header('Production left till next achievement')); - tooltip.lastChild.id = 'CMTooltipProductionHeader'; - var production = document.createElement('div'); - production.id = 'CMTooltipProduction'; - tooltip.appendChild(production); - } - - area.appendChild(tooltip); - } - - CM.Disp.tooltipType = type; - CM.Disp.tooltipName = name; - - CM.Disp.UpdateTooltip(); - - return l('tooltip').innerHTML; -} - -CM.Disp.UpdateTooltip = function() { - CM.Sim.CopyData(); - if (l('tooltipAnchor').style.display != 'none') { - - if (l('CMTooltipArea') != null) { - if (CM.Disp.tooltipType == 'b' || CM.Disp.tooltipType == 'u') { - // Error checking - if (CM.Disp.tooltipType == 'u' && (typeof Game.UpgradesInStore[CM.Disp.tooltipName] === 'undefined' || typeof CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name] === 'undefined')) { - return; - } - var price; - var bonus; - if (CM.Disp.tooltipType == 'b') { - var target = ''; - if (Game.buyMode == 1 && Game.buyBulk == 10) { - target = 'Objects10'; - price = CM.Cache[target][CM.Disp.tooltipName].price; - } - else if (Game.buyMode == 1 && Game.buyBulk == 100) { - target = 'Objects100'; - price = CM.Cache[target][CM.Disp.tooltipName].price; - } - else { - target = 'Objects'; - price = Game.Objects[CM.Disp.tooltipName].getPrice(); - } - bonus = CM.Cache[target][CM.Disp.tooltipName].bonus; - if (CM.Config.TooltipBuildUp == 1 && Game.buyMode == 1) { - l('CMTooltipBorder').className = CM.Disp.colorTextPre + CM.Cache[target][CM.Disp.tooltipName].color; - l('CMTooltipPP').textContent = Beautify(CM.Cache[target][CM.Disp.tooltipName].pp, 2); - l('CMTooltipPP').className = CM.Disp.colorTextPre + CM.Cache[target][CM.Disp.tooltipName].color; - } - if (CM.Config.TooltipBuildUp) { - for (var i in Game.Objects[CM.Disp.tooltipName].productionAchievs) { - if (!CM.Sim.HasAchiev(Game.Objects[CM.Disp.tooltipName].productionAchievs[i].achiev.name)) { - var nextProductionAchiev = Game.Objects[CM.Disp.tooltipName].productionAchievs[i] - break - } - } - if (typeof nextProductionAchiev != "undefined") { - l('CMTooltipTime').style.marginBottom = '4px'; - l('CMTooltipProductionHeader').style.display = ""; - l('CMTooltipProduction').className = "ProdAchievement" + CM.Disp.tooltipName; - l('CMTooltipProduction').textContent = Beautify(nextProductionAchiev.pow - CM.Sim.Objects[CM.Disp.tooltipName].totalCookies, 15); - l('CMTooltipProduction').style.color = "white"; - } else { - l('CMTooltipProductionHeader').style.display = "none"; - l('CMTooltipTime').style.marginBottom = '0px'; - } - } - } - else { // Upgrades - bonus = CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].bonus; - price = Game.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].getPrice(); - if (CM.Config.TooltipBuildUp == 1) { - l('CMTooltipBorder').className = CM.Disp.colorTextPre + CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].color; - l('CMTooltipPP').textContent = Beautify(CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].pp, 2); - l('CMTooltipPP').className = CM.Disp.colorTextPre + CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].color; - } - } - if (CM.Config.TooltipBuildUp == 1 && (CM.Disp.tooltipType != 'b' || Game.buyMode == 1)) { - l('CMTooltipIncome').textContent = Beautify(bonus, 2); - - var increase = Math.round(bonus / Game.cookiesPs * 10000); - if (isFinite(increase) && increase != 0) { - l('CMTooltipIncome').textContent += ' (' + (increase / 100) + '% of income)'; - } - - var timeColor = CM.Disp.GetTimeColor(price, (Game.cookies + CM.Disp.GetWrinkConfigBank()), CM.Disp.GetCPS()); - l('CMTooltipTime').textContent = timeColor.text; - l('CMTooltipTime').className = CM.Disp.colorTextPre + timeColor.color; - } - - if (CM.Config.ToolWarnPos == 0) { - CM.Disp.TooltipWarn.style.right = '0px'; - } - else { - CM.Disp.TooltipWarn.style.top = (l('tooltip').offsetHeight) + 'px'; - } - CM.Disp.TooltipWarn.style.width = (l('tooltip').offsetWidth - 6) + 'px'; - - if (CM.Config.ToolWarnLucky == 1) { - CM.Disp.TooltipWarn.style.display = 'block'; - var limitLucky = CM.Cache.Lucky; - if (CM.Config.ToolWarnBon == 1) { - var bonusNoFren = bonus; - bonusNoFren /= CM.Sim.getCPSBuffMult(); - limitLucky += ((bonusNoFren * 60 * 15) / 0.15); - } - var limitLuckyFrenzy = limitLucky * 7; - var amount = (Game.cookies + CM.Disp.GetWrinkConfigBank()) - price; - if ((amount < limitLucky || amount < limitLuckyFrenzy) && (CM.Disp.tooltipType != 'b' || Game.buyMode == 1)) { - if (amount < limitLucky) { - l('CMDispTooltipWarnLucky').style.display = ''; - l('CMDispTooltipWarnLuckyText').textContent = Beautify(limitLucky - amount) + ' (' + CM.Disp.FormatTime((limitLucky - amount) / CM.Disp.GetCPS()) + ')'; - l('CMDispTooltipWarnLuckyFrenzy').style.display = ''; - l('CMDispTooltipWarnLuckyFrenzyText').textContent = Beautify(limitLuckyFrenzy - amount) + ' (' + CM.Disp.FormatTime((limitLuckyFrenzy - amount) / CM.Disp.GetCPS()) + ')'; - } - else if (amount < limitLuckyFrenzy) { - l('CMDispTooltipWarnLuckyFrenzy').style.display = ''; - l('CMDispTooltipWarnLuckyFrenzyText').textContent = Beautify(limitLuckyFrenzy - amount) + ' (' + CM.Disp.FormatTime((limitLuckyFrenzy - amount) / CM.Disp.GetCPS()) + ')'; - l('CMDispTooltipWarnLucky').style.display = 'none'; - } - } else { - l('CMDispTooltipWarnLucky').style.display = 'none'; - l('CMDispTooltipWarnLuckyFrenzy').style.display = 'none'; - } - } - else { - l('CMDispTooltipWarnLucky').style.display = 'none'; - l('CMDispTooltipWarnLuckyFrenzy').style.display = 'none'; - } - - if (CM.Config.ToolWarnConjure == 1) { - CM.Disp.TooltipWarn.style.display = 'block'; - var limitLucky = CM.Cache.Lucky; - if (CM.Config.ToolWarnBon == 1) { - var bonusNoFren = bonus; - bonusNoFren /= CM.Sim.getCPSBuffMult(); - limitLucky += ((bonusNoFren * 60 * 15) / 0.15); - } - var limitConjure = limitLucky * 2; - var amount = (Game.cookies + CM.Disp.GetWrinkConfigBank()) - price; - if ((amount < limitConjure) && (CM.Disp.tooltipType != 'b' || Game.buyMode == 1)) { - l('CMDispTooltipWarnConjure').style.display = ''; - l('CMDispTooltipWarnConjureText').textContent = Beautify(limitConjure - amount) + ' (' + CM.Disp.FormatTime((limitConjure - amount) / CM.Disp.GetCPS()) + ')'; - } else { - l('CMDispTooltipWarnConjure').style.display = 'none'; - } - } - else { - l('CMDispTooltipWarnConjure').style.display = 'none'; - } - } - else if (CM.Disp.tooltipType === 's') { - // Adding information about Sugar Lumps. - - CM.Disp.TooltipWarn.style.display = 'none'; - l('CMDispTooltipWarnLucky').style.display = 'none'; - l('CMDispTooltipWarnLuckyFrenzy').style.display = 'none'; - l('CMDispTooltipWarnConjure').style.display = 'none'; - - if (CM.Config.TooltipLump === 1) { - l('CMTooltipArea').innerHTML = ''; - - l('tooltip').firstChild.style.paddingBottom = '4px'; - var lumpTooltip = document.createElement('div'); - lumpTooltip.style.border = '1px solid'; - lumpTooltip.style.padding = '4px'; - lumpTooltip.style.margin = '0px -4px'; - lumpTooltip.id = 'CMTooltipBorder'; - lumpTooltip.className = CM.Disp.colorTextPre + CM.Disp.colorGray; - - var lumpHeader = document.createElement('div'); - lumpHeader.style.fontWeight = 'bold'; - lumpHeader.className = CM.Disp.colorTextPre + CM.Disp.colorBlue; - lumpHeader.textContent = 'Current Sugar Lump'; - - lumpTooltip.appendChild(lumpHeader); - var lumpType = document.createElement('div'); - lumpType.id = 'CMTooltipTime'; - lumpTooltip.appendChild(lumpType); - var lumpColor = CM.Disp.GetLumpColor(Game.lumpCurrentType); - lumpType.textContent = lumpColor.text; - lumpType.className = CM.Disp.colorTextPre + lumpColor.color; - - l('CMTooltipArea').appendChild(lumpTooltip); - } - } - else if (CM.Disp.tooltipType === 'g') { - // Grimoire - CM.Disp.TooltipWarn.style.display = 'none'; - l('CMDispTooltipWarnLucky').style.display = 'none'; - l('CMDispTooltipWarnLuckyFrenzy').style.display = 'none'; - l('CMDispTooltipWarnConjure').style.display = 'none'; - - var minigame = Game.Objects['Wizard tower'].minigame; - var spellCost = minigame.getSpellCost(minigame.spellsById[CM.Disp.tooltipName]); - - if (CM.Config.TooltipGrim == 1 && spellCost <= minigame.magicM) { - l('CMTooltipArea').innerHTML = ''; - - l('tooltip').firstChild.style.paddingBottom = '4px'; - var tooltip = document.createElement('div'); - tooltip.style.border = '1px solid'; - tooltip.style.padding = '4px'; - tooltip.style.margin = '0px -4px'; - tooltip.id = 'CMTooltipBorder'; - tooltip.className = CM.Disp.colorTextPre + CM.Disp.colorGray; - - var header = function(text) { - var div = document.createElement('div'); - div.style.fontWeight = 'bold'; - div.className = CM.Disp.colorTextPre + CM.Disp.colorBlue; - div.textContent = text; - return div; - } - - tooltip.appendChild(header('Time Left')); - var time = document.createElement('div'); - time.id = 'CMTooltipTime'; - tooltip.appendChild(time); - var timeColor = CM.Disp.GetTimeColor(spellCost, minigame.magic, undefined, CM.Disp.CalculateGrimoireRefillTime(minigame.magic, minigame.magicM, spellCost)); - time.textContent = timeColor.text; - time.className = CM.Disp.colorTextPre + timeColor.color; - - if (spellCost <= minigame.magic) { - tooltip.appendChild(header('Recover Time')); - var recover = document.createElement('div'); - recover.id = 'CMTooltipRecover'; - tooltip.appendChild(recover); - var recoverColor = CM.Disp.GetTimeColor(minigame.magic, Math.max(0, minigame.magic - spellCost), undefined, CM.Disp.CalculateGrimoireRefillTime(Math.max(0, minigame.magic - spellCost), minigame.magicM, minigame.magic)); - recover.textContent = recoverColor.text; - recover.className = CM.Disp.colorTextPre + recoverColor.color; - } - - // Extra information when spell is Conjure Baked Goods (Name == 0) - if (CM.Disp.tooltipName == 0) { - tooltip.appendChild(header('Cookies to be gained/lost')); - var conjure = document.createElement('div'); - conjure.id = 'CMTooltipConjure'; - tooltip.appendChild(conjure); - var reward = document.createElement('span'); - reward.style.color = "#33FF00" - reward.textContent = Beautify(Math.min((Game.cookies + CM.Disp.GetWrinkConfigBank()) * 0.15, CM.Cache.NoGoldSwitchCookiesPS * 60 * 30), 2) - conjure.appendChild(reward) - var seperator = document.createElement('span'); - seperator.textContent = ' / ' - conjure.appendChild(seperator) - var loss = document.createElement('span'); - loss.style.color = "red" - loss.textContent = Beautify((CM.Cache.NoGoldSwitchCookiesPS * 60 * 15), 2); - conjure.appendChild(loss) - } - - l('CMTooltipArea').appendChild(tooltip); - } - } - } - else { - CM.Disp.TooltipWarn.style.display = 'none'; - } - } -} - -CM.Disp.DrawTooltipWarn = function() { - if (CM.Config.ToolWarnLucky == 1) { - l('CMDispTooltipWarnLucky').style.opacity = '0'; - l('CMDispTooltipWarnLuckyFrenzy').style.opacity = '0'; - } - if (CM.Config.ToolWarnConjure == 1) { - l('CMDispTooltipWarnConjure').style.opacity = '0'; - } -} - -CM.Disp.UpdateTooltipWarn = function() { - if (CM.Config.ToolWarnLucky == 1 && l('tooltipAnchor').style.display != 'none' && l('CMTooltipArea') != null) { - l('CMDispTooltipWarnLucky').style.opacity = '1'; - l('CMDispTooltipWarnLuckyFrenzy').style.opacity = '1'; - } - if (CM.Config.ToolWarnConjure == 1 && l('tooltipAnchor').style.display != 'none' && l('CMTooltipArea') != null) { - l('CMDispTooltipWarnConjure').style.opacity = '1'; - } -} - -CM.Disp.AddWrinklerAreaDetect = function() { - l('backgroundLeftCanvas').onmouseover = function() {CM.Disp.TooltipWrinklerArea = 1;}; - l('backgroundLeftCanvas').onmouseout = function() { - CM.Disp.TooltipWrinklerArea = 0; - Game.tooltip.hide(); - for (var i in Game.wrinklers) { - CM.Disp.TooltipWrinklerCache[i] = 0; - } - }; -} - -CM.Disp.CheckWrinklerTooltip = function() { - if (CM.Config.ToolWrink == 1 && CM.Disp.TooltipWrinklerArea == 1) { - var showingTooltip = false; - for (var i in Game.wrinklers) { - var me = Game.wrinklers[i]; - if (me.phase > 0 && me.selected) { - showingTooltip = true; - if (CM.Disp.TooltipWrinklerCache[i] == 0) { - var placeholder = document.createElement('div'); - var wrinkler = document.createElement('div'); - wrinkler.style.minWidth = '120px'; - wrinkler.style.marginBottom = '4px'; - var div = document.createElement('div'); - div.style.textAlign = 'center'; - div.id = 'CMTooltipWrinkler'; - wrinkler.appendChild(div); - placeholder.appendChild(wrinkler); - Game.tooltip.draw(this, escape(placeholder.innerHTML)); - CM.Disp.TooltipWrinkler = i; - CM.Disp.TooltipWrinklerCache[i] = 1; - } - else break; - } - else { - CM.Disp.TooltipWrinklerCache[i] = 0; - } - } - if (!showingTooltip) { - Game.tooltip.hide(); - } - } -} - -CM.Disp.UpdateWrinklerTooltip = function() { - if (CM.Config.ToolWrink == 1 && l('CMTooltipWrinkler') != null) { - var sucked = Game.wrinklers[CM.Disp.TooltipWrinkler].sucked; - var toSuck = 1.1; - if (Game.Has('Sacrilegious corruption')) toSuck *= 1.05; - if (Game.wrinklers[CM.Disp.TooltipWrinkler].type == 1) toSuck *= 3; // Shiny wrinklers - sucked *= toSuck; - if (Game.Has('Wrinklerspawn')) sucked *= 1.05; - if (CM.Sim.Objects.Temple.minigameLoaded) { - var godLvl = CM.Sim.hasGod('scorn'); - if (godLvl == 1) sucked *= 1.15; - else if (godLvl == 2) sucked *= 1.1; - else if (godLvl == 3) sucked *= 1.05; - } - l('CMTooltipWrinkler').textContent = Beautify(sucked); - } -} - -CM.Disp.UpdateAscendState = function() { - if (Game.OnAscend) { - l('game').style.bottom = '0px'; - if (CM.Config.BotBar == 1) CM.Disp.BotBar.style.display = 'none'; - if (CM.Config.TimerBar == 1) CM.Disp.TimerBar.style.display = 'none'; - } - else { - CM.Disp.ToggleBotBar(); - CM.Disp.ToggleTimerBar(); - } - - CM.Disp.UpdateBackground(); -} - -CM.Disp.UpdateAuraDescription = function() { - return "function(aura)\ - {\ - l('dragonAuraInfo').innerHTML=\ - '

'+Game.dragonAuras[aura].name+'

'+\ - '
'+\ - Game.dragonAuras[aura].desc+\ - '
'+\ - CM.\ - '
';\ - }" -} - -CM.Disp.ToggleSayTime = function() { - if (CM.Config.SayTime == 1) { - Game.sayTime = CM.Disp.sayTime; - } - else { - Game.sayTime = CM.Backup.sayTime; - } -} - -CM.Disp.RefreshScale = function() { - BeautifyAll(); - Game.RefreshStore(); - Game.RebuildUpgrades(); - - CM.Disp.UpdateBotBarOther(); - CM.Disp.UpdateBuildings(); - CM.Disp.UpdateUpgrades(); -} +/******** + * Section: Variables used in Disp functions + * TODO: Move certain variables to src/Data.js (e.g., CM.Disp.metric & CM.Disp.shortScale) */ CM.Disp.colorTextPre = 'CMText'; CM.Disp.colorBackPre = 'CMBack'; From cbaf06a76b1e4d3ed79932d2a82212ac335bd8c9 Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Thu, 3 Dec 2020 16:06:25 +0100 Subject: [PATCH 017/106] Updated GCTimer code --- CookieMonster.js | 48 ++++++++++++++++++++++++++---------------------- src/Disp.js | 45 +++++++++++++++++++++++++-------------------- 2 files changed, 51 insertions(+), 42 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index 55c23a6..d0e5854 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -877,6 +877,11 @@ CM.ConfigData.Scale = {type: 'bool', group: 'Other', label: ['Game\'s Setting Sc * Disp * ********/ +/******** + * Please make sure to annotate your code correctly. See the options page section for some examples. + * Only put functions related to graphics and displays in this file. + * All calculations and data should be put in others. */ + /******** * Section: Unsorted functions * TODO: Annotate most functions @@ -2018,9 +2023,13 @@ CM.Disp.UpdateTitle = function() { } /******** - * Section: Functions related to the Golden Cookie Timers - * TODO: Annotate functions */ + * Section: Functions related to the Golden Cookie Timers */ +/** + * This function creates a new Golden Cookie Timer and appends it CM.Disp.GCTimers based on the id of the cookie + * It is called by CM.Disp.CheckGoldenCookie() + * @param {object} cookie A Golden Cookie object + */ CM.Disp.CreateGCTimer = function(cookie) { GCTimer = document.createElement('div'); GCTimer.id = 'GCTimer' + cookie.id @@ -2034,6 +2043,7 @@ CM.Disp.CreateGCTimer = function(cookie) { GCTimer.style.fontSize = '35px'; GCTimer.style.cursor = 'pointer'; GCTimer.style.display = 'block'; + if (CM.Config.GCTimer == 0) GCTimer.style.display = 'none'; GCTimer.style.left = cookie.l.style.left; GCTimer.style.top = cookie.l.style.top; GCTimer.onclick = function () {cookie.pop();}; @@ -2044,20 +2054,20 @@ CM.Disp.CreateGCTimer = function(cookie) { l('shimmers').appendChild(GCTimer); } +/** + * This function toggles GC Timers are visible + * It is called by a change in CM.Config.GCTimer + */ CM.Disp.ToggleGCTimer = function() { if (CM.Config.GCTimer == 1) { - if (CM.Disp.lastGoldenCookieState) { - for (var i in CM.Disp.GCTimers) { - CM.Disp.GCTimers[i].style.display = 'block'; - CM.Disp.GCTimers[i].style.left = CM.Disp.goldenShimmersByID[i].l.style.left; - CM.Disp.GCTimers[i].style.top = CM.Disp.goldenShimmersByID[i].l.style.top; - } + for (var i in CM.Disp.GCTimers) { + CM.Disp.GCTimers[i].style.display = 'block'; + CM.Disp.GCTimers[i].style.left = CM.Disp.goldenShimmersByID[i].l.style.left; + CM.Disp.GCTimers[i].style.top = CM.Disp.goldenShimmersByID[i].l.style.top; } } else { - for (var i in CM.Disp.GCTimers) { - CM.Disp.GCTimers[i].style.display = 'none'; - } + for (var i in CM.Disp.GCTimers) CM.Disp.GCTimers[i].style.display = 'none'; } } @@ -2083,22 +2093,16 @@ CM.Disp.CheckGoldenCookie = function() { CM.Disp.PlaySound(CM.Config.GCSoundURL, 'GCSound', 'GCVolume'); CM.Disp.Notification('GCNotification', "Golden Cookie Spawned", "A Golden Cookie has spawned. Click it now!") } - CM.Disp.lastSpawnedGoldenCookieState = CM.Disp.currSpawnedGoldenCookieState + CM.Disp.UpdateFavicon(); - if (CM.Config.GCTimer == 1) { - for (var i in Game.shimmers) { - if (typeof CM.Disp.GCTimers[Game.shimmers[i].id] == "undefined") { - CM.Disp.CreateGCTimer(Game.shimmers[i]); - } + for (var i in Game.shimmers) { + if (typeof CM.Disp.GCTimers[Game.shimmers[i].id] == "undefined") { + CM.Disp.CreateGCTimer(Game.shimmers[i]); } } } - else if (CM.Config.GCTimer == 1) { - for (var i in CM.Disp.GCTimers) { - CM.Disp.GCTimers[i].style.display = 'none'; - } - } + CM.Disp.lastSpawnedGoldenCookieState = CM.Disp.currSpawnedGoldenCookieState } else if (CM.Config.GCTimer == 1 && CM.Disp.lastGoldenCookieState) { for (var i in CM.Disp.GCTimers) { diff --git a/src/Disp.js b/src/Disp.js index 67fae59..56f031b 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -2,6 +2,11 @@ * Disp * ********/ +/******** + * Please make sure to annotate your code correctly. See the options page section for some examples. + * Only put functions related to graphics and displays in this file. + * All calculations and data should be put in others. */ + /******** * Section: Unsorted functions * TODO: Annotate most functions @@ -1146,6 +1151,11 @@ CM.Disp.UpdateTitle = function() { * Section: Functions related to the Golden Cookie Timers * TODO: Annotate functions */ +/** + * This function creates a new Golden Cookie Timer and appends it CM.Disp.GCTimers based on the id of the cookie + * It is called by CM.Disp.CheckGoldenCookie() + * @param {object} cookie A Golden Cookie object + */ CM.Disp.CreateGCTimer = function(cookie) { GCTimer = document.createElement('div'); GCTimer.id = 'GCTimer' + cookie.id @@ -1159,6 +1169,7 @@ CM.Disp.CreateGCTimer = function(cookie) { GCTimer.style.fontSize = '35px'; GCTimer.style.cursor = 'pointer'; GCTimer.style.display = 'block'; + if (CM.Config.GCTimer == 0) GCTimer.style.display = 'none'; GCTimer.style.left = cookie.l.style.left; GCTimer.style.top = cookie.l.style.top; GCTimer.onclick = function () {cookie.pop();}; @@ -1169,20 +1180,20 @@ CM.Disp.CreateGCTimer = function(cookie) { l('shimmers').appendChild(GCTimer); } +/** + * This function toggles GC Timers are visible + * It is called by a change in CM.Config.GCTimer + */ CM.Disp.ToggleGCTimer = function() { if (CM.Config.GCTimer == 1) { - if (CM.Disp.lastGoldenCookieState) { - for (var i in CM.Disp.GCTimers) { - CM.Disp.GCTimers[i].style.display = 'block'; - CM.Disp.GCTimers[i].style.left = CM.Disp.goldenShimmersByID[i].l.style.left; - CM.Disp.GCTimers[i].style.top = CM.Disp.goldenShimmersByID[i].l.style.top; - } + for (var i in CM.Disp.GCTimers) { + CM.Disp.GCTimers[i].style.display = 'block'; + CM.Disp.GCTimers[i].style.left = CM.Disp.goldenShimmersByID[i].l.style.left; + CM.Disp.GCTimers[i].style.top = CM.Disp.goldenShimmersByID[i].l.style.top; } } else { - for (var i in CM.Disp.GCTimers) { - CM.Disp.GCTimers[i].style.display = 'none'; - } + for (var i in CM.Disp.GCTimers) CM.Disp.GCTimers[i].style.display = 'none'; } } @@ -1208,22 +1219,16 @@ CM.Disp.CheckGoldenCookie = function() { CM.Disp.PlaySound(CM.Config.GCSoundURL, 'GCSound', 'GCVolume'); CM.Disp.Notification('GCNotification', "Golden Cookie Spawned", "A Golden Cookie has spawned. Click it now!") } - CM.Disp.lastSpawnedGoldenCookieState = CM.Disp.currSpawnedGoldenCookieState + CM.Disp.UpdateFavicon(); - if (CM.Config.GCTimer == 1) { - for (var i in Game.shimmers) { - if (typeof CM.Disp.GCTimers[Game.shimmers[i].id] == "undefined") { - CM.Disp.CreateGCTimer(Game.shimmers[i]); - } + for (var i in Game.shimmers) { + if (typeof CM.Disp.GCTimers[Game.shimmers[i].id] == "undefined") { + CM.Disp.CreateGCTimer(Game.shimmers[i]); } } } - else if (CM.Config.GCTimer == 1) { - for (var i in CM.Disp.GCTimers) { - CM.Disp.GCTimers[i].style.display = 'none'; - } - } + CM.Disp.lastSpawnedGoldenCookieState = CM.Disp.currSpawnedGoldenCookieState } else if (CM.Config.GCTimer == 1 && CM.Disp.lastGoldenCookieState) { for (var i in CM.Disp.GCTimers) { From 8a303c2d271ca2df91c90510330229a556b40482 Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Thu, 3 Dec 2020 16:36:19 +0100 Subject: [PATCH 018/106] Update state-checking code --- CookieMonster.js | 384 ++++++++++++++++++++++++----------------------- src/Cache.js | 3 + src/Disp.js | 195 ++++-------------------- src/Main.js | 185 ++++++++++++++++++++--- 4 files changed, 399 insertions(+), 368 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index d0e5854..f34e6e9 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -27,6 +27,9 @@ if (typeof CM == "undefined") { * Cache * *********/ +/******** + * Section: UNSORTED */ + CM.Cache.AddQueue = function() { CM.Cache.Queue = document.createElement('script'); CM.Cache.Queue.type = 'text/javascript'; @@ -1054,18 +1057,6 @@ CM.Disp.UpdateColors = function() { CM.Disp.UpdateBuildings(); // Class has been already set } -CM.Disp.FindShimmer = function() { - CM.Disp.currSpawnedGoldenCookieState = 0 - CM.Disp.goldenShimmersByID = {} - for (var i in Game.shimmers) { - CM.Disp.goldenShimmersByID[Game.shimmers[i].id] = Game.shimmers[i] - if (Game.shimmers[i].spawnLead && Game.shimmers[i].type == 'golden') { - CM.Disp.spawnedGoldenShimmer = Game.shimmers[i]; - CM.Disp.currSpawnedGoldenCookieState += 1; - } - } -} - CM.Disp.CollectWrinklers = function() { for (var i in Game.wrinklers) { if (Game.wrinklers[i].sucked > 0 && Game.wrinklers[i].type == 0) { @@ -1943,12 +1934,12 @@ CM.Disp.CreateFavicon = function() { /** * This function updates the Favicon depending on whether a Golden Cookie has spawned - * It is called on every loop by CM.Disp.CheckGoldenCookie() or by a change in CM.Config.Favicon - * By relying on CM.Disp.spawnedGoldenShimmer it only changes for non-user spawned cookie + * It is called on every loop by CM.Main.CheckGoldenCookie() or by a change in CM.Config.Favicon + * By relying on CM.Cache.spawnedGoldenShimmer it only changes for non-user spawned cookie */ CM.Disp.UpdateFavicon = function() { if (CM.Config.Favicon == 1) { - if (CM.Disp.spawnedGoldenShimmer.wrath) CM.Disp.Favicon.href = 'https://aktanusa.github.io/CookieMonster/favicon/wrathCookie.ico'; + if (CM.Cache.spawnedGoldenShimmer.wrath) CM.Disp.Favicon.href = 'https://aktanusa.github.io/CookieMonster/favicon/wrathCookie.ico'; else CM.Disp.Favicon.href = 'https://aktanusa.github.io/CookieMonster/favicon/goldenCookie.ico'; } else CM.Disp.Favicon.href = 'https://orteil.dashnet.org/cookieclicker/favicon.ico'; @@ -1969,23 +1960,23 @@ CM.Disp.UpdateTitle = function() { var titleFC; var titleSP; - if (CM.Disp.spawnedGoldenShimmer) { - if (CM.Disp.spawnedGoldenShimmer.wrath) titleGC = '[W ' + Math.ceil(CM.Disp.spawnedGoldenShimmer.life / Game.fps) + ']'; - else titleGC = '[G ' + Math.ceil(CM.Disp.spawnedGoldenShimmer.life / Game.fps) + ']'; + if (CM.Cache.spawnedGoldenShimmer) { + if (CM.Cache.spawnedGoldenShimmer.wrath) titleGC = '[W ' + Math.ceil(CM.Cache.spawnedGoldenShimmer.life / Game.fps) + ']'; + else titleGC = '[G ' + Math.ceil(CM.Cache.spawnedGoldenShimmer.life / Game.fps) + ']'; } else if (!Game.Has('Golden switch [off]')) { titleGC = '[' + Math.ceil((Game.shimmerTypes['golden'].maxTime - Game.shimmerTypes['golden'].time) / Game.fps) + ']'; } else titleGC = '[GS]' - if (CM.Disp.lastTickerFortuneState) { + if (CM.Main.lastTickerFortuneState) { addFC = true; titleFC = '[F]'; } if (Game.season == 'christmas') { addSP = true; - if (CM.Disp.lastSeasonPopupState) titleSP = '[R ' + Math.ceil(CM.Disp.seasonPopShimmer.life / Game.fps) + ']'; + if (CM.Main.lastSeasonPopupState) titleSP = '[R ' + Math.ceil(CM.Cache.seasonPopShimmer.life / Game.fps) + ']'; else { titleSP = '[' + Math.ceil((Game.shimmerTypes['reindeer'].maxTime - Game.shimmerTypes['reindeer'].time) / Game.fps) + ']'; } @@ -2001,17 +1992,17 @@ CM.Disp.UpdateTitle = function() { else if (CM.Config.Title == 2) { var str = ''; var spawn = false; - if (CM.Disp.spawnedGoldenShimmer) { + if (CM.Cache.spawnedGoldenShimmer) { spawn = true; - if (CM.Disp.spawnedGoldenShimmer.wrath) str += '[W ' + Math.ceil(CM.Disp.spawnedGoldenShimmer.life / Game.fps) + ']'; - else str += '[G ' + Math.ceil(CM.Disp.spawnedGoldenShimmer.life / Game.fps) + ']'; + if (CM.Cache.spawnedGoldenShimmer.wrath) str += '[W ' + Math.ceil(CM.Cache.spawnedGoldenShimmer.life / Game.fps) + ']'; + else str += '[G ' + Math.ceil(CM.Cache.spawnedGoldenShimmer.life / Game.fps) + ']'; } - if (CM.Disp.lastTickerFortuneState) { + if (CM.Main.lastTickerFortuneState) { spawn = true; str += '[F]'; } - if (Game.season == 'christmas' && CM.Disp.lastSeasonPopupState) { - str += '[R ' + Math.ceil(CM.Disp.seasonPopShimmer.life / Game.fps) + ']'; + if (Game.season == 'christmas' && CM.Main.lastSeasonPopupState) { + str += '[R ' + Math.ceil(CM.Cache.seasonPopShimmer.life / Game.fps) + ']'; spawn = true; } if (spawn) str += ' - '; @@ -2023,11 +2014,11 @@ CM.Disp.UpdateTitle = function() { } /******** - * Section: Functions related to the Golden Cookie Timers */ + * Section: Functions related to the Golden Cookie Timers /** * This function creates a new Golden Cookie Timer and appends it CM.Disp.GCTimers based on the id of the cookie - * It is called by CM.Disp.CheckGoldenCookie() + * It is called by CM.Main.CheckGoldenCookie() * @param {object} cookie A Golden Cookie object */ CM.Disp.CreateGCTimer = function(cookie) { @@ -2062,8 +2053,8 @@ CM.Disp.ToggleGCTimer = function() { if (CM.Config.GCTimer == 1) { for (var i in CM.Disp.GCTimers) { CM.Disp.GCTimers[i].style.display = 'block'; - CM.Disp.GCTimers[i].style.left = CM.Disp.goldenShimmersByID[i].l.style.left; - CM.Disp.GCTimers[i].style.top = CM.Disp.goldenShimmersByID[i].l.style.top; + CM.Disp.GCTimers[i].style.left = CM.Cache.goldenShimmersByID[i].l.style.left; + CM.Disp.GCTimers[i].style.top = CM.Cache.goldenShimmersByID[i].l.style.top; } } else { @@ -2071,132 +2062,6 @@ CM.Disp.ToggleGCTimer = function() { } } -/******** - * Section: Functions related to checking for changes in Minigames/GC's/Ticker - * TODO: Annotate functions - * TODO: Possibly move this section */ - -CM.Disp.CheckGoldenCookie = function() { - CM.Disp.FindShimmer(); - for (var i in CM.Disp.GCTimers) { - if (typeof CM.Disp.goldenShimmersByID[i] == "undefined") { - CM.Disp.GCTimers[i].parentNode.removeChild(CM.Disp.GCTimers[i]); - // TODO remove delete here - delete CM.Disp.GCTimers[i]; - } - } - if (CM.Disp.lastGoldenCookieState != Game.shimmerTypes['golden'].n) { - CM.Disp.lastGoldenCookieState = Game.shimmerTypes['golden'].n; - if (CM.Disp.lastGoldenCookieState) { - if (CM.Disp.lastSpawnedGoldenCookieState < CM.Disp.currSpawnedGoldenCookieState) { - CM.Disp.Flash(3, 'GCFlash'); - CM.Disp.PlaySound(CM.Config.GCSoundURL, 'GCSound', 'GCVolume'); - CM.Disp.Notification('GCNotification', "Golden Cookie Spawned", "A Golden Cookie has spawned. Click it now!") - } - - CM.Disp.UpdateFavicon(); - - for (var i in Game.shimmers) { - if (typeof CM.Disp.GCTimers[Game.shimmers[i].id] == "undefined") { - CM.Disp.CreateGCTimer(Game.shimmers[i]); - } - } - } - CM.Disp.lastSpawnedGoldenCookieState = CM.Disp.currSpawnedGoldenCookieState - } - else if (CM.Config.GCTimer == 1 && CM.Disp.lastGoldenCookieState) { - for (var i in CM.Disp.GCTimers) { - CM.Disp.GCTimers[i].style.opacity = CM.Disp.goldenShimmersByID[i].l.style.opacity; - CM.Disp.GCTimers[i].style.transform = CM.Disp.goldenShimmersByID[i].l.style.transform; - CM.Disp.GCTimers[i].textContent = Math.ceil(CM.Disp.goldenShimmersByID[i].life / Game.fps); - } - } -} - -CM.Disp.CheckTickerFortune = function() { - if (CM.Disp.lastTickerFortuneState != (Game.TickerEffect && Game.TickerEffect.type == 'fortune')) { - CM.Disp.lastTickerFortuneState = (Game.TickerEffect && Game.TickerEffect.type == 'fortune'); - if (CM.Disp.lastTickerFortuneState) { - CM.Disp.Flash(3, 'FortuneFlash'); - CM.Disp.PlaySound(CM.Config.FortuneSoundURL, 'FortuneSound', 'FortuneVolume'); - CM.Disp.Notification('FortuneNotification', "Fortune Cookie found", "A Fortune Cookie has appeared on the Ticker.") - } - } -} - -CM.Disp.CheckSeasonPopup = function() { - if (CM.Disp.lastSeasonPopupState != Game.shimmerTypes['reindeer'].spawned) { - CM.Disp.lastSeasonPopupState = Game.shimmerTypes['reindeer'].spawned; - if (CM.Disp.lastSeasonPopupState && Game.season=='christmas') { - // Needed for some of the functions to use the right object - for (var i in Game.shimmers) { - if (Game.shimmers[i].spawnLead && Game.shimmers[i].type == 'reindeer') { - CM.Disp.seasonPopShimmer = Game.shimmers[i]; - break; - } - } - - CM.Disp.Flash(3, 'SeaFlash'); - CM.Disp.PlaySound(CM.Config.SeaSoundURL, 'SeaSound', 'SeaVolume'); - CM.Disp.Notification('SeaNotification',"Reindeer sighted!", "A Reindeer has spawned. Click it now!") - } - } -} - -CM.Disp.CheckGardenTick = function() { - if (Game.Objects['Farm'].minigameLoaded && CM.Disp.lastGardenNextStep != Game.Objects['Farm'].minigame.nextStep) { - if (CM.Disp.lastGardenNextStep != 0 && CM.Disp.lastGardenNextStep < Date.now()) { - CM.Disp.Flash(3, 'GardFlash'); - CM.Disp.PlaySound(CM.Config.GardSoundURL, 'GardSound', 'GardVolume'); - } - CM.Disp.lastGardenNextStep = Game.Objects['Farm'].minigame.nextStep; - } -} - -CM.Disp.CheckMagicMeter = function() { - if (Game.Objects['Wizard tower'].minigameLoaded && CM.Config.GrimoireBar == 1) { - var minigame = Game.Objects['Wizard tower'].minigame; - if (minigame.magic < minigame.magicM) { - CM.Disp.lastMagicBarFull = false; - } - else if (!CM.Disp.lastMagicBarFull) { - CM.Disp.lastMagicBarFull = true; - CM.Disp.Flash(3, 'MagicFlash'); - CM.Disp.PlaySound(CM.Config.MagicSoundURL, 'MagicSound', 'MagicVolume'); - CM.Disp.Notification('MagicNotification', "Magic Meter full", "Your Magic Meter is full. Cast a spell!") - } - } -} - -CM.Disp.CheckWrinklerCount = function() { - if (Game.elderWrath > 0) { - var CurrentWrinklers = 0; - for (var i in Game.wrinklers) { - if (Game.wrinklers[i].phase == 2) CurrentWrinklers++; - } - if (CurrentWrinklers > CM.Disp.lastWrinklerCount) { - CM.Disp.lastWrinklerCount = CurrentWrinklers - if (CurrentWrinklers == Game.getWrinklersMax() && CM.Config.WrinklerMaxFlash) { - CM.Disp.Flash(3, 'WrinklerMaxFlash'); - } else { - CM.Disp.Flash(3, 'WrinklerFlash'); - } - if (CurrentWrinklers == Game.getWrinklersMax() && CM.Config.WrinklerMaxSound) { - CM.Disp.PlaySound(CM.Config.WrinklerMaxSoundURL, 'WrinklerMaxSound', 'WrinklerMaxVolume'); - } else { - CM.Disp.PlaySound(CM.Config.WrinklerSoundURL, 'WrinklerSound', 'WrinklerVolume'); - } - if (CurrentWrinklers == Game.getWrinklersMax() && CM.Config.WrinklerMaxNotification) { - CM.Disp.Notification('WrinklerMaxNotification', "Maximum Wrinklers Reached", "You have reached your maximum ammount of wrinklers") - } else { - CM.Disp.Notification('WrinklerNotification', "A Wrinkler appeared", "A new wrinkler has appeared") - } - } else { - CM.Disp.lastWrinklerCount = CurrentWrinklers - } - } -} - /******** * Section: Functions related to Tooltips * TODO: Annotate functions */ @@ -3472,18 +3337,18 @@ CM.Disp.colorPink = 'Pink'; CM.Disp.colorBrown = 'Brown'; CM.Disp.colors = [CM.Disp.colorBlue, CM.Disp.colorGreen, CM.Disp.colorYellow, CM.Disp.colorOrange, CM.Disp.colorRed, CM.Disp.colorPurple, CM.Disp.colorGray, CM.Disp.colorPink, CM.Disp.colorBrown]; CM.Disp.buffColors = {'Frenzy': CM.Disp.colorYellow, 'Dragon Harvest': CM.Disp.colorBrown, 'Elder frenzy': CM.Disp.colorGreen, 'Clot': CM.Disp.colorRed, 'Click frenzy': CM.Disp.colorBlue, 'Dragonflight': CM.Disp.colorPink}; -CM.Disp.lastGoldenCookieState = 0; -CM.Disp.lastSpawnedGoldenCookieState = 0; -CM.Disp.currSpawnedGoldenCookieState -CM.Disp.lastTickerFortuneState = 0; -CM.Disp.lastSeasonPopupState = 0; -CM.Disp.lastGardenNextStep = 0; -CM.Disp.lastMagicBarFull = 0; -CM.Disp.lastWrinklerCount = 0; -CM.Disp.goldenShimmersByID = {}; -CM.Disp.spawnedGoldenShimmer = 0; +CM.Main.lastGoldenCookieState = 0; +CM.Main.lastSpawnedGoldenCookieState = 0; +CM.Main.currSpawnedGoldenCookieState +CM.Main.lastTickerFortuneState = 0; +CM.Main.lastSeasonPopupState = 0; +CM.Main.lastGardenNextStep = 0; +CM.Main.lastMagicBarFull = 0; +CM.Main.lastWrinklerCount = 0; +CM.Cache.goldenShimmersByID = {}; +CM.Cache.spawnedGoldenShimmer = 0; CM.Disp.GCTimers = {}; -CM.Disp.seasonPopShimmer; +CM.Cache.seasonPopShimmer; CM.Disp.lastAscendState = -1; CM.Disp.cookieTimes = [10, 15, 30, 60, 300, 600, 900, 1800]; @@ -3695,23 +3560,13 @@ CM.Loop = function() { CM.Disp.RefreshMenu(); } - // Check Golden Cookies - CM.Disp.CheckGoldenCookie(); - - // Check Fortune Cookies - CM.Disp.CheckTickerFortune(); - - // Check Season Popup - CM.Disp.CheckSeasonPopup(); - - // Check Garden Tick - CM.Disp.CheckGardenTick(); - - // Check Grimoire Meter - CM.Disp.CheckMagicMeter(); - - // Check Wrinklers - CM.Disp.CheckWrinklerCount(); + // Check all changing minigames and game-states + CM.Main.CheckGoldenCookie(); + CM.Main.CheckTickerFortune(); + CM.Main.CheckSeasonPopup(); + CM.Main.CheckGardenTick(); + CM.Main.CheckMagicMeter(); + CM.Main.CheckWrinklerCount(); // Update Average CPS (might need to move) CM.Cache.UpdateAvgCPS() @@ -3767,6 +3622,167 @@ CM.DelayInit = function() { Game.Win('Third-party'); } +/******** + * Section: Functions related to checking for changes in Minigames/GC's/Ticker + * TODO: Annotate functions + * TODO: Possibly move this section */ + +/** + * Auxilirary function that finds all currently spawned shimmers. + * CM.Cache.spawnedGoldenShimmer stores the non-user spawned cookie to later determine data for the favicon and tab-title + * It is called by CM.CM.Main.CheckGoldenCookie + */ +CM.Main.FindShimmer = function() { + CM.Main.currSpawnedGoldenCookieState = 0; + CM.Cache.goldenShimmersByID = {} + for (var i in Game.shimmers) { + CM.Cache.goldenShimmersByID[Game.shimmers[i].id] = Game.shimmers[i] + if (Game.shimmers[i].spawnLead && Game.shimmers[i].type == 'golden') { + CM.Cache.spawnedGoldenShimmer = Game.shimmers[i]; + CM.Main.currSpawnedGoldenCookieState += 1; + } + } +} + +/** + * This function checks for changes in the amount of Golden Cookies + * It is called by CM.Loop + * TODO: Remove the delete function, as it does not delete correctly and crowds CM.Disp.GCTimers + */ +CM.Main.CheckGoldenCookie = function() { + CM.Main.FindShimmer(); + for (var i in CM.Disp.GCTimers) { + if (typeof CM.Cache.goldenShimmersByID[i] == "undefined") { + CM.Disp.GCTimers[i].parentNode.removeChild(CM.Disp.GCTimers[i]); + // TODO remove delete here + delete CM.Disp.GCTimers[i]; + } + } + if (CM.Main.lastGoldenCookieState != Game.shimmerTypes['golden'].n) { + CM.Main.lastGoldenCookieState = Game.shimmerTypes['golden'].n; + if (CM.Main.lastGoldenCookieState) { + if (CM.Main.lastSpawnedGoldenCookieState < CM.Main.currSpawnedGoldenCookieState) { + CM.Disp.Flash(3, 'GCFlash'); + CM.Disp.PlaySound(CM.Config.GCSoundURL, 'GCSound', 'GCVolume'); + CM.Disp.Notification('GCNotification', "Golden Cookie Spawned", "A Golden Cookie has spawned. Click it now!") + } + CM.Disp.UpdateFavicon(); + + for (var i in Game.shimmers) { + if (typeof CM.Disp.GCTimers[Game.shimmers[i].id] == "undefined") { + CM.Disp.CreateGCTimer(Game.shimmers[i]); + } + } + } + CM.Main.lastSpawnedGoldenCookieState = CM.Main.currSpawnedGoldenCookieState + } + else if (CM.Config.GCTimer == 1 && CM.Main.lastGoldenCookieState) { + for (var i in CM.Disp.GCTimers) { + CM.Disp.GCTimers[i].style.opacity = CM.Cache.goldenShimmersByID[i].l.style.opacity; + CM.Disp.GCTimers[i].style.transform = CM.Cache.goldenShimmersByID[i].l.style.transform; + CM.Disp.GCTimers[i].textContent = Math.ceil(CM.Cache.goldenShimmersByID[i].life / Game.fps); + } + } +} + +/** + * This function checks if there is reindeer that has spawned + * It is called by CM.Loop + */ +CM.Main.CheckSeasonPopup = function() { + if (CM.Main.lastSeasonPopupState != Game.shimmerTypes['reindeer'].spawned) { + CM.Main.lastSeasonPopupState = Game.shimmerTypes['reindeer'].spawned; + for (var i in Game.shimmers) { + if (Game.shimmers[i].spawnLead && Game.shimmers[i].type == 'reindeer') { + CM.Cache.seasonPopShimmer = Game.shimmers[i]; + break; + } + } + CM.Disp.Flash(3, 'SeaFlash'); + CM.Disp.PlaySound(CM.Config.SeaSoundURL, 'SeaSound', 'SeaVolume'); + CM.Disp.Notification('SeaNotification',"Reindeer sighted!", "A Reindeer has spawned. Click it now!") + } +} + +/** + * This function checks if there is a fortune cookie on the ticker + * It is called by CM.Loop + */ +CM.Main.CheckTickerFortune = function() { + if (CM.Main.lastTickerFortuneState != (Game.TickerEffect && Game.TickerEffect.type == 'fortune')) { + CM.Main.lastTickerFortuneState = (Game.TickerEffect && Game.TickerEffect.type == 'fortune'); + if (CM.Main.lastTickerFortuneState) { + CM.Disp.Flash(3, 'FortuneFlash'); + CM.Disp.PlaySound(CM.Config.FortuneSoundURL, 'FortuneSound', 'FortuneVolume'); + CM.Disp.Notification('FortuneNotification', "Fortune Cookie found", "A Fortune Cookie has appeared on the Ticker.") + } + } +} + +/** + * This function checks if a garden tick has happened + * It is called by CM.Loop + */ +CM.Main.CheckGardenTick = function() { + if (Game.Objects['Farm'].minigameLoaded && CM.Main.lastGardenNextStep != Game.Objects['Farm'].minigame.nextStep) { + if (CM.Main.lastGardenNextStep != 0 && CM.Main.lastGardenNextStep < Date.now()) { + CM.Disp.Flash(3, 'GardFlash'); + CM.Disp.PlaySound(CM.Config.GardSoundURL, 'GardSound', 'GardVolume'); + } + CM.Main.lastGardenNextStep = Game.Objects['Farm'].minigame.nextStep; + } +} + +/** + * This function checks if the magic meter is full + * It is called by CM.Loop + */ +CM.Main.CheckMagicMeter = function() { + if (Game.Objects['Wizard tower'].minigameLoaded && CM.Config.GrimoireBar == 1) { + var minigame = Game.Objects['Wizard tower'].minigame; + if (minigame.magic < minigame.magicM) CM.Main.lastMagicBarFull = false; + else if (!CM.Main.lastMagicBarFull) { + CM.Main.lastMagicBarFull = true; + CM.Disp.Flash(3, 'MagicFlash'); + CM.Disp.PlaySound(CM.Config.MagicSoundURL, 'MagicSound', 'MagicVolume'); + CM.Disp.Notification('MagicNotification', "Magic Meter full", "Your Magic Meter is full. Cast a spell!") + } + } +} + +/** + * This function checks if any new Wrinklers have popped up + * It is called by CM.Loop + */ +CM.Main.CheckWrinklerCount = function() { + if (Game.elderWrath > 0) { + var CurrentWrinklers = 0; + for (var i in Game.wrinklers) { + if (Game.wrinklers[i].phase == 2) CurrentWrinklers++; + } + if (CurrentWrinklers > CM.Main.lastWrinklerCount) { + CM.Main.lastWrinklerCount = CurrentWrinklers + if (CurrentWrinklers == Game.getWrinklersMax() && CM.Config.WrinklerMaxFlash) { + CM.Disp.Flash(3, 'WrinklerMaxFlash'); + } else { + CM.Disp.Flash(3, 'WrinklerFlash'); + } + if (CurrentWrinklers == Game.getWrinklersMax() && CM.Config.WrinklerMaxSound) { + CM.Disp.PlaySound(CM.Config.WrinklerMaxSoundURL, 'WrinklerMaxSound', 'WrinklerMaxVolume'); + } else { + CM.Disp.PlaySound(CM.Config.WrinklerSoundURL, 'WrinklerSound', 'WrinklerVolume'); + } + if (CurrentWrinklers == Game.getWrinklersMax() && CM.Config.WrinklerMaxNotification) { + CM.Disp.Notification('WrinklerMaxNotification', "Maximum Wrinklers Reached", "You have reached your maximum ammount of wrinklers") + } else { + CM.Disp.Notification('WrinklerNotification', "A Wrinkler appeared", "A new wrinkler has appeared") + } + } else { + CM.Main.lastWrinklerCount = CurrentWrinklers + } + } +} + CM.HasReplaceNativeGrimoireLaunch = false; CM.HasReplaceNativeGrimoireDraw = false; diff --git a/src/Cache.js b/src/Cache.js index 3498447..3fdd91d 100644 --- a/src/Cache.js +++ b/src/Cache.js @@ -2,6 +2,9 @@ * Cache * *********/ +/******** + * Section: UNSORTED */ + CM.Cache.AddQueue = function() { CM.Cache.Queue = document.createElement('script'); CM.Cache.Queue.type = 'text/javascript'; diff --git a/src/Disp.js b/src/Disp.js index 56f031b..c1557f0 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -179,18 +179,6 @@ CM.Disp.UpdateColors = function() { CM.Disp.UpdateBuildings(); // Class has been already set } -CM.Disp.FindShimmer = function() { - CM.Disp.currSpawnedGoldenCookieState = 0 - CM.Disp.goldenShimmersByID = {} - for (var i in Game.shimmers) { - CM.Disp.goldenShimmersByID[Game.shimmers[i].id] = Game.shimmers[i] - if (Game.shimmers[i].spawnLead && Game.shimmers[i].type == 'golden') { - CM.Disp.spawnedGoldenShimmer = Game.shimmers[i]; - CM.Disp.currSpawnedGoldenCookieState += 1; - } - } -} - CM.Disp.CollectWrinklers = function() { for (var i in Game.wrinklers) { if (Game.wrinklers[i].sucked > 0 && Game.wrinklers[i].type == 0) { @@ -1068,12 +1056,12 @@ CM.Disp.CreateFavicon = function() { /** * This function updates the Favicon depending on whether a Golden Cookie has spawned - * It is called on every loop by CM.Disp.CheckGoldenCookie() or by a change in CM.Config.Favicon - * By relying on CM.Disp.spawnedGoldenShimmer it only changes for non-user spawned cookie + * It is called on every loop by CM.Main.CheckGoldenCookie() or by a change in CM.Config.Favicon + * By relying on CM.Cache.spawnedGoldenShimmer it only changes for non-user spawned cookie */ CM.Disp.UpdateFavicon = function() { if (CM.Config.Favicon == 1) { - if (CM.Disp.spawnedGoldenShimmer.wrath) CM.Disp.Favicon.href = 'https://aktanusa.github.io/CookieMonster/favicon/wrathCookie.ico'; + if (CM.Cache.spawnedGoldenShimmer.wrath) CM.Disp.Favicon.href = 'https://aktanusa.github.io/CookieMonster/favicon/wrathCookie.ico'; else CM.Disp.Favicon.href = 'https://aktanusa.github.io/CookieMonster/favicon/goldenCookie.ico'; } else CM.Disp.Favicon.href = 'https://orteil.dashnet.org/cookieclicker/favicon.ico'; @@ -1094,23 +1082,23 @@ CM.Disp.UpdateTitle = function() { var titleFC; var titleSP; - if (CM.Disp.spawnedGoldenShimmer) { - if (CM.Disp.spawnedGoldenShimmer.wrath) titleGC = '[W ' + Math.ceil(CM.Disp.spawnedGoldenShimmer.life / Game.fps) + ']'; - else titleGC = '[G ' + Math.ceil(CM.Disp.spawnedGoldenShimmer.life / Game.fps) + ']'; + if (CM.Cache.spawnedGoldenShimmer) { + if (CM.Cache.spawnedGoldenShimmer.wrath) titleGC = '[W ' + Math.ceil(CM.Cache.spawnedGoldenShimmer.life / Game.fps) + ']'; + else titleGC = '[G ' + Math.ceil(CM.Cache.spawnedGoldenShimmer.life / Game.fps) + ']'; } else if (!Game.Has('Golden switch [off]')) { titleGC = '[' + Math.ceil((Game.shimmerTypes['golden'].maxTime - Game.shimmerTypes['golden'].time) / Game.fps) + ']'; } else titleGC = '[GS]' - if (CM.Disp.lastTickerFortuneState) { + if (CM.Main.lastTickerFortuneState) { addFC = true; titleFC = '[F]'; } if (Game.season == 'christmas') { addSP = true; - if (CM.Disp.lastSeasonPopupState) titleSP = '[R ' + Math.ceil(CM.Disp.seasonPopShimmer.life / Game.fps) + ']'; + if (CM.Main.lastSeasonPopupState) titleSP = '[R ' + Math.ceil(CM.Cache.seasonPopShimmer.life / Game.fps) + ']'; else { titleSP = '[' + Math.ceil((Game.shimmerTypes['reindeer'].maxTime - Game.shimmerTypes['reindeer'].time) / Game.fps) + ']'; } @@ -1126,17 +1114,17 @@ CM.Disp.UpdateTitle = function() { else if (CM.Config.Title == 2) { var str = ''; var spawn = false; - if (CM.Disp.spawnedGoldenShimmer) { + if (CM.Cache.spawnedGoldenShimmer) { spawn = true; - if (CM.Disp.spawnedGoldenShimmer.wrath) str += '[W ' + Math.ceil(CM.Disp.spawnedGoldenShimmer.life / Game.fps) + ']'; - else str += '[G ' + Math.ceil(CM.Disp.spawnedGoldenShimmer.life / Game.fps) + ']'; + if (CM.Cache.spawnedGoldenShimmer.wrath) str += '[W ' + Math.ceil(CM.Cache.spawnedGoldenShimmer.life / Game.fps) + ']'; + else str += '[G ' + Math.ceil(CM.Cache.spawnedGoldenShimmer.life / Game.fps) + ']'; } - if (CM.Disp.lastTickerFortuneState) { + if (CM.Main.lastTickerFortuneState) { spawn = true; str += '[F]'; } - if (Game.season == 'christmas' && CM.Disp.lastSeasonPopupState) { - str += '[R ' + Math.ceil(CM.Disp.seasonPopShimmer.life / Game.fps) + ']'; + if (Game.season == 'christmas' && CM.Main.lastSeasonPopupState) { + str += '[R ' + Math.ceil(CM.Cache.seasonPopShimmer.life / Game.fps) + ']'; spawn = true; } if (spawn) str += ' - '; @@ -1149,11 +1137,10 @@ CM.Disp.UpdateTitle = function() { /******** * Section: Functions related to the Golden Cookie Timers - * TODO: Annotate functions */ /** * This function creates a new Golden Cookie Timer and appends it CM.Disp.GCTimers based on the id of the cookie - * It is called by CM.Disp.CheckGoldenCookie() + * It is called by CM.Main.CheckGoldenCookie() * @param {object} cookie A Golden Cookie object */ CM.Disp.CreateGCTimer = function(cookie) { @@ -1188,8 +1175,8 @@ CM.Disp.ToggleGCTimer = function() { if (CM.Config.GCTimer == 1) { for (var i in CM.Disp.GCTimers) { CM.Disp.GCTimers[i].style.display = 'block'; - CM.Disp.GCTimers[i].style.left = CM.Disp.goldenShimmersByID[i].l.style.left; - CM.Disp.GCTimers[i].style.top = CM.Disp.goldenShimmersByID[i].l.style.top; + CM.Disp.GCTimers[i].style.left = CM.Cache.goldenShimmersByID[i].l.style.left; + CM.Disp.GCTimers[i].style.top = CM.Cache.goldenShimmersByID[i].l.style.top; } } else { @@ -1197,132 +1184,6 @@ CM.Disp.ToggleGCTimer = function() { } } -/******** - * Section: Functions related to checking for changes in Minigames/GC's/Ticker - * TODO: Annotate functions - * TODO: Possibly move this section */ - -CM.Disp.CheckGoldenCookie = function() { - CM.Disp.FindShimmer(); - for (var i in CM.Disp.GCTimers) { - if (typeof CM.Disp.goldenShimmersByID[i] == "undefined") { - CM.Disp.GCTimers[i].parentNode.removeChild(CM.Disp.GCTimers[i]); - // TODO remove delete here - delete CM.Disp.GCTimers[i]; - } - } - if (CM.Disp.lastGoldenCookieState != Game.shimmerTypes['golden'].n) { - CM.Disp.lastGoldenCookieState = Game.shimmerTypes['golden'].n; - if (CM.Disp.lastGoldenCookieState) { - if (CM.Disp.lastSpawnedGoldenCookieState < CM.Disp.currSpawnedGoldenCookieState) { - CM.Disp.Flash(3, 'GCFlash'); - CM.Disp.PlaySound(CM.Config.GCSoundURL, 'GCSound', 'GCVolume'); - CM.Disp.Notification('GCNotification', "Golden Cookie Spawned", "A Golden Cookie has spawned. Click it now!") - } - - CM.Disp.UpdateFavicon(); - - for (var i in Game.shimmers) { - if (typeof CM.Disp.GCTimers[Game.shimmers[i].id] == "undefined") { - CM.Disp.CreateGCTimer(Game.shimmers[i]); - } - } - } - CM.Disp.lastSpawnedGoldenCookieState = CM.Disp.currSpawnedGoldenCookieState - } - else if (CM.Config.GCTimer == 1 && CM.Disp.lastGoldenCookieState) { - for (var i in CM.Disp.GCTimers) { - CM.Disp.GCTimers[i].style.opacity = CM.Disp.goldenShimmersByID[i].l.style.opacity; - CM.Disp.GCTimers[i].style.transform = CM.Disp.goldenShimmersByID[i].l.style.transform; - CM.Disp.GCTimers[i].textContent = Math.ceil(CM.Disp.goldenShimmersByID[i].life / Game.fps); - } - } -} - -CM.Disp.CheckTickerFortune = function() { - if (CM.Disp.lastTickerFortuneState != (Game.TickerEffect && Game.TickerEffect.type == 'fortune')) { - CM.Disp.lastTickerFortuneState = (Game.TickerEffect && Game.TickerEffect.type == 'fortune'); - if (CM.Disp.lastTickerFortuneState) { - CM.Disp.Flash(3, 'FortuneFlash'); - CM.Disp.PlaySound(CM.Config.FortuneSoundURL, 'FortuneSound', 'FortuneVolume'); - CM.Disp.Notification('FortuneNotification', "Fortune Cookie found", "A Fortune Cookie has appeared on the Ticker.") - } - } -} - -CM.Disp.CheckSeasonPopup = function() { - if (CM.Disp.lastSeasonPopupState != Game.shimmerTypes['reindeer'].spawned) { - CM.Disp.lastSeasonPopupState = Game.shimmerTypes['reindeer'].spawned; - if (CM.Disp.lastSeasonPopupState && Game.season=='christmas') { - // Needed for some of the functions to use the right object - for (var i in Game.shimmers) { - if (Game.shimmers[i].spawnLead && Game.shimmers[i].type == 'reindeer') { - CM.Disp.seasonPopShimmer = Game.shimmers[i]; - break; - } - } - - CM.Disp.Flash(3, 'SeaFlash'); - CM.Disp.PlaySound(CM.Config.SeaSoundURL, 'SeaSound', 'SeaVolume'); - CM.Disp.Notification('SeaNotification',"Reindeer sighted!", "A Reindeer has spawned. Click it now!") - } - } -} - -CM.Disp.CheckGardenTick = function() { - if (Game.Objects['Farm'].minigameLoaded && CM.Disp.lastGardenNextStep != Game.Objects['Farm'].minigame.nextStep) { - if (CM.Disp.lastGardenNextStep != 0 && CM.Disp.lastGardenNextStep < Date.now()) { - CM.Disp.Flash(3, 'GardFlash'); - CM.Disp.PlaySound(CM.Config.GardSoundURL, 'GardSound', 'GardVolume'); - } - CM.Disp.lastGardenNextStep = Game.Objects['Farm'].minigame.nextStep; - } -} - -CM.Disp.CheckMagicMeter = function() { - if (Game.Objects['Wizard tower'].minigameLoaded && CM.Config.GrimoireBar == 1) { - var minigame = Game.Objects['Wizard tower'].minigame; - if (minigame.magic < minigame.magicM) { - CM.Disp.lastMagicBarFull = false; - } - else if (!CM.Disp.lastMagicBarFull) { - CM.Disp.lastMagicBarFull = true; - CM.Disp.Flash(3, 'MagicFlash'); - CM.Disp.PlaySound(CM.Config.MagicSoundURL, 'MagicSound', 'MagicVolume'); - CM.Disp.Notification('MagicNotification', "Magic Meter full", "Your Magic Meter is full. Cast a spell!") - } - } -} - -CM.Disp.CheckWrinklerCount = function() { - if (Game.elderWrath > 0) { - var CurrentWrinklers = 0; - for (var i in Game.wrinklers) { - if (Game.wrinklers[i].phase == 2) CurrentWrinklers++; - } - if (CurrentWrinklers > CM.Disp.lastWrinklerCount) { - CM.Disp.lastWrinklerCount = CurrentWrinklers - if (CurrentWrinklers == Game.getWrinklersMax() && CM.Config.WrinklerMaxFlash) { - CM.Disp.Flash(3, 'WrinklerMaxFlash'); - } else { - CM.Disp.Flash(3, 'WrinklerFlash'); - } - if (CurrentWrinklers == Game.getWrinklersMax() && CM.Config.WrinklerMaxSound) { - CM.Disp.PlaySound(CM.Config.WrinklerMaxSoundURL, 'WrinklerMaxSound', 'WrinklerMaxVolume'); - } else { - CM.Disp.PlaySound(CM.Config.WrinklerSoundURL, 'WrinklerSound', 'WrinklerVolume'); - } - if (CurrentWrinklers == Game.getWrinklersMax() && CM.Config.WrinklerMaxNotification) { - CM.Disp.Notification('WrinklerMaxNotification', "Maximum Wrinklers Reached", "You have reached your maximum ammount of wrinklers") - } else { - CM.Disp.Notification('WrinklerNotification', "A Wrinkler appeared", "A new wrinkler has appeared") - } - } else { - CM.Disp.lastWrinklerCount = CurrentWrinklers - } - } -} - /******** * Section: Functions related to Tooltips * TODO: Annotate functions */ @@ -2598,18 +2459,18 @@ CM.Disp.colorPink = 'Pink'; CM.Disp.colorBrown = 'Brown'; CM.Disp.colors = [CM.Disp.colorBlue, CM.Disp.colorGreen, CM.Disp.colorYellow, CM.Disp.colorOrange, CM.Disp.colorRed, CM.Disp.colorPurple, CM.Disp.colorGray, CM.Disp.colorPink, CM.Disp.colorBrown]; CM.Disp.buffColors = {'Frenzy': CM.Disp.colorYellow, 'Dragon Harvest': CM.Disp.colorBrown, 'Elder frenzy': CM.Disp.colorGreen, 'Clot': CM.Disp.colorRed, 'Click frenzy': CM.Disp.colorBlue, 'Dragonflight': CM.Disp.colorPink}; -CM.Disp.lastGoldenCookieState = 0; -CM.Disp.lastSpawnedGoldenCookieState = 0; -CM.Disp.currSpawnedGoldenCookieState -CM.Disp.lastTickerFortuneState = 0; -CM.Disp.lastSeasonPopupState = 0; -CM.Disp.lastGardenNextStep = 0; -CM.Disp.lastMagicBarFull = 0; -CM.Disp.lastWrinklerCount = 0; -CM.Disp.goldenShimmersByID = {}; -CM.Disp.spawnedGoldenShimmer = 0; +CM.Main.lastGoldenCookieState = 0; +CM.Main.lastSpawnedGoldenCookieState = 0; +CM.Main.currSpawnedGoldenCookieState +CM.Main.lastTickerFortuneState = 0; +CM.Main.lastSeasonPopupState = 0; +CM.Main.lastGardenNextStep = 0; +CM.Main.lastMagicBarFull = 0; +CM.Main.lastWrinklerCount = 0; +CM.Cache.goldenShimmersByID = {}; +CM.Cache.spawnedGoldenShimmer = 0; CM.Disp.GCTimers = {}; -CM.Disp.seasonPopShimmer; +CM.Cache.seasonPopShimmer; CM.Disp.lastAscendState = -1; CM.Disp.cookieTimes = [10, 15, 30, 60, 300, 600, 900, 1800]; diff --git a/src/Main.js b/src/Main.js index 4c168ac..64abd2c 100644 --- a/src/Main.js +++ b/src/Main.js @@ -185,23 +185,13 @@ CM.Loop = function() { CM.Disp.RefreshMenu(); } - // Check Golden Cookies - CM.Disp.CheckGoldenCookie(); - - // Check Fortune Cookies - CM.Disp.CheckTickerFortune(); - - // Check Season Popup - CM.Disp.CheckSeasonPopup(); - - // Check Garden Tick - CM.Disp.CheckGardenTick(); - - // Check Grimoire Meter - CM.Disp.CheckMagicMeter(); - - // Check Wrinklers - CM.Disp.CheckWrinklerCount(); + // Check all changing minigames and game-states + CM.Main.CheckGoldenCookie(); + CM.Main.CheckTickerFortune(); + CM.Main.CheckSeasonPopup(); + CM.Main.CheckGardenTick(); + CM.Main.CheckMagicMeter(); + CM.Main.CheckWrinklerCount(); // Update Average CPS (might need to move) CM.Cache.UpdateAvgCPS() @@ -257,6 +247,167 @@ CM.DelayInit = function() { Game.Win('Third-party'); } +/******** + * Section: Functions related to checking for changes in Minigames/GC's/Ticker + * TODO: Annotate functions + * TODO: Possibly move this section */ + +/** + * Auxilirary function that finds all currently spawned shimmers. + * CM.Cache.spawnedGoldenShimmer stores the non-user spawned cookie to later determine data for the favicon and tab-title + * It is called by CM.CM.Main.CheckGoldenCookie + */ +CM.Main.FindShimmer = function() { + CM.Main.currSpawnedGoldenCookieState = 0; + CM.Cache.goldenShimmersByID = {} + for (var i in Game.shimmers) { + CM.Cache.goldenShimmersByID[Game.shimmers[i].id] = Game.shimmers[i] + if (Game.shimmers[i].spawnLead && Game.shimmers[i].type == 'golden') { + CM.Cache.spawnedGoldenShimmer = Game.shimmers[i]; + CM.Main.currSpawnedGoldenCookieState += 1; + } + } +} + +/** + * This function checks for changes in the amount of Golden Cookies + * It is called by CM.Loop + * TODO: Remove the delete function, as it does not delete correctly and crowds CM.Disp.GCTimers + */ +CM.Main.CheckGoldenCookie = function() { + CM.Main.FindShimmer(); + for (var i in CM.Disp.GCTimers) { + if (typeof CM.Cache.goldenShimmersByID[i] == "undefined") { + CM.Disp.GCTimers[i].parentNode.removeChild(CM.Disp.GCTimers[i]); + // TODO remove delete here + delete CM.Disp.GCTimers[i]; + } + } + if (CM.Main.lastGoldenCookieState != Game.shimmerTypes['golden'].n) { + CM.Main.lastGoldenCookieState = Game.shimmerTypes['golden'].n; + if (CM.Main.lastGoldenCookieState) { + if (CM.Main.lastSpawnedGoldenCookieState < CM.Main.currSpawnedGoldenCookieState) { + CM.Disp.Flash(3, 'GCFlash'); + CM.Disp.PlaySound(CM.Config.GCSoundURL, 'GCSound', 'GCVolume'); + CM.Disp.Notification('GCNotification', "Golden Cookie Spawned", "A Golden Cookie has spawned. Click it now!") + } + CM.Disp.UpdateFavicon(); + + for (var i in Game.shimmers) { + if (typeof CM.Disp.GCTimers[Game.shimmers[i].id] == "undefined") { + CM.Disp.CreateGCTimer(Game.shimmers[i]); + } + } + } + CM.Main.lastSpawnedGoldenCookieState = CM.Main.currSpawnedGoldenCookieState + } + else if (CM.Config.GCTimer == 1 && CM.Main.lastGoldenCookieState) { + for (var i in CM.Disp.GCTimers) { + CM.Disp.GCTimers[i].style.opacity = CM.Cache.goldenShimmersByID[i].l.style.opacity; + CM.Disp.GCTimers[i].style.transform = CM.Cache.goldenShimmersByID[i].l.style.transform; + CM.Disp.GCTimers[i].textContent = Math.ceil(CM.Cache.goldenShimmersByID[i].life / Game.fps); + } + } +} + +/** + * This function checks if there is reindeer that has spawned + * It is called by CM.Loop + */ +CM.Main.CheckSeasonPopup = function() { + if (CM.Main.lastSeasonPopupState != Game.shimmerTypes['reindeer'].spawned) { + CM.Main.lastSeasonPopupState = Game.shimmerTypes['reindeer'].spawned; + for (var i in Game.shimmers) { + if (Game.shimmers[i].spawnLead && Game.shimmers[i].type == 'reindeer') { + CM.Cache.seasonPopShimmer = Game.shimmers[i]; + break; + } + } + CM.Disp.Flash(3, 'SeaFlash'); + CM.Disp.PlaySound(CM.Config.SeaSoundURL, 'SeaSound', 'SeaVolume'); + CM.Disp.Notification('SeaNotification',"Reindeer sighted!", "A Reindeer has spawned. Click it now!") + } +} + +/** + * This function checks if there is a fortune cookie on the ticker + * It is called by CM.Loop + */ +CM.Main.CheckTickerFortune = function() { + if (CM.Main.lastTickerFortuneState != (Game.TickerEffect && Game.TickerEffect.type == 'fortune')) { + CM.Main.lastTickerFortuneState = (Game.TickerEffect && Game.TickerEffect.type == 'fortune'); + if (CM.Main.lastTickerFortuneState) { + CM.Disp.Flash(3, 'FortuneFlash'); + CM.Disp.PlaySound(CM.Config.FortuneSoundURL, 'FortuneSound', 'FortuneVolume'); + CM.Disp.Notification('FortuneNotification', "Fortune Cookie found", "A Fortune Cookie has appeared on the Ticker.") + } + } +} + +/** + * This function checks if a garden tick has happened + * It is called by CM.Loop + */ +CM.Main.CheckGardenTick = function() { + if (Game.Objects['Farm'].minigameLoaded && CM.Main.lastGardenNextStep != Game.Objects['Farm'].minigame.nextStep) { + if (CM.Main.lastGardenNextStep != 0 && CM.Main.lastGardenNextStep < Date.now()) { + CM.Disp.Flash(3, 'GardFlash'); + CM.Disp.PlaySound(CM.Config.GardSoundURL, 'GardSound', 'GardVolume'); + } + CM.Main.lastGardenNextStep = Game.Objects['Farm'].minigame.nextStep; + } +} + +/** + * This function checks if the magic meter is full + * It is called by CM.Loop + */ +CM.Main.CheckMagicMeter = function() { + if (Game.Objects['Wizard tower'].minigameLoaded && CM.Config.GrimoireBar == 1) { + var minigame = Game.Objects['Wizard tower'].minigame; + if (minigame.magic < minigame.magicM) CM.Main.lastMagicBarFull = false; + else if (!CM.Main.lastMagicBarFull) { + CM.Main.lastMagicBarFull = true; + CM.Disp.Flash(3, 'MagicFlash'); + CM.Disp.PlaySound(CM.Config.MagicSoundURL, 'MagicSound', 'MagicVolume'); + CM.Disp.Notification('MagicNotification', "Magic Meter full", "Your Magic Meter is full. Cast a spell!") + } + } +} + +/** + * This function checks if any new Wrinklers have popped up + * It is called by CM.Loop + */ +CM.Main.CheckWrinklerCount = function() { + if (Game.elderWrath > 0) { + var CurrentWrinklers = 0; + for (var i in Game.wrinklers) { + if (Game.wrinklers[i].phase == 2) CurrentWrinklers++; + } + if (CurrentWrinklers > CM.Main.lastWrinklerCount) { + CM.Main.lastWrinklerCount = CurrentWrinklers + if (CurrentWrinklers == Game.getWrinklersMax() && CM.Config.WrinklerMaxFlash) { + CM.Disp.Flash(3, 'WrinklerMaxFlash'); + } else { + CM.Disp.Flash(3, 'WrinklerFlash'); + } + if (CurrentWrinklers == Game.getWrinklersMax() && CM.Config.WrinklerMaxSound) { + CM.Disp.PlaySound(CM.Config.WrinklerMaxSoundURL, 'WrinklerMaxSound', 'WrinklerMaxVolume'); + } else { + CM.Disp.PlaySound(CM.Config.WrinklerSoundURL, 'WrinklerSound', 'WrinklerVolume'); + } + if (CurrentWrinklers == Game.getWrinklersMax() && CM.Config.WrinklerMaxNotification) { + CM.Disp.Notification('WrinklerMaxNotification', "Maximum Wrinklers Reached", "You have reached your maximum ammount of wrinklers") + } else { + CM.Disp.Notification('WrinklerNotification', "A Wrinkler appeared", "A new wrinkler has appeared") + } + } else { + CM.Main.lastWrinklerCount = CurrentWrinklers + } + } +} + CM.HasReplaceNativeGrimoireLaunch = false; CM.HasReplaceNativeGrimoireDraw = false; From 106331af851e1501e9fed1bb379ba944ccd49520 Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Thu, 3 Dec 2020 16:40:21 +0100 Subject: [PATCH 019/106] Update state-checking code v2 --- CookieMonster.js | 28 ++++++++++++++++------------ src/Cache.js | 4 +++- src/Disp.js | 13 ++----------- src/Header.js | 2 ++ src/Main.js | 9 +++++++++ 5 files changed, 32 insertions(+), 24 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index f34e6e9..945a469 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -16,6 +16,8 @@ RunCookieMonsterHeader = function() { CM.Disp = {}; + CM.Main = {}; + CM.Sim = {}; } @@ -552,7 +554,9 @@ CM.Cache.MissingCookies = Game.Upgrades; CM.Cache.UpgradesOwned = -1; CM.Cache.MissingUpgradesString = null; CM.Cache.MissingCookiesString = null; - +CM.Cache.seasonPopShimmer; +CM.Cache.goldenShimmersByID = {}; +CM.Cache.spawnedGoldenShimmer = 0; /********** * Config * **********/ @@ -3337,20 +3341,11 @@ CM.Disp.colorPink = 'Pink'; CM.Disp.colorBrown = 'Brown'; CM.Disp.colors = [CM.Disp.colorBlue, CM.Disp.colorGreen, CM.Disp.colorYellow, CM.Disp.colorOrange, CM.Disp.colorRed, CM.Disp.colorPurple, CM.Disp.colorGray, CM.Disp.colorPink, CM.Disp.colorBrown]; CM.Disp.buffColors = {'Frenzy': CM.Disp.colorYellow, 'Dragon Harvest': CM.Disp.colorBrown, 'Elder frenzy': CM.Disp.colorGreen, 'Clot': CM.Disp.colorRed, 'Click frenzy': CM.Disp.colorBlue, 'Dragonflight': CM.Disp.colorPink}; -CM.Main.lastGoldenCookieState = 0; -CM.Main.lastSpawnedGoldenCookieState = 0; -CM.Main.currSpawnedGoldenCookieState -CM.Main.lastTickerFortuneState = 0; -CM.Main.lastSeasonPopupState = 0; -CM.Main.lastGardenNextStep = 0; -CM.Main.lastMagicBarFull = 0; -CM.Main.lastWrinklerCount = 0; -CM.Cache.goldenShimmersByID = {}; -CM.Cache.spawnedGoldenShimmer = 0; CM.Disp.GCTimers = {}; -CM.Cache.seasonPopShimmer; CM.Disp.lastAscendState = -1; + + CM.Disp.cookieTimes = [10, 15, 30, 60, 300, 600, 900, 1800]; CM.Disp.clickTimes = [1, 5, 10, 15, 30]; @@ -3786,6 +3781,15 @@ CM.Main.CheckWrinklerCount = function() { CM.HasReplaceNativeGrimoireLaunch = false; CM.HasReplaceNativeGrimoireDraw = false; +CM.Main.lastGoldenCookieState = 0; +CM.Main.lastSpawnedGoldenCookieState = 0; +CM.Main.currSpawnedGoldenCookieState +CM.Main.lastTickerFortuneState = 0; +CM.Main.lastSeasonPopupState = 0; +CM.Main.lastGardenNextStep = 0; +CM.Main.lastMagicBarFull = 0; +CM.Main.lastWrinklerCount = 0; + CM.ConfigDefault = { BotBar: 1, TimerBar: 1, diff --git a/src/Cache.js b/src/Cache.js index 3fdd91d..b3a08ed 100644 --- a/src/Cache.js +++ b/src/Cache.js @@ -527,4 +527,6 @@ CM.Cache.MissingCookies = Game.Upgrades; CM.Cache.UpgradesOwned = -1; CM.Cache.MissingUpgradesString = null; CM.Cache.MissingCookiesString = null; - +CM.Cache.seasonPopShimmer; +CM.Cache.goldenShimmersByID = {}; +CM.Cache.spawnedGoldenShimmer = 0; diff --git a/src/Disp.js b/src/Disp.js index c1557f0..a1086fa 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -2459,20 +2459,11 @@ CM.Disp.colorPink = 'Pink'; CM.Disp.colorBrown = 'Brown'; CM.Disp.colors = [CM.Disp.colorBlue, CM.Disp.colorGreen, CM.Disp.colorYellow, CM.Disp.colorOrange, CM.Disp.colorRed, CM.Disp.colorPurple, CM.Disp.colorGray, CM.Disp.colorPink, CM.Disp.colorBrown]; CM.Disp.buffColors = {'Frenzy': CM.Disp.colorYellow, 'Dragon Harvest': CM.Disp.colorBrown, 'Elder frenzy': CM.Disp.colorGreen, 'Clot': CM.Disp.colorRed, 'Click frenzy': CM.Disp.colorBlue, 'Dragonflight': CM.Disp.colorPink}; -CM.Main.lastGoldenCookieState = 0; -CM.Main.lastSpawnedGoldenCookieState = 0; -CM.Main.currSpawnedGoldenCookieState -CM.Main.lastTickerFortuneState = 0; -CM.Main.lastSeasonPopupState = 0; -CM.Main.lastGardenNextStep = 0; -CM.Main.lastMagicBarFull = 0; -CM.Main.lastWrinklerCount = 0; -CM.Cache.goldenShimmersByID = {}; -CM.Cache.spawnedGoldenShimmer = 0; CM.Disp.GCTimers = {}; -CM.Cache.seasonPopShimmer; CM.Disp.lastAscendState = -1; + + CM.Disp.cookieTimes = [10, 15, 30, 60, 300, 600, 900, 1800]; CM.Disp.clickTimes = [1, 5, 10, 15, 30]; diff --git a/src/Header.js b/src/Header.js index 26893fb..3731fa3 100644 --- a/src/Header.js +++ b/src/Header.js @@ -16,6 +16,8 @@ RunCookieMonsterHeader = function() { CM.Disp = {}; + CM.Main = {}; + CM.Sim = {}; } diff --git a/src/Main.js b/src/Main.js index 64abd2c..a941cc0 100644 --- a/src/Main.js +++ b/src/Main.js @@ -411,6 +411,15 @@ CM.Main.CheckWrinklerCount = function() { CM.HasReplaceNativeGrimoireLaunch = false; CM.HasReplaceNativeGrimoireDraw = false; +CM.Main.lastGoldenCookieState = 0; +CM.Main.lastSpawnedGoldenCookieState = 0; +CM.Main.currSpawnedGoldenCookieState +CM.Main.lastTickerFortuneState = 0; +CM.Main.lastSeasonPopupState = 0; +CM.Main.lastGardenNextStep = 0; +CM.Main.lastMagicBarFull = 0; +CM.Main.lastWrinklerCount = 0; + CM.ConfigDefault = { BotBar: 1, TimerBar: 1, From d6aca47698d2e74726d5ae743f8f053bd7c44de9 Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Thu, 3 Dec 2020 18:17:07 +0100 Subject: [PATCH 020/106] Initial work on Tooltip section --- CookieMonster.js | 169 ++++++++++++++++++++++++++++++----------------- src/Disp.js | 158 +++++++++++++++++++++++++++++--------------- src/Main.js | 13 ++-- 3 files changed, 221 insertions(+), 119 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index 945a469..b8f4856 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -2068,9 +2068,16 @@ CM.Disp.ToggleGCTimer = function() { /******** * Section: Functions related to Tooltips - * TODO: Annotate functions */ -CM.Disp.CreateTooltip = function(placeholder, text, minWidth) { +/** + * This function creates some very basic tooltips, (e.g., the tooltips in the stats page) + * The tooltips are created with CM.Disp[placeholder].appendChild(desc) + * It is called by CM.DelayInit() + * @param {string} placeholder The name used to later refer and spawn the tooltip + * @param {string} text The text of the tooltip + * @param {string} minWidth The minimum width of the tooltip + */ +CM.Disp.CreateSimpleTooltip = function(placeholder, text, minWidth) { CM.Disp[placeholder] = document.createElement('div'); var desc = document.createElement('div'); desc.style.minWidth = minWidth; @@ -2082,18 +2089,11 @@ CM.Disp.CreateTooltip = function(placeholder, text, minWidth) { CM.Disp[placeholder].appendChild(desc); } -CM.Disp.UpdateTooltipLocation = function() { - if (Game.tooltip.origin == 'store') { - var warnOffset = 0; - if (CM.Config.ToolWarnLucky == 1 && CM.Config.ToolWarnPos == 1) warnOffset = CM.Disp.TooltipWarn.clientHeight - 4; - Game.tooltip.tta.style.top = Math.min(parseInt(Game.tooltip.tta.style.top), (l('game').clientHeight + l('topBar').clientHeight) - Game.tooltip.tt.clientHeight - warnOffset - 46) + 'px'; - } - // Kept for future possible use if the code changes again - /*else if (!Game.onCrate && !Game.OnAscend && CM.Config.TimerBar == 1 && CM.Config.TimerBarPos == 0) { - Game.tooltip.tta.style.top = (parseInt(Game.tooltip.tta.style.top) + parseInt(CM.Disp.TimerBar.style.height)) + 'px'; - }*/ -} - +/** + * This function creates the tooltip extension of Lucky/Chain and other warnings for the building and upgrade tooltips + * It is called by CM.DelayInit() and the tooltip is appended to the l('tooltipAnchor'). + * Visbility is then managed in CM.Disp.UpdateTooltip(). + */ CM.Disp.CreateTooltipWarn = function() { CM.Disp.TooltipWarn = document.createElement('div'); CM.Disp.TooltipWarn.style.position = 'absolute'; @@ -2105,10 +2105,11 @@ CM.Disp.CreateTooltipWarn = function() { var box = document.createElement('div'); box.id = boxId; box.style.display = 'none'; - box.style.WebkitTransition = 'opacity 0.1s ease-out'; - box.style.MozTransition = 'opacity 0.1s ease-out'; - box.style.MsTransition = 'opacity 0.1s ease-out'; - box.style.OTransition = 'opacity 0.1s ease-out'; + // TODO: This is very old code and can probably be removed + //box.style.WebkitTransition = 'opacity 0.1s ease-out'; + //box.style.MozTransition = 'opacity 0.1s ease-out'; + //box.style.MsTransition = 'opacity 0.1s ease-out'; + //box.style.OTransition = 'opacity 0.1s ease-out'; box.style.transition = 'opacity 0.1s ease-out'; box.className = CM.Disp.colorBorderPre + color; box.style.padding = '2px'; @@ -2135,51 +2136,55 @@ CM.Disp.CreateTooltipWarn = function() { CM.Disp.TooltipWarn.lastChild.style.marginBottom = '4px'; CM.Disp.TooltipWarn.appendChild(create('CMDispTooltipWarnConjure', CM.Disp.colorPurple, 'Warning: ', 'Purchase of this item will put you under the number of Cookies required for "Conjure Baked Goods"', 'CMDispTooltipWarnConjureText')); - l('tooltipAnchor').appendChild(CM.Disp.TooltipWarn); } -CM.Disp.ToggleToolWarnPos = function() { - if (CM.Config.ToolWarnPos == 0) { - CM.Disp.TooltipWarn.style.top = 'auto'; - CM.Disp.TooltipWarn.style.margin = '4px -4px'; - CM.Disp.TooltipWarn.style.padding = '3px 4px'; - } - else { - CM.Disp.TooltipWarn.style.right = 'auto'; - CM.Disp.TooltipWarn.style.margin = '4px'; - CM.Disp.TooltipWarn.style.padding = '4px 3px'; - } -} - -CM.Disp.AddTooltipBuild = function() { - CM.Disp.TooltipBuildBack = []; +/** + * This function replaces the original .onmouseover functions of buildings so that it calls CM.Disp.Tooltip() + * CM.Disp.Tooltip() sets the tooltip type to 'b' + * It is called by CM.DelayInit() + * TODO: Place all ReplaceTooltip functions either under CM.DelayInit() or CM.ReplaceNative() + */ +CM.Disp.ReplaceTooltipBuild = function() { + CM.Disp.TooltipBuildBackup = []; for (var i in Game.Objects) { var me = Game.Objects[i]; if (l('product' + me.id).onmouseover != null) { - CM.Disp.TooltipBuildBack[i] = l('product' + me.id).onmouseover; + CM.Disp.TooltipBuildBackup[i] = l('product' + me.id).onmouseover; eval('l(\'product\' + me.id).onmouseover = function() {Game.tooltip.dynamic = 1; Game.tooltip.draw(this, function() {return CM.Disp.Tooltip(\'b\', \'' + i + '\');}, \'store\'); Game.tooltip.wobble();}'); } } } -CM.Disp.AddTooltipUpgrade = function() { - CM.Disp.TooltipUpgradeBack = []; +/** + * This function replaces the original .onmouseover functions of upgrades so that it calls CM.Disp.Tooltip() + * CM.Disp.Tooltip() sets the tooltip type to 'u' + * It is called by CM.ReplaceNative() + * TODO: Place all ReplaceTooltip functions either under CM.DelayInit() or CM.ReplaceNative() + */ +CM.Disp.ReplaceTooltipUpgrade = function() { + CM.Disp.TooltipUpgradeBackup = []; for (var i in Game.UpgradesInStore) { var me = Game.UpgradesInStore[i]; if (l('upgrade' + i).onmouseover != null) { - CM.Disp.TooltipUpgradeBack[i] = l('upgrade' + i).onmouseover; + CM.Disp.TooltipUpgradeBackup[i] = l('upgrade' + i).onmouseover; eval('l(\'upgrade\' + i).onmouseover = function() {if (!Game.mouseDown) {Game.setOnCrate(this); Game.tooltip.dynamic = 1; Game.tooltip.draw(this, function() {return CM.Disp.Tooltip(\'u\', \'' + i + '\');}, \'store\'); Game.tooltip.wobble();}}'); } } } -CM.Disp.AddTooltipGrimoire = function() { +/** + * This function replaces the original .onmouseover functions of the Grimoire minigame so that it calls CM.Disp.Tooltip() + * CM.Disp.Tooltip() sets the tooltip type to 'g' + * The function is called by CM.DelayInit() + * TODO: Place all ReplaceTooltip functions either under CM.DelayInit() or CM.ReplaceNative() + */ +CM.Disp.ReplaceTooltipGrimoire = function() { if (Game.Objects['Wizard tower'].minigameLoaded) { - CM.Disp.TooltipGrimoireBack = []; + CM.Disp.TooltipGrimoireBackup = []; for (var i in Game.Objects['Wizard tower'].minigame.spellsById) { if (l('grimoireSpell' + i).onmouseover != null) { - CM.Disp.TooltipGrimoireBack[i] = l('grimoireSpell' + i).onmouseover; + CM.Disp.TooltipGrimoireBackup[i] = l('grimoireSpell' + i).onmouseover; eval('l(\'grimoireSpell\' + i).onmouseover = function() {Game.tooltip.dynamic = 1; Game.tooltip.draw(this, function() {return CM.Disp.Tooltip(\'g\', \'' + i + '\');}, \'this\'); Game.tooltip.wobble();}'); } } @@ -2187,16 +2192,22 @@ CM.Disp.AddTooltipGrimoire = function() { } /** - * This function improves Sugar Lump tooltip by adding extra infromation. - * @constructor + * This function replaces the original .onmouseover functions of sugar lumps so that it calls CM.Disp.Tooltip() + * CM.Disp.Tooltip() sets the tooltip type to 's' + * The function is called by CM.DelayInit() + * TODO: Place all ReplaceTooltip functions either under CM.DelayInit() or CM.ReplaceNative() */ -CM.Disp.AddTooltipLump = function() { +CM.Disp.ReplaceTooltipLump = function() { if (Game.canLumps()) { - CM.Disp.TooltipLumpBack = l('lumps').onmouseover; + CM.Disp.TooltipLumpBackup = l('lumps').onmouseover; eval('l(\'lumps\').onmouseover = function() {Game.tooltip.dynamic = 1; Game.tooltip.draw(this, function() {return CM.Disp.Tooltip(\'s\', \'Lump\');}, \'this\'); Game.tooltip.wobble();}'); } }; +/** + * This function creates tooltips by creating and changing l('tooltip') + * The function is called by .onmouseover events that have replaced original code to use CM.Disp.Tooltip( + */ CM.Disp.Tooltip = function(type, name) { if (type == 'b') { l('tooltip').innerHTML = Game.Objects[name].tooltip(); @@ -2547,6 +2558,35 @@ CM.Disp.UpdateTooltip = function() { } } +CM.Disp.UpdateTooltipLocation = function() { + if (Game.tooltip.origin == 'store') { + var warnOffset = 0; + if (CM.Config.ToolWarnLucky == 1 && CM.Config.ToolWarnPos == 1) warnOffset = CM.Disp.TooltipWarn.clientHeight - 4; + Game.tooltip.tta.style.top = Math.min(parseInt(Game.tooltip.tta.style.top), (l('game').clientHeight + l('topBar').clientHeight) - Game.tooltip.tt.clientHeight - warnOffset - 46) + 'px'; + } + // Kept for future possible use if the code changes again + /*else if (!Game.onCrate && !Game.OnAscend && CM.Config.TimerBar == 1 && CM.Config.TimerBarPos == 0) { + Game.tooltip.tta.style.top = (parseInt(Game.tooltip.tta.style.top) + parseInt(CM.Disp.TimerBar.style.height)) + 'px'; + }*/ +} + +/** + * This function toggles the position of the warnings created by CM.Disp.CreateTooltipWarn() + * It is called by a change in CM.Config.ToolWarnPos + */ +CM.Disp.ToggleToolWarnPos = function() { + if (CM.Config.ToolWarnPos == 0) { + CM.Disp.TooltipWarn.style.top = 'auto'; + CM.Disp.TooltipWarn.style.margin = '4px -4px'; + CM.Disp.TooltipWarn.style.padding = '3px 4px'; + } + else { + CM.Disp.TooltipWarn.style.right = 'auto'; + CM.Disp.TooltipWarn.style.margin = '4px'; + CM.Disp.TooltipWarn.style.padding = '4px 3px'; + } +} + CM.Disp.DrawTooltipWarn = function() { if (CM.Config.ToolWarnLucky == 1) { l('CMDispTooltipWarnLucky').style.opacity = '0'; @@ -3327,6 +3367,23 @@ CM.Disp.AddMissingUpgrades = function() { * Section: Variables used in Disp functions * TODO: Move certain variables to src/Data.js (e.g., CM.Disp.metric & CM.Disp.shortScale) */ +/** + * This list is used to make some very basic tooltips. + * It is used by CM.DelayInit() in the call of CM.Disp.CreateSimpleTooltip() + * @item {string} placeholder + * @item {string} text + * @item {string} minWidth + */ +CM.Disp.TooltipText = [ + ['GoldCookTooltipPlaceholder', 'Calculated with Golden Switch off', '200px'], + ['GoldCookDragonsFortuneTooltipPlaceholder', 'Calculated with Golden Switch off and at least one golden cookie on-screen', '240px'], + ['PrestMaxTooltipPlaceholder', 'The MAX prestige is calculated with the cookies gained from popping all wrinklers with Skruuia god in Diamond slot, selling all stock market goods, selling all buildings with Earth Shatterer and Reality Bending auras, and buying Chocolate egg', '320px'], + ['NextPrestTooltipPlaceholder', 'Calculated with cookies gained from wrinklers and Chocolate egg', '200px'], + ['HeavenChipMaxTooltipPlaceholder', 'The MAX heavenly chips is calculated with the cookies gained from popping all wrinklers with Skruuia god in Diamond slot, selling all stock market goods, selling all buildings with Earth Shatterer and Reality Bending auras, and buying Chocolate egg', '330px'], + ['ResetTooltipPlaceholder', 'The bonus income you would get from new prestige levels unlocked at 100% of its potential and from ascension achievements if you have the same buildings/upgrades after reset', '370px'], + ['ChoEggTooltipPlaceholder', 'The amount of cookies you would get from popping all wrinklers with Skruuia god in Diamond slot, selling all stock market goods, selling all buildings with Earth Shatterer and Reality Bending auras, and then buying Chocolate egg', '300px'] +]; + CM.Disp.colorTextPre = 'CMText'; CM.Disp.colorBackPre = 'CMBack'; CM.Disp.colorBorderPre = 'CMBorder'; @@ -3359,15 +3416,6 @@ for (var i in Game.wrinklers) { CM.Disp.TooltipWrinklerCache[i] = 0; } -CM.Disp.TooltipText = [ - ['GoldCookTooltipPlaceholder', 'Calculated with Golden Switch off', '200px'], - ['GoldCookDragonsFortuneTooltipPlaceholder', 'Calculated with Golden Switch off and at least one golden cookie on-screen', '240px'], - ['PrestMaxTooltipPlaceholder', 'The MAX prestige is calculated with the cookies gained from popping all wrinklers with Skruuia god in Diamond slot, selling all stock market goods, selling all buildings with Earth Shatterer and Reality Bending auras, and buying Chocolate egg', '320px'], - ['NextPrestTooltipPlaceholder', 'Calculated with cookies gained from wrinklers and Chocolate egg', '200px'], - ['HeavenChipMaxTooltipPlaceholder', 'The MAX heavenly chips is calculated with the cookies gained from popping all wrinklers with Skruuia god in Diamond slot, selling all stock market goods, selling all buildings with Earth Shatterer and Reality Bending auras, and buying Chocolate egg', '330px'], - ['ResetTooltipPlaceholder', 'The bonus income you would get from new prestige levels unlocked at 100% of its potential and from ascension achievements if you have the same buildings/upgrades after reset', '370px'], - ['ChoEggTooltipPlaceholder', 'The amount of cookies you would get from popping all wrinklers with Skruuia god in Diamond slot, selling all stock market goods, selling all buildings with Earth Shatterer and Reality Bending auras, and then buying Chocolate egg', '300px'] -]; /******** * Main * ********/ @@ -3421,10 +3469,12 @@ CM.ReplaceNative = function() { CM.ReplaceNativeGrimoire(); } + // TODO: Move this ReplaceTooltip function too other ReplaceTooltip functions + // OR: Move all other into this function CM.Backup.RebuildUpgrades = Game.RebuildUpgrades; Game.RebuildUpgrades = function() { CM.Backup.RebuildUpgrades(); - CM.Disp.AddTooltipUpgrade(); + CM.Disp.ReplaceTooltipUpgrade(); Game.CalculateGains(); } @@ -3594,12 +3644,12 @@ CM.DelayInit = function() { CM.Disp.CreateWhiteScreen(); CM.Disp.CreateFavicon(); for (var i in CM.Disp.TooltipText) { - CM.Disp.CreateTooltip(CM.Disp.TooltipText[i][0], CM.Disp.TooltipText[i][1], CM.Disp.TooltipText[i][2]); + CM.Disp.CreateSimpleTooltip(CM.Disp.TooltipText[i][0], CM.Disp.TooltipText[i][1], CM.Disp.TooltipText[i][2]); } CM.Disp.CreateTooltipWarn(); - CM.Disp.AddTooltipBuild(); - CM.Disp.AddTooltipGrimoire(); - CM.Disp.AddTooltipLump(); + CM.Disp.ReplaceTooltipBuild(); + CM.Disp.ReplaceTooltipGrimoire(); + CM.Disp.ReplaceTooltipLump(); CM.Disp.AddWrinklerAreaDetect(); CM.Cache.InitCookiesDiff(); CM.ReplaceNative(); @@ -3670,6 +3720,7 @@ CM.Main.CheckGoldenCookie = function() { } } CM.Main.lastSpawnedGoldenCookieState = CM.Main.currSpawnedGoldenCookieState + if (CM.Main.currSpawnedGoldenCookieState == 0) CM.Cache.spawnedGoldenShimmer = 0; } else if (CM.Config.GCTimer == 1 && CM.Main.lastGoldenCookieState) { for (var i in CM.Disp.GCTimers) { diff --git a/src/Disp.js b/src/Disp.js index a1086fa..756bb74 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -271,7 +271,7 @@ CM.Disp.RefreshScale = function() { * This function returns time as a string depending on TimeFormat setting * @param {number} time Time to be formatted * @param {number} longFormat 1 or 0 - * @returns {string} Formatted time` + * @returns {string} Formatted time */ CM.Disp.FormatTime = function(time, longFormat) { if (time == Infinity) return time; @@ -1186,9 +1186,16 @@ CM.Disp.ToggleGCTimer = function() { /******** * Section: Functions related to Tooltips - * TODO: Annotate functions */ -CM.Disp.CreateTooltip = function(placeholder, text, minWidth) { +/** + * This function creates some very basic tooltips, (e.g., the tooltips in the stats page) + * The tooltips are created with CM.Disp[placeholder].appendChild(desc) + * It is called by CM.DelayInit() + * @param {string} placeholder The name used to later refer and spawn the tooltip + * @param {string} text The text of the tooltip + * @param {string} minWidth The minimum width of the tooltip + */ +CM.Disp.CreateSimpleTooltip = function(placeholder, text, minWidth) { CM.Disp[placeholder] = document.createElement('div'); var desc = document.createElement('div'); desc.style.minWidth = minWidth; @@ -1200,18 +1207,11 @@ CM.Disp.CreateTooltip = function(placeholder, text, minWidth) { CM.Disp[placeholder].appendChild(desc); } -CM.Disp.UpdateTooltipLocation = function() { - if (Game.tooltip.origin == 'store') { - var warnOffset = 0; - if (CM.Config.ToolWarnLucky == 1 && CM.Config.ToolWarnPos == 1) warnOffset = CM.Disp.TooltipWarn.clientHeight - 4; - Game.tooltip.tta.style.top = Math.min(parseInt(Game.tooltip.tta.style.top), (l('game').clientHeight + l('topBar').clientHeight) - Game.tooltip.tt.clientHeight - warnOffset - 46) + 'px'; - } - // Kept for future possible use if the code changes again - /*else if (!Game.onCrate && !Game.OnAscend && CM.Config.TimerBar == 1 && CM.Config.TimerBarPos == 0) { - Game.tooltip.tta.style.top = (parseInt(Game.tooltip.tta.style.top) + parseInt(CM.Disp.TimerBar.style.height)) + 'px'; - }*/ -} - +/** + * This function creates the tooltip extension of Lucky/Chain and other warnings for the building and upgrade tooltips + * It is called by CM.DelayInit() and the tooltip is appended to the l('tooltipAnchor'). + * Visbility is then managed in CM.Disp.UpdateTooltip(). + */ CM.Disp.CreateTooltipWarn = function() { CM.Disp.TooltipWarn = document.createElement('div'); CM.Disp.TooltipWarn.style.position = 'absolute'; @@ -1223,10 +1223,11 @@ CM.Disp.CreateTooltipWarn = function() { var box = document.createElement('div'); box.id = boxId; box.style.display = 'none'; - box.style.WebkitTransition = 'opacity 0.1s ease-out'; - box.style.MozTransition = 'opacity 0.1s ease-out'; - box.style.MsTransition = 'opacity 0.1s ease-out'; - box.style.OTransition = 'opacity 0.1s ease-out'; + // TODO: This is very old code and can probably be removed + //box.style.WebkitTransition = 'opacity 0.1s ease-out'; + //box.style.MozTransition = 'opacity 0.1s ease-out'; + //box.style.MsTransition = 'opacity 0.1s ease-out'; + //box.style.OTransition = 'opacity 0.1s ease-out'; box.style.transition = 'opacity 0.1s ease-out'; box.className = CM.Disp.colorBorderPre + color; box.style.padding = '2px'; @@ -1253,51 +1254,55 @@ CM.Disp.CreateTooltipWarn = function() { CM.Disp.TooltipWarn.lastChild.style.marginBottom = '4px'; CM.Disp.TooltipWarn.appendChild(create('CMDispTooltipWarnConjure', CM.Disp.colorPurple, 'Warning: ', 'Purchase of this item will put you under the number of Cookies required for "Conjure Baked Goods"', 'CMDispTooltipWarnConjureText')); - l('tooltipAnchor').appendChild(CM.Disp.TooltipWarn); } -CM.Disp.ToggleToolWarnPos = function() { - if (CM.Config.ToolWarnPos == 0) { - CM.Disp.TooltipWarn.style.top = 'auto'; - CM.Disp.TooltipWarn.style.margin = '4px -4px'; - CM.Disp.TooltipWarn.style.padding = '3px 4px'; - } - else { - CM.Disp.TooltipWarn.style.right = 'auto'; - CM.Disp.TooltipWarn.style.margin = '4px'; - CM.Disp.TooltipWarn.style.padding = '4px 3px'; - } -} - -CM.Disp.AddTooltipBuild = function() { - CM.Disp.TooltipBuildBack = []; +/** + * This function replaces the original .onmouseover functions of buildings so that it calls CM.Disp.Tooltip() + * CM.Disp.Tooltip() sets the tooltip type to 'b' + * It is called by CM.DelayInit() + * TODO: Place all ReplaceTooltip functions either under CM.DelayInit() or CM.ReplaceNative() + */ +CM.Disp.ReplaceTooltipBuild = function() { + CM.Disp.TooltipBuildBackup = []; for (var i in Game.Objects) { var me = Game.Objects[i]; if (l('product' + me.id).onmouseover != null) { - CM.Disp.TooltipBuildBack[i] = l('product' + me.id).onmouseover; + CM.Disp.TooltipBuildBackup[i] = l('product' + me.id).onmouseover; eval('l(\'product\' + me.id).onmouseover = function() {Game.tooltip.dynamic = 1; Game.tooltip.draw(this, function() {return CM.Disp.Tooltip(\'b\', \'' + i + '\');}, \'store\'); Game.tooltip.wobble();}'); } } } -CM.Disp.AddTooltipUpgrade = function() { - CM.Disp.TooltipUpgradeBack = []; +/** + * This function replaces the original .onmouseover functions of upgrades so that it calls CM.Disp.Tooltip() + * CM.Disp.Tooltip() sets the tooltip type to 'u' + * It is called by CM.ReplaceNative() + * TODO: Place all ReplaceTooltip functions either under CM.DelayInit() or CM.ReplaceNative() + */ +CM.Disp.ReplaceTooltipUpgrade = function() { + CM.Disp.TooltipUpgradeBackup = []; for (var i in Game.UpgradesInStore) { var me = Game.UpgradesInStore[i]; if (l('upgrade' + i).onmouseover != null) { - CM.Disp.TooltipUpgradeBack[i] = l('upgrade' + i).onmouseover; + CM.Disp.TooltipUpgradeBackup[i] = l('upgrade' + i).onmouseover; eval('l(\'upgrade\' + i).onmouseover = function() {if (!Game.mouseDown) {Game.setOnCrate(this); Game.tooltip.dynamic = 1; Game.tooltip.draw(this, function() {return CM.Disp.Tooltip(\'u\', \'' + i + '\');}, \'store\'); Game.tooltip.wobble();}}'); } } } -CM.Disp.AddTooltipGrimoire = function() { +/** + * This function replaces the original .onmouseover functions of the Grimoire minigame so that it calls CM.Disp.Tooltip() + * CM.Disp.Tooltip() sets the tooltip type to 'g' + * The function is called by CM.DelayInit() + * TODO: Place all ReplaceTooltip functions either under CM.DelayInit() or CM.ReplaceNative() + */ +CM.Disp.ReplaceTooltipGrimoire = function() { if (Game.Objects['Wizard tower'].minigameLoaded) { - CM.Disp.TooltipGrimoireBack = []; + CM.Disp.TooltipGrimoireBackup = []; for (var i in Game.Objects['Wizard tower'].minigame.spellsById) { if (l('grimoireSpell' + i).onmouseover != null) { - CM.Disp.TooltipGrimoireBack[i] = l('grimoireSpell' + i).onmouseover; + CM.Disp.TooltipGrimoireBackup[i] = l('grimoireSpell' + i).onmouseover; eval('l(\'grimoireSpell\' + i).onmouseover = function() {Game.tooltip.dynamic = 1; Game.tooltip.draw(this, function() {return CM.Disp.Tooltip(\'g\', \'' + i + '\');}, \'this\'); Game.tooltip.wobble();}'); } } @@ -1305,16 +1310,22 @@ CM.Disp.AddTooltipGrimoire = function() { } /** - * This function improves Sugar Lump tooltip by adding extra infromation. - * @constructor + * This function replaces the original .onmouseover functions of sugar lumps so that it calls CM.Disp.Tooltip() + * CM.Disp.Tooltip() sets the tooltip type to 's' + * The function is called by CM.DelayInit() + * TODO: Place all ReplaceTooltip functions either under CM.DelayInit() or CM.ReplaceNative() */ -CM.Disp.AddTooltipLump = function() { +CM.Disp.ReplaceTooltipLump = function() { if (Game.canLumps()) { - CM.Disp.TooltipLumpBack = l('lumps').onmouseover; + CM.Disp.TooltipLumpBackup = l('lumps').onmouseover; eval('l(\'lumps\').onmouseover = function() {Game.tooltip.dynamic = 1; Game.tooltip.draw(this, function() {return CM.Disp.Tooltip(\'s\', \'Lump\');}, \'this\'); Game.tooltip.wobble();}'); } }; +/** + * This function creates tooltips by creating and changing l('tooltip') + * The function is called by .onmouseover events that have replaced original code to use CM.Disp.Tooltip( + */ CM.Disp.Tooltip = function(type, name) { if (type == 'b') { l('tooltip').innerHTML = Game.Objects[name].tooltip(); @@ -1665,6 +1676,35 @@ CM.Disp.UpdateTooltip = function() { } } +CM.Disp.UpdateTooltipLocation = function() { + if (Game.tooltip.origin == 'store') { + var warnOffset = 0; + if (CM.Config.ToolWarnLucky == 1 && CM.Config.ToolWarnPos == 1) warnOffset = CM.Disp.TooltipWarn.clientHeight - 4; + Game.tooltip.tta.style.top = Math.min(parseInt(Game.tooltip.tta.style.top), (l('game').clientHeight + l('topBar').clientHeight) - Game.tooltip.tt.clientHeight - warnOffset - 46) + 'px'; + } + // Kept for future possible use if the code changes again + /*else if (!Game.onCrate && !Game.OnAscend && CM.Config.TimerBar == 1 && CM.Config.TimerBarPos == 0) { + Game.tooltip.tta.style.top = (parseInt(Game.tooltip.tta.style.top) + parseInt(CM.Disp.TimerBar.style.height)) + 'px'; + }*/ +} + +/** + * This function toggles the position of the warnings created by CM.Disp.CreateTooltipWarn() + * It is called by a change in CM.Config.ToolWarnPos + */ +CM.Disp.ToggleToolWarnPos = function() { + if (CM.Config.ToolWarnPos == 0) { + CM.Disp.TooltipWarn.style.top = 'auto'; + CM.Disp.TooltipWarn.style.margin = '4px -4px'; + CM.Disp.TooltipWarn.style.padding = '3px 4px'; + } + else { + CM.Disp.TooltipWarn.style.right = 'auto'; + CM.Disp.TooltipWarn.style.margin = '4px'; + CM.Disp.TooltipWarn.style.padding = '4px 3px'; + } +} + CM.Disp.DrawTooltipWarn = function() { if (CM.Config.ToolWarnLucky == 1) { l('CMDispTooltipWarnLucky').style.opacity = '0'; @@ -2445,6 +2485,23 @@ CM.Disp.AddMissingUpgrades = function() { * Section: Variables used in Disp functions * TODO: Move certain variables to src/Data.js (e.g., CM.Disp.metric & CM.Disp.shortScale) */ +/** + * This list is used to make some very basic tooltips. + * It is used by CM.DelayInit() in the call of CM.Disp.CreateSimpleTooltip() + * @item {string} placeholder + * @item {string} text + * @item {string} minWidth + */ +CM.Disp.TooltipText = [ + ['GoldCookTooltipPlaceholder', 'Calculated with Golden Switch off', '200px'], + ['GoldCookDragonsFortuneTooltipPlaceholder', 'Calculated with Golden Switch off and at least one golden cookie on-screen', '240px'], + ['PrestMaxTooltipPlaceholder', 'The MAX prestige is calculated with the cookies gained from popping all wrinklers with Skruuia god in Diamond slot, selling all stock market goods, selling all buildings with Earth Shatterer and Reality Bending auras, and buying Chocolate egg', '320px'], + ['NextPrestTooltipPlaceholder', 'Calculated with cookies gained from wrinklers and Chocolate egg', '200px'], + ['HeavenChipMaxTooltipPlaceholder', 'The MAX heavenly chips is calculated with the cookies gained from popping all wrinklers with Skruuia god in Diamond slot, selling all stock market goods, selling all buildings with Earth Shatterer and Reality Bending auras, and buying Chocolate egg', '330px'], + ['ResetTooltipPlaceholder', 'The bonus income you would get from new prestige levels unlocked at 100% of its potential and from ascension achievements if you have the same buildings/upgrades after reset', '370px'], + ['ChoEggTooltipPlaceholder', 'The amount of cookies you would get from popping all wrinklers with Skruuia god in Diamond slot, selling all stock market goods, selling all buildings with Earth Shatterer and Reality Bending auras, and then buying Chocolate egg', '300px'] +]; + CM.Disp.colorTextPre = 'CMText'; CM.Disp.colorBackPre = 'CMBack'; CM.Disp.colorBorderPre = 'CMBorder'; @@ -2477,12 +2534,3 @@ for (var i in Game.wrinklers) { CM.Disp.TooltipWrinklerCache[i] = 0; } -CM.Disp.TooltipText = [ - ['GoldCookTooltipPlaceholder', 'Calculated with Golden Switch off', '200px'], - ['GoldCookDragonsFortuneTooltipPlaceholder', 'Calculated with Golden Switch off and at least one golden cookie on-screen', '240px'], - ['PrestMaxTooltipPlaceholder', 'The MAX prestige is calculated with the cookies gained from popping all wrinklers with Skruuia god in Diamond slot, selling all stock market goods, selling all buildings with Earth Shatterer and Reality Bending auras, and buying Chocolate egg', '320px'], - ['NextPrestTooltipPlaceholder', 'Calculated with cookies gained from wrinklers and Chocolate egg', '200px'], - ['HeavenChipMaxTooltipPlaceholder', 'The MAX heavenly chips is calculated with the cookies gained from popping all wrinklers with Skruuia god in Diamond slot, selling all stock market goods, selling all buildings with Earth Shatterer and Reality Bending auras, and buying Chocolate egg', '330px'], - ['ResetTooltipPlaceholder', 'The bonus income you would get from new prestige levels unlocked at 100% of its potential and from ascension achievements if you have the same buildings/upgrades after reset', '370px'], - ['ChoEggTooltipPlaceholder', 'The amount of cookies you would get from popping all wrinklers with Skruuia god in Diamond slot, selling all stock market goods, selling all buildings with Earth Shatterer and Reality Bending auras, and then buying Chocolate egg', '300px'] -]; diff --git a/src/Main.js b/src/Main.js index a941cc0..842c488 100644 --- a/src/Main.js +++ b/src/Main.js @@ -51,10 +51,12 @@ CM.ReplaceNative = function() { CM.ReplaceNativeGrimoire(); } + // TODO: Move this ReplaceTooltip function too other ReplaceTooltip functions + // OR: Move all other into this function CM.Backup.RebuildUpgrades = Game.RebuildUpgrades; Game.RebuildUpgrades = function() { CM.Backup.RebuildUpgrades(); - CM.Disp.AddTooltipUpgrade(); + CM.Disp.ReplaceTooltipUpgrade(); Game.CalculateGains(); } @@ -224,12 +226,12 @@ CM.DelayInit = function() { CM.Disp.CreateWhiteScreen(); CM.Disp.CreateFavicon(); for (var i in CM.Disp.TooltipText) { - CM.Disp.CreateTooltip(CM.Disp.TooltipText[i][0], CM.Disp.TooltipText[i][1], CM.Disp.TooltipText[i][2]); + CM.Disp.CreateSimpleTooltip(CM.Disp.TooltipText[i][0], CM.Disp.TooltipText[i][1], CM.Disp.TooltipText[i][2]); } CM.Disp.CreateTooltipWarn(); - CM.Disp.AddTooltipBuild(); - CM.Disp.AddTooltipGrimoire(); - CM.Disp.AddTooltipLump(); + CM.Disp.ReplaceTooltipBuild(); + CM.Disp.ReplaceTooltipGrimoire(); + CM.Disp.ReplaceTooltipLump(); CM.Disp.AddWrinklerAreaDetect(); CM.Cache.InitCookiesDiff(); CM.ReplaceNative(); @@ -300,6 +302,7 @@ CM.Main.CheckGoldenCookie = function() { } } CM.Main.lastSpawnedGoldenCookieState = CM.Main.currSpawnedGoldenCookieState + if (CM.Main.currSpawnedGoldenCookieState == 0) CM.Cache.spawnedGoldenShimmer = 0; } else if (CM.Config.GCTimer == 1 && CM.Main.lastGoldenCookieState) { for (var i in CM.Disp.GCTimers) { From 74b353d530778527d0fae669157c3e878feeef5b Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Thu, 3 Dec 2020 18:31:45 +0100 Subject: [PATCH 021/106] Fix CM.Sim.eff --- CookieMonster.js | 4 ++-- src/Sim.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index b8f4856..81d4165 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -1153,7 +1153,7 @@ CM.Disp.RefreshScale = function() { * This function returns time as a string depending on TimeFormat setting * @param {number} time Time to be formatted * @param {number} longFormat 1 or 0 - * @returns {string} Formatted time` + * @returns {string} Formatted time */ CM.Disp.FormatTime = function(time, longFormat) { if (time == Infinity) return time; @@ -4038,7 +4038,7 @@ CM.Sim.eff = function(name) { return CM.Sim.effs[name] } else { - return Game.effs[name]; + return CM.Sim.effs[name]; } } diff --git a/src/Sim.js b/src/Sim.js index 902cc7b..a19d38b 100644 --- a/src/Sim.js +++ b/src/Sim.js @@ -118,7 +118,7 @@ CM.Sim.eff = function(name) { return CM.Sim.effs[name] } else { - return Game.effs[name]; + return CM.Sim.effs[name]; } } From ed814ef39a3c6130e0aa39d10f474ffad6ee8b05 Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Thu, 3 Dec 2020 19:00:27 +0100 Subject: [PATCH 022/106] FIx for floating numbers --- CookieMonster.js | 7 +++++-- src/Disp.js | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index 81d4165..463fb1d 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -1224,8 +1224,11 @@ CM.Disp.Beautify = function(num, frac, forced) { } num = num.toString(); var timesTenToPowerThree = Math.trunc(Math.log10(num) / 3) - if (timesTenToPowerThree < 2) { - answer = num; + if (num == "0") { + return num + } + else if (timesTenToPowerThree < 2) { + answer = Math.round(num * 100) / 100; } else if (CM.Config.Scale == 3 && !forced || forced == 3) { // Scientific notation, 123456789 => 1.235E+8 answer = num[0] + '.' diff --git a/src/Disp.js b/src/Disp.js index 756bb74..a38b41a 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -342,8 +342,11 @@ CM.Disp.Beautify = function(num, frac, forced) { } num = num.toString(); var timesTenToPowerThree = Math.trunc(Math.log10(num) / 3) - if (timesTenToPowerThree < 2) { - answer = num; + if (num == "0") { + return num + } + else if (timesTenToPowerThree < 2) { + answer = Math.round(num * 100) / 100; } else if (CM.Config.Scale == 3 && !forced || forced == 3) { // Scientific notation, 123456789 => 1.235E+8 answer = num[0] + '.' From a3f2fe5dababf32fe34151a9def53a129c94357f Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Fri, 4 Dec 2020 20:23:58 +0100 Subject: [PATCH 023/106] Reworked Tooltip code v1 --- CookieMonster.js | 933 ++++++++++++++++++++++++----------------------- src/Disp.js | 911 ++++++++++++++++++++++----------------------- src/Main.js | 22 +- 3 files changed, 962 insertions(+), 904 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index 463fb1d..d26a337 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -1090,16 +1090,7 @@ CM.Disp.CalculateGrimoireRefillTime = function(currentMagic, maxMagic, targetMag return count / Game.fps; } -CM.Disp.AddWrinklerAreaDetect = function() { - l('backgroundLeftCanvas').onmouseover = function() {CM.Disp.TooltipWrinklerArea = 1;}; - l('backgroundLeftCanvas').onmouseout = function() { - CM.Disp.TooltipWrinklerArea = 0; - Game.tooltip.hide(); - for (var i in Game.wrinklers) { - CM.Disp.TooltipWrinklerCache[i] = 0; - } - }; -} + CM.Disp.UpdateAscendState = function() { if (Game.OnAscend) { @@ -1227,7 +1218,7 @@ CM.Disp.Beautify = function(num, frac, forced) { if (num == "0") { return num } - else if (timesTenToPowerThree < 2) { + else if (-1 < timesTenToPowerThree < 2) { answer = Math.round(num * 100) / 100; } else if (CM.Config.Scale == 3 && !forced || forced == 3) { // Scientific notation, 123456789 => 1.235E+8 @@ -2093,16 +2084,205 @@ CM.Disp.CreateSimpleTooltip = function(placeholder, text, minWidth) { } /** - * This function creates the tooltip extension of Lucky/Chain and other warnings for the building and upgrade tooltips - * It is called by CM.DelayInit() and the tooltip is appended to the l('tooltipAnchor'). - * Visbility is then managed in CM.Disp.UpdateTooltip(). + * This function replaces the original .onmouseover functions of buildings so that it calls CM.Disp.Tooltip() + * CM.Disp.Tooltip() sets the tooltip type to 'b' + * It is called by CM.DelayInit() + * TODO: Place all ReplaceTooltip functions either under CM.DelayInit() or CM.ReplaceNative() + * TODO: Move this code to Main.js file */ -CM.Disp.CreateTooltipWarn = function() { +CM.Disp.ReplaceTooltipBuild = function() { + CM.Disp.TooltipBuildBackup = []; + for (var i in Game.Objects) { + var me = Game.Objects[i]; + if (l('product' + me.id).onmouseover != null) { + CM.Disp.TooltipBuildBackup[i] = l('product' + me.id).onmouseover; + eval('l(\'product\' + me.id).onmouseover = function() {Game.tooltip.dynamic = 1; Game.tooltip.draw(this, function() {return CM.Disp.Tooltip(\'b\', \'' + i + '\');}, \'store\'); Game.tooltip.wobble();}'); + } + } +} + +/** + * This function replaces the original .onmouseover functions of upgrades so that it calls CM.Disp.Tooltip() + * CM.Disp.Tooltip() sets the tooltip type to 'u' + * It is called by CM.ReplaceNative() + * TODO: Place all ReplaceTooltip functions either under CM.DelayInit() or CM.ReplaceNative() + * TODO: Move this code to Main.js file + * + */ +CM.Disp.ReplaceTooltipUpgrade = function() { + CM.Disp.TooltipUpgradeBackup = []; + for (var i in Game.UpgradesInStore) { + var me = Game.UpgradesInStore[i]; + if (l('upgrade' + i).onmouseover != null) { + CM.Disp.TooltipUpgradeBackup[i] = l('upgrade' + i).onmouseover; + eval('l(\'upgrade\' + i).onmouseover = function() {if (!Game.mouseDown) {Game.setOnCrate(this); Game.tooltip.dynamic = 1; Game.tooltip.draw(this, function() {return CM.Disp.Tooltip(\'u\', \'' + i + '\');}, \'store\'); Game.tooltip.wobble();}}'); + } + } +} + +/** + * This function replaces the original .onmouseover functions of the Grimoire minigame so that it calls CM.Disp.Tooltip() + * CM.Disp.Tooltip() sets the tooltip type to 'g' + * The function is called by CM.DelayInit() + * TODO: Place all ReplaceTooltip functions either under CM.DelayInit() or CM.ReplaceNative() + * TODO: Move this code to Main.js file + */ +CM.Disp.ReplaceTooltipGrimoire = function() { + if (Game.Objects['Wizard tower'].minigameLoaded) { + CM.Disp.TooltipGrimoireBackup = []; + for (var i in Game.Objects['Wizard tower'].minigame.spellsById) { + if (l('grimoireSpell' + i).onmouseover != null) { + CM.Disp.TooltipGrimoireBackup[i] = l('grimoireSpell' + i).onmouseover; + eval('l(\'grimoireSpell\' + i).onmouseover = function() {Game.tooltip.dynamic = 1; Game.tooltip.draw(this, function() {return CM.Disp.Tooltip(\'g\', \'' + i + '\');}, \'this\'); Game.tooltip.wobble();}'); + } + } + } +} + +/** + * This function replaces the original .onmouseover functions of sugar lumps so that it calls CM.Disp.Tooltip() + * CM.Disp.Tooltip() sets the tooltip type to 's' + * The function is called by CM.DelayInit() + * TODO: Place all ReplaceTooltip functions either under CM.DelayInit() or CM.ReplaceNative() + * TODO: Move this code to Main.js file + */ +CM.Disp.ReplaceTooltipLump = function() { + if (Game.canLumps()) { + CM.Disp.TooltipLumpBackup = l('lumps').onmouseover; + eval('l(\'lumps\').onmouseover = function() {Game.tooltip.dynamic = 1; Game.tooltip.draw(this, function() {return CM.Disp.Tooltip(\'s\', \'Lump\');}, \'this\'); Game.tooltip.wobble();}'); + } +}; + +/** + * This function enhance the standard tooltips by creating and changing l('tooltip') + * The function is called by .onmouseover events that have replaced original code to use CM.Disp.Tooltip() + * @param {string} type Type of tooltip (b, u, s or g) + * @param {string} name Name of the object/item the tooltip relates to + * @returns {string} l('tooltip').innerHTML The HTML of the l('tooltip')-object + */ +CM.Disp.Tooltip = function(type, name) { + if (type == 'b') { // Buildings + l('tooltip').innerHTML = Game.Objects[name].tooltip(); + // Adds amortization info to the list of info per building + if (CM.Config.TooltipAmor == 1) { + var buildPrice = CM.Sim.BuildingGetPrice(Game.Objects[name], Game.Objects[name].basePrice, 0, Game.Objects[name].free, Game.Objects[name].amount); + var amortizeAmount = buildPrice - Game.Objects[name].totalCookies; + if (amortizeAmount > 0) { + l('tooltip').innerHTML = l('tooltip').innerHTML + .split('so far') + .join('so far
' + Beautify(amortizeAmount) + ' ' + (Math.floor(amortizeAmount) == 1 ? 'cookie' : 'cookies') + ' left to amortize (' + CM.Disp.GetTimeColor((buildPrice - Game.Objects[name].totalCookies) / (Game.Objects[name].storedTotalCps * Game.globalCpsMult)).text + ')'); + } + } + if (Game.buyMode == -1) { + /* + * Fix sell price displayed in the object tooltip. + * + * The buildings sell price displayed by the game itself (without any mod) is incorrect. + * The following line of code fixes this issue, and can be safely removed when the game gets fixed. + * + * This issue is extensively detailed here: https://github.com/Aktanusa/CookieMonster/issues/359#issuecomment-735658262 + */ + l('tooltip').innerHTML = l('tooltip').innerHTML.split(Beautify(Game.Objects[name].bulkPrice)).join(Beautify(CM.Sim.BuildingSell(Game.Objects[name], Game.Objects[name].basePrice, Game.Objects[name].amount, Game.Objects[name].free, Game.buyBulk, 1))); + } + } + else if (type == 'u') { // Upgrades + if (!Game.UpgradesInStore[name]) return ''; + l('tooltip').innerHTML = Game.crateTooltip(Game.UpgradesInStore[name], 'store'); + } + else if (type === 's') l('tooltip').innerHTML = Game.lumpTooltip(); // Sugar Lumps + else if (type === 'g') l('tooltip').innerHTML = Game.Objects['Wizard tower'].minigame.spellTooltip(name)(); // Grimoire + + // Adds area for extra tooltip-sections + var area = document.createElement('div'); + area.id = 'CMTooltipArea'; + l('tooltip').appendChild(area); + + // Sets global variables used by CM.Disp.UpdateTooltip() + CM.Disp.tooltipType = type; + CM.Disp.tooltipName = name; + + CM.Disp.UpdateTooltip(); + + return l('tooltip').innerHTML; +} + +/** + * This function creates a tooltipBox object which contains all CookieMonster added tooltip information. + * It is called by all CM.Disp.UpdateTooltip functions. + * @returns {object} div An object containing the stylized box + */ +CM.Disp.TooltipCreateTooltipBox = function() { + l('tooltip').firstChild.style.paddingBottom = '4px'; // Sets padding on base-tooltip + var tooltipBox = document.createElement('div'); + tooltipBox.style.border = '1px solid'; + tooltipBox.style.padding = '4px'; + tooltipBox.style.margin = '0px -4px'; + tooltipBox.id = 'CMTooltipBorder'; + tooltipBox.className = CM.Disp.colorTextPre + CM.Disp.colorGray; + return tooltipBox +} + +/** + * This function creates a header object for tooltips. + * It is called by all CM.Disp.UpdateTooltip functions. + * @param {string} text Title of header + * @returns {object} div An object containing the stylized header + */ +CM.Disp.TooltipCreateHeader = function(text) { + var div = document.createElement('div'); + div.style.fontWeight = 'bold'; + div.className = CM.Disp.colorTextPre + CM.Disp.colorBlue; + div.textContent = text; + return div; +} + +/** + * This function appends the sections for Bonus Income, PP and Time left (to achiev) to the tooltip-object + * It is called by CM.Disp.UpdateTooltipBuilding() and CM.Disp.UpdateTooltipUpgrade() + * The actual data is added by the Update-functions themselves + * @param {object} tooltip Object of a TooltipBox, normally created by a call to CM.Disp.TooltipCreateTooltipBox() + */ +CM.Disp.TooltipCreateCalculationSection = function(tooltip) { + tooltip.appendChild(CM.Disp.TooltipCreateHeader('Bonus Income')); + var income = document.createElement('div'); + income.style.marginBottom = '4px'; + income.style.color = 'white'; + income.id = 'CMTooltipIncome'; + tooltip.appendChild(income); + + tooltip.appendChild(CM.Disp.TooltipCreateHeader('Payback Period')); + var pp = document.createElement('div'); + pp.style.marginBottom = '4px'; + pp.id = 'CMTooltipPP'; + tooltip.appendChild(pp); + + tooltip.appendChild(CM.Disp.TooltipCreateHeader('Time Left')); + var time = document.createElement('div'); + time.id = 'CMTooltipTime'; + tooltip.appendChild(time); + + if (CM.Disp.tooltipType == 'b') { + tooltip.appendChild(CM.Disp.TooltipCreateHeader('Production left till next achievement')); + tooltip.lastChild.id = 'CMTooltipProductionHeader'; // Assign a id in order to hid when no achiev's are left + var production = document.createElement('div'); + production.id = 'CMTooltipProduction'; + tooltip.appendChild(production); + } +} + +/** + * This function creates the tooltip objectm for warnings + * It is called by CM.Disp.UpdateTooltipWarnings() whenever the tooltip type is 'b' or 'u' + * The object is also removed by CM.Disp.UpdateTooltipWarnings() when type is 's' or 'g' + * @returns {object} CM.Disp.TooltipWarn The Warnings-tooltip object + */ +CM.Disp.TooltipCreateWarningSection = function() { CM.Disp.TooltipWarn = document.createElement('div'); CM.Disp.TooltipWarn.style.position = 'absolute'; - CM.Disp.TooltipWarn.style.display = 'none'; + CM.Disp.TooltipWarn.style.display = 'block'; CM.Disp.TooltipWarn.style.left = 'auto'; CM.Disp.TooltipWarn.style.bottom = 'auto'; + CM.Disp.TooltipWarn.id = "CMDispTooltipWarningParent"; var create = function(boxId, color, labelTextFront, labelTextBack, deficitId) { var box = document.createElement('div'); @@ -2138,433 +2318,276 @@ CM.Disp.CreateTooltipWarn = function() { CM.Disp.TooltipWarn.appendChild(create('CMDispTooltipWarnLuckyFrenzy', CM.Disp.colorYellow, 'Warning: ', 'Purchase of this item will put you under the number of Cookies required for "Lucky!" (Frenzy)', 'CMDispTooltipWarnLuckyFrenzyText')); CM.Disp.TooltipWarn.lastChild.style.marginBottom = '4px'; CM.Disp.TooltipWarn.appendChild(create('CMDispTooltipWarnConjure', CM.Disp.colorPurple, 'Warning: ', 'Purchase of this item will put you under the number of Cookies required for "Conjure Baked Goods"', 'CMDispTooltipWarnConjureText')); - - l('tooltipAnchor').appendChild(CM.Disp.TooltipWarn); + + return CM.Disp.TooltipWarn; } /** - * This function replaces the original .onmouseover functions of buildings so that it calls CM.Disp.Tooltip() - * CM.Disp.Tooltip() sets the tooltip type to 'b' - * It is called by CM.DelayInit() - * TODO: Place all ReplaceTooltip functions either under CM.DelayInit() or CM.ReplaceNative() + * This function updates the sections of the tooltips created by CookieMonster + * It is called when tooltips are created by and CM.Disp.Tooltip() on every loop by CM.Loop() */ -CM.Disp.ReplaceTooltipBuild = function() { - CM.Disp.TooltipBuildBackup = []; - for (var i in Game.Objects) { - var me = Game.Objects[i]; - if (l('product' + me.id).onmouseover != null) { - CM.Disp.TooltipBuildBackup[i] = l('product' + me.id).onmouseover; - eval('l(\'product\' + me.id).onmouseover = function() {Game.tooltip.dynamic = 1; Game.tooltip.draw(this, function() {return CM.Disp.Tooltip(\'b\', \'' + i + '\');}, \'store\'); Game.tooltip.wobble();}'); - } - } -} - -/** - * This function replaces the original .onmouseover functions of upgrades so that it calls CM.Disp.Tooltip() - * CM.Disp.Tooltip() sets the tooltip type to 'u' - * It is called by CM.ReplaceNative() - * TODO: Place all ReplaceTooltip functions either under CM.DelayInit() or CM.ReplaceNative() - */ -CM.Disp.ReplaceTooltipUpgrade = function() { - CM.Disp.TooltipUpgradeBackup = []; - for (var i in Game.UpgradesInStore) { - var me = Game.UpgradesInStore[i]; - if (l('upgrade' + i).onmouseover != null) { - CM.Disp.TooltipUpgradeBackup[i] = l('upgrade' + i).onmouseover; - eval('l(\'upgrade\' + i).onmouseover = function() {if (!Game.mouseDown) {Game.setOnCrate(this); Game.tooltip.dynamic = 1; Game.tooltip.draw(this, function() {return CM.Disp.Tooltip(\'u\', \'' + i + '\');}, \'store\'); Game.tooltip.wobble();}}'); - } - } -} - -/** - * This function replaces the original .onmouseover functions of the Grimoire minigame so that it calls CM.Disp.Tooltip() - * CM.Disp.Tooltip() sets the tooltip type to 'g' - * The function is called by CM.DelayInit() - * TODO: Place all ReplaceTooltip functions either under CM.DelayInit() or CM.ReplaceNative() - */ -CM.Disp.ReplaceTooltipGrimoire = function() { - if (Game.Objects['Wizard tower'].minigameLoaded) { - CM.Disp.TooltipGrimoireBackup = []; - for (var i in Game.Objects['Wizard tower'].minigame.spellsById) { - if (l('grimoireSpell' + i).onmouseover != null) { - CM.Disp.TooltipGrimoireBackup[i] = l('grimoireSpell' + i).onmouseover; - eval('l(\'grimoireSpell\' + i).onmouseover = function() {Game.tooltip.dynamic = 1; Game.tooltip.draw(this, function() {return CM.Disp.Tooltip(\'g\', \'' + i + '\');}, \'this\'); Game.tooltip.wobble();}'); - } - } - } -} - -/** - * This function replaces the original .onmouseover functions of sugar lumps so that it calls CM.Disp.Tooltip() - * CM.Disp.Tooltip() sets the tooltip type to 's' - * The function is called by CM.DelayInit() - * TODO: Place all ReplaceTooltip functions either under CM.DelayInit() or CM.ReplaceNative() - */ -CM.Disp.ReplaceTooltipLump = function() { - if (Game.canLumps()) { - CM.Disp.TooltipLumpBackup = l('lumps').onmouseover; - eval('l(\'lumps\').onmouseover = function() {Game.tooltip.dynamic = 1; Game.tooltip.draw(this, function() {return CM.Disp.Tooltip(\'s\', \'Lump\');}, \'this\'); Game.tooltip.wobble();}'); - } -}; - -/** - * This function creates tooltips by creating and changing l('tooltip') - * The function is called by .onmouseover events that have replaced original code to use CM.Disp.Tooltip( - */ -CM.Disp.Tooltip = function(type, name) { - if (type == 'b') { - l('tooltip').innerHTML = Game.Objects[name].tooltip(); - if (CM.Config.TooltipAmor == 1) { - var buildPrice = CM.Sim.BuildingGetPrice(Game.Objects[name], Game.Objects[name].basePrice, 0, Game.Objects[name].free, Game.Objects[name].amount); - var amortizeAmount = buildPrice - Game.Objects[name].totalCookies; - if (amortizeAmount > 0) { - l('tooltip').innerHTML = l('tooltip').innerHTML - .split('so far') - .join('so far
' + Beautify(amortizeAmount) + ' ' + (Math.floor(amortizeAmount) == 1 ? 'cookie' : 'cookies') + ' left to amortize (' + CM.Disp.GetTimeColor((buildPrice - Game.Objects[name].totalCookies) / (Game.Objects[name].storedTotalCps * Game.globalCpsMult)).text + ')'); - } - } - if (Game.buyMode == 1) { - var target = ''; - var change = false; - if (Game.buyBulk == 10) { - target = 'Objects10'; - change = true; - } - else if (Game.buyBulk == 100) { - target = 'Objects100'; - change = true; - } - if (change) { - l('tooltip').innerHTML = l('tooltip').innerHTML.split(Beautify(Game.Objects[name].getPrice())).join(Beautify(CM.Cache[target][name].price)); - } - } - else if (Game.buyMode == -1) { - /* - * Fix sell price displayed in the object tooltip. - * - * The buildings sell price displayed by the game itself (without any mod) is incorrect. - * The following line of code fixes this issue, and can be safely removed when the game gets fixed. - * - * This issue is extensively detailed here: https://github.com/Aktanusa/CookieMonster/issues/359#issuecomment-735658262 - */ - l('tooltip').innerHTML = l('tooltip').innerHTML.split(Beautify(Game.Objects[name].bulkPrice)).join(Beautify(CM.Sim.BuildingSell(Game.Objects[name], Game.Objects[name].basePrice, Game.Objects[name].amount, Game.Objects[name].free, Game.buyBulk, 1))); - } - } - else if (type == 'u') { - if (!Game.UpgradesInStore[name]) return ''; - l('tooltip').innerHTML = Game.crateTooltip(Game.UpgradesInStore[name], 'store'); - } - else if (type === 's') { - // Sugar Lump - l('tooltip').innerHTML = Game.lumpTooltip(); - } - else { // Grimoire - l('tooltip').innerHTML = Game.Objects['Wizard tower'].minigame.spellTooltip(name)(); - } - - var area = document.createElement('div'); - area.id = 'CMTooltipArea'; - l('tooltip').appendChild(area); - - if (CM.Config.TooltipBuildUp == 1 && (type == 'u' || (type == 'b' && Game.buyMode == 1))) { - l('tooltip').firstChild.style.paddingBottom = '4px'; - var tooltip = document.createElement('div'); - tooltip.style.border = '1px solid'; - tooltip.style.padding = '4px'; - tooltip.style.margin = '0px -4px'; - tooltip.id = 'CMTooltipBorder'; - - var header = function(text) { - var div = document.createElement('div'); - div.style.fontWeight = 'bold'; - div.className = CM.Disp.colorTextPre + CM.Disp.colorBlue; - div.textContent = text; - return div; - } - - tooltip.appendChild(header('Bonus Income')); - var income = document.createElement('div'); - income.style.marginBottom = '4px'; - income.style.color = 'white'; - income.id = 'CMTooltipIncome'; - tooltip.appendChild(income); - tooltip.appendChild(header('Payback Period')); - var pp = document.createElement('div'); - pp.style.marginBottom = '4px'; - pp.id = 'CMTooltipPP'; - tooltip.appendChild(pp); - tooltip.appendChild(header('Time Left')); - var time = document.createElement('div'); - time.id = 'CMTooltipTime'; - tooltip.appendChild(time); - if (type == 'b') { - tooltip.appendChild(header('Production left till next achievement')); - tooltip.lastChild.id = 'CMTooltipProductionHeader'; - var production = document.createElement('div'); - production.id = 'CMTooltipProduction'; - tooltip.appendChild(production); - } - - area.appendChild(tooltip); - } - - CM.Disp.tooltipType = type; - CM.Disp.tooltipName = name; - - CM.Disp.UpdateTooltip(); - - return l('tooltip').innerHTML; -} - CM.Disp.UpdateTooltip = function() { CM.Sim.CopyData(); - if (l('tooltipAnchor').style.display != 'none') { + if (l('tooltipAnchor').style.display != 'none' && l('CMTooltipArea')) { + l('CMTooltipArea').innerHTML = ''; + tooltipBox = CM.Disp.TooltipCreateTooltipBox(); + l('CMTooltipArea').appendChild(tooltipBox); + + if (CM.Disp.tooltipType == 'b') { + CM.Disp.UpdateTooltipBuilding(); + } + else if (CM.Disp.tooltipType == 'u') { + CM.Disp.UpdateTooltipUpgrade(); + } + else if (CM.Disp.tooltipType === 's') { + CM.Disp.UpdateTooltipSugarLump(); + } + else if (CM.Disp.tooltipType === 'g') { + CM.Disp.UpdateTooltipGrimoire(); + } + CM.Disp.UpdateTooltipWarnings(); + } +} - if (l('CMTooltipArea') != null) { - if (CM.Disp.tooltipType == 'b' || CM.Disp.tooltipType == 'u') { - // Error checking - if (CM.Disp.tooltipType == 'u' && (typeof Game.UpgradesInStore[CM.Disp.tooltipName] === 'undefined' || typeof CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name] === 'undefined')) { - return; - } - var price; - var bonus; - if (CM.Disp.tooltipType == 'b') { - var target = ''; - if (Game.buyMode == 1 && Game.buyBulk == 10) { - target = 'Objects10'; - price = CM.Cache[target][CM.Disp.tooltipName].price; - } - else if (Game.buyMode == 1 && Game.buyBulk == 100) { - target = 'Objects100'; - price = CM.Cache[target][CM.Disp.tooltipName].price; - } - else { - target = 'Objects'; - price = Game.Objects[CM.Disp.tooltipName].getPrice(); - } - bonus = CM.Cache[target][CM.Disp.tooltipName].bonus; - if (CM.Config.TooltipBuildUp == 1 && Game.buyMode == 1) { - l('CMTooltipBorder').className = CM.Disp.colorTextPre + CM.Cache[target][CM.Disp.tooltipName].color; - l('CMTooltipPP').textContent = Beautify(CM.Cache[target][CM.Disp.tooltipName].pp, 2); - l('CMTooltipPP').className = CM.Disp.colorTextPre + CM.Cache[target][CM.Disp.tooltipName].color; - } - if (CM.Config.TooltipBuildUp) { - for (var i in Game.Objects[CM.Disp.tooltipName].productionAchievs) { - if (!CM.Sim.HasAchiev(Game.Objects[CM.Disp.tooltipName].productionAchievs[i].achiev.name)) { - var nextProductionAchiev = Game.Objects[CM.Disp.tooltipName].productionAchievs[i] - break - } - } - if (typeof nextProductionAchiev != "undefined") { - l('CMTooltipTime').style.marginBottom = '4px'; - l('CMTooltipProductionHeader').style.display = ""; - l('CMTooltipProduction').className = "ProdAchievement" + CM.Disp.tooltipName; - l('CMTooltipProduction').textContent = Beautify(nextProductionAchiev.pow - CM.Sim.Objects[CM.Disp.tooltipName].totalCookies, 15); - l('CMTooltipProduction').style.color = "white"; - } else { - l('CMTooltipProductionHeader').style.display = "none"; - l('CMTooltipTime').style.marginBottom = '0px'; - } - } - } - else { // Upgrades - bonus = CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].bonus; - price = Game.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].getPrice(); - if (CM.Config.TooltipBuildUp == 1) { - l('CMTooltipBorder').className = CM.Disp.colorTextPre + CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].color; - l('CMTooltipPP').textContent = Beautify(CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].pp, 2); - l('CMTooltipPP').className = CM.Disp.colorTextPre + CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].color; - } - } - if (CM.Config.TooltipBuildUp == 1 && (CM.Disp.tooltipType != 'b' || Game.buyMode == 1)) { - l('CMTooltipIncome').textContent = Beautify(bonus, 2); +/** + * This function adds extra info to the Building tooltips + * It is called when Building tooltips are created or refreshed by CM.Disp.UpdateTooltip() + */ +CM.Disp.UpdateTooltipBuilding = function() { + if (CM.Config.TooltipBuildUp == 1 && Game.buyMode == 1) { + tooltipBox = l('CMTooltipBorder'); + CM.Disp.TooltipCreateCalculationSection(tooltipBox); - var increase = Math.round(bonus / Game.cookiesPs * 10000); - if (isFinite(increase) && increase != 0) { - l('CMTooltipIncome').textContent += ' (' + (increase / 100) + '% of income)'; - } + var target = ''; + // TODO: Change the Cache code and variables to use Objects1, Objectes10, Objects100 + // That would depreciate this target setting code + if (Game.buyMode == 1 && Game.buyBulk == 10) target = 'Objects10' + else if (Game.buyMode == 1 && Game.buyBulk == 100) target = 'Objects100'; + else target = 'Objects'; - var timeColor = CM.Disp.GetTimeColor((price - (Game.cookies + CM.Disp.GetWrinkConfigBank())) / CM.Disp.GetCPS()); - l('CMTooltipTime').textContent = timeColor.text; - l('CMTooltipTime').className = CM.Disp.colorTextPre + timeColor.color; - } + var price = Game.Objects[CM.Disp.tooltipName].bulkPrice + CM.Disp.TooltipBonusIncome = CM.Cache[target][CM.Disp.tooltipName].bonus; + - if (CM.Config.ToolWarnPos == 0) { - CM.Disp.TooltipWarn.style.right = '0px'; - } - else { - CM.Disp.TooltipWarn.style.top = (l('tooltip').offsetHeight) + 'px'; - } - CM.Disp.TooltipWarn.style.width = (l('tooltip').offsetWidth - 6) + 'px'; + if (CM.Config.TooltipBuildUp == 1 && Game.buyMode == 1) { + l('CMTooltipIncome').textContent = Beautify(CM.Disp.TooltipBonusIncome, 2); + var increase = Math.round(CM.Disp.TooltipBonusIncome / Game.cookiesPs * 10000); + if (isFinite(increase) && increase != 0) { + l('CMTooltipIncome').textContent += ' (' + (increase / 100) + '% of income)'; + } + l('CMTooltipBorder').className = CM.Disp.colorTextPre + CM.Cache[target][CM.Disp.tooltipName].color; + l('CMTooltipPP').textContent = Beautify(CM.Cache[target][CM.Disp.tooltipName].pp, 2); + l('CMTooltipPP').className = CM.Disp.colorTextPre + CM.Cache[target][CM.Disp.tooltipName].color; + var timeColor = CM.Disp.GetTimeColor((price - (Game.cookies + CM.Disp.GetWrinkConfigBank())) / CM.Disp.GetCPS()); + l('CMTooltipTime').textContent = timeColor.text; + l('CMTooltipTime').className = CM.Disp.colorTextPre + timeColor.color; + } - if (CM.Config.ToolWarnLucky == 1) { - CM.Disp.TooltipWarn.style.display = 'block'; - var limitLucky = CM.Cache.Lucky; - if (CM.Config.ToolWarnBon == 1) { - var bonusNoFren = bonus; - bonusNoFren /= CM.Sim.getCPSBuffMult(); - limitLucky += ((bonusNoFren * 60 * 15) / 0.15); - } - var limitLuckyFrenzy = limitLucky * 7; - var amount = (Game.cookies + CM.Disp.GetWrinkConfigBank()) - price; - if ((amount < limitLucky || amount < limitLuckyFrenzy) && (CM.Disp.tooltipType != 'b' || Game.buyMode == 1)) { - if (amount < limitLucky) { - l('CMDispTooltipWarnLucky').style.display = ''; - l('CMDispTooltipWarnLuckyText').textContent = Beautify(limitLucky - amount) + ' (' + CM.Disp.FormatTime((limitLucky - amount) / CM.Disp.GetCPS()) + ')'; - l('CMDispTooltipWarnLuckyFrenzy').style.display = ''; - l('CMDispTooltipWarnLuckyFrenzyText').textContent = Beautify(limitLuckyFrenzy - amount) + ' (' + CM.Disp.FormatTime((limitLuckyFrenzy - amount) / CM.Disp.GetCPS()) + ')'; - } - else if (amount < limitLuckyFrenzy) { - l('CMDispTooltipWarnLuckyFrenzy').style.display = ''; - l('CMDispTooltipWarnLuckyFrenzyText').textContent = Beautify(limitLuckyFrenzy - amount) + ' (' + CM.Disp.FormatTime((limitLuckyFrenzy - amount) / CM.Disp.GetCPS()) + ')'; - l('CMDispTooltipWarnLucky').style.display = 'none'; - } - } else { - l('CMDispTooltipWarnLucky').style.display = 'none'; - l('CMDispTooltipWarnLuckyFrenzy').style.display = 'none'; - } + // Add "production left till next achievement"-bar + for (var i in Game.Objects[CM.Disp.tooltipName].productionAchievs) { + if (!CM.Sim.HasAchiev(Game.Objects[CM.Disp.tooltipName].productionAchievs[i].achiev.name)) { + var nextProductionAchiev = Game.Objects[CM.Disp.tooltipName].productionAchievs[i] + break + } + } + if (typeof nextProductionAchiev != "undefined") { + l('CMTooltipTime').style.marginBottom = '4px'; + l('CMTooltipProductionHeader').style.display = ""; + l('CMTooltipProduction').className = "ProdAchievement" + CM.Disp.tooltipName; + l('CMTooltipProduction').textContent = Beautify(nextProductionAchiev.pow - CM.Sim.Objects[CM.Disp.tooltipName].totalCookies, 15); + l('CMTooltipProduction').style.color = "white"; + } else { + l('CMTooltipProductionHeader').style.display = "none"; + l('CMTooltipTime').style.marginBottom = '0px'; + } + } +} + +/** + * This function adds extra info to the Upgrade tooltips + * It is called when Upgrade tooltips are created or refreshed by CM.Disp.UpdateTooltip() + */ +CM.Disp.UpdateTooltipUpgrade = function() { + tooltipBox = l('CMTooltipBorder'); + CM.Disp.TooltipCreateCalculationSection(tooltipBox); + + CM.Disp.TooltipBonusIncome = CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].bonus; + price = Game.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].getPrice(); + + if (CM.Config.TooltipBuildUp == 1) { + l('CMTooltipIncome').textContent = Beautify(CM.Disp.TooltipBonusIncome, 2); + var increase = Math.round(CM.Disp.TooltipBonusIncome / Game.cookiesPs * 10000); + if (isFinite(increase) && increase != 0) { + l('CMTooltipIncome').textContent += ' (' + (increase / 100) + '% of income)'; + } + l('CMTooltipBorder').className = CM.Disp.colorTextPre + CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].color; + l('CMTooltipPP').textContent = Beautify(CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].pp, 2); + l('CMTooltipPP').className = CM.Disp.colorTextPre + CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].color; + var timeColor = CM.Disp.GetTimeColor((price - (Game.cookies + CM.Disp.GetWrinkConfigBank())) / CM.Disp.GetCPS()); + l('CMTooltipTime').textContent = timeColor.text; + l('CMTooltipTime').className = CM.Disp.colorTextPre + timeColor.color; + } +} + +/** + * This function adds extra info to the Sugar Lump tooltip + * It is called when the Sugar Lump tooltip is created or refreshed by CM.Disp.UpdateTooltip() + * It adds to the additional information to l('CMTooltipArea') + */ +CM.Disp.UpdateTooltipSugarLump = function() { + if (CM.Config.TooltipLump === 1) { + tooltipBox = l('CMTooltipBorder'); + + tooltipBox.appendChild(CM.Disp.TooltipCreateHeader('Current Sugar Lump')); + + var lumpType = document.createElement('div'); + lumpType.id = 'CMTooltipTime'; + tooltipBox.appendChild(lumpType); + var lumpColor = CM.Disp.GetLumpColor(Game.lumpCurrentType); + lumpType.textContent = lumpColor.text; + lumpType.className = CM.Disp.colorTextPre + lumpColor.color; + } +} + +/** + * This function adds extra info to the Grimoire tooltips + * It is called when Grimoire tooltips are created or refreshed by CM.Disp.UpdateTooltip() + * It adds to the additional information to l('CMTooltipArea') + */ +CM.Disp.UpdateTooltipGrimoire = function() { + var minigame = Game.Objects['Wizard tower'].minigame; + var spellCost = minigame.getSpellCost(minigame.spellsById[CM.Disp.tooltipName]); + + if (CM.Config.TooltipGrim == 1 && spellCost <= minigame.magicM) { + tooltipBox = l('CMTooltipBorder'); + + // Time left till enough magic for spell + tooltipBox.appendChild(CM.Disp.TooltipCreateHeader('Time Left')); + var time = document.createElement('div'); + time.id = 'CMTooltipTime'; + tooltipBox.appendChild(time); + var timeColor = CM.Disp.GetTimeColor(CM.Disp.CalculateGrimoireRefillTime(minigame.magic, minigame.magicM, spellCost)); + time.textContent = timeColor.text; + time.className = CM.Disp.colorTextPre + timeColor.color; + + // Time left untill magic spent is recovered + if (spellCost <= minigame.magic) { + tooltipBox.appendChild(CM.Disp.TooltipCreateHeader('Recover Time')); + var recover = document.createElement('div'); + recover.id = 'CMTooltipRecover'; + tooltipBox.appendChild(recover); + var recoverColor = CM.Disp.GetTimeColor(CM.Disp.CalculateGrimoireRefillTime(Math.max(0, minigame.magic - spellCost), minigame.magicM, minigame.magic)); + recover.textContent = recoverColor.text; + recover.className = CM.Disp.colorTextPre + recoverColor.color; + } + + // Extra information on cookies gained when spell is Conjure Baked Goods (Name == 0) + if (CM.Disp.tooltipName == 0) { + tooltipBox.appendChild(CM.Disp.TooltipCreateHeader('Cookies to be gained/lost')); + var conjure = document.createElement('div'); + conjure.id = 'CMTooltipConjure'; + tooltipBox.appendChild(conjure); + var reward = document.createElement('span'); + reward.style.color = "#33FF00" + reward.textContent = Beautify(Math.min((Game.cookies + CM.Disp.GetWrinkConfigBank()) * 0.15, CM.Cache.NoGoldSwitchCookiesPS * 60 * 30), 2) + conjure.appendChild(reward) + var seperator = document.createElement('span'); + seperator.textContent = ' / ' + conjure.appendChild(seperator) + var loss = document.createElement('span'); + loss.style.color = "red" + loss.textContent = Beautify((CM.Cache.NoGoldSwitchCookiesPS * 60 * 15), 2); + conjure.appendChild(loss) + } + + l('CMTooltipArea').appendChild(tooltipBox); + } +} + +/** + * This function updates the warnings section of the building and upgrade tooltips + * It is called by CM.Disp.UpdateTooltip() + */ +CM.Disp.UpdateTooltipWarnings = function() { + if (CM.Disp.tooltipType == "b" || CM.Disp.tooltipType == "u") { + if (document.getElementById("tooltipWarn") == null) { + warningTooltip = CM.Disp.TooltipCreateWarningSection(); + l('tooltipAnchor').appendChild(warningTooltip); + } + + if (CM.Config.ToolWarnPos == 0) CM.Disp.TooltipWarn.style.right = '0px'; + else CM.Disp.TooltipWarn.style.top = (l('tooltip').offsetHeight) + 'px'; + + CM.Disp.TooltipWarn.style.width = (l('tooltip').offsetWidth - 6) + 'px'; + + if (CM.Config.ToolWarnLucky == 1) { + var limitLucky = CM.Cache.Lucky; + if (CM.Config.ToolWarnBon == 1) { + var bonusNoFren = CM.Disp.TooltipBonusIncome; + bonusNoFren /= CM.Sim.getCPSBuffMult(); + limitLucky += ((bonusNoFren * 60 * 15) / 0.15); + } + var limitLuckyFrenzy = limitLucky * 7; + var amount = (Game.cookies + CM.Disp.GetWrinkConfigBank()) - price; + if ((amount < limitLucky || amount < limitLuckyFrenzy) && (CM.Disp.tooltipType != 'b' || Game.buyMode == 1)) { + if (amount < limitLucky) { + l('CMDispTooltipWarnLucky').style.display = ''; + l('CMDispTooltipWarnLuckyText').textContent = Beautify(limitLucky - amount) + ' (' + CM.Disp.FormatTime((limitLucky - amount) / CM.Disp.GetCPS()) + ')'; + l('CMDispTooltipWarnLuckyFrenzy').style.display = ''; + l('CMDispTooltipWarnLuckyFrenzyText').textContent = Beautify(limitLuckyFrenzy - amount) + ' (' + CM.Disp.FormatTime((limitLuckyFrenzy - amount) / CM.Disp.GetCPS()) + ')'; } - else { + else if (amount < limitLuckyFrenzy) { + l('CMDispTooltipWarnLuckyFrenzy').style.display = ''; + l('CMDispTooltipWarnLuckyFrenzyText').textContent = Beautify(limitLuckyFrenzy - amount) + ' (' + CM.Disp.FormatTime((limitLuckyFrenzy - amount) / CM.Disp.GetCPS()) + ')'; l('CMDispTooltipWarnLucky').style.display = 'none'; - l('CMDispTooltipWarnLuckyFrenzy').style.display = 'none'; } - - if (CM.Config.ToolWarnConjure == 1) { - CM.Disp.TooltipWarn.style.display = 'block'; - var limitLucky = CM.Cache.Lucky; - if (CM.Config.ToolWarnBon == 1) { - var bonusNoFren = bonus; - bonusNoFren /= CM.Sim.getCPSBuffMult(); - limitLucky += ((bonusNoFren * 60 * 15) / 0.15); - } - var limitConjure = limitLucky * 2; - var amount = (Game.cookies + CM.Disp.GetWrinkConfigBank()) - price; - if ((amount < limitConjure) && (CM.Disp.tooltipType != 'b' || Game.buyMode == 1)) { - l('CMDispTooltipWarnConjure').style.display = ''; - l('CMDispTooltipWarnConjureText').textContent = Beautify(limitConjure - amount) + ' (' + CM.Disp.FormatTime((limitConjure - amount) / CM.Disp.GetCPS()) + ')'; - } else { - l('CMDispTooltipWarnConjure').style.display = 'none'; - } - } - else { - l('CMDispTooltipWarnConjure').style.display = 'none'; - } - } - else if (CM.Disp.tooltipType === 's') { - // Adding information about Sugar Lumps. - - CM.Disp.TooltipWarn.style.display = 'none'; - l('CMDispTooltipWarnLucky').style.display = 'none'; - l('CMDispTooltipWarnLuckyFrenzy').style.display = 'none'; - l('CMDispTooltipWarnConjure').style.display = 'none'; - - if (CM.Config.TooltipLump === 1) { - l('CMTooltipArea').innerHTML = ''; - - l('tooltip').firstChild.style.paddingBottom = '4px'; - var lumpTooltip = document.createElement('div'); - lumpTooltip.style.border = '1px solid'; - lumpTooltip.style.padding = '4px'; - lumpTooltip.style.margin = '0px -4px'; - lumpTooltip.id = 'CMTooltipBorder'; - lumpTooltip.className = CM.Disp.colorTextPre + CM.Disp.colorGray; - - var lumpHeader = document.createElement('div'); - lumpHeader.style.fontWeight = 'bold'; - lumpHeader.className = CM.Disp.colorTextPre + CM.Disp.colorBlue; - lumpHeader.textContent = 'Current Sugar Lump'; - - lumpTooltip.appendChild(lumpHeader); - var lumpType = document.createElement('div'); - lumpType.id = 'CMTooltipTime'; - lumpTooltip.appendChild(lumpType); - var lumpColor = CM.Disp.GetLumpColor(Game.lumpCurrentType); - lumpType.textContent = lumpColor.text; - lumpType.className = CM.Disp.colorTextPre + lumpColor.color; - - l('CMTooltipArea').appendChild(lumpTooltip); - } - } - else if (CM.Disp.tooltipType === 'g') { - // Grimoire - CM.Disp.TooltipWarn.style.display = 'none'; + } else { l('CMDispTooltipWarnLucky').style.display = 'none'; l('CMDispTooltipWarnLuckyFrenzy').style.display = 'none'; - l('CMDispTooltipWarnConjure').style.display = 'none'; - - var minigame = Game.Objects['Wizard tower'].minigame; - var spellCost = minigame.getSpellCost(minigame.spellsById[CM.Disp.tooltipName]); - - if (CM.Config.TooltipGrim == 1 && spellCost <= minigame.magicM) { - l('CMTooltipArea').innerHTML = ''; - - l('tooltip').firstChild.style.paddingBottom = '4px'; - var tooltip = document.createElement('div'); - tooltip.style.border = '1px solid'; - tooltip.style.padding = '4px'; - tooltip.style.margin = '0px -4px'; - tooltip.id = 'CMTooltipBorder'; - tooltip.className = CM.Disp.colorTextPre + CM.Disp.colorGray; - - var header = function(text) { - var div = document.createElement('div'); - div.style.fontWeight = 'bold'; - div.className = CM.Disp.colorTextPre + CM.Disp.colorBlue; - div.textContent = text; - return div; - } - - tooltip.appendChild(header('Time Left')); - var time = document.createElement('div'); - time.id = 'CMTooltipTime'; - tooltip.appendChild(time); - var timeColor = CM.Disp.GetTimeColor(CM.Disp.CalculateGrimoireRefillTime(minigame.magic, minigame.magicM, spellCost)); - time.textContent = timeColor.text; - time.className = CM.Disp.colorTextPre + timeColor.color; - - if (spellCost <= minigame.magic) { - tooltip.appendChild(header('Recover Time')); - var recover = document.createElement('div'); - recover.id = 'CMTooltipRecover'; - tooltip.appendChild(recover); - var recoverColor = CM.Disp.GetTimeColor(CM.Disp.CalculateGrimoireRefillTime(Math.max(0, minigame.magic - spellCost), minigame.magicM, minigame.magic)); - recover.textContent = recoverColor.text; - recover.className = CM.Disp.colorTextPre + recoverColor.color; - } - - // Extra information when spell is Conjure Baked Goods (Name == 0) - if (CM.Disp.tooltipName == 0) { - tooltip.appendChild(header('Cookies to be gained/lost')); - var conjure = document.createElement('div'); - conjure.id = 'CMTooltipConjure'; - tooltip.appendChild(conjure); - var reward = document.createElement('span'); - reward.style.color = "#33FF00" - reward.textContent = Beautify(Math.min((Game.cookies + CM.Disp.GetWrinkConfigBank()) * 0.15, CM.Cache.NoGoldSwitchCookiesPS * 60 * 30), 2) - conjure.appendChild(reward) - var seperator = document.createElement('span'); - seperator.textContent = ' / ' - conjure.appendChild(seperator) - var loss = document.createElement('span'); - loss.style.color = "red" - loss.textContent = Beautify((CM.Cache.NoGoldSwitchCookiesPS * 60 * 15), 2); - conjure.appendChild(loss) - } - - l('CMTooltipArea').appendChild(tooltip); - } } } else { - CM.Disp.TooltipWarn.style.display = 'none'; + l('CMDispTooltipWarnLucky').style.display = 'none'; + l('CMDispTooltipWarnLuckyFrenzy').style.display = 'none'; + } + + if (CM.Config.ToolWarnConjure == 1) { + var limitLucky = CM.Cache.Lucky; + if (CM.Config.ToolWarnBon == 1) { + var bonusNoFren = CM.Disp.TooltipBonusIncome; + bonusNoFren /= CM.Sim.getCPSBuffMult(); + limitLucky += ((bonusNoFren * 60 * 15) / 0.15); + } + var limitConjure = limitLucky * 2; + var amount = (Game.cookies + CM.Disp.GetWrinkConfigBank()) - price; + if ((amount < limitConjure) && (CM.Disp.tooltipType != 'b' || Game.buyMode == 1)) { + l('CMDispTooltipWarnConjure').style.display = ''; + l('CMDispTooltipWarnConjureText').textContent = Beautify(limitConjure - amount) + ' (' + CM.Disp.FormatTime((limitConjure - amount) / CM.Disp.GetCPS()) + ')'; + } else { + l('CMDispTooltipWarnConjure').style.display = 'none'; + } + } + else { + l('CMDispTooltipWarnConjure').style.display = 'none'; + } + } + else { + if (l('CMDispTooltipWarningParent') != null) { + l('CMDispTooltipWarningParent').remove(); } } } +/** + * This function updates the location of the tooltip + * It is called by Game.tooltip.update() because of CM.ReplaceNative() + */ CM.Disp.UpdateTooltipLocation = function() { if (Game.tooltip.origin == 'store') { var warnOffset = 0; - if (CM.Config.ToolWarnLucky == 1 && CM.Config.ToolWarnPos == 1) warnOffset = CM.Disp.TooltipWarn.clientHeight - 4; + if (CM.Config.ToolWarnLucky == 1 && CM.Config.ToolWarnPos == 1 && typeof CM.Disp.TooltipWarn != "undefined") { + warnOffset = CM.Disp.TooltipWarn.clientHeight - 4; + } Game.tooltip.tta.style.top = Math.min(parseInt(Game.tooltip.tta.style.top), (l('game').clientHeight + l('topBar').clientHeight) - Game.tooltip.tt.clientHeight - warnOffset - 46) + 'px'; } // Kept for future possible use if the code changes again @@ -2574,44 +2597,31 @@ CM.Disp.UpdateTooltipLocation = function() { } /** - * This function toggles the position of the warnings created by CM.Disp.CreateTooltipWarn() + * This function toggles the position of the warnings created by CM.Disp.TooltipCreateWarningSection() * It is called by a change in CM.Config.ToolWarnPos */ CM.Disp.ToggleToolWarnPos = function() { - if (CM.Config.ToolWarnPos == 0) { - CM.Disp.TooltipWarn.style.top = 'auto'; - CM.Disp.TooltipWarn.style.margin = '4px -4px'; - CM.Disp.TooltipWarn.style.padding = '3px 4px'; - } - else { - CM.Disp.TooltipWarn.style.right = 'auto'; - CM.Disp.TooltipWarn.style.margin = '4px'; - CM.Disp.TooltipWarn.style.padding = '4px 3px'; - } -} - -CM.Disp.DrawTooltipWarn = function() { - if (CM.Config.ToolWarnLucky == 1) { - l('CMDispTooltipWarnLucky').style.opacity = '0'; - l('CMDispTooltipWarnLuckyFrenzy').style.opacity = '0'; - } - if (CM.Config.ToolWarnConjure == 1) { - l('CMDispTooltipWarnConjure').style.opacity = '0'; - } -} - -CM.Disp.UpdateTooltipWarn = function() { - if (CM.Config.ToolWarnLucky == 1 && l('tooltipAnchor').style.display != 'none' && l('CMTooltipArea') != null) { - l('CMDispTooltipWarnLucky').style.opacity = '1'; - l('CMDispTooltipWarnLuckyFrenzy').style.opacity = '1'; - } - if (CM.Config.ToolWarnConjure == 1 && l('tooltipAnchor').style.display != 'none' && l('CMTooltipArea') != null) { - l('CMDispTooltipWarnConjure').style.opacity = '1'; + if (typeof CM.Disp.TooltipWarn != "undefined") { + if (CM.Config.ToolWarnPos == 0) { + CM.Disp.TooltipWarn.style.top = 'auto'; + CM.Disp.TooltipWarn.style.margin = '4px -4px'; + CM.Disp.TooltipWarn.style.padding = '3px 4px'; + } + else { + CM.Disp.TooltipWarn.style.right = 'auto'; + CM.Disp.TooltipWarn.style.margin = '4px'; + CM.Disp.TooltipWarn.style.padding = '4px 3px'; + } } } +/** + * This function checks and create a tooltip for the wrinklers + * It is called by CM.Loop() + * TODO: Change this code to be the same as other tooltips. (i.d., create tooltip with type "w") + */ CM.Disp.CheckWrinklerTooltip = function() { - if (CM.Config.ToolWrink == 1 && CM.Disp.TooltipWrinklerArea == 1) { + if (CM.Config.ToolWrink == 1 && CM.Disp.TooltipWrinklerArea == 1) { // Latter is set by CM.Main.AddWrinklerAreaDetect var showingTooltip = false; for (var i in Game.wrinklers) { var me = Game.wrinklers[i]; @@ -2643,6 +2653,11 @@ CM.Disp.CheckWrinklerTooltip = function() { } } +/** + * This function updates the amount to be displayed by the wrinkler tooltip created by CM.Disp.CheckWrinklerTooltip() + * It is called by CM.Loop() + * TODO: Change this code to be the same as other tooltips. Fit this into CM.Disp.UpdateTooltip() + */ CM.Disp.UpdateWrinklerTooltip = function() { if (CM.Config.ToolWrink == 1 && l('CMTooltipWrinkler') != null) { var sucked = Game.wrinklers[CM.Disp.TooltipWrinkler].sucked; @@ -3439,14 +3454,12 @@ CM.ReplaceNative = function() { eval('CM.Backup.tooltip.drawMod = ' + Game.tooltip.draw.toString().split('this').join('Game.tooltip')); Game.tooltip.draw = function(from, text, origin) { CM.Backup.tooltip.drawMod(from, text, origin); - CM.Disp.DrawTooltipWarn(); } CM.Backup.tooltip.update = Game.tooltip.update; eval('CM.Backup.tooltip.updateMod = ' + Game.tooltip.update.toString().split('this.').join('Game.tooltip.')); Game.tooltip.update = function() { CM.Backup.tooltip.updateMod(); - CM.Disp.UpdateTooltipWarn(); CM.Disp.UpdateTooltipLocation(); } @@ -3649,11 +3662,10 @@ CM.DelayInit = function() { for (var i in CM.Disp.TooltipText) { CM.Disp.CreateSimpleTooltip(CM.Disp.TooltipText[i][0], CM.Disp.TooltipText[i][1], CM.Disp.TooltipText[i][2]); } - CM.Disp.CreateTooltipWarn(); CM.Disp.ReplaceTooltipBuild(); CM.Disp.ReplaceTooltipGrimoire(); CM.Disp.ReplaceTooltipLump(); - CM.Disp.AddWrinklerAreaDetect(); + CM.Main.AddWrinklerAreaDetect(); CM.Cache.InitCookiesDiff(); CM.ReplaceNative(); CM.ReplaceNativeGrimoire(); @@ -3832,6 +3844,23 @@ CM.Main.CheckWrinklerCount = function() { } } +/** + * This function creates .onmouseover/out events that determine if the mouse is hovering-over a Wrinkler + * It is called by CM.DelayInit + * TODO: The system for displaying wrinklers should ideally use a similar system as other tooltips + * Thus, writing a CM.Disp.ReplaceTooltipWrinkler function etc. + */ +CM.Main.AddWrinklerAreaDetect = function() { + l('backgroundLeftCanvas').onmouseover = function() {CM.Disp.TooltipWrinklerArea = 1;}; + l('backgroundLeftCanvas').onmouseout = function() { + CM.Disp.TooltipWrinklerArea = 0; + Game.tooltip.hide(); + for (var i in Game.wrinklers) { + CM.Disp.TooltipWrinklerCache[i] = 0; + } + }; +} + CM.HasReplaceNativeGrimoireLaunch = false; CM.HasReplaceNativeGrimoireDraw = false; diff --git a/src/Disp.js b/src/Disp.js index a38b41a..a1ebf03 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -208,16 +208,7 @@ CM.Disp.CalculateGrimoireRefillTime = function(currentMagic, maxMagic, targetMag return count / Game.fps; } -CM.Disp.AddWrinklerAreaDetect = function() { - l('backgroundLeftCanvas').onmouseover = function() {CM.Disp.TooltipWrinklerArea = 1;}; - l('backgroundLeftCanvas').onmouseout = function() { - CM.Disp.TooltipWrinklerArea = 0; - Game.tooltip.hide(); - for (var i in Game.wrinklers) { - CM.Disp.TooltipWrinklerCache[i] = 0; - } - }; -} + CM.Disp.UpdateAscendState = function() { if (Game.OnAscend) { @@ -345,7 +336,7 @@ CM.Disp.Beautify = function(num, frac, forced) { if (num == "0") { return num } - else if (timesTenToPowerThree < 2) { + else if (-1 < timesTenToPowerThree < 2) { answer = Math.round(num * 100) / 100; } else if (CM.Config.Scale == 3 && !forced || forced == 3) { // Scientific notation, 123456789 => 1.235E+8 @@ -1211,16 +1202,205 @@ CM.Disp.CreateSimpleTooltip = function(placeholder, text, minWidth) { } /** - * This function creates the tooltip extension of Lucky/Chain and other warnings for the building and upgrade tooltips - * It is called by CM.DelayInit() and the tooltip is appended to the l('tooltipAnchor'). - * Visbility is then managed in CM.Disp.UpdateTooltip(). + * This function replaces the original .onmouseover functions of buildings so that it calls CM.Disp.Tooltip() + * CM.Disp.Tooltip() sets the tooltip type to 'b' + * It is called by CM.DelayInit() + * TODO: Place all ReplaceTooltip functions either under CM.DelayInit() or CM.ReplaceNative() + * TODO: Move this code to Main.js file */ -CM.Disp.CreateTooltipWarn = function() { +CM.Disp.ReplaceTooltipBuild = function() { + CM.Disp.TooltipBuildBackup = []; + for (var i in Game.Objects) { + var me = Game.Objects[i]; + if (l('product' + me.id).onmouseover != null) { + CM.Disp.TooltipBuildBackup[i] = l('product' + me.id).onmouseover; + eval('l(\'product\' + me.id).onmouseover = function() {Game.tooltip.dynamic = 1; Game.tooltip.draw(this, function() {return CM.Disp.Tooltip(\'b\', \'' + i + '\');}, \'store\'); Game.tooltip.wobble();}'); + } + } +} + +/** + * This function replaces the original .onmouseover functions of upgrades so that it calls CM.Disp.Tooltip() + * CM.Disp.Tooltip() sets the tooltip type to 'u' + * It is called by CM.ReplaceNative() + * TODO: Place all ReplaceTooltip functions either under CM.DelayInit() or CM.ReplaceNative() + * TODO: Move this code to Main.js file + * + */ +CM.Disp.ReplaceTooltipUpgrade = function() { + CM.Disp.TooltipUpgradeBackup = []; + for (var i in Game.UpgradesInStore) { + var me = Game.UpgradesInStore[i]; + if (l('upgrade' + i).onmouseover != null) { + CM.Disp.TooltipUpgradeBackup[i] = l('upgrade' + i).onmouseover; + eval('l(\'upgrade\' + i).onmouseover = function() {if (!Game.mouseDown) {Game.setOnCrate(this); Game.tooltip.dynamic = 1; Game.tooltip.draw(this, function() {return CM.Disp.Tooltip(\'u\', \'' + i + '\');}, \'store\'); Game.tooltip.wobble();}}'); + } + } +} + +/** + * This function replaces the original .onmouseover functions of the Grimoire minigame so that it calls CM.Disp.Tooltip() + * CM.Disp.Tooltip() sets the tooltip type to 'g' + * The function is called by CM.DelayInit() + * TODO: Place all ReplaceTooltip functions either under CM.DelayInit() or CM.ReplaceNative() + * TODO: Move this code to Main.js file + */ +CM.Disp.ReplaceTooltipGrimoire = function() { + if (Game.Objects['Wizard tower'].minigameLoaded) { + CM.Disp.TooltipGrimoireBackup = []; + for (var i in Game.Objects['Wizard tower'].minigame.spellsById) { + if (l('grimoireSpell' + i).onmouseover != null) { + CM.Disp.TooltipGrimoireBackup[i] = l('grimoireSpell' + i).onmouseover; + eval('l(\'grimoireSpell\' + i).onmouseover = function() {Game.tooltip.dynamic = 1; Game.tooltip.draw(this, function() {return CM.Disp.Tooltip(\'g\', \'' + i + '\');}, \'this\'); Game.tooltip.wobble();}'); + } + } + } +} + +/** + * This function replaces the original .onmouseover functions of sugar lumps so that it calls CM.Disp.Tooltip() + * CM.Disp.Tooltip() sets the tooltip type to 's' + * The function is called by CM.DelayInit() + * TODO: Place all ReplaceTooltip functions either under CM.DelayInit() or CM.ReplaceNative() + * TODO: Move this code to Main.js file + */ +CM.Disp.ReplaceTooltipLump = function() { + if (Game.canLumps()) { + CM.Disp.TooltipLumpBackup = l('lumps').onmouseover; + eval('l(\'lumps\').onmouseover = function() {Game.tooltip.dynamic = 1; Game.tooltip.draw(this, function() {return CM.Disp.Tooltip(\'s\', \'Lump\');}, \'this\'); Game.tooltip.wobble();}'); + } +}; + +/** + * This function enhance the standard tooltips by creating and changing l('tooltip') + * The function is called by .onmouseover events that have replaced original code to use CM.Disp.Tooltip() + * @param {string} type Type of tooltip (b, u, s or g) + * @param {string} name Name of the object/item the tooltip relates to + * @returns {string} l('tooltip').innerHTML The HTML of the l('tooltip')-object + */ +CM.Disp.Tooltip = function(type, name) { + if (type == 'b') { // Buildings + l('tooltip').innerHTML = Game.Objects[name].tooltip(); + // Adds amortization info to the list of info per building + if (CM.Config.TooltipAmor == 1) { + var buildPrice = CM.Sim.BuildingGetPrice(Game.Objects[name], Game.Objects[name].basePrice, 0, Game.Objects[name].free, Game.Objects[name].amount); + var amortizeAmount = buildPrice - Game.Objects[name].totalCookies; + if (amortizeAmount > 0) { + l('tooltip').innerHTML = l('tooltip').innerHTML + .split('so far') + .join('so far
' + Beautify(amortizeAmount) + ' ' + (Math.floor(amortizeAmount) == 1 ? 'cookie' : 'cookies') + ' left to amortize (' + CM.Disp.GetTimeColor((buildPrice - Game.Objects[name].totalCookies) / (Game.Objects[name].storedTotalCps * Game.globalCpsMult)).text + ')'); + } + } + if (Game.buyMode == -1) { + /* + * Fix sell price displayed in the object tooltip. + * + * The buildings sell price displayed by the game itself (without any mod) is incorrect. + * The following line of code fixes this issue, and can be safely removed when the game gets fixed. + * + * This issue is extensively detailed here: https://github.com/Aktanusa/CookieMonster/issues/359#issuecomment-735658262 + */ + l('tooltip').innerHTML = l('tooltip').innerHTML.split(Beautify(Game.Objects[name].bulkPrice)).join(Beautify(CM.Sim.BuildingSell(Game.Objects[name], Game.Objects[name].basePrice, Game.Objects[name].amount, Game.Objects[name].free, Game.buyBulk, 1))); + } + } + else if (type == 'u') { // Upgrades + if (!Game.UpgradesInStore[name]) return ''; + l('tooltip').innerHTML = Game.crateTooltip(Game.UpgradesInStore[name], 'store'); + } + else if (type === 's') l('tooltip').innerHTML = Game.lumpTooltip(); // Sugar Lumps + else if (type === 'g') l('tooltip').innerHTML = Game.Objects['Wizard tower'].minigame.spellTooltip(name)(); // Grimoire + + // Adds area for extra tooltip-sections + var area = document.createElement('div'); + area.id = 'CMTooltipArea'; + l('tooltip').appendChild(area); + + // Sets global variables used by CM.Disp.UpdateTooltip() + CM.Disp.tooltipType = type; + CM.Disp.tooltipName = name; + + CM.Disp.UpdateTooltip(); + + return l('tooltip').innerHTML; +} + +/** + * This function creates a tooltipBox object which contains all CookieMonster added tooltip information. + * It is called by all CM.Disp.UpdateTooltip functions. + * @returns {object} div An object containing the stylized box + */ +CM.Disp.TooltipCreateTooltipBox = function() { + l('tooltip').firstChild.style.paddingBottom = '4px'; // Sets padding on base-tooltip + var tooltipBox = document.createElement('div'); + tooltipBox.style.border = '1px solid'; + tooltipBox.style.padding = '4px'; + tooltipBox.style.margin = '0px -4px'; + tooltipBox.id = 'CMTooltipBorder'; + tooltipBox.className = CM.Disp.colorTextPre + CM.Disp.colorGray; + return tooltipBox +} + +/** + * This function creates a header object for tooltips. + * It is called by all CM.Disp.UpdateTooltip functions. + * @param {string} text Title of header + * @returns {object} div An object containing the stylized header + */ +CM.Disp.TooltipCreateHeader = function(text) { + var div = document.createElement('div'); + div.style.fontWeight = 'bold'; + div.className = CM.Disp.colorTextPre + CM.Disp.colorBlue; + div.textContent = text; + return div; +} + +/** + * This function appends the sections for Bonus Income, PP and Time left (to achiev) to the tooltip-object + * It is called by CM.Disp.UpdateTooltipBuilding() and CM.Disp.UpdateTooltipUpgrade() + * The actual data is added by the Update-functions themselves + * @param {object} tooltip Object of a TooltipBox, normally created by a call to CM.Disp.TooltipCreateTooltipBox() + */ +CM.Disp.TooltipCreateCalculationSection = function(tooltip) { + tooltip.appendChild(CM.Disp.TooltipCreateHeader('Bonus Income')); + var income = document.createElement('div'); + income.style.marginBottom = '4px'; + income.style.color = 'white'; + income.id = 'CMTooltipIncome'; + tooltip.appendChild(income); + + tooltip.appendChild(CM.Disp.TooltipCreateHeader('Payback Period')); + var pp = document.createElement('div'); + pp.style.marginBottom = '4px'; + pp.id = 'CMTooltipPP'; + tooltip.appendChild(pp); + + tooltip.appendChild(CM.Disp.TooltipCreateHeader('Time Left')); + var time = document.createElement('div'); + time.id = 'CMTooltipTime'; + tooltip.appendChild(time); + + if (CM.Disp.tooltipType == 'b') { + tooltip.appendChild(CM.Disp.TooltipCreateHeader('Production left till next achievement')); + tooltip.lastChild.id = 'CMTooltipProductionHeader'; // Assign a id in order to hid when no achiev's are left + var production = document.createElement('div'); + production.id = 'CMTooltipProduction'; + tooltip.appendChild(production); + } +} + +/** + * This function creates the tooltip objectm for warnings + * It is called by CM.Disp.UpdateTooltipWarnings() whenever the tooltip type is 'b' or 'u' + * The object is also removed by CM.Disp.UpdateTooltipWarnings() when type is 's' or 'g' + * @returns {object} CM.Disp.TooltipWarn The Warnings-tooltip object + */ +CM.Disp.TooltipCreateWarningSection = function() { CM.Disp.TooltipWarn = document.createElement('div'); CM.Disp.TooltipWarn.style.position = 'absolute'; - CM.Disp.TooltipWarn.style.display = 'none'; + CM.Disp.TooltipWarn.style.display = 'block'; CM.Disp.TooltipWarn.style.left = 'auto'; CM.Disp.TooltipWarn.style.bottom = 'auto'; + CM.Disp.TooltipWarn.id = "CMDispTooltipWarningParent"; var create = function(boxId, color, labelTextFront, labelTextBack, deficitId) { var box = document.createElement('div'); @@ -1256,433 +1436,276 @@ CM.Disp.CreateTooltipWarn = function() { CM.Disp.TooltipWarn.appendChild(create('CMDispTooltipWarnLuckyFrenzy', CM.Disp.colorYellow, 'Warning: ', 'Purchase of this item will put you under the number of Cookies required for "Lucky!" (Frenzy)', 'CMDispTooltipWarnLuckyFrenzyText')); CM.Disp.TooltipWarn.lastChild.style.marginBottom = '4px'; CM.Disp.TooltipWarn.appendChild(create('CMDispTooltipWarnConjure', CM.Disp.colorPurple, 'Warning: ', 'Purchase of this item will put you under the number of Cookies required for "Conjure Baked Goods"', 'CMDispTooltipWarnConjureText')); - - l('tooltipAnchor').appendChild(CM.Disp.TooltipWarn); + + return CM.Disp.TooltipWarn; } /** - * This function replaces the original .onmouseover functions of buildings so that it calls CM.Disp.Tooltip() - * CM.Disp.Tooltip() sets the tooltip type to 'b' - * It is called by CM.DelayInit() - * TODO: Place all ReplaceTooltip functions either under CM.DelayInit() or CM.ReplaceNative() + * This function updates the sections of the tooltips created by CookieMonster + * It is called when tooltips are created by and CM.Disp.Tooltip() on every loop by CM.Loop() */ -CM.Disp.ReplaceTooltipBuild = function() { - CM.Disp.TooltipBuildBackup = []; - for (var i in Game.Objects) { - var me = Game.Objects[i]; - if (l('product' + me.id).onmouseover != null) { - CM.Disp.TooltipBuildBackup[i] = l('product' + me.id).onmouseover; - eval('l(\'product\' + me.id).onmouseover = function() {Game.tooltip.dynamic = 1; Game.tooltip.draw(this, function() {return CM.Disp.Tooltip(\'b\', \'' + i + '\');}, \'store\'); Game.tooltip.wobble();}'); - } - } -} - -/** - * This function replaces the original .onmouseover functions of upgrades so that it calls CM.Disp.Tooltip() - * CM.Disp.Tooltip() sets the tooltip type to 'u' - * It is called by CM.ReplaceNative() - * TODO: Place all ReplaceTooltip functions either under CM.DelayInit() or CM.ReplaceNative() - */ -CM.Disp.ReplaceTooltipUpgrade = function() { - CM.Disp.TooltipUpgradeBackup = []; - for (var i in Game.UpgradesInStore) { - var me = Game.UpgradesInStore[i]; - if (l('upgrade' + i).onmouseover != null) { - CM.Disp.TooltipUpgradeBackup[i] = l('upgrade' + i).onmouseover; - eval('l(\'upgrade\' + i).onmouseover = function() {if (!Game.mouseDown) {Game.setOnCrate(this); Game.tooltip.dynamic = 1; Game.tooltip.draw(this, function() {return CM.Disp.Tooltip(\'u\', \'' + i + '\');}, \'store\'); Game.tooltip.wobble();}}'); - } - } -} - -/** - * This function replaces the original .onmouseover functions of the Grimoire minigame so that it calls CM.Disp.Tooltip() - * CM.Disp.Tooltip() sets the tooltip type to 'g' - * The function is called by CM.DelayInit() - * TODO: Place all ReplaceTooltip functions either under CM.DelayInit() or CM.ReplaceNative() - */ -CM.Disp.ReplaceTooltipGrimoire = function() { - if (Game.Objects['Wizard tower'].minigameLoaded) { - CM.Disp.TooltipGrimoireBackup = []; - for (var i in Game.Objects['Wizard tower'].minigame.spellsById) { - if (l('grimoireSpell' + i).onmouseover != null) { - CM.Disp.TooltipGrimoireBackup[i] = l('grimoireSpell' + i).onmouseover; - eval('l(\'grimoireSpell\' + i).onmouseover = function() {Game.tooltip.dynamic = 1; Game.tooltip.draw(this, function() {return CM.Disp.Tooltip(\'g\', \'' + i + '\');}, \'this\'); Game.tooltip.wobble();}'); - } - } - } -} - -/** - * This function replaces the original .onmouseover functions of sugar lumps so that it calls CM.Disp.Tooltip() - * CM.Disp.Tooltip() sets the tooltip type to 's' - * The function is called by CM.DelayInit() - * TODO: Place all ReplaceTooltip functions either under CM.DelayInit() or CM.ReplaceNative() - */ -CM.Disp.ReplaceTooltipLump = function() { - if (Game.canLumps()) { - CM.Disp.TooltipLumpBackup = l('lumps').onmouseover; - eval('l(\'lumps\').onmouseover = function() {Game.tooltip.dynamic = 1; Game.tooltip.draw(this, function() {return CM.Disp.Tooltip(\'s\', \'Lump\');}, \'this\'); Game.tooltip.wobble();}'); - } -}; - -/** - * This function creates tooltips by creating and changing l('tooltip') - * The function is called by .onmouseover events that have replaced original code to use CM.Disp.Tooltip( - */ -CM.Disp.Tooltip = function(type, name) { - if (type == 'b') { - l('tooltip').innerHTML = Game.Objects[name].tooltip(); - if (CM.Config.TooltipAmor == 1) { - var buildPrice = CM.Sim.BuildingGetPrice(Game.Objects[name], Game.Objects[name].basePrice, 0, Game.Objects[name].free, Game.Objects[name].amount); - var amortizeAmount = buildPrice - Game.Objects[name].totalCookies; - if (amortizeAmount > 0) { - l('tooltip').innerHTML = l('tooltip').innerHTML - .split('so far') - .join('so far
' + Beautify(amortizeAmount) + ' ' + (Math.floor(amortizeAmount) == 1 ? 'cookie' : 'cookies') + ' left to amortize (' + CM.Disp.GetTimeColor((buildPrice - Game.Objects[name].totalCookies) / (Game.Objects[name].storedTotalCps * Game.globalCpsMult)).text + ')'); - } - } - if (Game.buyMode == 1) { - var target = ''; - var change = false; - if (Game.buyBulk == 10) { - target = 'Objects10'; - change = true; - } - else if (Game.buyBulk == 100) { - target = 'Objects100'; - change = true; - } - if (change) { - l('tooltip').innerHTML = l('tooltip').innerHTML.split(Beautify(Game.Objects[name].getPrice())).join(Beautify(CM.Cache[target][name].price)); - } - } - else if (Game.buyMode == -1) { - /* - * Fix sell price displayed in the object tooltip. - * - * The buildings sell price displayed by the game itself (without any mod) is incorrect. - * The following line of code fixes this issue, and can be safely removed when the game gets fixed. - * - * This issue is extensively detailed here: https://github.com/Aktanusa/CookieMonster/issues/359#issuecomment-735658262 - */ - l('tooltip').innerHTML = l('tooltip').innerHTML.split(Beautify(Game.Objects[name].bulkPrice)).join(Beautify(CM.Sim.BuildingSell(Game.Objects[name], Game.Objects[name].basePrice, Game.Objects[name].amount, Game.Objects[name].free, Game.buyBulk, 1))); - } - } - else if (type == 'u') { - if (!Game.UpgradesInStore[name]) return ''; - l('tooltip').innerHTML = Game.crateTooltip(Game.UpgradesInStore[name], 'store'); - } - else if (type === 's') { - // Sugar Lump - l('tooltip').innerHTML = Game.lumpTooltip(); - } - else { // Grimoire - l('tooltip').innerHTML = Game.Objects['Wizard tower'].minigame.spellTooltip(name)(); - } - - var area = document.createElement('div'); - area.id = 'CMTooltipArea'; - l('tooltip').appendChild(area); - - if (CM.Config.TooltipBuildUp == 1 && (type == 'u' || (type == 'b' && Game.buyMode == 1))) { - l('tooltip').firstChild.style.paddingBottom = '4px'; - var tooltip = document.createElement('div'); - tooltip.style.border = '1px solid'; - tooltip.style.padding = '4px'; - tooltip.style.margin = '0px -4px'; - tooltip.id = 'CMTooltipBorder'; - - var header = function(text) { - var div = document.createElement('div'); - div.style.fontWeight = 'bold'; - div.className = CM.Disp.colorTextPre + CM.Disp.colorBlue; - div.textContent = text; - return div; - } - - tooltip.appendChild(header('Bonus Income')); - var income = document.createElement('div'); - income.style.marginBottom = '4px'; - income.style.color = 'white'; - income.id = 'CMTooltipIncome'; - tooltip.appendChild(income); - tooltip.appendChild(header('Payback Period')); - var pp = document.createElement('div'); - pp.style.marginBottom = '4px'; - pp.id = 'CMTooltipPP'; - tooltip.appendChild(pp); - tooltip.appendChild(header('Time Left')); - var time = document.createElement('div'); - time.id = 'CMTooltipTime'; - tooltip.appendChild(time); - if (type == 'b') { - tooltip.appendChild(header('Production left till next achievement')); - tooltip.lastChild.id = 'CMTooltipProductionHeader'; - var production = document.createElement('div'); - production.id = 'CMTooltipProduction'; - tooltip.appendChild(production); - } - - area.appendChild(tooltip); - } - - CM.Disp.tooltipType = type; - CM.Disp.tooltipName = name; - - CM.Disp.UpdateTooltip(); - - return l('tooltip').innerHTML; -} - CM.Disp.UpdateTooltip = function() { CM.Sim.CopyData(); - if (l('tooltipAnchor').style.display != 'none') { + if (l('tooltipAnchor').style.display != 'none' && l('CMTooltipArea')) { + l('CMTooltipArea').innerHTML = ''; + tooltipBox = CM.Disp.TooltipCreateTooltipBox(); + l('CMTooltipArea').appendChild(tooltipBox); + + if (CM.Disp.tooltipType == 'b') { + CM.Disp.UpdateTooltipBuilding(); + } + else if (CM.Disp.tooltipType == 'u') { + CM.Disp.UpdateTooltipUpgrade(); + } + else if (CM.Disp.tooltipType === 's') { + CM.Disp.UpdateTooltipSugarLump(); + } + else if (CM.Disp.tooltipType === 'g') { + CM.Disp.UpdateTooltipGrimoire(); + } + CM.Disp.UpdateTooltipWarnings(); + } +} - if (l('CMTooltipArea') != null) { - if (CM.Disp.tooltipType == 'b' || CM.Disp.tooltipType == 'u') { - // Error checking - if (CM.Disp.tooltipType == 'u' && (typeof Game.UpgradesInStore[CM.Disp.tooltipName] === 'undefined' || typeof CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name] === 'undefined')) { - return; - } - var price; - var bonus; - if (CM.Disp.tooltipType == 'b') { - var target = ''; - if (Game.buyMode == 1 && Game.buyBulk == 10) { - target = 'Objects10'; - price = CM.Cache[target][CM.Disp.tooltipName].price; - } - else if (Game.buyMode == 1 && Game.buyBulk == 100) { - target = 'Objects100'; - price = CM.Cache[target][CM.Disp.tooltipName].price; - } - else { - target = 'Objects'; - price = Game.Objects[CM.Disp.tooltipName].getPrice(); - } - bonus = CM.Cache[target][CM.Disp.tooltipName].bonus; - if (CM.Config.TooltipBuildUp == 1 && Game.buyMode == 1) { - l('CMTooltipBorder').className = CM.Disp.colorTextPre + CM.Cache[target][CM.Disp.tooltipName].color; - l('CMTooltipPP').textContent = Beautify(CM.Cache[target][CM.Disp.tooltipName].pp, 2); - l('CMTooltipPP').className = CM.Disp.colorTextPre + CM.Cache[target][CM.Disp.tooltipName].color; - } - if (CM.Config.TooltipBuildUp) { - for (var i in Game.Objects[CM.Disp.tooltipName].productionAchievs) { - if (!CM.Sim.HasAchiev(Game.Objects[CM.Disp.tooltipName].productionAchievs[i].achiev.name)) { - var nextProductionAchiev = Game.Objects[CM.Disp.tooltipName].productionAchievs[i] - break - } - } - if (typeof nextProductionAchiev != "undefined") { - l('CMTooltipTime').style.marginBottom = '4px'; - l('CMTooltipProductionHeader').style.display = ""; - l('CMTooltipProduction').className = "ProdAchievement" + CM.Disp.tooltipName; - l('CMTooltipProduction').textContent = Beautify(nextProductionAchiev.pow - CM.Sim.Objects[CM.Disp.tooltipName].totalCookies, 15); - l('CMTooltipProduction').style.color = "white"; - } else { - l('CMTooltipProductionHeader').style.display = "none"; - l('CMTooltipTime').style.marginBottom = '0px'; - } - } - } - else { // Upgrades - bonus = CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].bonus; - price = Game.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].getPrice(); - if (CM.Config.TooltipBuildUp == 1) { - l('CMTooltipBorder').className = CM.Disp.colorTextPre + CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].color; - l('CMTooltipPP').textContent = Beautify(CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].pp, 2); - l('CMTooltipPP').className = CM.Disp.colorTextPre + CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].color; - } - } - if (CM.Config.TooltipBuildUp == 1 && (CM.Disp.tooltipType != 'b' || Game.buyMode == 1)) { - l('CMTooltipIncome').textContent = Beautify(bonus, 2); +/** + * This function adds extra info to the Building tooltips + * It is called when Building tooltips are created or refreshed by CM.Disp.UpdateTooltip() + */ +CM.Disp.UpdateTooltipBuilding = function() { + if (CM.Config.TooltipBuildUp == 1 && Game.buyMode == 1) { + tooltipBox = l('CMTooltipBorder'); + CM.Disp.TooltipCreateCalculationSection(tooltipBox); - var increase = Math.round(bonus / Game.cookiesPs * 10000); - if (isFinite(increase) && increase != 0) { - l('CMTooltipIncome').textContent += ' (' + (increase / 100) + '% of income)'; - } + var target = ''; + // TODO: Change the Cache code and variables to use Objects1, Objectes10, Objects100 + // That would depreciate this target setting code + if (Game.buyMode == 1 && Game.buyBulk == 10) target = 'Objects10' + else if (Game.buyMode == 1 && Game.buyBulk == 100) target = 'Objects100'; + else target = 'Objects'; - var timeColor = CM.Disp.GetTimeColor((price - (Game.cookies + CM.Disp.GetWrinkConfigBank())) / CM.Disp.GetCPS()); - l('CMTooltipTime').textContent = timeColor.text; - l('CMTooltipTime').className = CM.Disp.colorTextPre + timeColor.color; - } + var price = Game.Objects[CM.Disp.tooltipName].bulkPrice + CM.Disp.TooltipBonusIncome = CM.Cache[target][CM.Disp.tooltipName].bonus; + - if (CM.Config.ToolWarnPos == 0) { - CM.Disp.TooltipWarn.style.right = '0px'; - } - else { - CM.Disp.TooltipWarn.style.top = (l('tooltip').offsetHeight) + 'px'; - } - CM.Disp.TooltipWarn.style.width = (l('tooltip').offsetWidth - 6) + 'px'; + if (CM.Config.TooltipBuildUp == 1 && Game.buyMode == 1) { + l('CMTooltipIncome').textContent = Beautify(CM.Disp.TooltipBonusIncome, 2); + var increase = Math.round(CM.Disp.TooltipBonusIncome / Game.cookiesPs * 10000); + if (isFinite(increase) && increase != 0) { + l('CMTooltipIncome').textContent += ' (' + (increase / 100) + '% of income)'; + } + l('CMTooltipBorder').className = CM.Disp.colorTextPre + CM.Cache[target][CM.Disp.tooltipName].color; + l('CMTooltipPP').textContent = Beautify(CM.Cache[target][CM.Disp.tooltipName].pp, 2); + l('CMTooltipPP').className = CM.Disp.colorTextPre + CM.Cache[target][CM.Disp.tooltipName].color; + var timeColor = CM.Disp.GetTimeColor((price - (Game.cookies + CM.Disp.GetWrinkConfigBank())) / CM.Disp.GetCPS()); + l('CMTooltipTime').textContent = timeColor.text; + l('CMTooltipTime').className = CM.Disp.colorTextPre + timeColor.color; + } - if (CM.Config.ToolWarnLucky == 1) { - CM.Disp.TooltipWarn.style.display = 'block'; - var limitLucky = CM.Cache.Lucky; - if (CM.Config.ToolWarnBon == 1) { - var bonusNoFren = bonus; - bonusNoFren /= CM.Sim.getCPSBuffMult(); - limitLucky += ((bonusNoFren * 60 * 15) / 0.15); - } - var limitLuckyFrenzy = limitLucky * 7; - var amount = (Game.cookies + CM.Disp.GetWrinkConfigBank()) - price; - if ((amount < limitLucky || amount < limitLuckyFrenzy) && (CM.Disp.tooltipType != 'b' || Game.buyMode == 1)) { - if (amount < limitLucky) { - l('CMDispTooltipWarnLucky').style.display = ''; - l('CMDispTooltipWarnLuckyText').textContent = Beautify(limitLucky - amount) + ' (' + CM.Disp.FormatTime((limitLucky - amount) / CM.Disp.GetCPS()) + ')'; - l('CMDispTooltipWarnLuckyFrenzy').style.display = ''; - l('CMDispTooltipWarnLuckyFrenzyText').textContent = Beautify(limitLuckyFrenzy - amount) + ' (' + CM.Disp.FormatTime((limitLuckyFrenzy - amount) / CM.Disp.GetCPS()) + ')'; - } - else if (amount < limitLuckyFrenzy) { - l('CMDispTooltipWarnLuckyFrenzy').style.display = ''; - l('CMDispTooltipWarnLuckyFrenzyText').textContent = Beautify(limitLuckyFrenzy - amount) + ' (' + CM.Disp.FormatTime((limitLuckyFrenzy - amount) / CM.Disp.GetCPS()) + ')'; - l('CMDispTooltipWarnLucky').style.display = 'none'; - } - } else { - l('CMDispTooltipWarnLucky').style.display = 'none'; - l('CMDispTooltipWarnLuckyFrenzy').style.display = 'none'; - } + // Add "production left till next achievement"-bar + for (var i in Game.Objects[CM.Disp.tooltipName].productionAchievs) { + if (!CM.Sim.HasAchiev(Game.Objects[CM.Disp.tooltipName].productionAchievs[i].achiev.name)) { + var nextProductionAchiev = Game.Objects[CM.Disp.tooltipName].productionAchievs[i] + break + } + } + if (typeof nextProductionAchiev != "undefined") { + l('CMTooltipTime').style.marginBottom = '4px'; + l('CMTooltipProductionHeader').style.display = ""; + l('CMTooltipProduction').className = "ProdAchievement" + CM.Disp.tooltipName; + l('CMTooltipProduction').textContent = Beautify(nextProductionAchiev.pow - CM.Sim.Objects[CM.Disp.tooltipName].totalCookies, 15); + l('CMTooltipProduction').style.color = "white"; + } else { + l('CMTooltipProductionHeader').style.display = "none"; + l('CMTooltipTime').style.marginBottom = '0px'; + } + } +} + +/** + * This function adds extra info to the Upgrade tooltips + * It is called when Upgrade tooltips are created or refreshed by CM.Disp.UpdateTooltip() + */ +CM.Disp.UpdateTooltipUpgrade = function() { + tooltipBox = l('CMTooltipBorder'); + CM.Disp.TooltipCreateCalculationSection(tooltipBox); + + CM.Disp.TooltipBonusIncome = CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].bonus; + price = Game.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].getPrice(); + + if (CM.Config.TooltipBuildUp == 1) { + l('CMTooltipIncome').textContent = Beautify(CM.Disp.TooltipBonusIncome, 2); + var increase = Math.round(CM.Disp.TooltipBonusIncome / Game.cookiesPs * 10000); + if (isFinite(increase) && increase != 0) { + l('CMTooltipIncome').textContent += ' (' + (increase / 100) + '% of income)'; + } + l('CMTooltipBorder').className = CM.Disp.colorTextPre + CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].color; + l('CMTooltipPP').textContent = Beautify(CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].pp, 2); + l('CMTooltipPP').className = CM.Disp.colorTextPre + CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].color; + var timeColor = CM.Disp.GetTimeColor((price - (Game.cookies + CM.Disp.GetWrinkConfigBank())) / CM.Disp.GetCPS()); + l('CMTooltipTime').textContent = timeColor.text; + l('CMTooltipTime').className = CM.Disp.colorTextPre + timeColor.color; + } +} + +/** + * This function adds extra info to the Sugar Lump tooltip + * It is called when the Sugar Lump tooltip is created or refreshed by CM.Disp.UpdateTooltip() + * It adds to the additional information to l('CMTooltipArea') + */ +CM.Disp.UpdateTooltipSugarLump = function() { + if (CM.Config.TooltipLump === 1) { + tooltipBox = l('CMTooltipBorder'); + + tooltipBox.appendChild(CM.Disp.TooltipCreateHeader('Current Sugar Lump')); + + var lumpType = document.createElement('div'); + lumpType.id = 'CMTooltipTime'; + tooltipBox.appendChild(lumpType); + var lumpColor = CM.Disp.GetLumpColor(Game.lumpCurrentType); + lumpType.textContent = lumpColor.text; + lumpType.className = CM.Disp.colorTextPre + lumpColor.color; + } +} + +/** + * This function adds extra info to the Grimoire tooltips + * It is called when Grimoire tooltips are created or refreshed by CM.Disp.UpdateTooltip() + * It adds to the additional information to l('CMTooltipArea') + */ +CM.Disp.UpdateTooltipGrimoire = function() { + var minigame = Game.Objects['Wizard tower'].minigame; + var spellCost = minigame.getSpellCost(minigame.spellsById[CM.Disp.tooltipName]); + + if (CM.Config.TooltipGrim == 1 && spellCost <= minigame.magicM) { + tooltipBox = l('CMTooltipBorder'); + + // Time left till enough magic for spell + tooltipBox.appendChild(CM.Disp.TooltipCreateHeader('Time Left')); + var time = document.createElement('div'); + time.id = 'CMTooltipTime'; + tooltipBox.appendChild(time); + var timeColor = CM.Disp.GetTimeColor(CM.Disp.CalculateGrimoireRefillTime(minigame.magic, minigame.magicM, spellCost)); + time.textContent = timeColor.text; + time.className = CM.Disp.colorTextPre + timeColor.color; + + // Time left untill magic spent is recovered + if (spellCost <= minigame.magic) { + tooltipBox.appendChild(CM.Disp.TooltipCreateHeader('Recover Time')); + var recover = document.createElement('div'); + recover.id = 'CMTooltipRecover'; + tooltipBox.appendChild(recover); + var recoverColor = CM.Disp.GetTimeColor(CM.Disp.CalculateGrimoireRefillTime(Math.max(0, minigame.magic - spellCost), minigame.magicM, minigame.magic)); + recover.textContent = recoverColor.text; + recover.className = CM.Disp.colorTextPre + recoverColor.color; + } + + // Extra information on cookies gained when spell is Conjure Baked Goods (Name == 0) + if (CM.Disp.tooltipName == 0) { + tooltipBox.appendChild(CM.Disp.TooltipCreateHeader('Cookies to be gained/lost')); + var conjure = document.createElement('div'); + conjure.id = 'CMTooltipConjure'; + tooltipBox.appendChild(conjure); + var reward = document.createElement('span'); + reward.style.color = "#33FF00" + reward.textContent = Beautify(Math.min((Game.cookies + CM.Disp.GetWrinkConfigBank()) * 0.15, CM.Cache.NoGoldSwitchCookiesPS * 60 * 30), 2) + conjure.appendChild(reward) + var seperator = document.createElement('span'); + seperator.textContent = ' / ' + conjure.appendChild(seperator) + var loss = document.createElement('span'); + loss.style.color = "red" + loss.textContent = Beautify((CM.Cache.NoGoldSwitchCookiesPS * 60 * 15), 2); + conjure.appendChild(loss) + } + + l('CMTooltipArea').appendChild(tooltipBox); + } +} + +/** + * This function updates the warnings section of the building and upgrade tooltips + * It is called by CM.Disp.UpdateTooltip() + */ +CM.Disp.UpdateTooltipWarnings = function() { + if (CM.Disp.tooltipType == "b" || CM.Disp.tooltipType == "u") { + if (document.getElementById("tooltipWarn") == null) { + warningTooltip = CM.Disp.TooltipCreateWarningSection(); + l('tooltipAnchor').appendChild(warningTooltip); + } + + if (CM.Config.ToolWarnPos == 0) CM.Disp.TooltipWarn.style.right = '0px'; + else CM.Disp.TooltipWarn.style.top = (l('tooltip').offsetHeight) + 'px'; + + CM.Disp.TooltipWarn.style.width = (l('tooltip').offsetWidth - 6) + 'px'; + + if (CM.Config.ToolWarnLucky == 1) { + var limitLucky = CM.Cache.Lucky; + if (CM.Config.ToolWarnBon == 1) { + var bonusNoFren = CM.Disp.TooltipBonusIncome; + bonusNoFren /= CM.Sim.getCPSBuffMult(); + limitLucky += ((bonusNoFren * 60 * 15) / 0.15); + } + var limitLuckyFrenzy = limitLucky * 7; + var amount = (Game.cookies + CM.Disp.GetWrinkConfigBank()) - price; + if ((amount < limitLucky || amount < limitLuckyFrenzy) && (CM.Disp.tooltipType != 'b' || Game.buyMode == 1)) { + if (amount < limitLucky) { + l('CMDispTooltipWarnLucky').style.display = ''; + l('CMDispTooltipWarnLuckyText').textContent = Beautify(limitLucky - amount) + ' (' + CM.Disp.FormatTime((limitLucky - amount) / CM.Disp.GetCPS()) + ')'; + l('CMDispTooltipWarnLuckyFrenzy').style.display = ''; + l('CMDispTooltipWarnLuckyFrenzyText').textContent = Beautify(limitLuckyFrenzy - amount) + ' (' + CM.Disp.FormatTime((limitLuckyFrenzy - amount) / CM.Disp.GetCPS()) + ')'; } - else { + else if (amount < limitLuckyFrenzy) { + l('CMDispTooltipWarnLuckyFrenzy').style.display = ''; + l('CMDispTooltipWarnLuckyFrenzyText').textContent = Beautify(limitLuckyFrenzy - amount) + ' (' + CM.Disp.FormatTime((limitLuckyFrenzy - amount) / CM.Disp.GetCPS()) + ')'; l('CMDispTooltipWarnLucky').style.display = 'none'; - l('CMDispTooltipWarnLuckyFrenzy').style.display = 'none'; } - - if (CM.Config.ToolWarnConjure == 1) { - CM.Disp.TooltipWarn.style.display = 'block'; - var limitLucky = CM.Cache.Lucky; - if (CM.Config.ToolWarnBon == 1) { - var bonusNoFren = bonus; - bonusNoFren /= CM.Sim.getCPSBuffMult(); - limitLucky += ((bonusNoFren * 60 * 15) / 0.15); - } - var limitConjure = limitLucky * 2; - var amount = (Game.cookies + CM.Disp.GetWrinkConfigBank()) - price; - if ((amount < limitConjure) && (CM.Disp.tooltipType != 'b' || Game.buyMode == 1)) { - l('CMDispTooltipWarnConjure').style.display = ''; - l('CMDispTooltipWarnConjureText').textContent = Beautify(limitConjure - amount) + ' (' + CM.Disp.FormatTime((limitConjure - amount) / CM.Disp.GetCPS()) + ')'; - } else { - l('CMDispTooltipWarnConjure').style.display = 'none'; - } - } - else { - l('CMDispTooltipWarnConjure').style.display = 'none'; - } - } - else if (CM.Disp.tooltipType === 's') { - // Adding information about Sugar Lumps. - - CM.Disp.TooltipWarn.style.display = 'none'; - l('CMDispTooltipWarnLucky').style.display = 'none'; - l('CMDispTooltipWarnLuckyFrenzy').style.display = 'none'; - l('CMDispTooltipWarnConjure').style.display = 'none'; - - if (CM.Config.TooltipLump === 1) { - l('CMTooltipArea').innerHTML = ''; - - l('tooltip').firstChild.style.paddingBottom = '4px'; - var lumpTooltip = document.createElement('div'); - lumpTooltip.style.border = '1px solid'; - lumpTooltip.style.padding = '4px'; - lumpTooltip.style.margin = '0px -4px'; - lumpTooltip.id = 'CMTooltipBorder'; - lumpTooltip.className = CM.Disp.colorTextPre + CM.Disp.colorGray; - - var lumpHeader = document.createElement('div'); - lumpHeader.style.fontWeight = 'bold'; - lumpHeader.className = CM.Disp.colorTextPre + CM.Disp.colorBlue; - lumpHeader.textContent = 'Current Sugar Lump'; - - lumpTooltip.appendChild(lumpHeader); - var lumpType = document.createElement('div'); - lumpType.id = 'CMTooltipTime'; - lumpTooltip.appendChild(lumpType); - var lumpColor = CM.Disp.GetLumpColor(Game.lumpCurrentType); - lumpType.textContent = lumpColor.text; - lumpType.className = CM.Disp.colorTextPre + lumpColor.color; - - l('CMTooltipArea').appendChild(lumpTooltip); - } - } - else if (CM.Disp.tooltipType === 'g') { - // Grimoire - CM.Disp.TooltipWarn.style.display = 'none'; + } else { l('CMDispTooltipWarnLucky').style.display = 'none'; l('CMDispTooltipWarnLuckyFrenzy').style.display = 'none'; - l('CMDispTooltipWarnConjure').style.display = 'none'; - - var minigame = Game.Objects['Wizard tower'].minigame; - var spellCost = minigame.getSpellCost(minigame.spellsById[CM.Disp.tooltipName]); - - if (CM.Config.TooltipGrim == 1 && spellCost <= minigame.magicM) { - l('CMTooltipArea').innerHTML = ''; - - l('tooltip').firstChild.style.paddingBottom = '4px'; - var tooltip = document.createElement('div'); - tooltip.style.border = '1px solid'; - tooltip.style.padding = '4px'; - tooltip.style.margin = '0px -4px'; - tooltip.id = 'CMTooltipBorder'; - tooltip.className = CM.Disp.colorTextPre + CM.Disp.colorGray; - - var header = function(text) { - var div = document.createElement('div'); - div.style.fontWeight = 'bold'; - div.className = CM.Disp.colorTextPre + CM.Disp.colorBlue; - div.textContent = text; - return div; - } - - tooltip.appendChild(header('Time Left')); - var time = document.createElement('div'); - time.id = 'CMTooltipTime'; - tooltip.appendChild(time); - var timeColor = CM.Disp.GetTimeColor(CM.Disp.CalculateGrimoireRefillTime(minigame.magic, minigame.magicM, spellCost)); - time.textContent = timeColor.text; - time.className = CM.Disp.colorTextPre + timeColor.color; - - if (spellCost <= minigame.magic) { - tooltip.appendChild(header('Recover Time')); - var recover = document.createElement('div'); - recover.id = 'CMTooltipRecover'; - tooltip.appendChild(recover); - var recoverColor = CM.Disp.GetTimeColor(CM.Disp.CalculateGrimoireRefillTime(Math.max(0, minigame.magic - spellCost), minigame.magicM, minigame.magic)); - recover.textContent = recoverColor.text; - recover.className = CM.Disp.colorTextPre + recoverColor.color; - } - - // Extra information when spell is Conjure Baked Goods (Name == 0) - if (CM.Disp.tooltipName == 0) { - tooltip.appendChild(header('Cookies to be gained/lost')); - var conjure = document.createElement('div'); - conjure.id = 'CMTooltipConjure'; - tooltip.appendChild(conjure); - var reward = document.createElement('span'); - reward.style.color = "#33FF00" - reward.textContent = Beautify(Math.min((Game.cookies + CM.Disp.GetWrinkConfigBank()) * 0.15, CM.Cache.NoGoldSwitchCookiesPS * 60 * 30), 2) - conjure.appendChild(reward) - var seperator = document.createElement('span'); - seperator.textContent = ' / ' - conjure.appendChild(seperator) - var loss = document.createElement('span'); - loss.style.color = "red" - loss.textContent = Beautify((CM.Cache.NoGoldSwitchCookiesPS * 60 * 15), 2); - conjure.appendChild(loss) - } - - l('CMTooltipArea').appendChild(tooltip); - } } } else { - CM.Disp.TooltipWarn.style.display = 'none'; + l('CMDispTooltipWarnLucky').style.display = 'none'; + l('CMDispTooltipWarnLuckyFrenzy').style.display = 'none'; + } + + if (CM.Config.ToolWarnConjure == 1) { + var limitLucky = CM.Cache.Lucky; + if (CM.Config.ToolWarnBon == 1) { + var bonusNoFren = CM.Disp.TooltipBonusIncome; + bonusNoFren /= CM.Sim.getCPSBuffMult(); + limitLucky += ((bonusNoFren * 60 * 15) / 0.15); + } + var limitConjure = limitLucky * 2; + var amount = (Game.cookies + CM.Disp.GetWrinkConfigBank()) - price; + if ((amount < limitConjure) && (CM.Disp.tooltipType != 'b' || Game.buyMode == 1)) { + l('CMDispTooltipWarnConjure').style.display = ''; + l('CMDispTooltipWarnConjureText').textContent = Beautify(limitConjure - amount) + ' (' + CM.Disp.FormatTime((limitConjure - amount) / CM.Disp.GetCPS()) + ')'; + } else { + l('CMDispTooltipWarnConjure').style.display = 'none'; + } + } + else { + l('CMDispTooltipWarnConjure').style.display = 'none'; + } + } + else { + if (l('CMDispTooltipWarningParent') != null) { + l('CMDispTooltipWarningParent').remove(); } } } +/** + * This function updates the location of the tooltip + * It is called by Game.tooltip.update() because of CM.ReplaceNative() + */ CM.Disp.UpdateTooltipLocation = function() { if (Game.tooltip.origin == 'store') { var warnOffset = 0; - if (CM.Config.ToolWarnLucky == 1 && CM.Config.ToolWarnPos == 1) warnOffset = CM.Disp.TooltipWarn.clientHeight - 4; + if (CM.Config.ToolWarnLucky == 1 && CM.Config.ToolWarnPos == 1 && typeof CM.Disp.TooltipWarn != "undefined") { + warnOffset = CM.Disp.TooltipWarn.clientHeight - 4; + } Game.tooltip.tta.style.top = Math.min(parseInt(Game.tooltip.tta.style.top), (l('game').clientHeight + l('topBar').clientHeight) - Game.tooltip.tt.clientHeight - warnOffset - 46) + 'px'; } // Kept for future possible use if the code changes again @@ -1692,44 +1715,31 @@ CM.Disp.UpdateTooltipLocation = function() { } /** - * This function toggles the position of the warnings created by CM.Disp.CreateTooltipWarn() + * This function toggles the position of the warnings created by CM.Disp.TooltipCreateWarningSection() * It is called by a change in CM.Config.ToolWarnPos */ CM.Disp.ToggleToolWarnPos = function() { - if (CM.Config.ToolWarnPos == 0) { - CM.Disp.TooltipWarn.style.top = 'auto'; - CM.Disp.TooltipWarn.style.margin = '4px -4px'; - CM.Disp.TooltipWarn.style.padding = '3px 4px'; - } - else { - CM.Disp.TooltipWarn.style.right = 'auto'; - CM.Disp.TooltipWarn.style.margin = '4px'; - CM.Disp.TooltipWarn.style.padding = '4px 3px'; - } -} - -CM.Disp.DrawTooltipWarn = function() { - if (CM.Config.ToolWarnLucky == 1) { - l('CMDispTooltipWarnLucky').style.opacity = '0'; - l('CMDispTooltipWarnLuckyFrenzy').style.opacity = '0'; - } - if (CM.Config.ToolWarnConjure == 1) { - l('CMDispTooltipWarnConjure').style.opacity = '0'; - } -} - -CM.Disp.UpdateTooltipWarn = function() { - if (CM.Config.ToolWarnLucky == 1 && l('tooltipAnchor').style.display != 'none' && l('CMTooltipArea') != null) { - l('CMDispTooltipWarnLucky').style.opacity = '1'; - l('CMDispTooltipWarnLuckyFrenzy').style.opacity = '1'; - } - if (CM.Config.ToolWarnConjure == 1 && l('tooltipAnchor').style.display != 'none' && l('CMTooltipArea') != null) { - l('CMDispTooltipWarnConjure').style.opacity = '1'; + if (typeof CM.Disp.TooltipWarn != "undefined") { + if (CM.Config.ToolWarnPos == 0) { + CM.Disp.TooltipWarn.style.top = 'auto'; + CM.Disp.TooltipWarn.style.margin = '4px -4px'; + CM.Disp.TooltipWarn.style.padding = '3px 4px'; + } + else { + CM.Disp.TooltipWarn.style.right = 'auto'; + CM.Disp.TooltipWarn.style.margin = '4px'; + CM.Disp.TooltipWarn.style.padding = '4px 3px'; + } } } +/** + * This function checks and create a tooltip for the wrinklers + * It is called by CM.Loop() + * TODO: Change this code to be the same as other tooltips. (i.d., create tooltip with type "w") + */ CM.Disp.CheckWrinklerTooltip = function() { - if (CM.Config.ToolWrink == 1 && CM.Disp.TooltipWrinklerArea == 1) { + if (CM.Config.ToolWrink == 1 && CM.Disp.TooltipWrinklerArea == 1) { // Latter is set by CM.Main.AddWrinklerAreaDetect var showingTooltip = false; for (var i in Game.wrinklers) { var me = Game.wrinklers[i]; @@ -1761,6 +1771,11 @@ CM.Disp.CheckWrinklerTooltip = function() { } } +/** + * This function updates the amount to be displayed by the wrinkler tooltip created by CM.Disp.CheckWrinklerTooltip() + * It is called by CM.Loop() + * TODO: Change this code to be the same as other tooltips. Fit this into CM.Disp.UpdateTooltip() + */ CM.Disp.UpdateWrinklerTooltip = function() { if (CM.Config.ToolWrink == 1 && l('CMTooltipWrinkler') != null) { var sucked = Game.wrinklers[CM.Disp.TooltipWrinkler].sucked; diff --git a/src/Main.js b/src/Main.js index 842c488..5bf1c02 100644 --- a/src/Main.js +++ b/src/Main.js @@ -18,14 +18,12 @@ CM.ReplaceNative = function() { eval('CM.Backup.tooltip.drawMod = ' + Game.tooltip.draw.toString().split('this').join('Game.tooltip')); Game.tooltip.draw = function(from, text, origin) { CM.Backup.tooltip.drawMod(from, text, origin); - CM.Disp.DrawTooltipWarn(); } CM.Backup.tooltip.update = Game.tooltip.update; eval('CM.Backup.tooltip.updateMod = ' + Game.tooltip.update.toString().split('this.').join('Game.tooltip.')); Game.tooltip.update = function() { CM.Backup.tooltip.updateMod(); - CM.Disp.UpdateTooltipWarn(); CM.Disp.UpdateTooltipLocation(); } @@ -228,11 +226,10 @@ CM.DelayInit = function() { for (var i in CM.Disp.TooltipText) { CM.Disp.CreateSimpleTooltip(CM.Disp.TooltipText[i][0], CM.Disp.TooltipText[i][1], CM.Disp.TooltipText[i][2]); } - CM.Disp.CreateTooltipWarn(); CM.Disp.ReplaceTooltipBuild(); CM.Disp.ReplaceTooltipGrimoire(); CM.Disp.ReplaceTooltipLump(); - CM.Disp.AddWrinklerAreaDetect(); + CM.Main.AddWrinklerAreaDetect(); CM.Cache.InitCookiesDiff(); CM.ReplaceNative(); CM.ReplaceNativeGrimoire(); @@ -411,6 +408,23 @@ CM.Main.CheckWrinklerCount = function() { } } +/** + * This function creates .onmouseover/out events that determine if the mouse is hovering-over a Wrinkler + * It is called by CM.DelayInit + * TODO: The system for displaying wrinklers should ideally use a similar system as other tooltips + * Thus, writing a CM.Disp.ReplaceTooltipWrinkler function etc. + */ +CM.Main.AddWrinklerAreaDetect = function() { + l('backgroundLeftCanvas').onmouseover = function() {CM.Disp.TooltipWrinklerArea = 1;}; + l('backgroundLeftCanvas').onmouseout = function() { + CM.Disp.TooltipWrinklerArea = 0; + Game.tooltip.hide(); + for (var i in Game.wrinklers) { + CM.Disp.TooltipWrinklerCache[i] = 0; + } + }; +} + CM.HasReplaceNativeGrimoireLaunch = false; CM.HasReplaceNativeGrimoireDraw = false; From 343327a1b592f8ba2c0b9dc4de94a2961ba1da80 Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Fri, 4 Dec 2020 21:06:23 +0100 Subject: [PATCH 024/106] Fix CalculateGains --- CookieMonster.js | 2 +- src/Sim.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index d26a337..292a280 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -4204,7 +4204,7 @@ CM.Sim.CalculateGains = function() { var mult = 1; // Include minigame effects var effs={}; - for (var i in CM.Cache.Objects) { + for (var i in Game.Objects) { // TODO Store minigames and effects in Cache // Include possibility of new/modded building and new/modded minigames if (CM.Sim.Objects[i].minigameLoaded && CM.Sim.Objects[i].minigame.effs) { diff --git a/src/Sim.js b/src/Sim.js index a19d38b..17988c2 100644 --- a/src/Sim.js +++ b/src/Sim.js @@ -252,7 +252,7 @@ CM.Sim.CalculateGains = function() { var mult = 1; // Include minigame effects var effs={}; - for (var i in CM.Cache.Objects) { + for (var i in Game.Objects) { // TODO Store minigames and effects in Cache // Include possibility of new/modded building and new/modded minigames if (CM.Sim.Objects[i].minigameLoaded && CM.Sim.Objects[i].minigame.effs) { From 02b31c8932f4b1af74ae562a6d53ae3ef62de897 Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Fri, 4 Dec 2020 21:14:17 +0100 Subject: [PATCH 025/106] Fixed CM.Disp.Beautify --- CookieMonster.js | 4 ++-- src/Disp.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index 292a280..179d501 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -1218,7 +1218,7 @@ CM.Disp.Beautify = function(num, frac, forced) { if (num == "0") { return num } - else if (-1 < timesTenToPowerThree < 2) { + else if (-1 < timesTenToPowerThree && timesTenToPowerThree < 2) { answer = Math.round(num * 100) / 100; } else if (CM.Config.Scale == 3 && !forced || forced == 3) { // Scientific notation, 123456789 => 1.235E+8 @@ -1267,7 +1267,7 @@ CM.Disp.Beautify = function(num, frac, forced) { answer = CM.Backup.Beautify(num, frac); } if (negative) answer = '-' + answer; - return answer; + return answer.toString(); } else if (num == Infinity) { return "Infinity"; diff --git a/src/Disp.js b/src/Disp.js index a1ebf03..95817e7 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -336,7 +336,7 @@ CM.Disp.Beautify = function(num, frac, forced) { if (num == "0") { return num } - else if (-1 < timesTenToPowerThree < 2) { + else if (-1 < timesTenToPowerThree && timesTenToPowerThree < 2) { answer = Math.round(num * 100) / 100; } else if (CM.Config.Scale == 3 && !forced || forced == 3) { // Scientific notation, 123456789 => 1.235E+8 @@ -385,7 +385,7 @@ CM.Disp.Beautify = function(num, frac, forced) { answer = CM.Backup.Beautify(num, frac); } if (negative) answer = '-' + answer; - return answer; + return answer.toString(); } else if (num == Infinity) { return "Infinity"; From 4baae5c9f7711a7ef43e7dc2781ae4d879a05121 Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Fri, 4 Dec 2020 22:38:14 +0100 Subject: [PATCH 026/106] Updated timer bar code --- CookieMonster.js | 368 ++++++++++++++++++++++------------------------- src/Disp.js | 368 ++++++++++++++++++++++------------------------- 2 files changed, 340 insertions(+), 396 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index 179d501..967cfe8 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -1402,8 +1402,11 @@ CM.Disp.CreateBotBarBuildingColumn = function(buildingName) { /******** * Section: Functions related to the Timer Bar - * TODO: Annotate functions */ +/** + * This function creates the TimerBar and appends it to l('wrapper') + * It is called by CM.DelayInit() + */ CM.Disp.CreateTimerBar = function() { CM.Disp.TimerBar = document.createElement('div'); CM.Disp.TimerBar.id = 'CMTimerBar'; @@ -1414,96 +1417,177 @@ CM.Disp.CreateTimerBar = function() { CM.Disp.TimerBar.style.fontWeight = 'bold'; CM.Disp.TimerBar.style.backgroundColor = 'black'; - var bar = function(name, bars, time) { - var div = document.createElement('div'); - div.style.width = '100%'; - div.style.height = '10px'; - div.style.margin = 'auto'; - div.style.position = 'absolute'; - div.style.left = '0px'; - div.style.top = '0px'; - div.style.right = '0px'; - div.style.bottom = '0px'; + CM.Disp.TimerBars = {}; + CM.Disp.BuffTimerBars = {}; - var type = document.createElement('span'); - type.style.display = 'inline-block'; - type.style.textAlign = 'right'; - type.style.width = '108px'; - type.style.marginRight = '5px'; - type.style.verticalAlign = 'text-top'; - type.textContent = name; - div.appendChild(type); + // Create standard Golden Cookie bar + CM.Disp.TimerBars['CMTimerBarGC'] = CM.Disp.TimerBarCreateBar('CMTimerBarGC', + 'Next Cookie', + [{id: 'CMTimerBarGCMinBar', color: CM.Disp.colorGray}, {id: 'CMTimerBarGCBar', color: CM.Disp.colorPurple}] + ); + CM.Disp.TimerBar.appendChild(CM.Disp.TimerBars['CMTimerBarGC']) - for (var i = 0; i < bars.length; i++) { - var colorBar = document.createElement('span'); - colorBar.id = bars[i].id - colorBar.style.display = 'inline-block'; - colorBar.style.height = '10px'; - if (bars.length - 1 == i) { - colorBar.style.borderTopRightRadius = '10px'; - colorBar.style.borderBottomRightRadius = '10px'; - } - if (typeof bars[i].color !== 'undefined') { - colorBar.className = CM.Disp.colorBackPre + bars[i].color; - } - div.appendChild(colorBar); - } - - var timer = document.createElement('span'); - timer.id = time; - timer.style.marginLeft = '5px'; - timer.style.verticalAlign = 'text-top'; - div.appendChild(timer); - return div - } - - CM.Disp.TimerBarGC = document.createElement('div'); - CM.Disp.TimerBarGC.id = 'CMTimerBarGC'; - CM.Disp.TimerBarGC.style.height = '12px'; - CM.Disp.TimerBarGC.style.margin = '0px 10px'; - CM.Disp.TimerBarGC.style.position = 'relative'; - CM.Disp.TimerBarGC.appendChild(bar('Next Cookie', [{id: 'CMTimerBarGCMinBar', color: CM.Disp.colorGray}, {id: 'CMTimerBarGCBar', color: CM.Disp.colorPurple}], 'CMTimerBarGCTime')); - CM.Disp.TimerBar.appendChild(CM.Disp.TimerBarGC); - - CM.Disp.TimerBarRen = document.createElement('div'); - CM.Disp.TimerBarRen.id = 'CMTimerBarRen'; - CM.Disp.TimerBarRen.style.height = '12px'; - CM.Disp.TimerBarRen.style.margin = '0px 10px'; - CM.Disp.TimerBarRen.style.position = 'relative'; - CM.Disp.TimerBarRen.appendChild(bar('Next Reindeer', [{id: 'CMTimerBarRenMinBar', color: CM.Disp.colorGray}, {id: 'CMTimerBarRenBar', color: CM.Disp.colorOrange}], 'CMTimerBarRenTime')); - CM.Disp.TimerBar.appendChild(CM.Disp.TimerBarRen); - - CM.Disp.TimerBarBuff1 = document.createElement('div'); - CM.Disp.TimerBarBuff1.id = 'CMTimerBarBuff1'; - CM.Disp.TimerBarBuff1.style.height = '12px'; - CM.Disp.TimerBarBuff1.style.margin = '0px 10px'; - CM.Disp.TimerBarBuff1.style.position = 'relative'; - CM.Disp.TimerBarBuff1.appendChild(bar('', [{id: 'CMTimerBarBuff1Bar'}], 'CMTimerBarBuff1Time')); - CM.Disp.TimerBarBuff1.firstChild.firstChild.id = 'CMTimerBarBuff1Type'; - CM.Disp.TimerBar.appendChild(CM.Disp.TimerBarBuff1); - - CM.Disp.TimerBarBuff2 = document.createElement('div'); - CM.Disp.TimerBarBuff2.id = 'CMTimerBarBuff2'; - CM.Disp.TimerBarBuff2.style.height = '12px'; - CM.Disp.TimerBarBuff2.style.margin = '0px 10px'; - CM.Disp.TimerBarBuff2.style.position = 'relative'; - CM.Disp.TimerBarBuff2.appendChild(bar('', [{id: 'CMTimerBarBuff2Bar'}], 'CMTimerBarBuff2Time')); - CM.Disp.TimerBarBuff2.firstChild.firstChild.id = 'CMTimerBarBuff2Type'; - CM.Disp.TimerBar.appendChild(CM.Disp.TimerBarBuff2); + // Create standard Reindeer bar + CM.Disp.TimerBars['CMTimerBarRen'] = CM.Disp.TimerBarCreateBar('CMTimerBarRen', + 'Next Reindeer', + [{id: 'CMTimerBarRenMinBar', color: CM.Disp.colorGray}, {id: 'CMTimerBarRenBar', color: CM.Disp.colorOrange}] + ); + CM.Disp.TimerBar.appendChild(CM.Disp.TimerBars['CMTimerBarRen']) l('wrapper').appendChild(CM.Disp.TimerBar); } -CM.Disp.ToggleTimerBar = function() { +/** + * This function creates an indivudual timer for the timer bar + * It is called by CM.DelayInit() + * @param {string} id An id to identify the timer + * @param {string} name The title of the timer + * @param [{{string}, {string}}, ...] bars ([id, color]) The id and colours of individual parts of the timer + */ +CM.Disp.TimerBarCreateBar = function(id, name, bars) { + timerBar = document.createElement('div'); + timerBar.id = 'CMTimerBarGC'; + timerBar.style.height = '12px'; + timerBar.style.margin = '0px 10px'; + timerBar.style.position = 'relative'; + + var div = document.createElement('div'); + div.style.width = '100%'; + div.style.height = '10px'; + div.style.margin = 'auto'; + div.style.position = 'absolute'; + div.style.left = '0px'; + div.style.top = '0px'; + div.style.right = '0px'; + div.style.bottom = '0px'; + + var type = document.createElement('span'); + type.style.display = 'inline-block'; + type.style.textAlign = 'right'; + type.style.width = '108px'; + type.style.marginRight = '5px'; + type.style.verticalAlign = 'text-top'; + type.textContent = name; + div.appendChild(type); + + for (var i = 0; i < bars.length; i++) { + var colorBar = document.createElement('span'); + colorBar.id = bars[i].id + colorBar.style.display = 'inline-block'; + colorBar.style.height = '10px'; + if (bars.length - 1 == i) { + colorBar.style.borderTopRightRadius = '10px'; + colorBar.style.borderBottomRightRadius = '10px'; + } + if (typeof bars[i].color !== 'undefined') { + colorBar.className = CM.Disp.colorBackPre + bars[i].color; + } + div.appendChild(colorBar); + } + + var timer = document.createElement('span'); + timer.id = id + 'Time'; + timer.style.marginLeft = '5px'; + timer.style.verticalAlign = 'text-top'; + div.appendChild(timer); + + timerBar.appendChild(div); + + return timerBar; +} + +/** + * This function creates an indivudual timer for the timer bar + * It is called by CM.Loop() + */ +CM.Disp.UpdateTimerBar = function() { if (CM.Config.TimerBar == 1) { - CM.Disp.TimerBar.style.display = ''; - } - else { - CM.Disp.TimerBar.style.display = 'none'; + // label width: 113, timer width: 26, div margin: 20 + var maxWidth = CM.Disp.TimerBar.offsetWidth - 159; + var numberOfTimers = 0; + + // Regulates visibility of Golden Cookie timer + if (Game.shimmerTypes['golden'].spawned == 0 && !Game.Has('Golden switch [off]')) { + CM.Disp.TimerBars['CMTimerBarGC'].style.display = ''; + l('CMTimerBarGCMinBar').style.width = Math.round(Math.max(0, Game.shimmerTypes['golden'].minTime - Game.shimmerTypes['golden'].time) * maxWidth / Game.shimmerTypes['golden'].maxTime) + 'px'; + if (Game.shimmerTypes['golden'].minTime == Game.shimmerTypes['golden'].maxTime) { + l('CMTimerBarGCMinBar').style.borderTopRightRadius = '10px'; + l('CMTimerBarGCMinBar').style.borderBottomRightRadius = '10px'; + } + else { + l('CMTimerBarGCMinBar').style.borderTopRightRadius = ''; + l('CMTimerBarGCMinBar').style.borderBottomRightRadius = ''; + } + l('CMTimerBarGCBar').style.width = Math.round(Math.min(Game.shimmerTypes['golden'].maxTime - Game.shimmerTypes['golden'].minTime, Game.shimmerTypes['golden'].maxTime - Game.shimmerTypes['golden'].time) * maxWidth / Game.shimmerTypes['golden'].maxTime) + 'px'; + l('CMTimerBarGCTime').textContent = Math.ceil((Game.shimmerTypes['golden'].maxTime - Game.shimmerTypes['golden'].time) / Game.fps); + numberOfTimers++; + } + else CM.Disp.TimerBars['CMTimerBarGC'].style.display = 'none'; + + // Regulates visibility of Reinder timer + if (Game.season == 'christmas' && Game.shimmerTypes['reindeer'].spawned == 0) { + CM.Disp.TimerBars['CMTimerBarRen'].style.display = ''; + l('CMTimerBarRenMinBar').style.width = Math.round(Math.max(0, Game.shimmerTypes['reindeer'].minTime - Game.shimmerTypes['reindeer'].time) * maxWidth / Game.shimmerTypes['reindeer'].maxTime) + 'px'; + l('CMTimerBarRenBar').style.width = Math.round(Math.min(Game.shimmerTypes['reindeer'].maxTime - Game.shimmerTypes['reindeer'].minTime, Game.shimmerTypes['reindeer'].maxTime - Game.shimmerTypes['reindeer'].time) * maxWidth / Game.shimmerTypes['reindeer'].maxTime) + 'px'; + l('CMTimerBarRenTime').textContent = Math.ceil((Game.shimmerTypes['reindeer'].maxTime - Game.shimmerTypes['reindeer'].time) / Game.fps); + numberOfTimers++; + } + else { + CM.Disp.TimerBars['CMTimerBarRen'].style.display = 'none'; + } + + // On every frame all buff-timers are deleted and re-created + for (var i in CM.Disp.BuffTimerBars) { + CM.Disp.BuffTimerBars[i].remove() + } + CM.Disp.BuffTimerBars = {} + for (var i in Game.buffs) { + if (Game.buffs[i]) { + timer = CM.Disp.TimerBarCreateBar(Game.buffs[i].name, Game.buffs[i].name, [{id: Game.buffs[i].name + 'Bar'}]) + timer.style.display = ''; + var classColor = ''; + // Gives specific timers specific colors + if (typeof CM.Disp.buffColors[Game.buffs[i].name] !== 'undefined') { + classColor = CM.Disp.buffColors[Game.buffs[i].name]; + } + else classColor = CM.Disp.colorPurple; + timer.lastChild.children[1].className = CM.Disp.colorBackPre + classColor; + timer.lastChild.children[1].style.width = Math.round(Game.buffs[i].time * maxWidth / Game.buffs[i].maxTime) + 'px'; + timer.lastChild.children[2].textContent = Math.ceil(Game.buffs[i].time / Game.fps); + numberOfTimers++; + CM.Disp.BuffTimerBars[Game.buffs[i].name] = timer + } + } + for (var i in CM.Disp.BuffTimerBars) { + CM.Disp.TimerBar.appendChild(CM.Disp.BuffTimerBars[i]) + } + + if (numberOfTimers != 0) { + var height = 48 / numberOfTimers; + for (var i in CM.Disp.TimerBars) { + CM.Disp.TimerBars[i].style.height = height + 'px'; + } + for (var i in CM.Disp.BuffTimerBars) { + CM.Disp.BuffTimerBars[i].style.height = height + 'px'; + } + } } +} + +/** + * This function changes the visibility of the timer bar + * It is called by CM.Disp.UpdateAscendState() or a change in CM.Config.TimerBar + */ +CM.Disp.ToggleTimerBar = function() { + if (CM.Config.TimerBar == 1) CM.Disp.TimerBar.style.display = ''; + else CM.Disp.TimerBar.style.display = 'none'; CM.Disp.UpdateBotTimerBarPosition(); } +/** + * This function changes the position of the timer bar + * It is called by a change in CM.Config.TimerBarPos + */ CM.Disp.ToggleTimerBarPos = function() { if (CM.Config.TimerBarPos == 0) { CM.Disp.TimerBar.style.width = '30%'; @@ -1518,125 +1602,13 @@ CM.Disp.ToggleTimerBarPos = function() { CM.Disp.UpdateBotTimerBarPosition(); } -CM.Disp.UpdateTimerBar = function() { - if (CM.Config.TimerBar == 1) { - // label width: 113, timer width: 26, div margin: 20 - var maxWidth = CM.Disp.TimerBar.offsetWidth - 159; - var count = 0; - - if (Game.shimmerTypes['golden'].spawned == 0 && !Game.Has('Golden switch [off]')) { - CM.Disp.TimerBarGC.style.display = ''; - l('CMTimerBarGCMinBar').style.width = Math.round(Math.max(0, Game.shimmerTypes['golden'].minTime - Game.shimmerTypes['golden'].time) * maxWidth / Game.shimmerTypes['golden'].maxTime) + 'px'; - if (Game.shimmerTypes['golden'].minTime == Game.shimmerTypes['golden'].maxTime) { - l('CMTimerBarGCMinBar').style.borderTopRightRadius = '10px'; - l('CMTimerBarGCMinBar').style.borderBottomRightRadius = '10px'; - } - else { - l('CMTimerBarGCMinBar').style.borderTopRightRadius = ''; - l('CMTimerBarGCMinBar').style.borderBottomRightRadius = ''; - } - l('CMTimerBarGCBar').style.width = Math.round(Math.min(Game.shimmerTypes['golden'].maxTime - Game.shimmerTypes['golden'].minTime, Game.shimmerTypes['golden'].maxTime - Game.shimmerTypes['golden'].time) * maxWidth / Game.shimmerTypes['golden'].maxTime) + 'px'; - l('CMTimerBarGCTime').textContent = Math.ceil((Game.shimmerTypes['golden'].maxTime - Game.shimmerTypes['golden'].time) / Game.fps); - count++; - } - else { - CM.Disp.TimerBarGC.style.display = 'none'; - } - - if (Game.season == 'christmas' && Game.shimmerTypes['reindeer'].spawned == 0) { - CM.Disp.TimerBarRen.style.display = ''; - l('CMTimerBarRenMinBar').style.width = Math.round(Math.max(0, Game.shimmerTypes['reindeer'].minTime - Game.shimmerTypes['reindeer'].time) * maxWidth / Game.shimmerTypes['reindeer'].maxTime) + 'px'; - l('CMTimerBarRenBar').style.width = Math.round(Math.min(Game.shimmerTypes['reindeer'].maxTime - Game.shimmerTypes['reindeer'].minTime, Game.shimmerTypes['reindeer'].maxTime - Game.shimmerTypes['reindeer'].time) * maxWidth / Game.shimmerTypes['reindeer'].maxTime) + 'px'; - l('CMTimerBarRenTime').textContent = Math.ceil((Game.shimmerTypes['reindeer'].maxTime - Game.shimmerTypes['reindeer'].time) / Game.fps); - count++; - } - else { - CM.Disp.TimerBarRen.style.display = 'none'; - } - - var buffCount = 0; - for (var i in Game.buffs) { - if (Game.buffs[i]) { - buffCount++; - CM.Disp['TimerBarBuff' + buffCount].style.display = ''; - l('CMTimerBarBuff' + buffCount + 'Type').textContent = Game.buffs[i].name; - var classColor = ''; - if (typeof CM.Disp.buffColors[Game.buffs[i].name] !== 'undefined') { - classColor = CM.Disp.buffColors[Game.buffs[i].name]; - } - else { - classColor = CM.Disp.colorPurple; - } - l('CMTimerBarBuff' + buffCount + 'Bar').className = CM.Disp.colorBackPre + classColor; - l('CMTimerBarBuff' + buffCount + 'Bar').style.width = Math.round(Game.buffs[i].time * maxWidth / Game.buffs[i].maxTime) + 'px'; - l('CMTimerBarBuff' + buffCount + 'Time').textContent = Math.ceil(Game.buffs[i].time / Game.fps); - count++; - if (buffCount == 2) { - break; - } - } - } - if (buffCount < 2) { - CM.Disp.TimerBarBuff2.style.display = 'none'; - if (buffCount < 1) { - CM.Disp.TimerBarBuff1.style.display = 'none'; - } - } - - /*if (Game.frenzy > 0) { - CM.Disp.TimerBarBuff1.style.display = ''; - if (Game.frenzyPower == 7) { - l('CMTimerBarBuff1Type').textContent = 'Frenzy'; - l('CMTimerBarBuff1Bar').className = CM.Disp.colorBackPre + CM.Disp.colorYellow; - } - else if (Game.frenzyPower == 0.5) { - l('CMTimerBarBuff1Type').textContent = 'Clot'; - l('CMTimerBarBuff1Bar').className = CM.Disp.colorBackPre + CM.Disp.colorRed; - } - else if (Game.frenzyPower == 15) { - l('CMTimerBarBuff1Type').textContent = 'Dragon Harvest'; - l('CMTimerBarBuff1Bar').className = CM.Disp.colorBackPre + CM.Disp.colorBrown; - } - else { - l('CMTimerBarBuff1Type').textContent = 'Blood Frenzy'; - l('CMTimerBarBuff1Bar').className = CM.Disp.colorBackPre + CM.Disp.colorGreen; - } - l('CMTimerBarBuff1Bar').style.width = Math.round(Game.frenzy * maxWidth / Game.frenzyMax) + 'px'; - l('CMTimerBarBuff1Time').textContent = Math.ceil(Game.frenzy / Game.fps); - count++; - } - else { - CM.Disp.TimerBarBuff1.style.display = 'none'; - } - - if (Game.clickFrenzy > 0) { - CM.Disp.TimerBarBuff2.style.display = ''; - if (Game.clickFrenzyPower == 777) { - l('CMTimerBarBuff2Type').textContent = 'Click Frenzy'; - l('CMTimerBarBuff2Bar').className = CM.Disp.colorBackPre + CM.Disp.colorBlue; - } - else { - l('CMTimerBarBuff2Type').textContent = 'Dragonflight'; - l('CMTimerBarBuff2Bar').className = CM.Disp.colorBackPre + CM.Disp.colorPink; - } - l('CMTimerBarBuff2Bar').style.width = Math.round(Game.clickFrenzy * maxWidth / Game.clickFrenzyMax) + 'px'; - l('CMTimerBarBuff2Time').textContent = Math.ceil(Game.clickFrenzy / Game.fps); - count++; - } - else { - CM.Disp.TimerBarBuff2.style.display = 'none'; - }*/ - - if (count != 0) { - var height = 48 / count; - CM.Disp.TimerBarGC.style.height = height + 'px'; - CM.Disp.TimerBarRen.style.height = height + 'px'; - CM.Disp.TimerBarBuff1.style.height = height + 'px'; - CM.Disp.TimerBarBuff2.style.height = height + 'px'; - } - } -} +/******** + * Section: Functions related to the both the bottom and timer bar +/** + * This function changes the position of both the bottom and timer bar + * It is called by CM.Disp.ToggleTimerBar(), CM.Disp.ToggleTimerBarPos() and CM.Disp.ToggleBotBar() + */ CM.Disp.UpdateBotTimerBarPosition = function() { if (CM.Config.BotBar == 1 && CM.Config.TimerBar == 1 && CM.Config.TimerBarPos == 1) { CM.Disp.BotBar.style.bottom = '48px'; diff --git a/src/Disp.js b/src/Disp.js index 95817e7..b4cb85a 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -520,8 +520,11 @@ CM.Disp.CreateBotBarBuildingColumn = function(buildingName) { /******** * Section: Functions related to the Timer Bar - * TODO: Annotate functions */ +/** + * This function creates the TimerBar and appends it to l('wrapper') + * It is called by CM.DelayInit() + */ CM.Disp.CreateTimerBar = function() { CM.Disp.TimerBar = document.createElement('div'); CM.Disp.TimerBar.id = 'CMTimerBar'; @@ -532,96 +535,177 @@ CM.Disp.CreateTimerBar = function() { CM.Disp.TimerBar.style.fontWeight = 'bold'; CM.Disp.TimerBar.style.backgroundColor = 'black'; - var bar = function(name, bars, time) { - var div = document.createElement('div'); - div.style.width = '100%'; - div.style.height = '10px'; - div.style.margin = 'auto'; - div.style.position = 'absolute'; - div.style.left = '0px'; - div.style.top = '0px'; - div.style.right = '0px'; - div.style.bottom = '0px'; + CM.Disp.TimerBars = {}; + CM.Disp.BuffTimerBars = {}; - var type = document.createElement('span'); - type.style.display = 'inline-block'; - type.style.textAlign = 'right'; - type.style.width = '108px'; - type.style.marginRight = '5px'; - type.style.verticalAlign = 'text-top'; - type.textContent = name; - div.appendChild(type); + // Create standard Golden Cookie bar + CM.Disp.TimerBars['CMTimerBarGC'] = CM.Disp.TimerBarCreateBar('CMTimerBarGC', + 'Next Cookie', + [{id: 'CMTimerBarGCMinBar', color: CM.Disp.colorGray}, {id: 'CMTimerBarGCBar', color: CM.Disp.colorPurple}] + ); + CM.Disp.TimerBar.appendChild(CM.Disp.TimerBars['CMTimerBarGC']) - for (var i = 0; i < bars.length; i++) { - var colorBar = document.createElement('span'); - colorBar.id = bars[i].id - colorBar.style.display = 'inline-block'; - colorBar.style.height = '10px'; - if (bars.length - 1 == i) { - colorBar.style.borderTopRightRadius = '10px'; - colorBar.style.borderBottomRightRadius = '10px'; - } - if (typeof bars[i].color !== 'undefined') { - colorBar.className = CM.Disp.colorBackPre + bars[i].color; - } - div.appendChild(colorBar); - } - - var timer = document.createElement('span'); - timer.id = time; - timer.style.marginLeft = '5px'; - timer.style.verticalAlign = 'text-top'; - div.appendChild(timer); - return div - } - - CM.Disp.TimerBarGC = document.createElement('div'); - CM.Disp.TimerBarGC.id = 'CMTimerBarGC'; - CM.Disp.TimerBarGC.style.height = '12px'; - CM.Disp.TimerBarGC.style.margin = '0px 10px'; - CM.Disp.TimerBarGC.style.position = 'relative'; - CM.Disp.TimerBarGC.appendChild(bar('Next Cookie', [{id: 'CMTimerBarGCMinBar', color: CM.Disp.colorGray}, {id: 'CMTimerBarGCBar', color: CM.Disp.colorPurple}], 'CMTimerBarGCTime')); - CM.Disp.TimerBar.appendChild(CM.Disp.TimerBarGC); - - CM.Disp.TimerBarRen = document.createElement('div'); - CM.Disp.TimerBarRen.id = 'CMTimerBarRen'; - CM.Disp.TimerBarRen.style.height = '12px'; - CM.Disp.TimerBarRen.style.margin = '0px 10px'; - CM.Disp.TimerBarRen.style.position = 'relative'; - CM.Disp.TimerBarRen.appendChild(bar('Next Reindeer', [{id: 'CMTimerBarRenMinBar', color: CM.Disp.colorGray}, {id: 'CMTimerBarRenBar', color: CM.Disp.colorOrange}], 'CMTimerBarRenTime')); - CM.Disp.TimerBar.appendChild(CM.Disp.TimerBarRen); - - CM.Disp.TimerBarBuff1 = document.createElement('div'); - CM.Disp.TimerBarBuff1.id = 'CMTimerBarBuff1'; - CM.Disp.TimerBarBuff1.style.height = '12px'; - CM.Disp.TimerBarBuff1.style.margin = '0px 10px'; - CM.Disp.TimerBarBuff1.style.position = 'relative'; - CM.Disp.TimerBarBuff1.appendChild(bar('', [{id: 'CMTimerBarBuff1Bar'}], 'CMTimerBarBuff1Time')); - CM.Disp.TimerBarBuff1.firstChild.firstChild.id = 'CMTimerBarBuff1Type'; - CM.Disp.TimerBar.appendChild(CM.Disp.TimerBarBuff1); - - CM.Disp.TimerBarBuff2 = document.createElement('div'); - CM.Disp.TimerBarBuff2.id = 'CMTimerBarBuff2'; - CM.Disp.TimerBarBuff2.style.height = '12px'; - CM.Disp.TimerBarBuff2.style.margin = '0px 10px'; - CM.Disp.TimerBarBuff2.style.position = 'relative'; - CM.Disp.TimerBarBuff2.appendChild(bar('', [{id: 'CMTimerBarBuff2Bar'}], 'CMTimerBarBuff2Time')); - CM.Disp.TimerBarBuff2.firstChild.firstChild.id = 'CMTimerBarBuff2Type'; - CM.Disp.TimerBar.appendChild(CM.Disp.TimerBarBuff2); + // Create standard Reindeer bar + CM.Disp.TimerBars['CMTimerBarRen'] = CM.Disp.TimerBarCreateBar('CMTimerBarRen', + 'Next Reindeer', + [{id: 'CMTimerBarRenMinBar', color: CM.Disp.colorGray}, {id: 'CMTimerBarRenBar', color: CM.Disp.colorOrange}] + ); + CM.Disp.TimerBar.appendChild(CM.Disp.TimerBars['CMTimerBarRen']) l('wrapper').appendChild(CM.Disp.TimerBar); } -CM.Disp.ToggleTimerBar = function() { +/** + * This function creates an indivudual timer for the timer bar + * It is called by CM.DelayInit() + * @param {string} id An id to identify the timer + * @param {string} name The title of the timer + * @param [{{string}, {string}}, ...] bars ([id, color]) The id and colours of individual parts of the timer + */ +CM.Disp.TimerBarCreateBar = function(id, name, bars) { + timerBar = document.createElement('div'); + timerBar.id = 'CMTimerBarGC'; + timerBar.style.height = '12px'; + timerBar.style.margin = '0px 10px'; + timerBar.style.position = 'relative'; + + var div = document.createElement('div'); + div.style.width = '100%'; + div.style.height = '10px'; + div.style.margin = 'auto'; + div.style.position = 'absolute'; + div.style.left = '0px'; + div.style.top = '0px'; + div.style.right = '0px'; + div.style.bottom = '0px'; + + var type = document.createElement('span'); + type.style.display = 'inline-block'; + type.style.textAlign = 'right'; + type.style.width = '108px'; + type.style.marginRight = '5px'; + type.style.verticalAlign = 'text-top'; + type.textContent = name; + div.appendChild(type); + + for (var i = 0; i < bars.length; i++) { + var colorBar = document.createElement('span'); + colorBar.id = bars[i].id + colorBar.style.display = 'inline-block'; + colorBar.style.height = '10px'; + if (bars.length - 1 == i) { + colorBar.style.borderTopRightRadius = '10px'; + colorBar.style.borderBottomRightRadius = '10px'; + } + if (typeof bars[i].color !== 'undefined') { + colorBar.className = CM.Disp.colorBackPre + bars[i].color; + } + div.appendChild(colorBar); + } + + var timer = document.createElement('span'); + timer.id = id + 'Time'; + timer.style.marginLeft = '5px'; + timer.style.verticalAlign = 'text-top'; + div.appendChild(timer); + + timerBar.appendChild(div); + + return timerBar; +} + +/** + * This function creates an indivudual timer for the timer bar + * It is called by CM.Loop() + */ +CM.Disp.UpdateTimerBar = function() { if (CM.Config.TimerBar == 1) { - CM.Disp.TimerBar.style.display = ''; - } - else { - CM.Disp.TimerBar.style.display = 'none'; + // label width: 113, timer width: 26, div margin: 20 + var maxWidth = CM.Disp.TimerBar.offsetWidth - 159; + var numberOfTimers = 0; + + // Regulates visibility of Golden Cookie timer + if (Game.shimmerTypes['golden'].spawned == 0 && !Game.Has('Golden switch [off]')) { + CM.Disp.TimerBars['CMTimerBarGC'].style.display = ''; + l('CMTimerBarGCMinBar').style.width = Math.round(Math.max(0, Game.shimmerTypes['golden'].minTime - Game.shimmerTypes['golden'].time) * maxWidth / Game.shimmerTypes['golden'].maxTime) + 'px'; + if (Game.shimmerTypes['golden'].minTime == Game.shimmerTypes['golden'].maxTime) { + l('CMTimerBarGCMinBar').style.borderTopRightRadius = '10px'; + l('CMTimerBarGCMinBar').style.borderBottomRightRadius = '10px'; + } + else { + l('CMTimerBarGCMinBar').style.borderTopRightRadius = ''; + l('CMTimerBarGCMinBar').style.borderBottomRightRadius = ''; + } + l('CMTimerBarGCBar').style.width = Math.round(Math.min(Game.shimmerTypes['golden'].maxTime - Game.shimmerTypes['golden'].minTime, Game.shimmerTypes['golden'].maxTime - Game.shimmerTypes['golden'].time) * maxWidth / Game.shimmerTypes['golden'].maxTime) + 'px'; + l('CMTimerBarGCTime').textContent = Math.ceil((Game.shimmerTypes['golden'].maxTime - Game.shimmerTypes['golden'].time) / Game.fps); + numberOfTimers++; + } + else CM.Disp.TimerBars['CMTimerBarGC'].style.display = 'none'; + + // Regulates visibility of Reinder timer + if (Game.season == 'christmas' && Game.shimmerTypes['reindeer'].spawned == 0) { + CM.Disp.TimerBars['CMTimerBarRen'].style.display = ''; + l('CMTimerBarRenMinBar').style.width = Math.round(Math.max(0, Game.shimmerTypes['reindeer'].minTime - Game.shimmerTypes['reindeer'].time) * maxWidth / Game.shimmerTypes['reindeer'].maxTime) + 'px'; + l('CMTimerBarRenBar').style.width = Math.round(Math.min(Game.shimmerTypes['reindeer'].maxTime - Game.shimmerTypes['reindeer'].minTime, Game.shimmerTypes['reindeer'].maxTime - Game.shimmerTypes['reindeer'].time) * maxWidth / Game.shimmerTypes['reindeer'].maxTime) + 'px'; + l('CMTimerBarRenTime').textContent = Math.ceil((Game.shimmerTypes['reindeer'].maxTime - Game.shimmerTypes['reindeer'].time) / Game.fps); + numberOfTimers++; + } + else { + CM.Disp.TimerBars['CMTimerBarRen'].style.display = 'none'; + } + + // On every frame all buff-timers are deleted and re-created + for (var i in CM.Disp.BuffTimerBars) { + CM.Disp.BuffTimerBars[i].remove() + } + CM.Disp.BuffTimerBars = {} + for (var i in Game.buffs) { + if (Game.buffs[i]) { + timer = CM.Disp.TimerBarCreateBar(Game.buffs[i].name, Game.buffs[i].name, [{id: Game.buffs[i].name + 'Bar'}]) + timer.style.display = ''; + var classColor = ''; + // Gives specific timers specific colors + if (typeof CM.Disp.buffColors[Game.buffs[i].name] !== 'undefined') { + classColor = CM.Disp.buffColors[Game.buffs[i].name]; + } + else classColor = CM.Disp.colorPurple; + timer.lastChild.children[1].className = CM.Disp.colorBackPre + classColor; + timer.lastChild.children[1].style.width = Math.round(Game.buffs[i].time * maxWidth / Game.buffs[i].maxTime) + 'px'; + timer.lastChild.children[2].textContent = Math.ceil(Game.buffs[i].time / Game.fps); + numberOfTimers++; + CM.Disp.BuffTimerBars[Game.buffs[i].name] = timer + } + } + for (var i in CM.Disp.BuffTimerBars) { + CM.Disp.TimerBar.appendChild(CM.Disp.BuffTimerBars[i]) + } + + if (numberOfTimers != 0) { + var height = 48 / numberOfTimers; + for (var i in CM.Disp.TimerBars) { + CM.Disp.TimerBars[i].style.height = height + 'px'; + } + for (var i in CM.Disp.BuffTimerBars) { + CM.Disp.BuffTimerBars[i].style.height = height + 'px'; + } + } } +} + +/** + * This function changes the visibility of the timer bar + * It is called by CM.Disp.UpdateAscendState() or a change in CM.Config.TimerBar + */ +CM.Disp.ToggleTimerBar = function() { + if (CM.Config.TimerBar == 1) CM.Disp.TimerBar.style.display = ''; + else CM.Disp.TimerBar.style.display = 'none'; CM.Disp.UpdateBotTimerBarPosition(); } +/** + * This function changes the position of the timer bar + * It is called by a change in CM.Config.TimerBarPos + */ CM.Disp.ToggleTimerBarPos = function() { if (CM.Config.TimerBarPos == 0) { CM.Disp.TimerBar.style.width = '30%'; @@ -636,125 +720,13 @@ CM.Disp.ToggleTimerBarPos = function() { CM.Disp.UpdateBotTimerBarPosition(); } -CM.Disp.UpdateTimerBar = function() { - if (CM.Config.TimerBar == 1) { - // label width: 113, timer width: 26, div margin: 20 - var maxWidth = CM.Disp.TimerBar.offsetWidth - 159; - var count = 0; - - if (Game.shimmerTypes['golden'].spawned == 0 && !Game.Has('Golden switch [off]')) { - CM.Disp.TimerBarGC.style.display = ''; - l('CMTimerBarGCMinBar').style.width = Math.round(Math.max(0, Game.shimmerTypes['golden'].minTime - Game.shimmerTypes['golden'].time) * maxWidth / Game.shimmerTypes['golden'].maxTime) + 'px'; - if (Game.shimmerTypes['golden'].minTime == Game.shimmerTypes['golden'].maxTime) { - l('CMTimerBarGCMinBar').style.borderTopRightRadius = '10px'; - l('CMTimerBarGCMinBar').style.borderBottomRightRadius = '10px'; - } - else { - l('CMTimerBarGCMinBar').style.borderTopRightRadius = ''; - l('CMTimerBarGCMinBar').style.borderBottomRightRadius = ''; - } - l('CMTimerBarGCBar').style.width = Math.round(Math.min(Game.shimmerTypes['golden'].maxTime - Game.shimmerTypes['golden'].minTime, Game.shimmerTypes['golden'].maxTime - Game.shimmerTypes['golden'].time) * maxWidth / Game.shimmerTypes['golden'].maxTime) + 'px'; - l('CMTimerBarGCTime').textContent = Math.ceil((Game.shimmerTypes['golden'].maxTime - Game.shimmerTypes['golden'].time) / Game.fps); - count++; - } - else { - CM.Disp.TimerBarGC.style.display = 'none'; - } - - if (Game.season == 'christmas' && Game.shimmerTypes['reindeer'].spawned == 0) { - CM.Disp.TimerBarRen.style.display = ''; - l('CMTimerBarRenMinBar').style.width = Math.round(Math.max(0, Game.shimmerTypes['reindeer'].minTime - Game.shimmerTypes['reindeer'].time) * maxWidth / Game.shimmerTypes['reindeer'].maxTime) + 'px'; - l('CMTimerBarRenBar').style.width = Math.round(Math.min(Game.shimmerTypes['reindeer'].maxTime - Game.shimmerTypes['reindeer'].minTime, Game.shimmerTypes['reindeer'].maxTime - Game.shimmerTypes['reindeer'].time) * maxWidth / Game.shimmerTypes['reindeer'].maxTime) + 'px'; - l('CMTimerBarRenTime').textContent = Math.ceil((Game.shimmerTypes['reindeer'].maxTime - Game.shimmerTypes['reindeer'].time) / Game.fps); - count++; - } - else { - CM.Disp.TimerBarRen.style.display = 'none'; - } - - var buffCount = 0; - for (var i in Game.buffs) { - if (Game.buffs[i]) { - buffCount++; - CM.Disp['TimerBarBuff' + buffCount].style.display = ''; - l('CMTimerBarBuff' + buffCount + 'Type').textContent = Game.buffs[i].name; - var classColor = ''; - if (typeof CM.Disp.buffColors[Game.buffs[i].name] !== 'undefined') { - classColor = CM.Disp.buffColors[Game.buffs[i].name]; - } - else { - classColor = CM.Disp.colorPurple; - } - l('CMTimerBarBuff' + buffCount + 'Bar').className = CM.Disp.colorBackPre + classColor; - l('CMTimerBarBuff' + buffCount + 'Bar').style.width = Math.round(Game.buffs[i].time * maxWidth / Game.buffs[i].maxTime) + 'px'; - l('CMTimerBarBuff' + buffCount + 'Time').textContent = Math.ceil(Game.buffs[i].time / Game.fps); - count++; - if (buffCount == 2) { - break; - } - } - } - if (buffCount < 2) { - CM.Disp.TimerBarBuff2.style.display = 'none'; - if (buffCount < 1) { - CM.Disp.TimerBarBuff1.style.display = 'none'; - } - } - - /*if (Game.frenzy > 0) { - CM.Disp.TimerBarBuff1.style.display = ''; - if (Game.frenzyPower == 7) { - l('CMTimerBarBuff1Type').textContent = 'Frenzy'; - l('CMTimerBarBuff1Bar').className = CM.Disp.colorBackPre + CM.Disp.colorYellow; - } - else if (Game.frenzyPower == 0.5) { - l('CMTimerBarBuff1Type').textContent = 'Clot'; - l('CMTimerBarBuff1Bar').className = CM.Disp.colorBackPre + CM.Disp.colorRed; - } - else if (Game.frenzyPower == 15) { - l('CMTimerBarBuff1Type').textContent = 'Dragon Harvest'; - l('CMTimerBarBuff1Bar').className = CM.Disp.colorBackPre + CM.Disp.colorBrown; - } - else { - l('CMTimerBarBuff1Type').textContent = 'Blood Frenzy'; - l('CMTimerBarBuff1Bar').className = CM.Disp.colorBackPre + CM.Disp.colorGreen; - } - l('CMTimerBarBuff1Bar').style.width = Math.round(Game.frenzy * maxWidth / Game.frenzyMax) + 'px'; - l('CMTimerBarBuff1Time').textContent = Math.ceil(Game.frenzy / Game.fps); - count++; - } - else { - CM.Disp.TimerBarBuff1.style.display = 'none'; - } - - if (Game.clickFrenzy > 0) { - CM.Disp.TimerBarBuff2.style.display = ''; - if (Game.clickFrenzyPower == 777) { - l('CMTimerBarBuff2Type').textContent = 'Click Frenzy'; - l('CMTimerBarBuff2Bar').className = CM.Disp.colorBackPre + CM.Disp.colorBlue; - } - else { - l('CMTimerBarBuff2Type').textContent = 'Dragonflight'; - l('CMTimerBarBuff2Bar').className = CM.Disp.colorBackPre + CM.Disp.colorPink; - } - l('CMTimerBarBuff2Bar').style.width = Math.round(Game.clickFrenzy * maxWidth / Game.clickFrenzyMax) + 'px'; - l('CMTimerBarBuff2Time').textContent = Math.ceil(Game.clickFrenzy / Game.fps); - count++; - } - else { - CM.Disp.TimerBarBuff2.style.display = 'none'; - }*/ - - if (count != 0) { - var height = 48 / count; - CM.Disp.TimerBarGC.style.height = height + 'px'; - CM.Disp.TimerBarRen.style.height = height + 'px'; - CM.Disp.TimerBarBuff1.style.height = height + 'px'; - CM.Disp.TimerBarBuff2.style.height = height + 'px'; - } - } -} +/******** + * Section: Functions related to the both the bottom and timer bar +/** + * This function changes the position of both the bottom and timer bar + * It is called by CM.Disp.ToggleTimerBar(), CM.Disp.ToggleTimerBarPos() and CM.Disp.ToggleBotBar() + */ CM.Disp.UpdateBotTimerBarPosition = function() { if (CM.Config.BotBar == 1 && CM.Config.TimerBar == 1 && CM.Config.TimerBarPos == 1) { CM.Disp.BotBar.style.bottom = '48px'; From 9dc95d760ae12f2c4fb5d6a2e80e591272458a2c Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Fri, 4 Dec 2020 23:41:23 +0100 Subject: [PATCH 027/106] Almost done with updating Disp.js --- CookieMonster.js | 196 +++++++++++++++++++++++++++-------------------- src/Data.js | 4 + src/Disp.js | 192 ++++++++++++++++++++++++++-------------------- 3 files changed, 230 insertions(+), 162 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index 967cfe8..66c9b12 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -744,6 +744,10 @@ CM.Data.ChristCookies = ['Christmas tree biscuits', 'Snowflake biscuits', 'Snowm CM.Data.ValCookies = ['Pure heart biscuits', 'Ardent heart biscuits', 'Sour heart biscuits', 'Weeping heart biscuits', 'Golden heart biscuits', 'Eternal heart biscuits', 'Prism heart biscuits']; +/******** + * Section: Data for the various scales used by CookieMonster */ +CM.Data.metric = ['', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y']; +CM.Data.shortScale = ['', 'M', 'B', 'Tr', 'Quadr', 'Quint', 'Sext', 'Sept', 'Oct', 'Non', 'Dec', 'Undec', 'Duodec', 'Tredec', 'Quattuordec', 'Quindec', 'Sexdec', 'Septendec', 'Octodec', 'Novemdec', 'Vigint', 'Unvigint', 'Duovigint', 'Trevigint', 'Quattuorvigint']; /******** * Section: An array containing all Config groups and their to-be displayed title */ @@ -894,11 +898,15 @@ CM.ConfigData.Scale = {type: 'bool', group: 'Other', label: ['Game\'s Setting Sc * TODO: Annotate most functions * TODO: Sort functionsn in relevant (new) sections or files */ +CM.Disp.TooltipWrinklerCache = []; +for (var i in Game.wrinklers) { + CM.Disp.TooltipWrinklerCache[i] = 0; +} + /** * This function returns Name and Color as object for sugar lump type that is given as input param. * @param type Sugar Lump Type. * @returns {{text: string, color: string}} - * @constructor */ CM.Disp.GetLumpColor = function(type) { var name = ""; @@ -966,20 +974,7 @@ CM.Disp.AddJscolor = function() { document.head.appendChild(CM.Disp.Jscolor); } -CM.Disp.CreateCssArea = function() { - CM.Disp.Css = document.createElement('style'); - CM.Disp.Css.type = 'text/css'; - document.head.appendChild(CM.Disp.Css); - - // given the architecture of your code, you probably want these lines somewhere else, - // but I stuck them here for convenience - l("products").style.display = "grid"; - l("storeBulk").style.gridRow = "1/1"; - - l("upgrades").style.display = "flex"; - l("upgrades").style["flex-wrap"] = "wrap"; -} CM.Disp.UpdateUpgrades = function() { if (CM.Config.UpBarColor > 0) { @@ -1137,6 +1132,22 @@ CM.Disp.RefreshScale = function() { CM.Disp.UpdateBuildings(); CM.Disp.UpdateUpgrades(); } + +CM.Disp.CreateCssArea = function() { + CM.Disp.Css = document.createElement('style'); + CM.Disp.Css.type = 'text/css'; + + document.head.appendChild(CM.Disp.Css); + + // given the architecture of your code, you probably want these lines somewhere else, + // but I stuck them here for convenience + l("products").style.display = "grid"; + l("storeBulk").style.gridRow = "1/1"; + + l("upgrades").style.display = "flex"; + l("upgrades").style["flex-wrap"] = "wrap"; +} + /******** * Section: General functions to format or beautify strings */ @@ -1243,16 +1254,16 @@ CM.Disp.Beautify = function(num, frac, forced) { // answer is now "xxx.xx" (e.g., 123456789 would be 123.46) if (CM.Config.Scale == 1 && !forced || forced == 1) { // Metric scale, 123456789 => 123.457 M - if (timesTenToPowerThree - 1 < CM.Disp.metric.length) { - answer += ' ' + CM.Disp.metric[timesTenToPowerThree - 1] + if (timesTenToPowerThree - 1 < CM.Data.metric.length) { + answer += ' ' + CM.Data.metric[timesTenToPowerThree - 1] } else { // If number is too large, revert to scientific notation return CM.Disp.Beautify(num, 0, 3); } } else if (CM.Config.Scale == 2 && !forced || forced == 2) { // Short scale, 123456789 => 123.457 M - if (timesTenToPowerThree < CM.Disp.shortScale.length + 1) { - answer += ' ' + CM.Disp.shortScale[timesTenToPowerThree - 1]; + if (timesTenToPowerThree < CM.Data.shortScale.length + 1) { + answer += ' ' + CM.Data.shortScale[timesTenToPowerThree - 1]; } else { // If number is too large, revert to scientific notation return CM.Disp.Beautify(num, 0, 3); @@ -1637,20 +1648,19 @@ CM.Disp.UpdateBotTimerBarPosition = function() { /******** * Section: Functions related to column of buildings/objects - * TODO: Annotate functions */ +/** + * This function adjusts some things in the column of buildings. + * It colours them, helps display the correct sell-price and shuffles the order when CM.Config.SortBuildings is set + * The function is called by CM.Loop(), CM.Disp.UpdateColors() & CM.Disp.RefreshScale() + * And by changes in CM.Config.BuildColor, CM.Config.SortBuild & CM.ConfigData.BulkBuildColor + */ CM.Disp.UpdateBuildings = function() { if (CM.Config.BuildColor == 1 && Game.buyMode == 1) { var target = ''; - if (Game.buyBulk == 10 && CM.Config.BulkBuildColor == 1) { - target = 'Objects10'; - } - else if (Game.buyBulk == 100 && CM.Config.BulkBuildColor == 1) { - target = 'Objects100'; - } - else { - target = 'Objects'; - } + if (Game.buyBulk == 10 && CM.Config.BulkBuildColor == 1) target = 'Objects10'; + else if (Game.buyBulk == 100 && CM.Config.BulkBuildColor == 1) target = 'Objects100'; + else target = 'Objects'; for (var i in CM.Cache[target]) { l('productPrice' + Game.Objects[i].id).style.color = CM.Config.Colors[CM.Cache[target][i].color]; } @@ -2652,6 +2662,10 @@ CM.Disp.UpdateWrinklerTooltip = function() { * Section: General functions related to the Options/Stats pages * TODO: Annotate functions */ +/** + * This function adds the calll the functions to add extra info to the stats and options pages + * It is called by Game.UpdateMenu() + */ CM.Disp.AddMenu = function() { var title = function() { var div = document.createElement('div'); @@ -2667,13 +2681,13 @@ CM.Disp.AddMenu = function() { if (CM.Config.Stats) { CM.Disp.AddMenuStats(title); } - - if (CM.Config.MissingUpgrades) { - CM.Disp.AddMissingUpgrades(); - } } } +/** + * This function refreshes the stats page, CM.Config.UpStats determines the rate at which that happens + * It is called by CM.Loop() + */ CM.Disp.RefreshMenu = function() { if (CM.Config.UpStats && Game.onMenu == 'stats' && (Game.drawT - 1) % (Game.fps * 5) != 0 && (Game.drawT - 1) % Game.fps == 0) Game.UpdateMenu(); } @@ -2720,9 +2734,9 @@ CM.Disp.AddMenuPref = function(title) { /** * This function creates a header-object for the options page * It is called by CM.Disp.AddMenuPref() - * @param {string} config The name of the Config-group - * @param {string} text The to-be displayed name of the header - * @returns {object} div The header object + * @param {string} config The name of the Config-group + * @param {string} text The to-be displayed name of the header + * @returns {object} div The header object */ CM.Disp.CreatePrefHeader = function(config, text) { var div = document.createElement('div'); @@ -2752,8 +2766,8 @@ CM.Disp.CreatePrefHeader = function(config, text) { /** * This function creates an option-object for the options page * It is called by CM.Disp.AddMenuPref() - * @param {string} config The name of the option - * @returns {object} div The option object + * @param {string} config The name of the option + * @returns {object} div The option object */ CM.Disp.CreatePrefOption = function(config) { if (CM.ConfigData[config].type == "bool") { @@ -2854,34 +2868,8 @@ CM.Disp.CreatePrefOption = function(config) { * TODO: Annotate functions */ CM.Disp.AddMenuStats = function(title) { - var header = function(text, config) { - var div = document.createElement('div'); - div.className = 'listing'; - div.style.padding = '5px 16px'; - div.style.opacity = '0.7'; - div.style.fontSize = '17px'; - div.style.fontFamily = '\"Kavoon\", Georgia, serif'; - div.appendChild(document.createTextNode(text + ' ')); - var span = document.createElement('span'); - span.style.cursor = 'pointer'; - span.style.display = 'inline-block'; - span.style.height = '14px'; - span.style.width = '14px'; - span.style.borderRadius = '7px'; - span.style.textAlign = 'center'; - span.style.backgroundColor = '#C0C0C0'; - span.style.color = 'black'; - span.style.fontSize = '13px'; - span.style.verticalAlign = 'middle'; - span.textContent = CM.Config.StatsPref[config] ? '-' : '+'; - span.onclick = function() {CM.ToggleStatsConfig(config); Game.UpdateMenu();}; - div.appendChild(span); - return div; - } - var stats = document.createElement('div'); stats.className = 'subsection'; - stats.appendChild(title()); var listing = function(name, text) { @@ -2957,7 +2945,7 @@ CM.Disp.AddMenuStats = function(title) { var goldCookTooltip = CM.Sim.auraMult('Dragon\'s Fortune') ? 'GoldCookDragonsFortuneTooltipPlaceholder' : 'GoldCookTooltipPlaceholder'; - stats.appendChild(header('Lucky Cookies', 'Lucky')); + stats.appendChild(CreateStatsHeader('Lucky Cookies', 'Lucky')); if (CM.Config.StatsPref.Lucky) { var luckyColor = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.Lucky) ? CM.Disp.colorRed : CM.Disp.colorGreen; var luckyTime = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.Lucky) ? CM.Disp.FormatTime((CM.Cache.Lucky - (Game.cookies + CM.Disp.GetWrinkConfigBank())) / CM.Disp.GetCPS()) : ''; @@ -3001,7 +2989,7 @@ CM.Disp.AddMenuStats = function(title) { stats.appendChild(listing(listingQuest('\"Lucky!\" Reward (CUR)' + (luckySplit ? ' (Golden / Wrath)' : ''), goldCookTooltip), document.createTextNode(Beautify(luckyCur) + (luckySplit ? (' / ' + Beautify(luckyCurWrath)) : '')))); } - stats.appendChild(header('Chain Cookies', 'Chain')); + stats.appendChild(CreateStatsHeader('Chain Cookies', 'Chain')); if (CM.Config.StatsPref.Chain) { var chainColor = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.Chain) ? CM.Disp.colorRed : CM.Disp.colorGreen; var chainTime = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.Chain) ? CM.Disp.FormatTime((CM.Cache.Chain - (Game.cookies + CM.Disp.GetWrinkConfigBank())) / CM.Disp.GetCPS()) : ''; @@ -3074,7 +3062,7 @@ CM.Disp.AddMenuStats = function(title) { stats.appendChild(listing(listingQuest('\"Chain\" Reward (CUR) (Golden / Wrath)', goldCookTooltip), document.createTextNode(Beautify(chainCur) + ' / ' + Beautify(chainCurWrath)))); } - stats.appendChild(header('Conjure Baked Goods', 'Conjure')); + stats.appendChild(CreateStatsHeader('Conjure Baked Goods', 'Conjure')); if (CM.Config.StatsPref.Conjure) { var conjureColor = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.Conjure) ? CM.Disp.colorRed : CM.Disp.colorGreen; var conjureCur = Math.min((Game.cookies + CM.Disp.GetWrinkConfigBank()) * 0.15, CM.Cache.NoGoldSwitchCookiesPS * 60 * 30); @@ -3099,7 +3087,7 @@ CM.Disp.AddMenuStats = function(title) { var choEgg = (Game.HasUnlocked('Chocolate egg') && !Game.Has('Chocolate egg')); // Needs to be done for the checking below - stats.appendChild(header('Prestige', 'Prestige')); + stats.appendChild(CreateStatsHeader('Prestige', 'Prestige')); if (CM.Config.StatsPref.Prestige) { var possiblePresMax = Math.floor(Game.HowMuchPrestige(CM.Cache.RealCookiesEarned + Game.cookiesReset + CM.Cache.WrinkGodBank + (choEgg ? CM.Cache.lastChoEgg : 0))); var neededCook = Game.HowManyCookiesReset(possiblePresMax + 1) - (CM.Cache.RealCookiesEarned + Game.cookiesReset + CM.Cache.WrinkGodBank + (choEgg ? CM.Cache.lastChoEgg : 0)); @@ -3177,7 +3165,7 @@ CM.Disp.AddMenuStats = function(title) { } if (Game.cpsSucked > 0) { - stats.appendChild(header('Wrinklers', 'Wrink')); + stats.appendChild(CreateStatsHeader('Wrinklers', 'Wrink')); if (CM.Config.StatsPref.Wrink) { var popAllFrag = document.createDocumentFragment(); popAllFrag.appendChild(document.createTextNode(Beautify(CM.Cache.WrinkBank) + ' ')); @@ -3230,7 +3218,7 @@ CM.Disp.AddMenuStats = function(title) { var centEgg = Game.Has('Century egg'); if (Game.season == 'christmas' || specDisp || choEgg || centEgg) { - stats.appendChild(header('Season Specials', 'Sea')); + stats.appendChild(CreateStatsHeader('Season Specials', 'Sea')); if (CM.Config.StatsPref.Sea) { if (specDisp) { if (halloCook.length != 0) stats.appendChild(listing('Halloween Cookies Left to Buy', createMissDisp(halloCook))); @@ -3250,7 +3238,7 @@ CM.Disp.AddMenuStats = function(title) { } } - stats.appendChild(header('Miscellaneous', 'Misc')); + stats.appendChild(CreateStatsHeader('Miscellaneous', 'Misc')); if (CM.Config.StatsPref.Misc) { stats.appendChild(listing( 'Average Cookies Per Second (Past ' + (CM.Disp.cookieTimes[CM.Config.AvgCPSHist] < 60 ? (CM.Disp.cookieTimes[CM.Config.AvgCPSHist] + ' seconds') : ((CM.Disp.cookieTimes[CM.Config.AvgCPSHist] / 60) + (CM.Config.AvgCPSHist == 3 ? ' minute' : ' minutes'))) + ')', @@ -3274,6 +3262,42 @@ CM.Disp.AddMenuStats = function(title) { } l('menu').insertBefore(stats, l('menu').childNodes[2]); + + if (CM.Config.MissingUpgrades) { + CM.Disp.AddMissingUpgrades(); + } +} + +/** + * This function creates a header-object for the stats page + * It is called by CM.Disp.AddMenuStats() + * @param {string} config The name of the Config-group + * @param {string} text The to-be displayed name of the header + * @returns {object} div The header object + */ +CM.Disp.CreateStatsHeader = function(text, config) { + var div = document.createElement('div'); + div.className = 'listing'; + div.style.padding = '5px 16px'; + div.style.opacity = '0.7'; + div.style.fontSize = '17px'; + div.style.fontFamily = '\"Kavoon\", Georgia, serif'; + div.appendChild(document.createTextNode(text + ' ')); + var span = document.createElement('span'); + span.style.cursor = 'pointer'; + span.style.display = 'inline-block'; + span.style.height = '14px'; + span.style.width = '14px'; + span.style.borderRadius = '7px'; + span.style.textAlign = 'center'; + span.style.backgroundColor = '#C0C0C0'; + span.style.color = 'black'; + span.style.fontSize = '13px'; + span.style.verticalAlign = 'middle'; + span.textContent = CM.Config.StatsPref[config] ? '-' : '+'; + span.onclick = function() {CM.ToggleStatsConfig(config); Game.UpdateMenu();}; + div.appendChild(span); + return div; } CM.Disp.AddMissingUpgrades = function() { @@ -3355,7 +3379,7 @@ CM.Disp.AddMissingUpgrades = function() { /******** * Section: Variables used in Disp functions - * TODO: Move certain variables to src/Data.js (e.g., CM.Disp.metric & CM.Disp.shortScale) */ + */ /** * This list is used to make some very basic tooltips. @@ -3374,9 +3398,16 @@ CM.Disp.TooltipText = [ ['ChoEggTooltipPlaceholder', 'The amount of cookies you would get from popping all wrinklers with Skruuia god in Diamond slot, selling all stock market goods, selling all buildings with Earth Shatterer and Reality Bending auras, and then buying Chocolate egg', '300px'] ]; +/** + * These are variables used to create DOM object names and id (e.g., 'CMTextTooltip) + */ CM.Disp.colorTextPre = 'CMText'; CM.Disp.colorBackPre = 'CMBack'; CM.Disp.colorBorderPre = 'CMBorder'; + +/** + * These are variables which can be set in the options by the user to standardize colours throughout CookieMonster + */ CM.Disp.colorBlue = 'Blue'; CM.Disp.colorGreen = 'Green'; CM.Disp.colorYellow = 'Yellow'; @@ -3387,25 +3418,28 @@ CM.Disp.colorGray = 'Gray'; CM.Disp.colorPink = 'Pink'; CM.Disp.colorBrown = 'Brown'; CM.Disp.colors = [CM.Disp.colorBlue, CM.Disp.colorGreen, CM.Disp.colorYellow, CM.Disp.colorOrange, CM.Disp.colorRed, CM.Disp.colorPurple, CM.Disp.colorGray, CM.Disp.colorPink, CM.Disp.colorBrown]; + + +/** + * This array is used to give certain timers specific colours + */ CM.Disp.buffColors = {'Frenzy': CM.Disp.colorYellow, 'Dragon Harvest': CM.Disp.colorBrown, 'Elder frenzy': CM.Disp.colorGreen, 'Clot': CM.Disp.colorRed, 'Click frenzy': CM.Disp.colorBlue, 'Dragonflight': CM.Disp.colorPink}; CM.Disp.GCTimers = {}; CM.Disp.lastAscendState = -1; - - +/** + * These lists are used in the stats page to show + * average cookies per {CM.Disp.cookieTimes/CM.Disp.clickTimes} seconds + */ CM.Disp.cookieTimes = [10, 15, 30, 60, 300, 600, 900, 1800]; CM.Disp.clickTimes = [1, 5, 10, 15, 30]; -CM.Disp.metric = ['', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y']; -CM.Disp.shortScale = ['', 'M', 'B', 'Tr', 'Quadr', 'Quint', 'Sext', 'Sept', 'Oct', 'Non', 'Dec', 'Undec', 'Duodec', 'Tredec', 'Quattuordec', 'Quindec', 'Sexdec', 'Septendec', 'Octodec', 'Novemdec', 'Vigint', 'Unvigint', 'Duovigint', 'Trevigint', 'Quattuorvigint']; - +/** + * These are variables with base-values that get initalized when initliazing CookieMonster + * TODO: See if these can be removed or moved + */ CM.Disp.TooltipWrinklerArea = 0; CM.Disp.TooltipWrinkler = -1; -CM.Disp.TooltipWrinklerCache = []; -for (var i in Game.wrinklers) { - CM.Disp.TooltipWrinklerCache[i] = 0; -} - /******** * Main * ********/ diff --git a/src/Data.js b/src/Data.js index e50b3ba..24a727e 100644 --- a/src/Data.js +++ b/src/Data.js @@ -32,6 +32,10 @@ CM.Data.ChristCookies = ['Christmas tree biscuits', 'Snowflake biscuits', 'Snowm CM.Data.ValCookies = ['Pure heart biscuits', 'Ardent heart biscuits', 'Sour heart biscuits', 'Weeping heart biscuits', 'Golden heart biscuits', 'Eternal heart biscuits', 'Prism heart biscuits']; +/******** + * Section: Data for the various scales used by CookieMonster */ +CM.Data.metric = ['', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y']; +CM.Data.shortScale = ['', 'M', 'B', 'Tr', 'Quadr', 'Quint', 'Sext', 'Sept', 'Oct', 'Non', 'Dec', 'Undec', 'Duodec', 'Tredec', 'Quattuordec', 'Quindec', 'Sexdec', 'Septendec', 'Octodec', 'Novemdec', 'Vigint', 'Unvigint', 'Duovigint', 'Trevigint', 'Quattuorvigint']; /******** * Section: An array containing all Config groups and their to-be displayed title */ diff --git a/src/Disp.js b/src/Disp.js index b4cb85a..35e7a12 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -12,11 +12,15 @@ * TODO: Annotate most functions * TODO: Sort functionsn in relevant (new) sections or files */ +CM.Disp.TooltipWrinklerCache = []; +for (var i in Game.wrinklers) { + CM.Disp.TooltipWrinklerCache[i] = 0; +} + /** * This function returns Name and Color as object for sugar lump type that is given as input param. * @param type Sugar Lump Type. * @returns {{text: string, color: string}} - * @constructor */ CM.Disp.GetLumpColor = function(type) { var name = ""; @@ -84,20 +88,7 @@ CM.Disp.AddJscolor = function() { document.head.appendChild(CM.Disp.Jscolor); } -CM.Disp.CreateCssArea = function() { - CM.Disp.Css = document.createElement('style'); - CM.Disp.Css.type = 'text/css'; - document.head.appendChild(CM.Disp.Css); - - // given the architecture of your code, you probably want these lines somewhere else, - // but I stuck them here for convenience - l("products").style.display = "grid"; - l("storeBulk").style.gridRow = "1/1"; - - l("upgrades").style.display = "flex"; - l("upgrades").style["flex-wrap"] = "wrap"; -} CM.Disp.UpdateUpgrades = function() { if (CM.Config.UpBarColor > 0) { @@ -255,6 +246,22 @@ CM.Disp.RefreshScale = function() { CM.Disp.UpdateBuildings(); CM.Disp.UpdateUpgrades(); } + +CM.Disp.CreateCssArea = function() { + CM.Disp.Css = document.createElement('style'); + CM.Disp.Css.type = 'text/css'; + + document.head.appendChild(CM.Disp.Css); + + // given the architecture of your code, you probably want these lines somewhere else, + // but I stuck them here for convenience + l("products").style.display = "grid"; + l("storeBulk").style.gridRow = "1/1"; + + l("upgrades").style.display = "flex"; + l("upgrades").style["flex-wrap"] = "wrap"; +} + /******** * Section: General functions to format or beautify strings */ @@ -361,16 +368,16 @@ CM.Disp.Beautify = function(num, frac, forced) { // answer is now "xxx.xx" (e.g., 123456789 would be 123.46) if (CM.Config.Scale == 1 && !forced || forced == 1) { // Metric scale, 123456789 => 123.457 M - if (timesTenToPowerThree - 1 < CM.Disp.metric.length) { - answer += ' ' + CM.Disp.metric[timesTenToPowerThree - 1] + if (timesTenToPowerThree - 1 < CM.Data.metric.length) { + answer += ' ' + CM.Data.metric[timesTenToPowerThree - 1] } else { // If number is too large, revert to scientific notation return CM.Disp.Beautify(num, 0, 3); } } else if (CM.Config.Scale == 2 && !forced || forced == 2) { // Short scale, 123456789 => 123.457 M - if (timesTenToPowerThree < CM.Disp.shortScale.length + 1) { - answer += ' ' + CM.Disp.shortScale[timesTenToPowerThree - 1]; + if (timesTenToPowerThree < CM.Data.shortScale.length + 1) { + answer += ' ' + CM.Data.shortScale[timesTenToPowerThree - 1]; } else { // If number is too large, revert to scientific notation return CM.Disp.Beautify(num, 0, 3); @@ -755,20 +762,19 @@ CM.Disp.UpdateBotTimerBarPosition = function() { /******** * Section: Functions related to column of buildings/objects - * TODO: Annotate functions */ +/** + * This function adjusts some things in the column of buildings. + * It colours them, helps display the correct sell-price and shuffles the order when CM.Config.SortBuildings is set + * The function is called by CM.Loop(), CM.Disp.UpdateColors() & CM.Disp.RefreshScale() + * And by changes in CM.Config.BuildColor, CM.Config.SortBuild & CM.ConfigData.BulkBuildColor + */ CM.Disp.UpdateBuildings = function() { if (CM.Config.BuildColor == 1 && Game.buyMode == 1) { var target = ''; - if (Game.buyBulk == 10 && CM.Config.BulkBuildColor == 1) { - target = 'Objects10'; - } - else if (Game.buyBulk == 100 && CM.Config.BulkBuildColor == 1) { - target = 'Objects100'; - } - else { - target = 'Objects'; - } + if (Game.buyBulk == 10 && CM.Config.BulkBuildColor == 1) target = 'Objects10'; + else if (Game.buyBulk == 100 && CM.Config.BulkBuildColor == 1) target = 'Objects100'; + else target = 'Objects'; for (var i in CM.Cache[target]) { l('productPrice' + Game.Objects[i].id).style.color = CM.Config.Colors[CM.Cache[target][i].color]; } @@ -1770,6 +1776,10 @@ CM.Disp.UpdateWrinklerTooltip = function() { * Section: General functions related to the Options/Stats pages * TODO: Annotate functions */ +/** + * This function adds the calll the functions to add extra info to the stats and options pages + * It is called by Game.UpdateMenu() + */ CM.Disp.AddMenu = function() { var title = function() { var div = document.createElement('div'); @@ -1785,13 +1795,13 @@ CM.Disp.AddMenu = function() { if (CM.Config.Stats) { CM.Disp.AddMenuStats(title); } - - if (CM.Config.MissingUpgrades) { - CM.Disp.AddMissingUpgrades(); - } } } +/** + * This function refreshes the stats page, CM.Config.UpStats determines the rate at which that happens + * It is called by CM.Loop() + */ CM.Disp.RefreshMenu = function() { if (CM.Config.UpStats && Game.onMenu == 'stats' && (Game.drawT - 1) % (Game.fps * 5) != 0 && (Game.drawT - 1) % Game.fps == 0) Game.UpdateMenu(); } @@ -1838,9 +1848,9 @@ CM.Disp.AddMenuPref = function(title) { /** * This function creates a header-object for the options page * It is called by CM.Disp.AddMenuPref() - * @param {string} config The name of the Config-group - * @param {string} text The to-be displayed name of the header - * @returns {object} div The header object + * @param {string} config The name of the Config-group + * @param {string} text The to-be displayed name of the header + * @returns {object} div The header object */ CM.Disp.CreatePrefHeader = function(config, text) { var div = document.createElement('div'); @@ -1870,8 +1880,8 @@ CM.Disp.CreatePrefHeader = function(config, text) { /** * This function creates an option-object for the options page * It is called by CM.Disp.AddMenuPref() - * @param {string} config The name of the option - * @returns {object} div The option object + * @param {string} config The name of the option + * @returns {object} div The option object */ CM.Disp.CreatePrefOption = function(config) { if (CM.ConfigData[config].type == "bool") { @@ -1972,34 +1982,8 @@ CM.Disp.CreatePrefOption = function(config) { * TODO: Annotate functions */ CM.Disp.AddMenuStats = function(title) { - var header = function(text, config) { - var div = document.createElement('div'); - div.className = 'listing'; - div.style.padding = '5px 16px'; - div.style.opacity = '0.7'; - div.style.fontSize = '17px'; - div.style.fontFamily = '\"Kavoon\", Georgia, serif'; - div.appendChild(document.createTextNode(text + ' ')); - var span = document.createElement('span'); - span.style.cursor = 'pointer'; - span.style.display = 'inline-block'; - span.style.height = '14px'; - span.style.width = '14px'; - span.style.borderRadius = '7px'; - span.style.textAlign = 'center'; - span.style.backgroundColor = '#C0C0C0'; - span.style.color = 'black'; - span.style.fontSize = '13px'; - span.style.verticalAlign = 'middle'; - span.textContent = CM.Config.StatsPref[config] ? '-' : '+'; - span.onclick = function() {CM.ToggleStatsConfig(config); Game.UpdateMenu();}; - div.appendChild(span); - return div; - } - var stats = document.createElement('div'); stats.className = 'subsection'; - stats.appendChild(title()); var listing = function(name, text) { @@ -2075,7 +2059,7 @@ CM.Disp.AddMenuStats = function(title) { var goldCookTooltip = CM.Sim.auraMult('Dragon\'s Fortune') ? 'GoldCookDragonsFortuneTooltipPlaceholder' : 'GoldCookTooltipPlaceholder'; - stats.appendChild(header('Lucky Cookies', 'Lucky')); + stats.appendChild(CreateStatsHeader('Lucky Cookies', 'Lucky')); if (CM.Config.StatsPref.Lucky) { var luckyColor = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.Lucky) ? CM.Disp.colorRed : CM.Disp.colorGreen; var luckyTime = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.Lucky) ? CM.Disp.FormatTime((CM.Cache.Lucky - (Game.cookies + CM.Disp.GetWrinkConfigBank())) / CM.Disp.GetCPS()) : ''; @@ -2119,7 +2103,7 @@ CM.Disp.AddMenuStats = function(title) { stats.appendChild(listing(listingQuest('\"Lucky!\" Reward (CUR)' + (luckySplit ? ' (Golden / Wrath)' : ''), goldCookTooltip), document.createTextNode(Beautify(luckyCur) + (luckySplit ? (' / ' + Beautify(luckyCurWrath)) : '')))); } - stats.appendChild(header('Chain Cookies', 'Chain')); + stats.appendChild(CreateStatsHeader('Chain Cookies', 'Chain')); if (CM.Config.StatsPref.Chain) { var chainColor = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.Chain) ? CM.Disp.colorRed : CM.Disp.colorGreen; var chainTime = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.Chain) ? CM.Disp.FormatTime((CM.Cache.Chain - (Game.cookies + CM.Disp.GetWrinkConfigBank())) / CM.Disp.GetCPS()) : ''; @@ -2192,7 +2176,7 @@ CM.Disp.AddMenuStats = function(title) { stats.appendChild(listing(listingQuest('\"Chain\" Reward (CUR) (Golden / Wrath)', goldCookTooltip), document.createTextNode(Beautify(chainCur) + ' / ' + Beautify(chainCurWrath)))); } - stats.appendChild(header('Conjure Baked Goods', 'Conjure')); + stats.appendChild(CreateStatsHeader('Conjure Baked Goods', 'Conjure')); if (CM.Config.StatsPref.Conjure) { var conjureColor = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.Conjure) ? CM.Disp.colorRed : CM.Disp.colorGreen; var conjureCur = Math.min((Game.cookies + CM.Disp.GetWrinkConfigBank()) * 0.15, CM.Cache.NoGoldSwitchCookiesPS * 60 * 30); @@ -2217,7 +2201,7 @@ CM.Disp.AddMenuStats = function(title) { var choEgg = (Game.HasUnlocked('Chocolate egg') && !Game.Has('Chocolate egg')); // Needs to be done for the checking below - stats.appendChild(header('Prestige', 'Prestige')); + stats.appendChild(CreateStatsHeader('Prestige', 'Prestige')); if (CM.Config.StatsPref.Prestige) { var possiblePresMax = Math.floor(Game.HowMuchPrestige(CM.Cache.RealCookiesEarned + Game.cookiesReset + CM.Cache.WrinkGodBank + (choEgg ? CM.Cache.lastChoEgg : 0))); var neededCook = Game.HowManyCookiesReset(possiblePresMax + 1) - (CM.Cache.RealCookiesEarned + Game.cookiesReset + CM.Cache.WrinkGodBank + (choEgg ? CM.Cache.lastChoEgg : 0)); @@ -2295,7 +2279,7 @@ CM.Disp.AddMenuStats = function(title) { } if (Game.cpsSucked > 0) { - stats.appendChild(header('Wrinklers', 'Wrink')); + stats.appendChild(CreateStatsHeader('Wrinklers', 'Wrink')); if (CM.Config.StatsPref.Wrink) { var popAllFrag = document.createDocumentFragment(); popAllFrag.appendChild(document.createTextNode(Beautify(CM.Cache.WrinkBank) + ' ')); @@ -2348,7 +2332,7 @@ CM.Disp.AddMenuStats = function(title) { var centEgg = Game.Has('Century egg'); if (Game.season == 'christmas' || specDisp || choEgg || centEgg) { - stats.appendChild(header('Season Specials', 'Sea')); + stats.appendChild(CreateStatsHeader('Season Specials', 'Sea')); if (CM.Config.StatsPref.Sea) { if (specDisp) { if (halloCook.length != 0) stats.appendChild(listing('Halloween Cookies Left to Buy', createMissDisp(halloCook))); @@ -2368,7 +2352,7 @@ CM.Disp.AddMenuStats = function(title) { } } - stats.appendChild(header('Miscellaneous', 'Misc')); + stats.appendChild(CreateStatsHeader('Miscellaneous', 'Misc')); if (CM.Config.StatsPref.Misc) { stats.appendChild(listing( 'Average Cookies Per Second (Past ' + (CM.Disp.cookieTimes[CM.Config.AvgCPSHist] < 60 ? (CM.Disp.cookieTimes[CM.Config.AvgCPSHist] + ' seconds') : ((CM.Disp.cookieTimes[CM.Config.AvgCPSHist] / 60) + (CM.Config.AvgCPSHist == 3 ? ' minute' : ' minutes'))) + ')', @@ -2392,6 +2376,42 @@ CM.Disp.AddMenuStats = function(title) { } l('menu').insertBefore(stats, l('menu').childNodes[2]); + + if (CM.Config.MissingUpgrades) { + CM.Disp.AddMissingUpgrades(); + } +} + +/** + * This function creates a header-object for the stats page + * It is called by CM.Disp.AddMenuStats() + * @param {string} config The name of the Config-group + * @param {string} text The to-be displayed name of the header + * @returns {object} div The header object + */ +CM.Disp.CreateStatsHeader = function(text, config) { + var div = document.createElement('div'); + div.className = 'listing'; + div.style.padding = '5px 16px'; + div.style.opacity = '0.7'; + div.style.fontSize = '17px'; + div.style.fontFamily = '\"Kavoon\", Georgia, serif'; + div.appendChild(document.createTextNode(text + ' ')); + var span = document.createElement('span'); + span.style.cursor = 'pointer'; + span.style.display = 'inline-block'; + span.style.height = '14px'; + span.style.width = '14px'; + span.style.borderRadius = '7px'; + span.style.textAlign = 'center'; + span.style.backgroundColor = '#C0C0C0'; + span.style.color = 'black'; + span.style.fontSize = '13px'; + span.style.verticalAlign = 'middle'; + span.textContent = CM.Config.StatsPref[config] ? '-' : '+'; + span.onclick = function() {CM.ToggleStatsConfig(config); Game.UpdateMenu();}; + div.appendChild(span); + return div; } CM.Disp.AddMissingUpgrades = function() { @@ -2473,7 +2493,7 @@ CM.Disp.AddMissingUpgrades = function() { /******** * Section: Variables used in Disp functions - * TODO: Move certain variables to src/Data.js (e.g., CM.Disp.metric & CM.Disp.shortScale) */ + */ /** * This list is used to make some very basic tooltips. @@ -2492,9 +2512,16 @@ CM.Disp.TooltipText = [ ['ChoEggTooltipPlaceholder', 'The amount of cookies you would get from popping all wrinklers with Skruuia god in Diamond slot, selling all stock market goods, selling all buildings with Earth Shatterer and Reality Bending auras, and then buying Chocolate egg', '300px'] ]; +/** + * These are variables used to create DOM object names and id (e.g., 'CMTextTooltip) + */ CM.Disp.colorTextPre = 'CMText'; CM.Disp.colorBackPre = 'CMBack'; CM.Disp.colorBorderPre = 'CMBorder'; + +/** + * These are variables which can be set in the options by the user to standardize colours throughout CookieMonster + */ CM.Disp.colorBlue = 'Blue'; CM.Disp.colorGreen = 'Green'; CM.Disp.colorYellow = 'Yellow'; @@ -2505,22 +2532,25 @@ CM.Disp.colorGray = 'Gray'; CM.Disp.colorPink = 'Pink'; CM.Disp.colorBrown = 'Brown'; CM.Disp.colors = [CM.Disp.colorBlue, CM.Disp.colorGreen, CM.Disp.colorYellow, CM.Disp.colorOrange, CM.Disp.colorRed, CM.Disp.colorPurple, CM.Disp.colorGray, CM.Disp.colorPink, CM.Disp.colorBrown]; + + +/** + * This array is used to give certain timers specific colours + */ CM.Disp.buffColors = {'Frenzy': CM.Disp.colorYellow, 'Dragon Harvest': CM.Disp.colorBrown, 'Elder frenzy': CM.Disp.colorGreen, 'Clot': CM.Disp.colorRed, 'Click frenzy': CM.Disp.colorBlue, 'Dragonflight': CM.Disp.colorPink}; CM.Disp.GCTimers = {}; CM.Disp.lastAscendState = -1; - - +/** + * These lists are used in the stats page to show + * average cookies per {CM.Disp.cookieTimes/CM.Disp.clickTimes} seconds + */ CM.Disp.cookieTimes = [10, 15, 30, 60, 300, 600, 900, 1800]; CM.Disp.clickTimes = [1, 5, 10, 15, 30]; -CM.Disp.metric = ['', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y']; -CM.Disp.shortScale = ['', 'M', 'B', 'Tr', 'Quadr', 'Quint', 'Sext', 'Sept', 'Oct', 'Non', 'Dec', 'Undec', 'Duodec', 'Tredec', 'Quattuordec', 'Quindec', 'Sexdec', 'Septendec', 'Octodec', 'Novemdec', 'Vigint', 'Unvigint', 'Duovigint', 'Trevigint', 'Quattuorvigint']; - +/** + * These are variables with base-values that get initalized when initliazing CookieMonster + * TODO: See if these can be removed or moved + */ CM.Disp.TooltipWrinklerArea = 0; CM.Disp.TooltipWrinkler = -1; -CM.Disp.TooltipWrinklerCache = []; -for (var i in Game.wrinklers) { - CM.Disp.TooltipWrinklerCache[i] = 0; -} - From e0915bc3075c3718088e4e5bcc2d75eef30f2dbc Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Sat, 5 Dec 2020 14:10:42 +0100 Subject: [PATCH 028/106] Fix CM.Disp.Beautify failing when num=0 --- CookieMonster.js | 2 +- src/Disp.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index 66c9b12..00e9ea1 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -1273,7 +1273,7 @@ CM.Disp.Beautify = function(num, frac, forced) { answer += 'E+' + (timesTenToPowerThree * 3); } } - if (answer == '') { + if (answer === '') { console.log("Could not beautify number with CM.Disp.Beautify"); answer = CM.Backup.Beautify(num, frac); } diff --git a/src/Disp.js b/src/Disp.js index 35e7a12..1898582 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -387,7 +387,7 @@ CM.Disp.Beautify = function(num, frac, forced) { answer += 'E+' + (timesTenToPowerThree * 3); } } - if (answer == '') { + if (answer === '') { console.log("Could not beautify number with CM.Disp.Beautify"); answer = CM.Backup.Beautify(num, frac); } From b6cdc77064cd87efa816c17eb91d5f2cba156e37 Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Sat, 5 Dec 2020 14:27:48 +0100 Subject: [PATCH 029/106] Fixed Warning tooltips --- CookieMonster.js | 23 +++++++++++++++-------- src/Disp.js | 23 +++++++++++++++-------- 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index 00e9ea1..dbf3981 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -2329,6 +2329,11 @@ CM.Disp.UpdateTooltip = function() { } CM.Disp.UpdateTooltipWarnings(); } + else if (l('CMTooltipArea') == null) { // Remove warnings if its a basic tooltip + if (l('CMDispTooltipWarningParent') != null) { + l('CMDispTooltipWarningParent').remove(); + } + } } /** @@ -2347,7 +2352,7 @@ CM.Disp.UpdateTooltipBuilding = function() { else if (Game.buyMode == 1 && Game.buyBulk == 100) target = 'Objects100'; else target = 'Objects'; - var price = Game.Objects[CM.Disp.tooltipName].bulkPrice + CM.Disp.TooltipPrice = Game.Objects[CM.Disp.tooltipName].bulkPrice CM.Disp.TooltipBonusIncome = CM.Cache[target][CM.Disp.tooltipName].bonus; @@ -2360,7 +2365,7 @@ CM.Disp.UpdateTooltipBuilding = function() { l('CMTooltipBorder').className = CM.Disp.colorTextPre + CM.Cache[target][CM.Disp.tooltipName].color; l('CMTooltipPP').textContent = Beautify(CM.Cache[target][CM.Disp.tooltipName].pp, 2); l('CMTooltipPP').className = CM.Disp.colorTextPre + CM.Cache[target][CM.Disp.tooltipName].color; - var timeColor = CM.Disp.GetTimeColor((price - (Game.cookies + CM.Disp.GetWrinkConfigBank())) / CM.Disp.GetCPS()); + var timeColor = CM.Disp.GetTimeColor((CM.Disp.TooltipPrice - (Game.cookies + CM.Disp.GetWrinkConfigBank())) / CM.Disp.GetCPS()); l('CMTooltipTime').textContent = timeColor.text; l('CMTooltipTime').className = CM.Disp.colorTextPre + timeColor.color; } @@ -2394,7 +2399,7 @@ CM.Disp.UpdateTooltipUpgrade = function() { CM.Disp.TooltipCreateCalculationSection(tooltipBox); CM.Disp.TooltipBonusIncome = CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].bonus; - price = Game.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].getPrice(); + CM.Disp.TooltipPrice = Game.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].getPrice(); if (CM.Config.TooltipBuildUp == 1) { l('CMTooltipIncome').textContent = Beautify(CM.Disp.TooltipBonusIncome, 2); @@ -2405,7 +2410,7 @@ CM.Disp.UpdateTooltipUpgrade = function() { l('CMTooltipBorder').className = CM.Disp.colorTextPre + CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].color; l('CMTooltipPP').textContent = Beautify(CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].pp, 2); l('CMTooltipPP').className = CM.Disp.colorTextPre + CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].color; - var timeColor = CM.Disp.GetTimeColor((price - (Game.cookies + CM.Disp.GetWrinkConfigBank())) / CM.Disp.GetCPS()); + var timeColor = CM.Disp.GetTimeColor((CM.Disp.TooltipPrice - (Game.cookies + CM.Disp.GetWrinkConfigBank())) / CM.Disp.GetCPS()); l('CMTooltipTime').textContent = timeColor.text; l('CMTooltipTime').className = CM.Disp.colorTextPre + timeColor.color; } @@ -2492,9 +2497,10 @@ CM.Disp.UpdateTooltipGrimoire = function() { */ CM.Disp.UpdateTooltipWarnings = function() { if (CM.Disp.tooltipType == "b" || CM.Disp.tooltipType == "u") { - if (document.getElementById("tooltipWarn") == null) { + if (document.getElementById("CMDispTooltipWarningParent") == null) { warningTooltip = CM.Disp.TooltipCreateWarningSection(); l('tooltipAnchor').appendChild(warningTooltip); + CM.Disp.ToggleToolWarnPos(); } if (CM.Config.ToolWarnPos == 0) CM.Disp.TooltipWarn.style.right = '0px'; @@ -2510,7 +2516,7 @@ CM.Disp.UpdateTooltipWarnings = function() { limitLucky += ((bonusNoFren * 60 * 15) / 0.15); } var limitLuckyFrenzy = limitLucky * 7; - var amount = (Game.cookies + CM.Disp.GetWrinkConfigBank()) - price; + var amount = (Game.cookies + CM.Disp.GetWrinkConfigBank()) - CM.Disp.TooltipPrice; if ((amount < limitLucky || amount < limitLuckyFrenzy) && (CM.Disp.tooltipType != 'b' || Game.buyMode == 1)) { if (amount < limitLucky) { l('CMDispTooltipWarnLucky').style.display = ''; @@ -2541,7 +2547,7 @@ CM.Disp.UpdateTooltipWarnings = function() { limitLucky += ((bonusNoFren * 60 * 15) / 0.15); } var limitConjure = limitLucky * 2; - var amount = (Game.cookies + CM.Disp.GetWrinkConfigBank()) - price; + var amount = (Game.cookies + CM.Disp.GetWrinkConfigBank()) - CM.Disp.TooltipPrice; if ((amount < limitConjure) && (CM.Disp.tooltipType != 'b' || Game.buyMode == 1)) { l('CMDispTooltipWarnConjure').style.display = ''; l('CMDispTooltipWarnConjureText').textContent = Beautify(limitConjure - amount) + ' (' + CM.Disp.FormatTime((limitConjure - amount) / CM.Disp.GetCPS()) + ')'; @@ -2580,7 +2586,8 @@ CM.Disp.UpdateTooltipLocation = function() { /** * This function toggles the position of the warnings created by CM.Disp.TooltipCreateWarningSection() - * It is called by a change in CM.Config.ToolWarnPos + * It is called by a change in CM.Config.ToolWarnPos + * and upon creation of the warning tooltip by CM.Disp.UpdateTooltipWarnings() */ CM.Disp.ToggleToolWarnPos = function() { if (typeof CM.Disp.TooltipWarn != "undefined") { diff --git a/src/Disp.js b/src/Disp.js index 1898582..e019436 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -1443,6 +1443,11 @@ CM.Disp.UpdateTooltip = function() { } CM.Disp.UpdateTooltipWarnings(); } + else if (l('CMTooltipArea') == null) { // Remove warnings if its a basic tooltip + if (l('CMDispTooltipWarningParent') != null) { + l('CMDispTooltipWarningParent').remove(); + } + } } /** @@ -1461,7 +1466,7 @@ CM.Disp.UpdateTooltipBuilding = function() { else if (Game.buyMode == 1 && Game.buyBulk == 100) target = 'Objects100'; else target = 'Objects'; - var price = Game.Objects[CM.Disp.tooltipName].bulkPrice + CM.Disp.TooltipPrice = Game.Objects[CM.Disp.tooltipName].bulkPrice CM.Disp.TooltipBonusIncome = CM.Cache[target][CM.Disp.tooltipName].bonus; @@ -1474,7 +1479,7 @@ CM.Disp.UpdateTooltipBuilding = function() { l('CMTooltipBorder').className = CM.Disp.colorTextPre + CM.Cache[target][CM.Disp.tooltipName].color; l('CMTooltipPP').textContent = Beautify(CM.Cache[target][CM.Disp.tooltipName].pp, 2); l('CMTooltipPP').className = CM.Disp.colorTextPre + CM.Cache[target][CM.Disp.tooltipName].color; - var timeColor = CM.Disp.GetTimeColor((price - (Game.cookies + CM.Disp.GetWrinkConfigBank())) / CM.Disp.GetCPS()); + var timeColor = CM.Disp.GetTimeColor((CM.Disp.TooltipPrice - (Game.cookies + CM.Disp.GetWrinkConfigBank())) / CM.Disp.GetCPS()); l('CMTooltipTime').textContent = timeColor.text; l('CMTooltipTime').className = CM.Disp.colorTextPre + timeColor.color; } @@ -1508,7 +1513,7 @@ CM.Disp.UpdateTooltipUpgrade = function() { CM.Disp.TooltipCreateCalculationSection(tooltipBox); CM.Disp.TooltipBonusIncome = CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].bonus; - price = Game.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].getPrice(); + CM.Disp.TooltipPrice = Game.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].getPrice(); if (CM.Config.TooltipBuildUp == 1) { l('CMTooltipIncome').textContent = Beautify(CM.Disp.TooltipBonusIncome, 2); @@ -1519,7 +1524,7 @@ CM.Disp.UpdateTooltipUpgrade = function() { l('CMTooltipBorder').className = CM.Disp.colorTextPre + CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].color; l('CMTooltipPP').textContent = Beautify(CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].pp, 2); l('CMTooltipPP').className = CM.Disp.colorTextPre + CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].color; - var timeColor = CM.Disp.GetTimeColor((price - (Game.cookies + CM.Disp.GetWrinkConfigBank())) / CM.Disp.GetCPS()); + var timeColor = CM.Disp.GetTimeColor((CM.Disp.TooltipPrice - (Game.cookies + CM.Disp.GetWrinkConfigBank())) / CM.Disp.GetCPS()); l('CMTooltipTime').textContent = timeColor.text; l('CMTooltipTime').className = CM.Disp.colorTextPre + timeColor.color; } @@ -1606,9 +1611,10 @@ CM.Disp.UpdateTooltipGrimoire = function() { */ CM.Disp.UpdateTooltipWarnings = function() { if (CM.Disp.tooltipType == "b" || CM.Disp.tooltipType == "u") { - if (document.getElementById("tooltipWarn") == null) { + if (document.getElementById("CMDispTooltipWarningParent") == null) { warningTooltip = CM.Disp.TooltipCreateWarningSection(); l('tooltipAnchor').appendChild(warningTooltip); + CM.Disp.ToggleToolWarnPos(); } if (CM.Config.ToolWarnPos == 0) CM.Disp.TooltipWarn.style.right = '0px'; @@ -1624,7 +1630,7 @@ CM.Disp.UpdateTooltipWarnings = function() { limitLucky += ((bonusNoFren * 60 * 15) / 0.15); } var limitLuckyFrenzy = limitLucky * 7; - var amount = (Game.cookies + CM.Disp.GetWrinkConfigBank()) - price; + var amount = (Game.cookies + CM.Disp.GetWrinkConfigBank()) - CM.Disp.TooltipPrice; if ((amount < limitLucky || amount < limitLuckyFrenzy) && (CM.Disp.tooltipType != 'b' || Game.buyMode == 1)) { if (amount < limitLucky) { l('CMDispTooltipWarnLucky').style.display = ''; @@ -1655,7 +1661,7 @@ CM.Disp.UpdateTooltipWarnings = function() { limitLucky += ((bonusNoFren * 60 * 15) / 0.15); } var limitConjure = limitLucky * 2; - var amount = (Game.cookies + CM.Disp.GetWrinkConfigBank()) - price; + var amount = (Game.cookies + CM.Disp.GetWrinkConfigBank()) - CM.Disp.TooltipPrice; if ((amount < limitConjure) && (CM.Disp.tooltipType != 'b' || Game.buyMode == 1)) { l('CMDispTooltipWarnConjure').style.display = ''; l('CMDispTooltipWarnConjureText').textContent = Beautify(limitConjure - amount) + ' (' + CM.Disp.FormatTime((limitConjure - amount) / CM.Disp.GetCPS()) + ')'; @@ -1694,7 +1700,8 @@ CM.Disp.UpdateTooltipLocation = function() { /** * This function toggles the position of the warnings created by CM.Disp.TooltipCreateWarningSection() - * It is called by a change in CM.Config.ToolWarnPos + * It is called by a change in CM.Config.ToolWarnPos + * and upon creation of the warning tooltip by CM.Disp.UpdateTooltipWarnings() */ CM.Disp.ToggleToolWarnPos = function() { if (typeof CM.Disp.TooltipWarn != "undefined") { From 77447cfca38a131d80e8eca496d6d6ad3d465fdd Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Sat, 5 Dec 2020 15:44:33 +0100 Subject: [PATCH 030/106] Further revision of Disp.js --- CookieMonster.js | 536 +++++++++++++++++++++++++---------------------- src/Config.js | 4 +- src/Data.js | 5 +- src/Disp.js | 488 +++++++++++++++++++++--------------------- src/Main.js | 38 +++- 5 files changed, 569 insertions(+), 502 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index dbf3981..d6a1001 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -647,7 +647,7 @@ CM.ToggleConfigUp = function(config) { if (typeof CM.ConfigData[config].func !== 'undefined') { CM.ConfigData[config].func(); } - l(CM.ConfigPrefix + config).innerHTML = CM.Disp.GetConfigDisplay(config); + l(CM.ConfigPrefix + config).innerHTML = CM.ConfigData[config].label[CM.Config[config]]; CM.SaveConfig(CM.Config); } @@ -659,7 +659,7 @@ CM.ToggleConfigDown = function(config) { if (typeof CM.ConfigData[config].func !== 'undefined') { CM.ConfigData[config].func(); } - l(CM.ConfigPrefix + config).innerHTML = CM.Disp.GetConfigDisplay(config); + l(CM.ConfigPrefix + config).innerHTML = CM.ConfigData[config].label[CM.Config[config]]; CM.SaveConfig(CM.Config); } @@ -880,33 +880,70 @@ CM.ConfigData.Stats = {type: 'bool', group: 'Statistics', label: ['Statistics OF CM.ConfigData.MissingUpgrades = {type: 'bool', group: 'Statistics', label: ['Missing Upgrades OFF', 'Missing Upgrades ON'], desc: 'Shows Missing upgrades in Stats Menu. This feature can be laggy for users with a low amount of unlocked achievements.', toggle: true}; CM.ConfigData.UpStats = {type: 'bool', group: 'Statistics', label: ['Statistics Update Rate (Default)', 'Statistics Update Rate (1s)'], desc: 'Default Game rate is once every 5 seconds', toggle: false}; CM.ConfigData.TimeFormat = {type: 'bool', group: 'Statistics', label: ['Time XXd, XXh, XXm, XXs', 'Time XX:XX:XX:XX:XX'], desc: 'Change the time format', toggle: false}; -CM.ConfigData.SayTime = {type: 'bool', group: 'Statistics', label: ['Format Time OFF', 'Format Time ON'], desc: 'Change how time is displayed in statistics', toggle: true, func: function() {CM.Disp.ToggleSayTime();}}; +CM.ConfigData.DetailedTime = {type: 'bool', group: 'Statistics', label: ['Detailed Time OFF', 'Detailed Time ON'], desc: 'Change how time is displayed in certain statistics and tooltips', toggle: true, func: function() {CM.Disp.ToggleDetailedTime();}}; CM.ConfigData.GrimoireBar = {type: 'bool', group: 'Statistics', label: ['Grimoire Magic Meter Timer OFF', 'Grimoire Magic Meter Timer ON'], desc: 'A timer on how long before the Grimoire magic meter is full', toggle: true}; // Statistics -CM.ConfigData.Scale = {type: 'bool', group: 'Other', label: ['Game\'s Setting Scale', 'Metric', 'Short Scale', 'Scientific Notation', 'Engineering Notation'], desc: 'Change how long numbers are handled', toggle: false, func: function() {CM.Disp.RefreshScale();}};/******** +CM.ConfigData.Scale = {type: 'bool', group: 'Other', label: ['Game\'s Setting Scale', 'Metric', 'Short Scale', 'Scientific Notation', 'Engineering Notation'], desc: 'Change how long numbers are handled', toggle: false, func: function() {CM.Disp.RefreshScale();}}; + +/******** * Disp * ********/ /******** - * Please make sure to annotate your code correctly. See the options page section for some examples. + * Please make sure to annotate your code correctly using JSDoc. See the options page section for some examples. * Only put functions related to graphics and displays in this file. - * All calculations and data should be put in others. */ + * All calculations and data should preferrably be put in other files. */ /******** - * Section: Unsorted functions - * TODO: Annotate most functions - * TODO: Sort functionsn in relevant (new) sections or files */ + * Section: Auxilirary functions used by other functions -CM.Disp.TooltipWrinklerCache = []; -for (var i in Game.wrinklers) { - CM.Disp.TooltipWrinklerCache[i] = 0; +/** + * This function returns the total amount stored in the Wrinkler Bank + * as calculated by CM.Cache.RemakeWrinkBank() if CM.Config.CalcWrink is set + * @returns {number} 0 or the amount of cookies stored (CM.Cache.WrinkBank) + */ +CM.Disp.GetWrinkConfigBank = function() { + if (CM.Config.CalcWrink) + return CM.Cache.WrinkBank; + else + return 0; +} + +/** + * This function returns the cps as either current or average CPS depending on CM.Config.CPSMode + * @returns {number} The average or current cps + */ +CM.Disp.GetCPS = function() { + if (CM.Config.CPSMode) + return CM.Cache.AvgCPS; + else + return (Game.cookiesPs * (1 - Game.cpsSucked)); +} + +/** + * This function calculates the time it takes to reach a certain magic level + * It is called by CM.Disp.UpdateTooltipGrimoire() + * @param {number} currentMagic The current magic level + * @param {number} maxMagic The user's max magic level + * @param {number} targetMagic The target magic level + * @returns {number} count / Game.fps The time it takes to reach targetMagic + */ +CM.Disp.CalculateGrimoireRefillTime = function(currentMagic, maxMagic, targetMagic) { + var count = 0; + while (currentMagic < targetMagic) { + currentMagic += Math.max(0.002, Math.pow(currentMagic / Math.max(maxMagic, 100), 0.5)) * 0.002; + count++; + } + return count / Game.fps; } /** * This function returns Name and Color as object for sugar lump type that is given as input param. - * @param type Sugar Lump Type. - * @returns {{text: string, color: string}} + * It is called by CM.Disp.UpdateTooltipSugarLump() + * TODO: Can't this be done with a normal array in Data.js? Or as variable-array at end of this file? + * @param {string} type Sugar Lump Type. + * @returns {{string}, {string}} text, color An array containing the text and display-color of the sugar lump */ CM.Disp.GetLumpColor = function(type) { var name = ""; @@ -942,212 +979,6 @@ CM.Disp.GetLumpColor = function(type) { return {text: name, color: color}; }; -CM.Disp.GetWrinkConfigBank = function() { - if (CM.Config.CalcWrink) - return CM.Cache.WrinkBank; - else - return 0; -} - -CM.Disp.GetCPS = function() { - if (CM.Config.CPSMode) - return CM.Cache.AvgCPS; - else - return (Game.cookiesPs * (1 - Game.cpsSucked)); -} - -CM.Disp.UpdateBackground = function() { - Game.Background.canvas.width = Game.Background.canvas.parentNode.offsetWidth; - Game.Background.canvas.height = Game.Background.canvas.parentNode.offsetHeight; - Game.LeftBackground.canvas.width = Game.LeftBackground.canvas.parentNode.offsetWidth; - Game.LeftBackground.canvas.height = Game.LeftBackground.canvas.parentNode.offsetHeight; -} - -CM.Disp.GetConfigDisplay = function(config) { - return CM.ConfigData[config].label[CM.Config[config]]; -} - -CM.Disp.AddJscolor = function() { - CM.Disp.Jscolor = document.createElement('script'); - CM.Disp.Jscolor.type = 'text/javascript'; - CM.Disp.Jscolor.setAttribute('src', 'https://aktanusa.github.io/CookieMonster/jscolor/jscolor.js'); - document.head.appendChild(CM.Disp.Jscolor); -} - - - -CM.Disp.UpdateUpgrades = function() { - if (CM.Config.UpBarColor > 0) { - var blue = 0; - var green = 0; - var yellow = 0; - var orange = 0; - var red = 0; - var purple = 0; - var gray = 0; - - for (var i in Game.UpgradesInStore) { - var me = Game.UpgradesInStore[i]; - var addedColor = false; - for (var j = 0; j < l('upgrade' + i).childNodes.length; j++) { - if (l('upgrade' + i).childNodes[j].className.indexOf(CM.Disp.colorBackPre) != -1) { - l('upgrade' + i).childNodes[j].className = CM.Disp.colorBackPre + CM.Cache.Upgrades[me.name].color; - addedColor = true; - break; - } - } - if (!addedColor) { - var div = document.createElement('div'); - div.style.width = '10px'; - div.style.height = '10px'; - div.className = CM.Disp.colorBackPre + CM.Cache.Upgrades[me.name].color; - l('upgrade' + i).appendChild(div); - } - if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorBlue) blue++; - else if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorGreen) green++; - else if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorYellow) yellow++; - else if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorOrange) orange++; - else if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorRed) red++; - else if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorPurple) purple++; - else if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorGray) gray++; - } - - l('CMUpgradeBarBlue').textContent = blue; - l('CMUpgradeBarGreen').textContent = green; - l('CMUpgradeBarYellow').textContent = yellow; - l('CMUpgradeBarOrange').textContent = orange; - l('CMUpgradeBarRed').textContent = red; - l('CMUpgradeBarPurple').textContent = purple; - l('CMUpgradeBarGray').textContent = gray; - } - - // Build array of pointers, sort by pp, set flex positions - var arr = []; - for (var x = 0; x < Game.UpgradesInStore.length; x++){ - var o = {}; - o.name = Game.UpgradesInStore[x].name; - o.price = Game.UpgradesInStore[x].basePrice; - o.pp = CM.Cache.Upgrades[o.name].pp; - arr.push(o); - } - - if (CM.Config.SortUpgrades) - arr.sort((a, b) => a.pp - b.pp); - else - arr.sort((a, b) => a.price - b.price); - - for (var x = 0; x < Game.UpgradesInStore.length; x++){ - l("upgrade" + x).style.order = arr.findIndex(e => e.name === Game.UpgradesInStore[x].name) + 1 - } -} - -CM.Disp.UpdateColors = function() { - var str = ''; - for (var i = 0; i < CM.Disp.colors.length; i++) { - str += '.' + CM.Disp.colorTextPre + CM.Disp.colors[i] + ' { color: ' + CM.Config.Colors[CM.Disp.colors[i]] + '; }\n'; - } - for (var i = 0; i < CM.Disp.colors.length; i++) { - str += '.' + CM.Disp.colorBackPre + CM.Disp.colors[i] + ' { background-color: ' + CM.Config.Colors[CM.Disp.colors[i]] + '; }\n'; - } - for (var i = 0; i < CM.Disp.colors.length; i++) { - str += '.' + CM.Disp.colorBorderPre + CM.Disp.colors[i] + ' { border: 1px solid ' + CM.Config.Colors[CM.Disp.colors[i]] + '; }\n'; - } - CM.Disp.Css.textContent = str; - CM.Disp.UpdateBuildings(); // Class has been already set -} - -CM.Disp.CollectWrinklers = function() { - for (var i in Game.wrinklers) { - if (Game.wrinklers[i].sucked > 0 && Game.wrinklers[i].type == 0) { - Game.wrinklers[i].hp = 0; - } - } -} - -CM.Disp.FixMouseY = function(target) { - if (CM.Config.TimerBar == 1 && CM.Config.TimerBarPos == 0) { - var timerBarHeight = parseInt(CM.Disp.TimerBar.style.height); - Game.mouseY -= timerBarHeight; - target(); - Game.mouseY += timerBarHeight; - } - else { - target(); - } -} - -CM.Disp.CalculateGrimoireRefillTime = function(currentMagic, maxMagic, targetMagic) { - var count = 0; - while (currentMagic < targetMagic) { - currentMagic += Math.max(0.002, Math.pow(currentMagic / Math.max(maxMagic, 100), 0.5)) * 0.002; - count++; - } - return count / Game.fps; -} - - - -CM.Disp.UpdateAscendState = function() { - if (Game.OnAscend) { - l('game').style.bottom = '0px'; - if (CM.Config.BotBar == 1) CM.Disp.BotBar.style.display = 'none'; - if (CM.Config.TimerBar == 1) CM.Disp.TimerBar.style.display = 'none'; - } - else { - CM.Disp.ToggleBotBar(); - CM.Disp.ToggleTimerBar(); - } - - CM.Disp.UpdateBackground(); -} - -CM.Disp.UpdateAuraDescription = function() { - return "function(aura)\ - {\ - l('dragonAuraInfo').innerHTML=\ - '

'+Game.dragonAuras[aura].name+'

'+\ - '
'+\ - Game.dragonAuras[aura].desc+\ - '
'+\ - CM.\ - '
';\ - }" -} - -CM.Disp.ToggleSayTime = function() { - if (CM.Config.SayTime == 1) { - Game.sayTime = CM.Disp.sayTime; - } - else { - Game.sayTime = CM.Backup.sayTime; - } -} - -CM.Disp.RefreshScale = function() { - BeautifyAll(); - Game.RefreshStore(); - Game.RebuildUpgrades(); - - CM.Disp.UpdateBotBar(); - CM.Disp.UpdateBuildings(); - CM.Disp.UpdateUpgrades(); -} - -CM.Disp.CreateCssArea = function() { - CM.Disp.Css = document.createElement('style'); - CM.Disp.Css.type = 'text/css'; - - document.head.appendChild(CM.Disp.Css); - - // given the architecture of your code, you probably want these lines somewhere else, - // but I stuck them here for convenience - l("products").style.display = "grid"; - l("storeBulk").style.gridRow = "1/1"; - - l("upgrades").style.display = "flex"; - l("upgrades").style["flex-wrap"] = "wrap"; -} - /******** * Section: General functions to format or beautify strings */ @@ -1290,7 +1121,58 @@ CM.Disp.Beautify = function(num, frac, forced) { } /******** - * Section: Functions related to the Bottom Bar */ + * Section: Functions related to display of the full page and initialization of the page */ + +/** + * This function disables and shows the bars created by CookieMonster when the game is "ascending" + * It is called by CM.Loop() + */ +CM.Disp.UpdateAscendState = function() { + if (Game.OnAscend) { + l('game').style.bottom = '0px'; + if (CM.Config.BotBar == 1) CM.Disp.BotBar.style.display = 'none'; + if (CM.Config.TimerBar == 1) CM.Disp.TimerBar.style.display = 'none'; + } + else { + CM.Disp.ToggleBotBar(); + CM.Disp.ToggleTimerBar(); + } + CM.Disp.UpdateBackground(); +} + +/** + * This function creates a CSS style that stores certain standard CSS classes used by CookieMonster + * It is called by CM.DelayInit() + */ +CM.Disp.CreateCssArea = function() { + CM.Disp.Css = document.createElement('style'); + CM.Disp.Css.type = 'text/css'; + + document.head.appendChild(CM.Disp.Css); +} + +/** + * TODO: What does this do? @Aktanusa + * It is called by CM.Init() + */ +CM.Disp.AddJscolor = function() { + CM.Disp.Jscolor = document.createElement('script'); + CM.Disp.Jscolor.type = 'text/javascript'; + CM.Disp.Jscolor.setAttribute('src', 'https://aktanusa.github.io/CookieMonster/jscolor/jscolor.js'); + document.head.appendChild(CM.Disp.Jscolor); +} + +/** + * This function sets the size of the background of the full game and the left column + * depending on whether certain abrs are activated + * It is called by CM.Disp.UpdateAscendState() and CM.Disp.UpdateBotTimerBarPosition() + */ +CM.Disp.UpdateBackground = function() { + Game.Background.canvas.width = Game.Background.canvas.parentNode.offsetWidth; + Game.Background.canvas.height = Game.Background.canvas.parentNode.offsetHeight; + Game.LeftBackground.canvas.width = Game.LeftBackground.canvas.parentNode.offsetWidth; + Game.LeftBackground.canvas.height = Game.LeftBackground.canvas.parentNode.offsetHeight; +} /** * This function toggle the bottom bar @@ -1647,7 +1529,7 @@ CM.Disp.UpdateBotTimerBarPosition = function() { } /******** - * Section: Functions related to column of buildings/objects + * Section: Functions related to right column of the screen (buildings/upgrades) /** * This function adjusts some things in the column of buildings. @@ -1683,6 +1565,7 @@ CM.Disp.UpdateBuildings = function() { // Build array of pointers, sort by pp, use array index (+2) as the grid row number // (grid rows are 1-based indexing, and row 1 is the bulk buy/sell options) + // This regulates sorting of buildings if (Game.buyMode == 1 && CM.Config.SortBuildings) { var arr = Object.keys(CM.Cache[target]).map(k => { @@ -1712,6 +1595,79 @@ CM.Disp.UpdateBuildings = function() { } } +/** + * This function adjusts some things in the upgrades section + * It colours them and shuffles the order when CM.Config.SortBuildings is set + * The function is called by CM.Loop(), CM.Disp.ToggleUpgradeBarAndColor & CM.Disp.RefreshScale() + * And by changes in CM.Config.SortUpgrades + */ +CM.Disp.UpdateUpgrades = function() { + // This counts the amount of upgrades for each pp group and updates the Upgrade Bar + if (CM.Config.UpBarColor > 0) { + var blue = 0; + var green = 0; + var yellow = 0; + var orange = 0; + var red = 0; + var purple = 0; + var gray = 0; + + for (var i in Game.UpgradesInStore) { + var me = Game.UpgradesInStore[i]; + var addedColor = false; + for (var j = 0; j < l('upgrade' + i).childNodes.length; j++) { + if (l('upgrade' + i).childNodes[j].className.indexOf(CM.Disp.colorBackPre) != -1) { + l('upgrade' + i).childNodes[j].className = CM.Disp.colorBackPre + CM.Cache.Upgrades[me.name].color; + addedColor = true; + break; + } + } + if (!addedColor) { + var div = document.createElement('div'); + div.style.width = '10px'; + div.style.height = '10px'; + div.className = CM.Disp.colorBackPre + CM.Cache.Upgrades[me.name].color; + l('upgrade' + i).appendChild(div); + } + if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorBlue) blue++; + else if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorGreen) green++; + else if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorYellow) yellow++; + else if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorOrange) orange++; + else if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorRed) red++; + else if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorPurple) purple++; + else if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorGray) gray++; + } + + l('CMUpgradeBarBlue').textContent = blue; + l('CMUpgradeBarGreen').textContent = green; + l('CMUpgradeBarYellow').textContent = yellow; + l('CMUpgradeBarOrange').textContent = orange; + l('CMUpgradeBarRed').textContent = red; + l('CMUpgradeBarPurple').textContent = purple; + l('CMUpgradeBarGray').textContent = gray; + } + + // Build array of pointers, sort by pp, set flex positions + // This regulates sorting of upgrades + var arr = []; + for (var x = 0; x < Game.UpgradesInStore.length; x++){ + var o = {}; + o.name = Game.UpgradesInStore[x].name; + o.price = Game.UpgradesInStore[x].basePrice; + o.pp = CM.Cache.Upgrades[o.name].pp; + arr.push(o); + } + + if (CM.Config.SortUpgrades) + arr.sort((a, b) => a.pp - b.pp); + else + arr.sort((a, b) => a.price - b.price); + + for (var x = 0; x < Game.UpgradesInStore.length; x++){ + l("upgrade" + x).style.order = arr.findIndex(e => e.name === Game.UpgradesInStore[x].name) + 1 + } +} + /******** * Section: Functions related to the Upgrade Bar @@ -2616,7 +2572,7 @@ CM.Disp.CheckWrinklerTooltip = function() { var me = Game.wrinklers[i]; if (me.phase > 0 && me.selected) { showingTooltip = true; - if (CM.Disp.TooltipWrinklerCache[i] == 0) { + if (CM.Disp.TooltipWrinklerBeingShown[i] == 0 || CM.Disp.TooltipWrinklerBeingShown[i] == undefined) { var placeholder = document.createElement('div'); var wrinkler = document.createElement('div'); wrinkler.style.minWidth = '120px'; @@ -2628,12 +2584,12 @@ CM.Disp.CheckWrinklerTooltip = function() { placeholder.appendChild(wrinkler); Game.tooltip.draw(this, escape(placeholder.innerHTML)); CM.Disp.TooltipWrinkler = i; - CM.Disp.TooltipWrinklerCache[i] = 1; + CM.Disp.TooltipWrinklerBeingShown[i] = 1; } else break; } else { - CM.Disp.TooltipWrinklerCache[i] = 0; + CM.Disp.TooltipWrinklerBeingShown[i] = 0; } } if (!showingTooltip) { @@ -2667,7 +2623,6 @@ CM.Disp.UpdateWrinklerTooltip = function() { /******** * Section: General functions related to the Options/Stats pages - * TODO: Annotate functions */ /** * This function adds the calll the functions to add extra info to the stats and options pages @@ -2731,11 +2686,6 @@ CM.Disp.AddMenuPref = function(title) { frag.appendChild(resDef); l('menu').childNodes[2].insertBefore(frag, l('menu').childNodes[2].childNodes[l('menu').childNodes[2].childNodes.length - 1]); - - // TODO: What does this do? @DanielNoord - CM.Disp.FormatButtonOnClickBak = l('formatButton').onclick; - eval('l(\'formatButton\').onclick = ' + l('formatButton').onclick.toString().split('mp3\');').join('mp3\'); CM.Disp.RefreshScale();')); - //l('formatButton').onclick = function() {Game.Toggle('format', 'formatButton', 'Short numbers OFF', 'Short numbers ON', '1'); PlaySound('snd/tick.mp3'); CM.Disp.RefreshScale();}; } /** @@ -2789,7 +2739,7 @@ CM.Disp.CreatePrefOption = function(config) { } a.id = CM.ConfigPrefix + config; a.onclick = function() {CM.ToggleConfig(config);}; - a.textContent = CM.Disp.GetConfigDisplay(config); + a.textContent = CM.ConfigData[config].label[CM.Config[config]]; div.appendChild(a); var label = document.createElement('label'); label.textContent = CM.ConfigData[config].desc; @@ -2797,25 +2747,24 @@ CM.Disp.CreatePrefOption = function(config) { return div; } else if (CM.ConfigData[config].type == "vol") { - var volConfig = config; var volume = document.createElement('div'); volume.className = 'listing'; var minus = document.createElement('a'); minus.className = 'option'; - minus.onclick = function() {CM.ToggleConfigDown(volConfig);}; + minus.onclick = function() {CM.ToggleConfigDown(config);}; minus.textContent = '-'; volume.appendChild(minus); var volText = document.createElement('span'); - volText.id = CM.ConfigPrefix + volConfig; - volText.textContent = CM.Disp.GetConfigDisplay(volConfig); + volText.id = CM.ConfigPrefix + config; + volText.textContent = CM.ConfigData[config].label[CM.Config[config]]; volume.appendChild(volText); var plus = document.createElement('a'); plus.className = 'option'; - plus.onclick = function() {CM.ToggleConfigUp(volConfig);}; + plus.onclick = function() {CM.ToggleConfigUp(config);}; plus.textContent = '+'; volume.appendChild(plus); var volLabel = document.createElement('label'); - volLabel.textContent = CM.ConfigData[volConfig].desc; + volLabel.textContent = CM.ConfigData[config].desc; volume.appendChild(volLabel); return volume; } @@ -2870,6 +2819,48 @@ CM.Disp.CreatePrefOption = function(config) { } } +/** + * This function changes some of the time-displays in the game to be more detailed + * It is called by a change in CM.Config.DetailedTime + */ +CM.Disp.ToggleDetailedTime = function() { + if (CM.Config.DetailedTime == 1) Game.sayTime = CM.Disp.sayTime; + else Game.sayTime = CM.Backup.sayTime; +} + +/** + * This function refreshes all numbers after a change in scale-setting + * It is therefore called by a change in CM.Config.Scale + */ +CM.Disp.RefreshScale = function() { + BeautifyAll(); + Game.RefreshStore(); + Game.RebuildUpgrades(); + + CM.Disp.UpdateBotBar(); + CM.Disp.UpdateBuildings(); + CM.Disp.UpdateUpgrades(); +} + +/** + * This function changes/refreshes colours if the user has set new standard colours + * The function is therefore called by a change in CM.Config.Colors + */ +CM.Disp.UpdateColors = function() { + var str = ''; + for (var i = 0; i < CM.Disp.colors.length; i++) { + str += '.' + CM.Disp.colorTextPre + CM.Disp.colors[i] + ' { color: ' + CM.Config.Colors[CM.Disp.colors[i]] + '; }\n'; + } + for (var i = 0; i < CM.Disp.colors.length; i++) { + str += '.' + CM.Disp.colorBackPre + CM.Disp.colors[i] + ' { background-color: ' + CM.Config.Colors[CM.Disp.colors[i]] + '; }\n'; + } + for (var i = 0; i < CM.Disp.colors.length; i++) { + str += '.' + CM.Disp.colorBorderPre + CM.Disp.colors[i] + ' { border: 1px solid ' + CM.Config.Colors[CM.Disp.colors[i]] + '; }\n'; + } + CM.Disp.Css.textContent = str; + CM.Disp.UpdateBuildings(); // Class has been already set +} + /******** * Section: Functions related to the Stats page * TODO: Annotate functions */ @@ -2952,7 +2943,7 @@ CM.Disp.AddMenuStats = function(title) { var goldCookTooltip = CM.Sim.auraMult('Dragon\'s Fortune') ? 'GoldCookDragonsFortuneTooltipPlaceholder' : 'GoldCookTooltipPlaceholder'; - stats.appendChild(CreateStatsHeader('Lucky Cookies', 'Lucky')); + stats.appendChild(CM.Disp.CreateStatsHeader('Lucky Cookies', 'Lucky')); if (CM.Config.StatsPref.Lucky) { var luckyColor = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.Lucky) ? CM.Disp.colorRed : CM.Disp.colorGreen; var luckyTime = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.Lucky) ? CM.Disp.FormatTime((CM.Cache.Lucky - (Game.cookies + CM.Disp.GetWrinkConfigBank())) / CM.Disp.GetCPS()) : ''; @@ -2996,7 +2987,7 @@ CM.Disp.AddMenuStats = function(title) { stats.appendChild(listing(listingQuest('\"Lucky!\" Reward (CUR)' + (luckySplit ? ' (Golden / Wrath)' : ''), goldCookTooltip), document.createTextNode(Beautify(luckyCur) + (luckySplit ? (' / ' + Beautify(luckyCurWrath)) : '')))); } - stats.appendChild(CreateStatsHeader('Chain Cookies', 'Chain')); + stats.appendChild(CM.Disp.CreateStatsHeader('Chain Cookies', 'Chain')); if (CM.Config.StatsPref.Chain) { var chainColor = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.Chain) ? CM.Disp.colorRed : CM.Disp.colorGreen; var chainTime = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.Chain) ? CM.Disp.FormatTime((CM.Cache.Chain - (Game.cookies + CM.Disp.GetWrinkConfigBank())) / CM.Disp.GetCPS()) : ''; @@ -3069,7 +3060,7 @@ CM.Disp.AddMenuStats = function(title) { stats.appendChild(listing(listingQuest('\"Chain\" Reward (CUR) (Golden / Wrath)', goldCookTooltip), document.createTextNode(Beautify(chainCur) + ' / ' + Beautify(chainCurWrath)))); } - stats.appendChild(CreateStatsHeader('Conjure Baked Goods', 'Conjure')); + stats.appendChild(CM.Disp.CreateStatsHeader('Conjure Baked Goods', 'Conjure')); if (CM.Config.StatsPref.Conjure) { var conjureColor = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.Conjure) ? CM.Disp.colorRed : CM.Disp.colorGreen; var conjureCur = Math.min((Game.cookies + CM.Disp.GetWrinkConfigBank()) * 0.15, CM.Cache.NoGoldSwitchCookiesPS * 60 * 30); @@ -3094,7 +3085,7 @@ CM.Disp.AddMenuStats = function(title) { var choEgg = (Game.HasUnlocked('Chocolate egg') && !Game.Has('Chocolate egg')); // Needs to be done for the checking below - stats.appendChild(CreateStatsHeader('Prestige', 'Prestige')); + stats.appendChild(CM.Disp.CreateStatsHeader('Prestige', 'Prestige')); if (CM.Config.StatsPref.Prestige) { var possiblePresMax = Math.floor(Game.HowMuchPrestige(CM.Cache.RealCookiesEarned + Game.cookiesReset + CM.Cache.WrinkGodBank + (choEgg ? CM.Cache.lastChoEgg : 0))); var neededCook = Game.HowManyCookiesReset(possiblePresMax + 1) - (CM.Cache.RealCookiesEarned + Game.cookiesReset + CM.Cache.WrinkGodBank + (choEgg ? CM.Cache.lastChoEgg : 0)); @@ -3171,8 +3162,17 @@ CM.Disp.AddMenuStats = function(title) { } } + // TODO: Collapse this function and just write it as code + CM.Disp.CollectWrinklers = function() { + for (var i in Game.wrinklers) { + if (Game.wrinklers[i].sucked > 0 && Game.wrinklers[i].type == 0) { + Game.wrinklers[i].hp = 0; + } + } + } + if (Game.cpsSucked > 0) { - stats.appendChild(CreateStatsHeader('Wrinklers', 'Wrink')); + stats.appendChild(CM.Disp.CreateStatsHeader('Wrinklers', 'Wrink')); if (CM.Config.StatsPref.Wrink) { var popAllFrag = document.createDocumentFragment(); popAllFrag.appendChild(document.createTextNode(Beautify(CM.Cache.WrinkBank) + ' ')); @@ -3225,7 +3225,7 @@ CM.Disp.AddMenuStats = function(title) { var centEgg = Game.Has('Century egg'); if (Game.season == 'christmas' || specDisp || choEgg || centEgg) { - stats.appendChild(CreateStatsHeader('Season Specials', 'Sea')); + stats.appendChild(CM.Disp.CreateStatsHeader('Season Specials', 'Sea')); if (CM.Config.StatsPref.Sea) { if (specDisp) { if (halloCook.length != 0) stats.appendChild(listing('Halloween Cookies Left to Buy', createMissDisp(halloCook))); @@ -3245,7 +3245,7 @@ CM.Disp.AddMenuStats = function(title) { } } - stats.appendChild(CreateStatsHeader('Miscellaneous', 'Misc')); + stats.appendChild(CM.Disp.CreateStatsHeader('Miscellaneous', 'Misc')); if (CM.Config.StatsPref.Misc) { stats.appendChild(listing( 'Average Cookies Per Second (Past ' + (CM.Disp.cookieTimes[CM.Config.AvgCPSHist] < 60 ? (CM.Disp.cookieTimes[CM.Config.AvgCPSHist] + ' seconds') : ((CM.Disp.cookieTimes[CM.Config.AvgCPSHist] / 60) + (CM.Config.AvgCPSHist == 3 ? ' minute' : ' minutes'))) + ')', @@ -3441,12 +3441,20 @@ CM.Disp.lastAscendState = -1; CM.Disp.cookieTimes = [10, 15, 30, 60, 300, 600, 900, 1800]; CM.Disp.clickTimes = [1, 5, 10, 15, 30]; +/** + * This lists is used to store whether a Wrinkler tooltip is being shown or not + * [i] = 1 means tooltip is being shown, [i] = 0 means hidden + * It is used by CM.Disp.CheckWrinklerTooltip() and CM.Main.AddWrinklerAreaDetect() + */ +CM.Disp.TooltipWrinklerBeingShown = []; + /** * These are variables with base-values that get initalized when initliazing CookieMonster * TODO: See if these can be removed or moved */ CM.Disp.TooltipWrinklerArea = 0; CM.Disp.TooltipWrinkler = -1; + /******** * Main * ********/ @@ -3478,17 +3486,17 @@ CM.ReplaceNative = function() { CM.Backup.UpdateWrinklers = Game.UpdateWrinklers; Game.UpdateWrinklers = function() { - CM.Disp.FixMouseY(CM.Backup.UpdateWrinklers); + CM.Main.FixMouseY(CM.Backup.UpdateWrinklers); } CM.Backup.UpdateSpecial = Game.UpdateSpecial; Game.UpdateSpecial = function() { - CM.Disp.FixMouseY(CM.Backup.UpdateSpecial); + CM.Main.FixMouseY(CM.Backup.UpdateSpecial); } // Assumes newer browsers l('bigCookie').removeEventListener('click', Game.ClickCookie, false); - l('bigCookie').addEventListener('click', function() { CM.Disp.FixMouseY(Game.ClickCookie); }, false); + l('bigCookie').addEventListener('click', function() { CM.Main.FixMouseY(Game.ClickCookie); }, false); // Probably better to load per minigame CM.Backup.scriptLoaded = Game.scriptLoaded; @@ -3691,13 +3699,19 @@ CM.DelayInit = function() { if (Game.prefs.popups) Game.Popup('Cookie Monster version ' + CM.VersionMajor + '.' + CM.VersionMinor + ' loaded!'); else Game.Notify('Cookie Monster version ' + CM.VersionMajor + '.' + CM.VersionMinor + ' loaded!', '', '', 1, 1); + // given the architecture of your code, you probably want these lines somewhere else, + // but I stuck them here for convenience + l("products").style.display = "grid"; + l("storeBulk").style.gridRow = "1/1"; + + l("upgrades").style.display = "flex"; + l("upgrades").style["flex-wrap"] = "wrap"; Game.Win('Third-party'); } /******** * Section: Functions related to checking for changes in Minigames/GC's/Ticker - * TODO: Annotate functions * TODO: Possibly move this section */ /** @@ -3869,11 +3883,31 @@ CM.Main.AddWrinklerAreaDetect = function() { CM.Disp.TooltipWrinklerArea = 0; Game.tooltip.hide(); for (var i in Game.wrinklers) { - CM.Disp.TooltipWrinklerCache[i] = 0; + CM.Disp.TooltipWrinklerBeingShown[i] = 0; } }; } +/******** + * Section: Functions related to the mouse */ + +/** + * This function fixes Game.mouseY as a result of bars that are added by CookieMonster + * It is called by Game.UpdateWrinklers(), Game.UpdateSpecial() and the .onmousover of the BigCookie + * before execution of their actual function + */ +CM.Main.FixMouseY = function(target) { + if (CM.Config.TimerBar == 1 && CM.Config.TimerBarPos == 0) { + var timerBarHeight = parseInt(CM.Disp.TimerBar.style.height); + Game.mouseY -= timerBarHeight; + target(); + Game.mouseY += timerBarHeight; + } + else { + target(); + } +} + CM.HasReplaceNativeGrimoireLaunch = false; CM.HasReplaceNativeGrimoireDraw = false; @@ -3949,7 +3983,7 @@ CM.ConfigDefault = { MissingUpgrades: 0, UpStats: 1, TimeFormat: 0, - SayTime: 1, + DetailedTime: 1, GrimoireBar: 1, Scale: 2, OptionsPref: {BarsColors: 1, Calculation: 1, Notification: 1, Tooltip: 1, Statistics: 1, Other: 1}, diff --git a/src/Config.js b/src/Config.js index 8a00a3e..38d6d49 100644 --- a/src/Config.js +++ b/src/Config.js @@ -88,7 +88,7 @@ CM.ToggleConfigUp = function(config) { if (typeof CM.ConfigData[config].func !== 'undefined') { CM.ConfigData[config].func(); } - l(CM.ConfigPrefix + config).innerHTML = CM.Disp.GetConfigDisplay(config); + l(CM.ConfigPrefix + config).innerHTML = CM.ConfigData[config].label[CM.Config[config]]; CM.SaveConfig(CM.Config); } @@ -100,7 +100,7 @@ CM.ToggleConfigDown = function(config) { if (typeof CM.ConfigData[config].func !== 'undefined') { CM.ConfigData[config].func(); } - l(CM.ConfigPrefix + config).innerHTML = CM.Disp.GetConfigDisplay(config); + l(CM.ConfigPrefix + config).innerHTML = CM.ConfigData[config].label[CM.Config[config]]; CM.SaveConfig(CM.Config); } diff --git a/src/Data.js b/src/Data.js index 24a727e..b005688 100644 --- a/src/Data.js +++ b/src/Data.js @@ -168,8 +168,9 @@ CM.ConfigData.Stats = {type: 'bool', group: 'Statistics', label: ['Statistics OF CM.ConfigData.MissingUpgrades = {type: 'bool', group: 'Statistics', label: ['Missing Upgrades OFF', 'Missing Upgrades ON'], desc: 'Shows Missing upgrades in Stats Menu. This feature can be laggy for users with a low amount of unlocked achievements.', toggle: true}; CM.ConfigData.UpStats = {type: 'bool', group: 'Statistics', label: ['Statistics Update Rate (Default)', 'Statistics Update Rate (1s)'], desc: 'Default Game rate is once every 5 seconds', toggle: false}; CM.ConfigData.TimeFormat = {type: 'bool', group: 'Statistics', label: ['Time XXd, XXh, XXm, XXs', 'Time XX:XX:XX:XX:XX'], desc: 'Change the time format', toggle: false}; -CM.ConfigData.SayTime = {type: 'bool', group: 'Statistics', label: ['Format Time OFF', 'Format Time ON'], desc: 'Change how time is displayed in statistics', toggle: true, func: function() {CM.Disp.ToggleSayTime();}}; +CM.ConfigData.DetailedTime = {type: 'bool', group: 'Statistics', label: ['Detailed Time OFF', 'Detailed Time ON'], desc: 'Change how time is displayed in certain statistics and tooltips', toggle: true, func: function() {CM.Disp.ToggleDetailedTime();}}; CM.ConfigData.GrimoireBar = {type: 'bool', group: 'Statistics', label: ['Grimoire Magic Meter Timer OFF', 'Grimoire Magic Meter Timer ON'], desc: 'A timer on how long before the Grimoire magic meter is full', toggle: true}; // Statistics -CM.ConfigData.Scale = {type: 'bool', group: 'Other', label: ['Game\'s Setting Scale', 'Metric', 'Short Scale', 'Scientific Notation', 'Engineering Notation'], desc: 'Change how long numbers are handled', toggle: false, func: function() {CM.Disp.RefreshScale();}}; \ No newline at end of file +CM.ConfigData.Scale = {type: 'bool', group: 'Other', label: ['Game\'s Setting Scale', 'Metric', 'Short Scale', 'Scientific Notation', 'Engineering Notation'], desc: 'Change how long numbers are handled', toggle: false, func: function() {CM.Disp.RefreshScale();}}; + diff --git a/src/Disp.js b/src/Disp.js index e019436..ea8cbe1 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -3,24 +3,59 @@ ********/ /******** - * Please make sure to annotate your code correctly. See the options page section for some examples. + * Please make sure to annotate your code correctly using JSDoc. See the options page section for some examples. * Only put functions related to graphics and displays in this file. - * All calculations and data should be put in others. */ + * All calculations and data should preferrably be put in other files. */ /******** - * Section: Unsorted functions - * TODO: Annotate most functions - * TODO: Sort functionsn in relevant (new) sections or files */ + * Section: Auxilirary functions used by other functions -CM.Disp.TooltipWrinklerCache = []; -for (var i in Game.wrinklers) { - CM.Disp.TooltipWrinklerCache[i] = 0; +/** + * This function returns the total amount stored in the Wrinkler Bank + * as calculated by CM.Cache.RemakeWrinkBank() if CM.Config.CalcWrink is set + * @returns {number} 0 or the amount of cookies stored (CM.Cache.WrinkBank) + */ +CM.Disp.GetWrinkConfigBank = function() { + if (CM.Config.CalcWrink) + return CM.Cache.WrinkBank; + else + return 0; +} + +/** + * This function returns the cps as either current or average CPS depending on CM.Config.CPSMode + * @returns {number} The average or current cps + */ +CM.Disp.GetCPS = function() { + if (CM.Config.CPSMode) + return CM.Cache.AvgCPS; + else + return (Game.cookiesPs * (1 - Game.cpsSucked)); +} + +/** + * This function calculates the time it takes to reach a certain magic level + * It is called by CM.Disp.UpdateTooltipGrimoire() + * @param {number} currentMagic The current magic level + * @param {number} maxMagic The user's max magic level + * @param {number} targetMagic The target magic level + * @returns {number} count / Game.fps The time it takes to reach targetMagic + */ +CM.Disp.CalculateGrimoireRefillTime = function(currentMagic, maxMagic, targetMagic) { + var count = 0; + while (currentMagic < targetMagic) { + currentMagic += Math.max(0.002, Math.pow(currentMagic / Math.max(maxMagic, 100), 0.5)) * 0.002; + count++; + } + return count / Game.fps; } /** * This function returns Name and Color as object for sugar lump type that is given as input param. - * @param type Sugar Lump Type. - * @returns {{text: string, color: string}} + * It is called by CM.Disp.UpdateTooltipSugarLump() + * TODO: Can't this be done with a normal array in Data.js? Or as variable-array at end of this file? + * @param {string} type Sugar Lump Type. + * @returns {{string}, {string}} text, color An array containing the text and display-color of the sugar lump */ CM.Disp.GetLumpColor = function(type) { var name = ""; @@ -56,212 +91,6 @@ CM.Disp.GetLumpColor = function(type) { return {text: name, color: color}; }; -CM.Disp.GetWrinkConfigBank = function() { - if (CM.Config.CalcWrink) - return CM.Cache.WrinkBank; - else - return 0; -} - -CM.Disp.GetCPS = function() { - if (CM.Config.CPSMode) - return CM.Cache.AvgCPS; - else - return (Game.cookiesPs * (1 - Game.cpsSucked)); -} - -CM.Disp.UpdateBackground = function() { - Game.Background.canvas.width = Game.Background.canvas.parentNode.offsetWidth; - Game.Background.canvas.height = Game.Background.canvas.parentNode.offsetHeight; - Game.LeftBackground.canvas.width = Game.LeftBackground.canvas.parentNode.offsetWidth; - Game.LeftBackground.canvas.height = Game.LeftBackground.canvas.parentNode.offsetHeight; -} - -CM.Disp.GetConfigDisplay = function(config) { - return CM.ConfigData[config].label[CM.Config[config]]; -} - -CM.Disp.AddJscolor = function() { - CM.Disp.Jscolor = document.createElement('script'); - CM.Disp.Jscolor.type = 'text/javascript'; - CM.Disp.Jscolor.setAttribute('src', 'https://aktanusa.github.io/CookieMonster/jscolor/jscolor.js'); - document.head.appendChild(CM.Disp.Jscolor); -} - - - -CM.Disp.UpdateUpgrades = function() { - if (CM.Config.UpBarColor > 0) { - var blue = 0; - var green = 0; - var yellow = 0; - var orange = 0; - var red = 0; - var purple = 0; - var gray = 0; - - for (var i in Game.UpgradesInStore) { - var me = Game.UpgradesInStore[i]; - var addedColor = false; - for (var j = 0; j < l('upgrade' + i).childNodes.length; j++) { - if (l('upgrade' + i).childNodes[j].className.indexOf(CM.Disp.colorBackPre) != -1) { - l('upgrade' + i).childNodes[j].className = CM.Disp.colorBackPre + CM.Cache.Upgrades[me.name].color; - addedColor = true; - break; - } - } - if (!addedColor) { - var div = document.createElement('div'); - div.style.width = '10px'; - div.style.height = '10px'; - div.className = CM.Disp.colorBackPre + CM.Cache.Upgrades[me.name].color; - l('upgrade' + i).appendChild(div); - } - if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorBlue) blue++; - else if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorGreen) green++; - else if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorYellow) yellow++; - else if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorOrange) orange++; - else if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorRed) red++; - else if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorPurple) purple++; - else if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorGray) gray++; - } - - l('CMUpgradeBarBlue').textContent = blue; - l('CMUpgradeBarGreen').textContent = green; - l('CMUpgradeBarYellow').textContent = yellow; - l('CMUpgradeBarOrange').textContent = orange; - l('CMUpgradeBarRed').textContent = red; - l('CMUpgradeBarPurple').textContent = purple; - l('CMUpgradeBarGray').textContent = gray; - } - - // Build array of pointers, sort by pp, set flex positions - var arr = []; - for (var x = 0; x < Game.UpgradesInStore.length; x++){ - var o = {}; - o.name = Game.UpgradesInStore[x].name; - o.price = Game.UpgradesInStore[x].basePrice; - o.pp = CM.Cache.Upgrades[o.name].pp; - arr.push(o); - } - - if (CM.Config.SortUpgrades) - arr.sort((a, b) => a.pp - b.pp); - else - arr.sort((a, b) => a.price - b.price); - - for (var x = 0; x < Game.UpgradesInStore.length; x++){ - l("upgrade" + x).style.order = arr.findIndex(e => e.name === Game.UpgradesInStore[x].name) + 1 - } -} - -CM.Disp.UpdateColors = function() { - var str = ''; - for (var i = 0; i < CM.Disp.colors.length; i++) { - str += '.' + CM.Disp.colorTextPre + CM.Disp.colors[i] + ' { color: ' + CM.Config.Colors[CM.Disp.colors[i]] + '; }\n'; - } - for (var i = 0; i < CM.Disp.colors.length; i++) { - str += '.' + CM.Disp.colorBackPre + CM.Disp.colors[i] + ' { background-color: ' + CM.Config.Colors[CM.Disp.colors[i]] + '; }\n'; - } - for (var i = 0; i < CM.Disp.colors.length; i++) { - str += '.' + CM.Disp.colorBorderPre + CM.Disp.colors[i] + ' { border: 1px solid ' + CM.Config.Colors[CM.Disp.colors[i]] + '; }\n'; - } - CM.Disp.Css.textContent = str; - CM.Disp.UpdateBuildings(); // Class has been already set -} - -CM.Disp.CollectWrinklers = function() { - for (var i in Game.wrinklers) { - if (Game.wrinklers[i].sucked > 0 && Game.wrinklers[i].type == 0) { - Game.wrinklers[i].hp = 0; - } - } -} - -CM.Disp.FixMouseY = function(target) { - if (CM.Config.TimerBar == 1 && CM.Config.TimerBarPos == 0) { - var timerBarHeight = parseInt(CM.Disp.TimerBar.style.height); - Game.mouseY -= timerBarHeight; - target(); - Game.mouseY += timerBarHeight; - } - else { - target(); - } -} - -CM.Disp.CalculateGrimoireRefillTime = function(currentMagic, maxMagic, targetMagic) { - var count = 0; - while (currentMagic < targetMagic) { - currentMagic += Math.max(0.002, Math.pow(currentMagic / Math.max(maxMagic, 100), 0.5)) * 0.002; - count++; - } - return count / Game.fps; -} - - - -CM.Disp.UpdateAscendState = function() { - if (Game.OnAscend) { - l('game').style.bottom = '0px'; - if (CM.Config.BotBar == 1) CM.Disp.BotBar.style.display = 'none'; - if (CM.Config.TimerBar == 1) CM.Disp.TimerBar.style.display = 'none'; - } - else { - CM.Disp.ToggleBotBar(); - CM.Disp.ToggleTimerBar(); - } - - CM.Disp.UpdateBackground(); -} - -CM.Disp.UpdateAuraDescription = function() { - return "function(aura)\ - {\ - l('dragonAuraInfo').innerHTML=\ - '

'+Game.dragonAuras[aura].name+'

'+\ - '
'+\ - Game.dragonAuras[aura].desc+\ - '
'+\ - CM.\ - '
';\ - }" -} - -CM.Disp.ToggleSayTime = function() { - if (CM.Config.SayTime == 1) { - Game.sayTime = CM.Disp.sayTime; - } - else { - Game.sayTime = CM.Backup.sayTime; - } -} - -CM.Disp.RefreshScale = function() { - BeautifyAll(); - Game.RefreshStore(); - Game.RebuildUpgrades(); - - CM.Disp.UpdateBotBar(); - CM.Disp.UpdateBuildings(); - CM.Disp.UpdateUpgrades(); -} - -CM.Disp.CreateCssArea = function() { - CM.Disp.Css = document.createElement('style'); - CM.Disp.Css.type = 'text/css'; - - document.head.appendChild(CM.Disp.Css); - - // given the architecture of your code, you probably want these lines somewhere else, - // but I stuck them here for convenience - l("products").style.display = "grid"; - l("storeBulk").style.gridRow = "1/1"; - - l("upgrades").style.display = "flex"; - l("upgrades").style["flex-wrap"] = "wrap"; -} - /******** * Section: General functions to format or beautify strings */ @@ -404,7 +233,58 @@ CM.Disp.Beautify = function(num, frac, forced) { } /******** - * Section: Functions related to the Bottom Bar */ + * Section: Functions related to display of the full page and initialization of the page */ + +/** + * This function disables and shows the bars created by CookieMonster when the game is "ascending" + * It is called by CM.Loop() + */ +CM.Disp.UpdateAscendState = function() { + if (Game.OnAscend) { + l('game').style.bottom = '0px'; + if (CM.Config.BotBar == 1) CM.Disp.BotBar.style.display = 'none'; + if (CM.Config.TimerBar == 1) CM.Disp.TimerBar.style.display = 'none'; + } + else { + CM.Disp.ToggleBotBar(); + CM.Disp.ToggleTimerBar(); + } + CM.Disp.UpdateBackground(); +} + +/** + * This function creates a CSS style that stores certain standard CSS classes used by CookieMonster + * It is called by CM.DelayInit() + */ +CM.Disp.CreateCssArea = function() { + CM.Disp.Css = document.createElement('style'); + CM.Disp.Css.type = 'text/css'; + + document.head.appendChild(CM.Disp.Css); +} + +/** + * TODO: What does this do? @Aktanusa + * It is called by CM.Init() + */ +CM.Disp.AddJscolor = function() { + CM.Disp.Jscolor = document.createElement('script'); + CM.Disp.Jscolor.type = 'text/javascript'; + CM.Disp.Jscolor.setAttribute('src', 'https://aktanusa.github.io/CookieMonster/jscolor/jscolor.js'); + document.head.appendChild(CM.Disp.Jscolor); +} + +/** + * This function sets the size of the background of the full game and the left column + * depending on whether certain abrs are activated + * It is called by CM.Disp.UpdateAscendState() and CM.Disp.UpdateBotTimerBarPosition() + */ +CM.Disp.UpdateBackground = function() { + Game.Background.canvas.width = Game.Background.canvas.parentNode.offsetWidth; + Game.Background.canvas.height = Game.Background.canvas.parentNode.offsetHeight; + Game.LeftBackground.canvas.width = Game.LeftBackground.canvas.parentNode.offsetWidth; + Game.LeftBackground.canvas.height = Game.LeftBackground.canvas.parentNode.offsetHeight; +} /** * This function toggle the bottom bar @@ -761,7 +641,7 @@ CM.Disp.UpdateBotTimerBarPosition = function() { } /******** - * Section: Functions related to column of buildings/objects + * Section: Functions related to right column of the screen (buildings/upgrades) /** * This function adjusts some things in the column of buildings. @@ -797,6 +677,7 @@ CM.Disp.UpdateBuildings = function() { // Build array of pointers, sort by pp, use array index (+2) as the grid row number // (grid rows are 1-based indexing, and row 1 is the bulk buy/sell options) + // This regulates sorting of buildings if (Game.buyMode == 1 && CM.Config.SortBuildings) { var arr = Object.keys(CM.Cache[target]).map(k => { @@ -826,6 +707,79 @@ CM.Disp.UpdateBuildings = function() { } } +/** + * This function adjusts some things in the upgrades section + * It colours them and shuffles the order when CM.Config.SortBuildings is set + * The function is called by CM.Loop(), CM.Disp.ToggleUpgradeBarAndColor & CM.Disp.RefreshScale() + * And by changes in CM.Config.SortUpgrades + */ +CM.Disp.UpdateUpgrades = function() { + // This counts the amount of upgrades for each pp group and updates the Upgrade Bar + if (CM.Config.UpBarColor > 0) { + var blue = 0; + var green = 0; + var yellow = 0; + var orange = 0; + var red = 0; + var purple = 0; + var gray = 0; + + for (var i in Game.UpgradesInStore) { + var me = Game.UpgradesInStore[i]; + var addedColor = false; + for (var j = 0; j < l('upgrade' + i).childNodes.length; j++) { + if (l('upgrade' + i).childNodes[j].className.indexOf(CM.Disp.colorBackPre) != -1) { + l('upgrade' + i).childNodes[j].className = CM.Disp.colorBackPre + CM.Cache.Upgrades[me.name].color; + addedColor = true; + break; + } + } + if (!addedColor) { + var div = document.createElement('div'); + div.style.width = '10px'; + div.style.height = '10px'; + div.className = CM.Disp.colorBackPre + CM.Cache.Upgrades[me.name].color; + l('upgrade' + i).appendChild(div); + } + if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorBlue) blue++; + else if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorGreen) green++; + else if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorYellow) yellow++; + else if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorOrange) orange++; + else if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorRed) red++; + else if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorPurple) purple++; + else if (CM.Cache.Upgrades[me.name].color == CM.Disp.colorGray) gray++; + } + + l('CMUpgradeBarBlue').textContent = blue; + l('CMUpgradeBarGreen').textContent = green; + l('CMUpgradeBarYellow').textContent = yellow; + l('CMUpgradeBarOrange').textContent = orange; + l('CMUpgradeBarRed').textContent = red; + l('CMUpgradeBarPurple').textContent = purple; + l('CMUpgradeBarGray').textContent = gray; + } + + // Build array of pointers, sort by pp, set flex positions + // This regulates sorting of upgrades + var arr = []; + for (var x = 0; x < Game.UpgradesInStore.length; x++){ + var o = {}; + o.name = Game.UpgradesInStore[x].name; + o.price = Game.UpgradesInStore[x].basePrice; + o.pp = CM.Cache.Upgrades[o.name].pp; + arr.push(o); + } + + if (CM.Config.SortUpgrades) + arr.sort((a, b) => a.pp - b.pp); + else + arr.sort((a, b) => a.price - b.price); + + for (var x = 0; x < Game.UpgradesInStore.length; x++){ + l("upgrade" + x).style.order = arr.findIndex(e => e.name === Game.UpgradesInStore[x].name) + 1 + } +} + /******** * Section: Functions related to the Upgrade Bar @@ -1730,7 +1684,7 @@ CM.Disp.CheckWrinklerTooltip = function() { var me = Game.wrinklers[i]; if (me.phase > 0 && me.selected) { showingTooltip = true; - if (CM.Disp.TooltipWrinklerCache[i] == 0) { + if (CM.Disp.TooltipWrinklerBeingShown[i] == 0 || CM.Disp.TooltipWrinklerBeingShown[i] == undefined) { var placeholder = document.createElement('div'); var wrinkler = document.createElement('div'); wrinkler.style.minWidth = '120px'; @@ -1742,12 +1696,12 @@ CM.Disp.CheckWrinklerTooltip = function() { placeholder.appendChild(wrinkler); Game.tooltip.draw(this, escape(placeholder.innerHTML)); CM.Disp.TooltipWrinkler = i; - CM.Disp.TooltipWrinklerCache[i] = 1; + CM.Disp.TooltipWrinklerBeingShown[i] = 1; } else break; } else { - CM.Disp.TooltipWrinklerCache[i] = 0; + CM.Disp.TooltipWrinklerBeingShown[i] = 0; } } if (!showingTooltip) { @@ -1781,7 +1735,6 @@ CM.Disp.UpdateWrinklerTooltip = function() { /******** * Section: General functions related to the Options/Stats pages - * TODO: Annotate functions */ /** * This function adds the calll the functions to add extra info to the stats and options pages @@ -1845,11 +1798,6 @@ CM.Disp.AddMenuPref = function(title) { frag.appendChild(resDef); l('menu').childNodes[2].insertBefore(frag, l('menu').childNodes[2].childNodes[l('menu').childNodes[2].childNodes.length - 1]); - - // TODO: What does this do? @DanielNoord - CM.Disp.FormatButtonOnClickBak = l('formatButton').onclick; - eval('l(\'formatButton\').onclick = ' + l('formatButton').onclick.toString().split('mp3\');').join('mp3\'); CM.Disp.RefreshScale();')); - //l('formatButton').onclick = function() {Game.Toggle('format', 'formatButton', 'Short numbers OFF', 'Short numbers ON', '1'); PlaySound('snd/tick.mp3'); CM.Disp.RefreshScale();}; } /** @@ -1903,7 +1851,7 @@ CM.Disp.CreatePrefOption = function(config) { } a.id = CM.ConfigPrefix + config; a.onclick = function() {CM.ToggleConfig(config);}; - a.textContent = CM.Disp.GetConfigDisplay(config); + a.textContent = CM.ConfigData[config].label[CM.Config[config]]; div.appendChild(a); var label = document.createElement('label'); label.textContent = CM.ConfigData[config].desc; @@ -1911,25 +1859,24 @@ CM.Disp.CreatePrefOption = function(config) { return div; } else if (CM.ConfigData[config].type == "vol") { - var volConfig = config; var volume = document.createElement('div'); volume.className = 'listing'; var minus = document.createElement('a'); minus.className = 'option'; - minus.onclick = function() {CM.ToggleConfigDown(volConfig);}; + minus.onclick = function() {CM.ToggleConfigDown(config);}; minus.textContent = '-'; volume.appendChild(minus); var volText = document.createElement('span'); - volText.id = CM.ConfigPrefix + volConfig; - volText.textContent = CM.Disp.GetConfigDisplay(volConfig); + volText.id = CM.ConfigPrefix + config; + volText.textContent = CM.ConfigData[config].label[CM.Config[config]]; volume.appendChild(volText); var plus = document.createElement('a'); plus.className = 'option'; - plus.onclick = function() {CM.ToggleConfigUp(volConfig);}; + plus.onclick = function() {CM.ToggleConfigUp(config);}; plus.textContent = '+'; volume.appendChild(plus); var volLabel = document.createElement('label'); - volLabel.textContent = CM.ConfigData[volConfig].desc; + volLabel.textContent = CM.ConfigData[config].desc; volume.appendChild(volLabel); return volume; } @@ -1984,6 +1931,48 @@ CM.Disp.CreatePrefOption = function(config) { } } +/** + * This function changes some of the time-displays in the game to be more detailed + * It is called by a change in CM.Config.DetailedTime + */ +CM.Disp.ToggleDetailedTime = function() { + if (CM.Config.DetailedTime == 1) Game.sayTime = CM.Disp.sayTime; + else Game.sayTime = CM.Backup.sayTime; +} + +/** + * This function refreshes all numbers after a change in scale-setting + * It is therefore called by a change in CM.Config.Scale + */ +CM.Disp.RefreshScale = function() { + BeautifyAll(); + Game.RefreshStore(); + Game.RebuildUpgrades(); + + CM.Disp.UpdateBotBar(); + CM.Disp.UpdateBuildings(); + CM.Disp.UpdateUpgrades(); +} + +/** + * This function changes/refreshes colours if the user has set new standard colours + * The function is therefore called by a change in CM.Config.Colors + */ +CM.Disp.UpdateColors = function() { + var str = ''; + for (var i = 0; i < CM.Disp.colors.length; i++) { + str += '.' + CM.Disp.colorTextPre + CM.Disp.colors[i] + ' { color: ' + CM.Config.Colors[CM.Disp.colors[i]] + '; }\n'; + } + for (var i = 0; i < CM.Disp.colors.length; i++) { + str += '.' + CM.Disp.colorBackPre + CM.Disp.colors[i] + ' { background-color: ' + CM.Config.Colors[CM.Disp.colors[i]] + '; }\n'; + } + for (var i = 0; i < CM.Disp.colors.length; i++) { + str += '.' + CM.Disp.colorBorderPre + CM.Disp.colors[i] + ' { border: 1px solid ' + CM.Config.Colors[CM.Disp.colors[i]] + '; }\n'; + } + CM.Disp.Css.textContent = str; + CM.Disp.UpdateBuildings(); // Class has been already set +} + /******** * Section: Functions related to the Stats page * TODO: Annotate functions */ @@ -2066,7 +2055,7 @@ CM.Disp.AddMenuStats = function(title) { var goldCookTooltip = CM.Sim.auraMult('Dragon\'s Fortune') ? 'GoldCookDragonsFortuneTooltipPlaceholder' : 'GoldCookTooltipPlaceholder'; - stats.appendChild(CreateStatsHeader('Lucky Cookies', 'Lucky')); + stats.appendChild(CM.Disp.CreateStatsHeader('Lucky Cookies', 'Lucky')); if (CM.Config.StatsPref.Lucky) { var luckyColor = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.Lucky) ? CM.Disp.colorRed : CM.Disp.colorGreen; var luckyTime = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.Lucky) ? CM.Disp.FormatTime((CM.Cache.Lucky - (Game.cookies + CM.Disp.GetWrinkConfigBank())) / CM.Disp.GetCPS()) : ''; @@ -2110,7 +2099,7 @@ CM.Disp.AddMenuStats = function(title) { stats.appendChild(listing(listingQuest('\"Lucky!\" Reward (CUR)' + (luckySplit ? ' (Golden / Wrath)' : ''), goldCookTooltip), document.createTextNode(Beautify(luckyCur) + (luckySplit ? (' / ' + Beautify(luckyCurWrath)) : '')))); } - stats.appendChild(CreateStatsHeader('Chain Cookies', 'Chain')); + stats.appendChild(CM.Disp.CreateStatsHeader('Chain Cookies', 'Chain')); if (CM.Config.StatsPref.Chain) { var chainColor = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.Chain) ? CM.Disp.colorRed : CM.Disp.colorGreen; var chainTime = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.Chain) ? CM.Disp.FormatTime((CM.Cache.Chain - (Game.cookies + CM.Disp.GetWrinkConfigBank())) / CM.Disp.GetCPS()) : ''; @@ -2183,7 +2172,7 @@ CM.Disp.AddMenuStats = function(title) { stats.appendChild(listing(listingQuest('\"Chain\" Reward (CUR) (Golden / Wrath)', goldCookTooltip), document.createTextNode(Beautify(chainCur) + ' / ' + Beautify(chainCurWrath)))); } - stats.appendChild(CreateStatsHeader('Conjure Baked Goods', 'Conjure')); + stats.appendChild(CM.Disp.CreateStatsHeader('Conjure Baked Goods', 'Conjure')); if (CM.Config.StatsPref.Conjure) { var conjureColor = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.Conjure) ? CM.Disp.colorRed : CM.Disp.colorGreen; var conjureCur = Math.min((Game.cookies + CM.Disp.GetWrinkConfigBank()) * 0.15, CM.Cache.NoGoldSwitchCookiesPS * 60 * 30); @@ -2208,7 +2197,7 @@ CM.Disp.AddMenuStats = function(title) { var choEgg = (Game.HasUnlocked('Chocolate egg') && !Game.Has('Chocolate egg')); // Needs to be done for the checking below - stats.appendChild(CreateStatsHeader('Prestige', 'Prestige')); + stats.appendChild(CM.Disp.CreateStatsHeader('Prestige', 'Prestige')); if (CM.Config.StatsPref.Prestige) { var possiblePresMax = Math.floor(Game.HowMuchPrestige(CM.Cache.RealCookiesEarned + Game.cookiesReset + CM.Cache.WrinkGodBank + (choEgg ? CM.Cache.lastChoEgg : 0))); var neededCook = Game.HowManyCookiesReset(possiblePresMax + 1) - (CM.Cache.RealCookiesEarned + Game.cookiesReset + CM.Cache.WrinkGodBank + (choEgg ? CM.Cache.lastChoEgg : 0)); @@ -2285,8 +2274,17 @@ CM.Disp.AddMenuStats = function(title) { } } + // TODO: Collapse this function and just write it as code + CM.Disp.CollectWrinklers = function() { + for (var i in Game.wrinklers) { + if (Game.wrinklers[i].sucked > 0 && Game.wrinklers[i].type == 0) { + Game.wrinklers[i].hp = 0; + } + } + } + if (Game.cpsSucked > 0) { - stats.appendChild(CreateStatsHeader('Wrinklers', 'Wrink')); + stats.appendChild(CM.Disp.CreateStatsHeader('Wrinklers', 'Wrink')); if (CM.Config.StatsPref.Wrink) { var popAllFrag = document.createDocumentFragment(); popAllFrag.appendChild(document.createTextNode(Beautify(CM.Cache.WrinkBank) + ' ')); @@ -2339,7 +2337,7 @@ CM.Disp.AddMenuStats = function(title) { var centEgg = Game.Has('Century egg'); if (Game.season == 'christmas' || specDisp || choEgg || centEgg) { - stats.appendChild(CreateStatsHeader('Season Specials', 'Sea')); + stats.appendChild(CM.Disp.CreateStatsHeader('Season Specials', 'Sea')); if (CM.Config.StatsPref.Sea) { if (specDisp) { if (halloCook.length != 0) stats.appendChild(listing('Halloween Cookies Left to Buy', createMissDisp(halloCook))); @@ -2359,7 +2357,7 @@ CM.Disp.AddMenuStats = function(title) { } } - stats.appendChild(CreateStatsHeader('Miscellaneous', 'Misc')); + stats.appendChild(CM.Disp.CreateStatsHeader('Miscellaneous', 'Misc')); if (CM.Config.StatsPref.Misc) { stats.appendChild(listing( 'Average Cookies Per Second (Past ' + (CM.Disp.cookieTimes[CM.Config.AvgCPSHist] < 60 ? (CM.Disp.cookieTimes[CM.Config.AvgCPSHist] + ' seconds') : ((CM.Disp.cookieTimes[CM.Config.AvgCPSHist] / 60) + (CM.Config.AvgCPSHist == 3 ? ' minute' : ' minutes'))) + ')', @@ -2555,9 +2553,17 @@ CM.Disp.lastAscendState = -1; CM.Disp.cookieTimes = [10, 15, 30, 60, 300, 600, 900, 1800]; CM.Disp.clickTimes = [1, 5, 10, 15, 30]; +/** + * This lists is used to store whether a Wrinkler tooltip is being shown or not + * [i] = 1 means tooltip is being shown, [i] = 0 means hidden + * It is used by CM.Disp.CheckWrinklerTooltip() and CM.Main.AddWrinklerAreaDetect() + */ +CM.Disp.TooltipWrinklerBeingShown = []; + /** * These are variables with base-values that get initalized when initliazing CookieMonster * TODO: See if these can be removed or moved */ CM.Disp.TooltipWrinklerArea = 0; CM.Disp.TooltipWrinkler = -1; + diff --git a/src/Main.js b/src/Main.js index 5bf1c02..6b936e7 100644 --- a/src/Main.js +++ b/src/Main.js @@ -29,17 +29,17 @@ CM.ReplaceNative = function() { CM.Backup.UpdateWrinklers = Game.UpdateWrinklers; Game.UpdateWrinklers = function() { - CM.Disp.FixMouseY(CM.Backup.UpdateWrinklers); + CM.Main.FixMouseY(CM.Backup.UpdateWrinklers); } CM.Backup.UpdateSpecial = Game.UpdateSpecial; Game.UpdateSpecial = function() { - CM.Disp.FixMouseY(CM.Backup.UpdateSpecial); + CM.Main.FixMouseY(CM.Backup.UpdateSpecial); } // Assumes newer browsers l('bigCookie').removeEventListener('click', Game.ClickCookie, false); - l('bigCookie').addEventListener('click', function() { CM.Disp.FixMouseY(Game.ClickCookie); }, false); + l('bigCookie').addEventListener('click', function() { CM.Main.FixMouseY(Game.ClickCookie); }, false); // Probably better to load per minigame CM.Backup.scriptLoaded = Game.scriptLoaded; @@ -242,13 +242,19 @@ CM.DelayInit = function() { if (Game.prefs.popups) Game.Popup('Cookie Monster version ' + CM.VersionMajor + '.' + CM.VersionMinor + ' loaded!'); else Game.Notify('Cookie Monster version ' + CM.VersionMajor + '.' + CM.VersionMinor + ' loaded!', '', '', 1, 1); + // given the architecture of your code, you probably want these lines somewhere else, + // but I stuck them here for convenience + l("products").style.display = "grid"; + l("storeBulk").style.gridRow = "1/1"; + + l("upgrades").style.display = "flex"; + l("upgrades").style["flex-wrap"] = "wrap"; Game.Win('Third-party'); } /******** * Section: Functions related to checking for changes in Minigames/GC's/Ticker - * TODO: Annotate functions * TODO: Possibly move this section */ /** @@ -420,11 +426,31 @@ CM.Main.AddWrinklerAreaDetect = function() { CM.Disp.TooltipWrinklerArea = 0; Game.tooltip.hide(); for (var i in Game.wrinklers) { - CM.Disp.TooltipWrinklerCache[i] = 0; + CM.Disp.TooltipWrinklerBeingShown[i] = 0; } }; } +/******** + * Section: Functions related to the mouse */ + +/** + * This function fixes Game.mouseY as a result of bars that are added by CookieMonster + * It is called by Game.UpdateWrinklers(), Game.UpdateSpecial() and the .onmousover of the BigCookie + * before execution of their actual function + */ +CM.Main.FixMouseY = function(target) { + if (CM.Config.TimerBar == 1 && CM.Config.TimerBarPos == 0) { + var timerBarHeight = parseInt(CM.Disp.TimerBar.style.height); + Game.mouseY -= timerBarHeight; + target(); + Game.mouseY += timerBarHeight; + } + else { + target(); + } +} + CM.HasReplaceNativeGrimoireLaunch = false; CM.HasReplaceNativeGrimoireDraw = false; @@ -500,7 +526,7 @@ CM.ConfigDefault = { MissingUpgrades: 0, UpStats: 1, TimeFormat: 0, - SayTime: 1, + DetailedTime: 1, GrimoireBar: 1, Scale: 2, OptionsPref: {BarsColors: 1, Calculation: 1, Notification: 1, Tooltip: 1, Statistics: 1, Other: 1}, From 7cd62e17354ac90fd2f661d93a1cd210549ea1f8 Mon Sep 17 00:00:00 2001 From: Chorizorro Date: Sat, 5 Dec 2020 16:01:46 +0100 Subject: [PATCH 031/106] Enhance autosave timer refresh #375 --- CookieMonster.js | 34 +++++++++++++++++++++++++++++++--- src/Disp.js | 25 ++++++++++++++++++++++--- src/Main.js | 9 +++++++++ 3 files changed, 62 insertions(+), 6 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index d6a1001..dc173ae 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -1121,7 +1121,7 @@ CM.Disp.Beautify = function(num, frac, forced) { } /******** - * Section: Functions related to display of the full page and initialization of the page */ + * Section: General functions related to display, drawing and initialization of the page */ /** * This function disables and shows the bars created by CookieMonster when the game is "ascending" @@ -1293,6 +1293,23 @@ CM.Disp.CreateBotBarBuildingColumn = function(buildingName) { time.appendChild(document.createElement('td')); } +/** + * This function handles custom drawing for the Game.Draw() function. + * It is hooked on 'draw' by CM.RegisterHooks() + */ +CM.Disp.Draw = function () { + // Draw autosave timer in stats menu + if ( + (Game.prefs.autosave && Game.drawT % 10 == 0) && // with autosave ON and every 10 ticks + (Game.onMenu == 'stats' && CM.Config.Stats) // while being on the stats menu only + ) { + var timer = document.getElementById('CMStatsAutosaveTimer'); + if (timer) { + timer.innerText = Game.sayTime(Game.fps * 60 - (Game.T % (Game.fps * 60)), 4); + } + } +} + /******** * Section: Functions related to the Timer Bar @@ -3263,8 +3280,10 @@ CM.Disp.AddMenuStats = function(title) { } stats.appendChild(listing('Missed Golden Cookies', document.createTextNode(Beautify(Game.missedGoldenClicks)))); if (Game.prefs.autosave) { - var timeTillAutosave = Math.min((Game.fps*60 - (Game.T%(Game.fps*60))) / Game.fps, !Game.OnAscend * 60) - stats.appendChild(listing('Seconds till autosave', document.createTextNode(Math.floor(timeTillAutosave)))); + var timer = document.createElement('span'); + timer.id = 'CMStatsAutosaveTimer'; + timer.innerText = Game.sayTime(Game.fps * 60 - (Game.OnAscend ? 0 : (Game.T % (Game.fps * 60))), 4); + stats.appendChild(listing('Time till autosave', timer)); } } @@ -3707,9 +3726,18 @@ CM.DelayInit = function() { l("upgrades").style.display = "flex"; l("upgrades").style["flex-wrap"] = "wrap"; + CM.Main.RegisterHooks(); + Game.Win('Third-party'); } +/** + * Hook custom methods into the game + */ +CM.Main.RegisterHooks = function() { + Game.registerHook('draw', CM.Disp.Draw); +} + /******** * Section: Functions related to checking for changes in Minigames/GC's/Ticker * TODO: Possibly move this section */ diff --git a/src/Disp.js b/src/Disp.js index ea8cbe1..0092f57 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -233,7 +233,7 @@ CM.Disp.Beautify = function(num, frac, forced) { } /******** - * Section: Functions related to display of the full page and initialization of the page */ + * Section: General functions related to display, drawing and initialization of the page */ /** * This function disables and shows the bars created by CookieMonster when the game is "ascending" @@ -405,6 +405,23 @@ CM.Disp.CreateBotBarBuildingColumn = function(buildingName) { time.appendChild(document.createElement('td')); } +/** + * This function handles custom drawing for the Game.Draw() function. + * It is hooked on 'draw' by CM.RegisterHooks() + */ +CM.Disp.Draw = function () { + // Draw autosave timer in stats menu + if ( + (Game.prefs.autosave && Game.drawT % 10 == 0) && // with autosave ON and every 10 ticks + (Game.onMenu == 'stats' && CM.Config.Stats) // while being on the stats menu only + ) { + var timer = document.getElementById('CMStatsAutosaveTimer'); + if (timer) { + timer.innerText = Game.sayTime(Game.fps * 60 - (Game.T % (Game.fps * 60)), 4); + } + } +} + /******** * Section: Functions related to the Timer Bar @@ -2375,8 +2392,10 @@ CM.Disp.AddMenuStats = function(title) { } stats.appendChild(listing('Missed Golden Cookies', document.createTextNode(Beautify(Game.missedGoldenClicks)))); if (Game.prefs.autosave) { - var timeTillAutosave = Math.min((Game.fps*60 - (Game.T%(Game.fps*60))) / Game.fps, !Game.OnAscend * 60) - stats.appendChild(listing('Seconds till autosave', document.createTextNode(Math.floor(timeTillAutosave)))); + var timer = document.createElement('span'); + timer.id = 'CMStatsAutosaveTimer'; + timer.innerText = Game.sayTime(Game.fps * 60 - (Game.OnAscend ? 0 : (Game.T % (Game.fps * 60))), 4); + stats.appendChild(listing('Time till autosave', timer)); } } diff --git a/src/Main.js b/src/Main.js index 6b936e7..3b336d7 100644 --- a/src/Main.js +++ b/src/Main.js @@ -250,9 +250,18 @@ CM.DelayInit = function() { l("upgrades").style.display = "flex"; l("upgrades").style["flex-wrap"] = "wrap"; + CM.Main.RegisterHooks(); + Game.Win('Third-party'); } +/** + * Hook custom methods into the game + */ +CM.Main.RegisterHooks = function() { + Game.registerHook('draw', CM.Disp.Draw); +} + /******** * Section: Functions related to checking for changes in Minigames/GC's/Ticker * TODO: Possibly move this section */ From 15d467992d55f999b50430541373561ba5ddac2e Mon Sep 17 00:00:00 2001 From: Chorizorro Date: Sat, 5 Dec 2020 22:31:40 +0100 Subject: [PATCH 032/106] Move CM.Disp.Draw out of bottom bar section --- CookieMonster.js | 37 ++++++++++++++++++++----------------- src/Disp.js | 37 ++++++++++++++++++++----------------- 2 files changed, 40 insertions(+), 34 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index dc173ae..49d8928 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -1174,6 +1174,26 @@ CM.Disp.UpdateBackground = function() { Game.LeftBackground.canvas.height = Game.LeftBackground.canvas.parentNode.offsetHeight; } +/** + * This function handles custom drawing for the Game.Draw() function. + * It is hooked on 'draw' by CM.RegisterHooks() + */ +CM.Disp.Draw = function () { + // Draw autosave timer in stats menu + if ( + (Game.prefs.autosave && Game.drawT % 10 == 0) && // with autosave ON and every 10 ticks + (Game.onMenu == 'stats' && CM.Config.Stats) // while being on the stats menu only + ) { + var timer = document.getElementById('CMStatsAutosaveTimer'); + if (timer) { + timer.innerText = Game.sayTime(Game.fps * 60 - (Game.T % (Game.fps * 60)), 4); + } + } +} + +/******** + * Section: Functions related to the Bottom Bar */ + /** * This function toggle the bottom bar * It is called by CM.Disp.UpdateAscendState() and a change in CM.Config.BotBar @@ -1293,23 +1313,6 @@ CM.Disp.CreateBotBarBuildingColumn = function(buildingName) { time.appendChild(document.createElement('td')); } -/** - * This function handles custom drawing for the Game.Draw() function. - * It is hooked on 'draw' by CM.RegisterHooks() - */ -CM.Disp.Draw = function () { - // Draw autosave timer in stats menu - if ( - (Game.prefs.autosave && Game.drawT % 10 == 0) && // with autosave ON and every 10 ticks - (Game.onMenu == 'stats' && CM.Config.Stats) // while being on the stats menu only - ) { - var timer = document.getElementById('CMStatsAutosaveTimer'); - if (timer) { - timer.innerText = Game.sayTime(Game.fps * 60 - (Game.T % (Game.fps * 60)), 4); - } - } -} - /******** * Section: Functions related to the Timer Bar diff --git a/src/Disp.js b/src/Disp.js index 0092f57..7816777 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -286,6 +286,26 @@ CM.Disp.UpdateBackground = function() { Game.LeftBackground.canvas.height = Game.LeftBackground.canvas.parentNode.offsetHeight; } +/** + * This function handles custom drawing for the Game.Draw() function. + * It is hooked on 'draw' by CM.RegisterHooks() + */ +CM.Disp.Draw = function () { + // Draw autosave timer in stats menu + if ( + (Game.prefs.autosave && Game.drawT % 10 == 0) && // with autosave ON and every 10 ticks + (Game.onMenu == 'stats' && CM.Config.Stats) // while being on the stats menu only + ) { + var timer = document.getElementById('CMStatsAutosaveTimer'); + if (timer) { + timer.innerText = Game.sayTime(Game.fps * 60 - (Game.T % (Game.fps * 60)), 4); + } + } +} + +/******** + * Section: Functions related to the Bottom Bar */ + /** * This function toggle the bottom bar * It is called by CM.Disp.UpdateAscendState() and a change in CM.Config.BotBar @@ -405,23 +425,6 @@ CM.Disp.CreateBotBarBuildingColumn = function(buildingName) { time.appendChild(document.createElement('td')); } -/** - * This function handles custom drawing for the Game.Draw() function. - * It is hooked on 'draw' by CM.RegisterHooks() - */ -CM.Disp.Draw = function () { - // Draw autosave timer in stats menu - if ( - (Game.prefs.autosave && Game.drawT % 10 == 0) && // with autosave ON and every 10 ticks - (Game.onMenu == 'stats' && CM.Config.Stats) // while being on the stats menu only - ) { - var timer = document.getElementById('CMStatsAutosaveTimer'); - if (timer) { - timer.innerText = Game.sayTime(Game.fps * 60 - (Game.T % (Game.fps * 60)), 4); - } - } -} - /******** * Section: Functions related to the Timer Bar From 36e64d3d90469096c1ab51841640f6b50db119e7 Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Sat, 5 Dec 2020 23:13:28 +0100 Subject: [PATCH 033/106] First version of stats page --- CookieMonster.js | 208 +++++++++++++++++++++++++++-------------------- src/Disp.js | 204 ++++++++++++++++++++++++++-------------------- 2 files changed, 238 insertions(+), 174 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index d6a1001..ac8d14e 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -891,7 +891,7 @@ CM.ConfigData.Scale = {type: 'bool', group: 'Other', label: ['Game\'s Setting Sc ********/ /******** - * Please make sure to annotate your code correctly using JSDoc. See the options page section for some examples. + * Please make sure to annotate your code correctly using JSDoc. * Only put functions related to graphics and displays in this file. * All calculations and data should preferrably be put in other files. */ @@ -2869,7 +2869,6 @@ CM.Disp.AddMenuStats = function(title) { var stats = document.createElement('div'); stats.className = 'subsection'; stats.appendChild(title()); - var listing = function(name, text) { var div = document.createElement('div'); div.className = 'listing'; @@ -2882,65 +2881,6 @@ CM.Disp.AddMenuStats = function(title) { return div; } - var listingQuest = function(text, placeholder) { - var frag = document.createDocumentFragment(); - frag.appendChild(document.createTextNode(text + ' ')); - var span = document.createElement('span'); - span.onmouseout = function() { Game.tooltip.hide(); }; - span.onmouseover = function() {Game.tooltip.draw(this, escape(CM.Disp[placeholder].innerHTML));}; - span.style.cursor = 'default'; - span.style.display = 'inline-block'; - span.style.height = '10px'; - span.style.width = '10px'; - span.style.borderRadius = '5px'; - span.style.textAlign = 'center'; - span.style.backgroundColor = '#C0C0C0'; - span.style.color = 'black'; - span.style.fontSize = '9px'; - span.style.verticalAlign = 'bottom'; - span.textContent = '?'; - frag.appendChild(span); - return frag; - } - - var createMissDisp = function(theMissDisp) { - var frag = document.createDocumentFragment(); - frag.appendChild(document.createTextNode(theMissDisp.length + ' ')); - var span = document.createElement('span'); - span.onmouseout = function() { Game.tooltip.hide(); }; - var placeholder = document.createElement('div'); - var missing = document.createElement('div'); - missing.style.minWidth = '140px'; - missing.style.marginBottom = '4px'; - var title = document.createElement('div'); - title.className = 'name'; - title.style.marginBottom = '4px'; - title.style.textAlign = 'center'; - title.textContent = 'Missing'; - missing.appendChild(title); - for (var i in theMissDisp) { - var div = document.createElement('div'); - div.style.textAlign = 'center'; - div.appendChild(document.createTextNode(theMissDisp[i])); - missing.appendChild(div); - } - placeholder.appendChild(missing); - span.onmouseover = function() {Game.tooltip.draw(this, escape(placeholder.innerHTML));}; - span.style.cursor = 'default'; - span.style.display = 'inline-block'; - span.style.height = '10px'; - span.style.width = '10px'; - span.style.borderRadius = '5px'; - span.style.textAlign = 'center'; - span.style.backgroundColor = '#C0C0C0'; - span.style.color = 'black'; - span.style.fontSize = '9px'; - span.style.verticalAlign = 'bottom'; - span.textContent = '?'; - frag.appendChild(span); - return frag; - } - var goldCookTooltip = CM.Sim.auraMult('Dragon\'s Fortune') ? 'GoldCookDragonsFortuneTooltipPlaceholder' : 'GoldCookTooltipPlaceholder'; stats.appendChild(CM.Disp.CreateStatsHeader('Lucky Cookies', 'Lucky')); @@ -2969,7 +2909,10 @@ CM.Disp.AddMenuStats = function(title) { luckyReqSmall.textContent = ' (' + luckyTime + ')'; luckyReqFrag.appendChild(luckyReqSmall); } - stats.appendChild(listing(listingQuest('\"Lucky!\" Cookies Required', goldCookTooltip), luckyReqFrag)); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Lucky!\" Cookies Required', Beautify(CM.Cache.Lucky), goldCookTooltip)); + + + var luckyReqFrenFrag = document.createDocumentFragment(); var luckyReqFrenSpan = document.createElement('span'); luckyReqFrenSpan.style.fontWeight = 'bold'; @@ -2981,10 +2924,10 @@ CM.Disp.AddMenuStats = function(title) { luckyReqFrenSmall.textContent = ' (' + luckyTimeFrenzy + ')'; luckyReqFrenFrag.appendChild(luckyReqFrenSmall); } - stats.appendChild(listing(listingQuest('\"Lucky!\" Cookies Required (Frenzy)', goldCookTooltip), luckyReqFrenFrag)); - stats.appendChild(listing(listingQuest('\"Lucky!\" Reward (MAX)' + (luckySplit ? ' (Golden / Wrath)' : ''), goldCookTooltip), document.createTextNode(Beautify(luckyRewardMax) + (luckySplit ? (' / ' + Beautify(luckyRewardMaxWrath)) : '')))); - stats.appendChild(listing(listingQuest('\"Lucky!\" Reward (MAX) (Frenzy)' + (luckySplit ? ' (Golden / Wrath)' : ''), goldCookTooltip), document.createTextNode(Beautify(luckyRewardFrenzyMax) + (luckySplit ? (' / ' + Beautify(luckyRewardFrenzyMaxWrath)) : '')))); - stats.appendChild(listing(listingQuest('\"Lucky!\" Reward (CUR)' + (luckySplit ? ' (Golden / Wrath)' : ''), goldCookTooltip), document.createTextNode(Beautify(luckyCur) + (luckySplit ? (' / ' + Beautify(luckyCurWrath)) : '')))); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Lucky!\" Cookies Required (Frenzy)', luckyReqFrenFrag, goldCookTooltip)); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Lucky!\" Reward (MAX)' + (luckySplit ? ' (Golden / Wrath)' : ''), Beautify(luckyRewardMax) + (luckySplit ? (' / ' + Beautify(luckyRewardMaxWrath)) : ''), goldCookTooltip)); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Lucky!\" Reward (MAX) (Frenzy)' + (luckySplit ? ' (Golden / Wrath)' : ''), Beautify(luckyRewardFrenzyMax) + (luckySplit ? (' / ' + Beautify(luckyRewardFrenzyMaxWrath)) : ''), goldCookTooltip)); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Lucky!\" Reward (CUR)' + (luckySplit ? ' (Golden / Wrath)' : ''), Beautify(luckyCur) + (luckySplit ? (' / ' + Beautify(luckyCurWrath)) : ''), goldCookTooltip)); } stats.appendChild(CM.Disp.CreateStatsHeader('Chain Cookies', 'Chain')); @@ -3017,7 +2960,7 @@ CM.Disp.AddMenuStats = function(title) { chainReqSmall.textContent = ' (' + chainTime + ')'; chainReqFrag.appendChild(chainReqSmall); } - stats.appendChild(listing(listingQuest('\"Chain\" Cookies Required', goldCookTooltip), chainReqFrag)); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Chain\" Cookies Required', chainReqFrag, goldCookTooltip)); var chainWrathReqFrag = document.createDocumentFragment(); var chainWrathReqSpan = document.createElement('span'); chainWrathReqSpan.style.fontWeight = 'bold'; @@ -3029,7 +2972,7 @@ CM.Disp.AddMenuStats = function(title) { chainWrathReqSmall.textContent = ' (' + chainWrathTime + ')'; chainWrathReqFrag.appendChild(chainWrathReqSmall); } - stats.appendChild(listing(listingQuest('\"Chain\" Cookies Required (Wrath)', goldCookTooltip), chainWrathReqFrag)); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Chain\" Cookies Required (Wrath)', chainWrathReqFrag, goldCookTooltip)); var chainReqFrenFrag = document.createDocumentFragment(); var chainReqFrenSpan = document.createElement('span'); chainReqFrenSpan.style.fontWeight = 'bold'; @@ -3041,7 +2984,7 @@ CM.Disp.AddMenuStats = function(title) { chainReqFrenSmall.textContent = ' (' + chainTimeFrenzy + ')'; chainReqFrenFrag.appendChild(chainReqFrenSmall); } - stats.appendChild(listing(listingQuest('\"Chain\" Cookies Required (Frenzy)', goldCookTooltip), chainReqFrenFrag)); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Chain\" Cookies Required (Frenzy)', chainReqFrenFrag, goldCookTooltip)); var chainWrathReqFrenFrag = document.createDocumentFragment(); var chainWrathReqFrenFrag = document.createDocumentFragment(); var chainWrathReqFrenSpan = document.createElement('span'); @@ -3054,10 +2997,10 @@ CM.Disp.AddMenuStats = function(title) { chainWrathReqFrenSmall.textContent = ' (' + chainWrathTimeFrenzy + ')'; chainWrathReqFrenFrag.appendChild(chainWrathReqFrenSmall); } - stats.appendChild(listing(listingQuest('\"Chain\" Cookies Required (Frenzy) (Wrath)', goldCookTooltip), chainWrathReqFrenFrag)); - stats.appendChild(listing(listingQuest('\"Chain\" Reward (MAX) (Golden / Wrath)', goldCookTooltip), document.createTextNode(Beautify(chainRewardMax) + ' / ' + Beautify(chainWrathRewardMax)))); - stats.appendChild(listing(listingQuest('\"Chain\" Reward (MAX) (Frenzy) (Golden / Wrath)', goldCookTooltip), document.createTextNode(Beautify(chainFrenzyRewardMax) + ' / ' + Beautify(chainFrenzyWrathRewardMax)))); - stats.appendChild(listing(listingQuest('\"Chain\" Reward (CUR) (Golden / Wrath)', goldCookTooltip), document.createTextNode(Beautify(chainCur) + ' / ' + Beautify(chainCurWrath)))); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Chain\" Cookies Required (Frenzy) (Wrath)', chainWrathReqFrenFrag, goldCookTooltip)); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Chain\" Reward (MAX) (Golden / Wrath)', Beautify(chainRewardMax) + ' / ' + Beautify(chainWrathRewardMax), goldCookTooltip)); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Chain\" Reward (MAX) (Frenzy) (Golden / Wrath)', Beautify(chainFrenzyRewardMax) + ' / ' + Beautify(chainFrenzyWrathRewardMax), goldCookTooltip)); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Chain\" Reward (CUR) (Golden / Wrath)', Beautify(chainCur) + ' / ' + Beautify(chainCurWrath), goldCookTooltip)); } stats.appendChild(CM.Disp.CreateStatsHeader('Conjure Baked Goods', 'Conjure')); @@ -3078,9 +3021,9 @@ CM.Disp.AddMenuStats = function(title) { conjureReqSmall.textContent = ' (' + conjureTime + ')'; conjureReqFrag.appendChild(conjureReqSmall); } - stats.appendChild(listing(listingQuest('\"Conjure Baked Goods\" Cookies Required', 'GoldCookTooltipPlaceholder'), conjureReqFrag)); - stats.appendChild(listing(listingQuest('\"Conjure Baked Goods\" Reward (MAX)', 'GoldCookTooltipPlaceholder'), document.createTextNode(Beautify(conjureRewardMax)))); - stats.appendChild(listing(listingQuest('\"Conjure Baked Goods\" Reward (CUR)', 'GoldCookTooltipPlaceholder'), document.createTextNode(Beautify(conjureCur)))); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Conjure Baked Goods\" Cookies Required', conjureReqFrag, 'GoldCookTooltipPlaceholder')); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Conjure Baked Goods\" Reward (MAX)', conjureRewardMax, 'GoldCookTooltipPlaceholder')); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Conjure Baked Goods\" Reward (CUR)', conjureCur, 'GoldCookTooltipPlaceholder')); } var choEgg = (Game.HasUnlocked('Chocolate egg') && !Game.Has('Chocolate egg')); // Needs to be done for the checking below @@ -3089,15 +3032,15 @@ CM.Disp.AddMenuStats = function(title) { if (CM.Config.StatsPref.Prestige) { var possiblePresMax = Math.floor(Game.HowMuchPrestige(CM.Cache.RealCookiesEarned + Game.cookiesReset + CM.Cache.WrinkGodBank + (choEgg ? CM.Cache.lastChoEgg : 0))); var neededCook = Game.HowManyCookiesReset(possiblePresMax + 1) - (CM.Cache.RealCookiesEarned + Game.cookiesReset + CM.Cache.WrinkGodBank + (choEgg ? CM.Cache.lastChoEgg : 0)); - stats.appendChild(listing(listingQuest('Prestige Level (CUR / MAX)', 'PrestMaxTooltipPlaceholder'), document.createTextNode(Beautify(Game.prestige) + ' / ' + Beautify(possiblePresMax)))); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", 'Prestige Level (CUR / MAX)', Beautify(Game.prestige) + ' / ' + Beautify(possiblePresMax), 'PrestMaxTooltipPlaceholder')); var cookiesNextFrag = document.createDocumentFragment(); cookiesNextFrag.appendChild(document.createTextNode(Beautify(neededCook))); var cookiesNextSmall = document.createElement('small'); cookiesNextSmall.textContent = ' (' + (CM.Disp.FormatTime(neededCook / CM.Cache.AvgCPSChoEgg, 1)) + ')'; cookiesNextFrag.appendChild(cookiesNextSmall); - stats.appendChild(listing(listingQuest('Cookies To Next Level', 'NextPrestTooltipPlaceholder'), cookiesNextFrag)); - stats.appendChild(listing(listingQuest('Heavenly Chips (CUR / MAX)', 'HeavenChipMaxTooltipPlaceholder'), document.createTextNode(Beautify(Game.heavenlyChips) + ' / ' + Beautify((possiblePresMax - Game.prestige) + Game.heavenlyChips)))); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", 'Cookies To Next Level', cookiesNextFrag, 'NextPrestTooltipPlaceholder')); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", 'Heavenly Chips (CUR / MAX)', Beautify(Game.heavenlyChips) + ' / ' + Beautify((possiblePresMax - Game.prestige) + Game.heavenlyChips), 'HeavenChipMaxTooltipPlaceholder')); var resetBonus = CM.Sim.ResetBonus(possiblePresMax); var resetFrag = document.createDocumentFragment(); @@ -3108,7 +3051,7 @@ CM.Disp.AddMenuStats = function(title) { resetSmall.textContent = ' (' + (increase / 100) + '% of income)'; resetFrag.appendChild(resetSmall); } - stats.appendChild(listing(listingQuest('Reset Bonus Income', 'ResetTooltipPlaceholder'), resetFrag)); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", 'Reset Bonus Income', resetFrag, 'ResetTooltipPlaceholder')); var currentPrestige = Math.floor(Game.HowMuchPrestige(Game.cookiesReset)); var willHave = Math.floor(Game.HowMuchPrestige(Game.cookiesReset + Game.cookiesEarned)); @@ -3228,16 +3171,16 @@ CM.Disp.AddMenuStats = function(title) { stats.appendChild(CM.Disp.CreateStatsHeader('Season Specials', 'Sea')); if (CM.Config.StatsPref.Sea) { if (specDisp) { - if (halloCook.length != 0) stats.appendChild(listing('Halloween Cookies Left to Buy', createMissDisp(halloCook))); - if (christCook.length != 0) stats.appendChild(listing('Christmas Cookies Left to Buy', createMissDisp(christCook))); - if (valCook.length != 0) stats.appendChild(listing('Valentine Cookies Left to Buy', createMissDisp(valCook))); - if (normEggs.length != 0) stats.appendChild(listing('Normal Easter Eggs Left to Unlock', createMissDisp(normEggs))); - if (rareEggs.length != 0) stats.appendChild(listing('Rare Easter Eggs Left to Unlock', createMissDisp(rareEggs))); + if (halloCook.length != 0) stats.appendChild(listing('Halloween Cookies Left to Buy', CM.Disp.CreateStatsMissDisp(halloCook))); + if (christCook.length != 0) stats.appendChild(listing('Christmas Cookies Left to Buy', CM.Disp.CreateStatsMissDisp(christCook))); + if (valCook.length != 0) stats.appendChild(listing('Valentine Cookies Left to Buy', CM.Disp.CreateStatsMissDisp(valCook))); + if (normEggs.length != 0) stats.appendChild(listing('Normal Easter Eggs Left to Unlock', CM.Disp.CreateStatsMissDisp(normEggs))); + if (rareEggs.length != 0) stats.appendChild(listing('Rare Easter Eggs Left to Unlock', CM.Disp.CreateStatsMissDisp(rareEggs))); } if (Game.season == 'christmas') stats.appendChild(listing('Reindeer Reward', document.createTextNode(Beautify(CM.Cache.SeaSpec)))); if (choEgg) { - stats.appendChild(listing(listingQuest('Chocolate Egg Cookies', 'ChoEggTooltipPlaceholder'), document.createTextNode(Beautify(CM.Cache.lastChoEgg)))); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", 'Chocolate Egg Cookies', Beautify(CM.Cache.lastChoEgg), 'ChoEggTooltipPlaceholder')); } if (centEgg) { stats.appendChild(listing('Century Egg Multiplier', document.createTextNode((Math.round((CM.Cache.CentEgg - 1) * 10000) / 100) + '%'))); @@ -3259,7 +3202,7 @@ CM.Disp.AddMenuStats = function(title) { fortunes.push(CM.Data.Fortunes[i]); } } - if (fortunes.length != 0) stats.appendChild(listing('Fortune Upgrades Left to Buy', createMissDisp(fortunes))); + if (fortunes.length != 0) stats.appendChild(listing('Fortune Upgrades Left to Buy', CM.Disp.CreateStatsMissDisp(fortunes))); } stats.appendChild(listing('Missed Golden Cookies', document.createTextNode(Beautify(Game.missedGoldenClicks)))); if (Game.prefs.autosave) { @@ -3307,6 +3250,97 @@ CM.Disp.CreateStatsHeader = function(text, config) { return div; } +/** + * This function creates an stats-listing-object for the stats page + * It is called by CM.Disp.AddMenuStats() + * @param {string} type The type fo the listing + * @param {string} name The name of the option + * @param {object} text The text-object of the option + * @param {string} placeholder The id of the to-be displayed tooltip if applicable + * @returns {object} div The option object + */ +CM.Disp.CreateStatsListing = function(type, name, text, placeholder) { + if (type == "withTooltip") { + var div = document.createElement('div'); + div.className = 'listingWithTooltip'; + + + + var listingName = document.createElement('span'); + listingName.textContent = name + ' ' + div.appendChild(listingName); + + var frag = document.createDocumentFragment(); + var tooltip = document.createElement('span'); + tooltip.onmouseout = function() { Game.tooltip.hide(); }; + tooltip.onmouseover = function() {Game.tooltip.draw(this, escape(CM.Disp[placeholder].innerHTML));}; + tooltip.style.cursor = 'default'; + tooltip.style.display = 'inline-block'; + tooltip.style.height = '10px'; + tooltip.style.width = '10px'; + tooltip.style.borderRadius = '5px'; + tooltip.style.textAlign = 'center'; + tooltip.style.backgroundColor = '#C0C0C0'; + tooltip.style.color = 'black'; + tooltip.style.fontSize = '9px'; + tooltip.style.verticalAlign = 'bottom'; + tooltip.textContent = '?'; + frag.appendChild(tooltip); + frag.appendChild(document.createTextNode(' : ')); + div.appendChild(frag); + + div.appendChild(text); + return div; + } + +} + + +/** + * This function ? + * @param {string} theMissDisp The type fo the listing + * @returns {object} frag The option object + */ +CM.Disp.CreateStatsMissDisp = function(theMissDisp) { + var frag = document.createDocumentFragment(); + frag.appendChild(document.createTextNode(theMissDisp.length + ' ')); + var span = document.createElement('span'); + span.onmouseout = function() { Game.tooltip.hide(); }; + var placeholder = document.createElement('div'); + var missing = document.createElement('div'); + missing.style.minWidth = '140px'; + missing.style.marginBottom = '4px'; + var title = document.createElement('div'); + title.className = 'name'; + title.style.marginBottom = '4px'; + title.style.textAlign = 'center'; + title.textContent = 'Missing'; + missing.appendChild(title); + for (var i in theMissDisp) { + var div = document.createElement('div'); + div.style.textAlign = 'center'; + div.appendChild(document.createTextNode(theMissDisp[i])); + missing.appendChild(div); + } + placeholder.appendChild(missing); + span.onmouseover = function() {Game.tooltip.draw(this, escape(placeholder.innerHTML));}; + span.style.cursor = 'default'; + span.style.display = 'inline-block'; + span.style.height = '10px'; + span.style.width = '10px'; + span.style.borderRadius = '5px'; + span.style.textAlign = 'center'; + span.style.backgroundColor = '#C0C0C0'; + span.style.color = 'black'; + span.style.fontSize = '9px'; + span.style.verticalAlign = 'bottom'; + span.textContent = '?'; + frag.appendChild(span); + return frag; +} + + + CM.Disp.AddMissingUpgrades = function() { if (CM.Cache.UpgradesOwned != Game.UpgradesOwned) { CM.Cache.CalcMissingUpgrades(); diff --git a/src/Disp.js b/src/Disp.js index ea8cbe1..0c5b9c2 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -3,7 +3,7 @@ ********/ /******** - * Please make sure to annotate your code correctly using JSDoc. See the options page section for some examples. + * Please make sure to annotate your code correctly using JSDoc. * Only put functions related to graphics and displays in this file. * All calculations and data should preferrably be put in other files. */ @@ -1981,7 +1981,6 @@ CM.Disp.AddMenuStats = function(title) { var stats = document.createElement('div'); stats.className = 'subsection'; stats.appendChild(title()); - var listing = function(name, text) { var div = document.createElement('div'); div.className = 'listing'; @@ -1994,65 +1993,6 @@ CM.Disp.AddMenuStats = function(title) { return div; } - var listingQuest = function(text, placeholder) { - var frag = document.createDocumentFragment(); - frag.appendChild(document.createTextNode(text + ' ')); - var span = document.createElement('span'); - span.onmouseout = function() { Game.tooltip.hide(); }; - span.onmouseover = function() {Game.tooltip.draw(this, escape(CM.Disp[placeholder].innerHTML));}; - span.style.cursor = 'default'; - span.style.display = 'inline-block'; - span.style.height = '10px'; - span.style.width = '10px'; - span.style.borderRadius = '5px'; - span.style.textAlign = 'center'; - span.style.backgroundColor = '#C0C0C0'; - span.style.color = 'black'; - span.style.fontSize = '9px'; - span.style.verticalAlign = 'bottom'; - span.textContent = '?'; - frag.appendChild(span); - return frag; - } - - var createMissDisp = function(theMissDisp) { - var frag = document.createDocumentFragment(); - frag.appendChild(document.createTextNode(theMissDisp.length + ' ')); - var span = document.createElement('span'); - span.onmouseout = function() { Game.tooltip.hide(); }; - var placeholder = document.createElement('div'); - var missing = document.createElement('div'); - missing.style.minWidth = '140px'; - missing.style.marginBottom = '4px'; - var title = document.createElement('div'); - title.className = 'name'; - title.style.marginBottom = '4px'; - title.style.textAlign = 'center'; - title.textContent = 'Missing'; - missing.appendChild(title); - for (var i in theMissDisp) { - var div = document.createElement('div'); - div.style.textAlign = 'center'; - div.appendChild(document.createTextNode(theMissDisp[i])); - missing.appendChild(div); - } - placeholder.appendChild(missing); - span.onmouseover = function() {Game.tooltip.draw(this, escape(placeholder.innerHTML));}; - span.style.cursor = 'default'; - span.style.display = 'inline-block'; - span.style.height = '10px'; - span.style.width = '10px'; - span.style.borderRadius = '5px'; - span.style.textAlign = 'center'; - span.style.backgroundColor = '#C0C0C0'; - span.style.color = 'black'; - span.style.fontSize = '9px'; - span.style.verticalAlign = 'bottom'; - span.textContent = '?'; - frag.appendChild(span); - return frag; - } - var goldCookTooltip = CM.Sim.auraMult('Dragon\'s Fortune') ? 'GoldCookDragonsFortuneTooltipPlaceholder' : 'GoldCookTooltipPlaceholder'; stats.appendChild(CM.Disp.CreateStatsHeader('Lucky Cookies', 'Lucky')); @@ -2081,7 +2021,10 @@ CM.Disp.AddMenuStats = function(title) { luckyReqSmall.textContent = ' (' + luckyTime + ')'; luckyReqFrag.appendChild(luckyReqSmall); } - stats.appendChild(listing(listingQuest('\"Lucky!\" Cookies Required', goldCookTooltip), luckyReqFrag)); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Lucky!\" Cookies Required', Beautify(CM.Cache.Lucky), goldCookTooltip)); + + + var luckyReqFrenFrag = document.createDocumentFragment(); var luckyReqFrenSpan = document.createElement('span'); luckyReqFrenSpan.style.fontWeight = 'bold'; @@ -2093,10 +2036,10 @@ CM.Disp.AddMenuStats = function(title) { luckyReqFrenSmall.textContent = ' (' + luckyTimeFrenzy + ')'; luckyReqFrenFrag.appendChild(luckyReqFrenSmall); } - stats.appendChild(listing(listingQuest('\"Lucky!\" Cookies Required (Frenzy)', goldCookTooltip), luckyReqFrenFrag)); - stats.appendChild(listing(listingQuest('\"Lucky!\" Reward (MAX)' + (luckySplit ? ' (Golden / Wrath)' : ''), goldCookTooltip), document.createTextNode(Beautify(luckyRewardMax) + (luckySplit ? (' / ' + Beautify(luckyRewardMaxWrath)) : '')))); - stats.appendChild(listing(listingQuest('\"Lucky!\" Reward (MAX) (Frenzy)' + (luckySplit ? ' (Golden / Wrath)' : ''), goldCookTooltip), document.createTextNode(Beautify(luckyRewardFrenzyMax) + (luckySplit ? (' / ' + Beautify(luckyRewardFrenzyMaxWrath)) : '')))); - stats.appendChild(listing(listingQuest('\"Lucky!\" Reward (CUR)' + (luckySplit ? ' (Golden / Wrath)' : ''), goldCookTooltip), document.createTextNode(Beautify(luckyCur) + (luckySplit ? (' / ' + Beautify(luckyCurWrath)) : '')))); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Lucky!\" Cookies Required (Frenzy)', luckyReqFrenFrag, goldCookTooltip)); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Lucky!\" Reward (MAX)' + (luckySplit ? ' (Golden / Wrath)' : ''), Beautify(luckyRewardMax) + (luckySplit ? (' / ' + Beautify(luckyRewardMaxWrath)) : ''), goldCookTooltip)); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Lucky!\" Reward (MAX) (Frenzy)' + (luckySplit ? ' (Golden / Wrath)' : ''), Beautify(luckyRewardFrenzyMax) + (luckySplit ? (' / ' + Beautify(luckyRewardFrenzyMaxWrath)) : ''), goldCookTooltip)); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Lucky!\" Reward (CUR)' + (luckySplit ? ' (Golden / Wrath)' : ''), Beautify(luckyCur) + (luckySplit ? (' / ' + Beautify(luckyCurWrath)) : ''), goldCookTooltip)); } stats.appendChild(CM.Disp.CreateStatsHeader('Chain Cookies', 'Chain')); @@ -2129,7 +2072,7 @@ CM.Disp.AddMenuStats = function(title) { chainReqSmall.textContent = ' (' + chainTime + ')'; chainReqFrag.appendChild(chainReqSmall); } - stats.appendChild(listing(listingQuest('\"Chain\" Cookies Required', goldCookTooltip), chainReqFrag)); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Chain\" Cookies Required', chainReqFrag, goldCookTooltip)); var chainWrathReqFrag = document.createDocumentFragment(); var chainWrathReqSpan = document.createElement('span'); chainWrathReqSpan.style.fontWeight = 'bold'; @@ -2141,7 +2084,7 @@ CM.Disp.AddMenuStats = function(title) { chainWrathReqSmall.textContent = ' (' + chainWrathTime + ')'; chainWrathReqFrag.appendChild(chainWrathReqSmall); } - stats.appendChild(listing(listingQuest('\"Chain\" Cookies Required (Wrath)', goldCookTooltip), chainWrathReqFrag)); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Chain\" Cookies Required (Wrath)', chainWrathReqFrag, goldCookTooltip)); var chainReqFrenFrag = document.createDocumentFragment(); var chainReqFrenSpan = document.createElement('span'); chainReqFrenSpan.style.fontWeight = 'bold'; @@ -2153,7 +2096,7 @@ CM.Disp.AddMenuStats = function(title) { chainReqFrenSmall.textContent = ' (' + chainTimeFrenzy + ')'; chainReqFrenFrag.appendChild(chainReqFrenSmall); } - stats.appendChild(listing(listingQuest('\"Chain\" Cookies Required (Frenzy)', goldCookTooltip), chainReqFrenFrag)); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Chain\" Cookies Required (Frenzy)', chainReqFrenFrag, goldCookTooltip)); var chainWrathReqFrenFrag = document.createDocumentFragment(); var chainWrathReqFrenFrag = document.createDocumentFragment(); var chainWrathReqFrenSpan = document.createElement('span'); @@ -2166,10 +2109,10 @@ CM.Disp.AddMenuStats = function(title) { chainWrathReqFrenSmall.textContent = ' (' + chainWrathTimeFrenzy + ')'; chainWrathReqFrenFrag.appendChild(chainWrathReqFrenSmall); } - stats.appendChild(listing(listingQuest('\"Chain\" Cookies Required (Frenzy) (Wrath)', goldCookTooltip), chainWrathReqFrenFrag)); - stats.appendChild(listing(listingQuest('\"Chain\" Reward (MAX) (Golden / Wrath)', goldCookTooltip), document.createTextNode(Beautify(chainRewardMax) + ' / ' + Beautify(chainWrathRewardMax)))); - stats.appendChild(listing(listingQuest('\"Chain\" Reward (MAX) (Frenzy) (Golden / Wrath)', goldCookTooltip), document.createTextNode(Beautify(chainFrenzyRewardMax) + ' / ' + Beautify(chainFrenzyWrathRewardMax)))); - stats.appendChild(listing(listingQuest('\"Chain\" Reward (CUR) (Golden / Wrath)', goldCookTooltip), document.createTextNode(Beautify(chainCur) + ' / ' + Beautify(chainCurWrath)))); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Chain\" Cookies Required (Frenzy) (Wrath)', chainWrathReqFrenFrag, goldCookTooltip)); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Chain\" Reward (MAX) (Golden / Wrath)', Beautify(chainRewardMax) + ' / ' + Beautify(chainWrathRewardMax), goldCookTooltip)); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Chain\" Reward (MAX) (Frenzy) (Golden / Wrath)', Beautify(chainFrenzyRewardMax) + ' / ' + Beautify(chainFrenzyWrathRewardMax), goldCookTooltip)); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Chain\" Reward (CUR) (Golden / Wrath)', Beautify(chainCur) + ' / ' + Beautify(chainCurWrath), goldCookTooltip)); } stats.appendChild(CM.Disp.CreateStatsHeader('Conjure Baked Goods', 'Conjure')); @@ -2190,9 +2133,9 @@ CM.Disp.AddMenuStats = function(title) { conjureReqSmall.textContent = ' (' + conjureTime + ')'; conjureReqFrag.appendChild(conjureReqSmall); } - stats.appendChild(listing(listingQuest('\"Conjure Baked Goods\" Cookies Required', 'GoldCookTooltipPlaceholder'), conjureReqFrag)); - stats.appendChild(listing(listingQuest('\"Conjure Baked Goods\" Reward (MAX)', 'GoldCookTooltipPlaceholder'), document.createTextNode(Beautify(conjureRewardMax)))); - stats.appendChild(listing(listingQuest('\"Conjure Baked Goods\" Reward (CUR)', 'GoldCookTooltipPlaceholder'), document.createTextNode(Beautify(conjureCur)))); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Conjure Baked Goods\" Cookies Required', conjureReqFrag, 'GoldCookTooltipPlaceholder')); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Conjure Baked Goods\" Reward (MAX)', conjureRewardMax, 'GoldCookTooltipPlaceholder')); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Conjure Baked Goods\" Reward (CUR)', conjureCur, 'GoldCookTooltipPlaceholder')); } var choEgg = (Game.HasUnlocked('Chocolate egg') && !Game.Has('Chocolate egg')); // Needs to be done for the checking below @@ -2201,15 +2144,15 @@ CM.Disp.AddMenuStats = function(title) { if (CM.Config.StatsPref.Prestige) { var possiblePresMax = Math.floor(Game.HowMuchPrestige(CM.Cache.RealCookiesEarned + Game.cookiesReset + CM.Cache.WrinkGodBank + (choEgg ? CM.Cache.lastChoEgg : 0))); var neededCook = Game.HowManyCookiesReset(possiblePresMax + 1) - (CM.Cache.RealCookiesEarned + Game.cookiesReset + CM.Cache.WrinkGodBank + (choEgg ? CM.Cache.lastChoEgg : 0)); - stats.appendChild(listing(listingQuest('Prestige Level (CUR / MAX)', 'PrestMaxTooltipPlaceholder'), document.createTextNode(Beautify(Game.prestige) + ' / ' + Beautify(possiblePresMax)))); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", 'Prestige Level (CUR / MAX)', Beautify(Game.prestige) + ' / ' + Beautify(possiblePresMax), 'PrestMaxTooltipPlaceholder')); var cookiesNextFrag = document.createDocumentFragment(); cookiesNextFrag.appendChild(document.createTextNode(Beautify(neededCook))); var cookiesNextSmall = document.createElement('small'); cookiesNextSmall.textContent = ' (' + (CM.Disp.FormatTime(neededCook / CM.Cache.AvgCPSChoEgg, 1)) + ')'; cookiesNextFrag.appendChild(cookiesNextSmall); - stats.appendChild(listing(listingQuest('Cookies To Next Level', 'NextPrestTooltipPlaceholder'), cookiesNextFrag)); - stats.appendChild(listing(listingQuest('Heavenly Chips (CUR / MAX)', 'HeavenChipMaxTooltipPlaceholder'), document.createTextNode(Beautify(Game.heavenlyChips) + ' / ' + Beautify((possiblePresMax - Game.prestige) + Game.heavenlyChips)))); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", 'Cookies To Next Level', cookiesNextFrag, 'NextPrestTooltipPlaceholder')); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", 'Heavenly Chips (CUR / MAX)', Beautify(Game.heavenlyChips) + ' / ' + Beautify((possiblePresMax - Game.prestige) + Game.heavenlyChips), 'HeavenChipMaxTooltipPlaceholder')); var resetBonus = CM.Sim.ResetBonus(possiblePresMax); var resetFrag = document.createDocumentFragment(); @@ -2220,7 +2163,7 @@ CM.Disp.AddMenuStats = function(title) { resetSmall.textContent = ' (' + (increase / 100) + '% of income)'; resetFrag.appendChild(resetSmall); } - stats.appendChild(listing(listingQuest('Reset Bonus Income', 'ResetTooltipPlaceholder'), resetFrag)); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", 'Reset Bonus Income', resetFrag, 'ResetTooltipPlaceholder')); var currentPrestige = Math.floor(Game.HowMuchPrestige(Game.cookiesReset)); var willHave = Math.floor(Game.HowMuchPrestige(Game.cookiesReset + Game.cookiesEarned)); @@ -2340,16 +2283,16 @@ CM.Disp.AddMenuStats = function(title) { stats.appendChild(CM.Disp.CreateStatsHeader('Season Specials', 'Sea')); if (CM.Config.StatsPref.Sea) { if (specDisp) { - if (halloCook.length != 0) stats.appendChild(listing('Halloween Cookies Left to Buy', createMissDisp(halloCook))); - if (christCook.length != 0) stats.appendChild(listing('Christmas Cookies Left to Buy', createMissDisp(christCook))); - if (valCook.length != 0) stats.appendChild(listing('Valentine Cookies Left to Buy', createMissDisp(valCook))); - if (normEggs.length != 0) stats.appendChild(listing('Normal Easter Eggs Left to Unlock', createMissDisp(normEggs))); - if (rareEggs.length != 0) stats.appendChild(listing('Rare Easter Eggs Left to Unlock', createMissDisp(rareEggs))); + if (halloCook.length != 0) stats.appendChild(listing('Halloween Cookies Left to Buy', CM.Disp.CreateStatsMissDisp(halloCook))); + if (christCook.length != 0) stats.appendChild(listing('Christmas Cookies Left to Buy', CM.Disp.CreateStatsMissDisp(christCook))); + if (valCook.length != 0) stats.appendChild(listing('Valentine Cookies Left to Buy', CM.Disp.CreateStatsMissDisp(valCook))); + if (normEggs.length != 0) stats.appendChild(listing('Normal Easter Eggs Left to Unlock', CM.Disp.CreateStatsMissDisp(normEggs))); + if (rareEggs.length != 0) stats.appendChild(listing('Rare Easter Eggs Left to Unlock', CM.Disp.CreateStatsMissDisp(rareEggs))); } if (Game.season == 'christmas') stats.appendChild(listing('Reindeer Reward', document.createTextNode(Beautify(CM.Cache.SeaSpec)))); if (choEgg) { - stats.appendChild(listing(listingQuest('Chocolate Egg Cookies', 'ChoEggTooltipPlaceholder'), document.createTextNode(Beautify(CM.Cache.lastChoEgg)))); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", 'Chocolate Egg Cookies', Beautify(CM.Cache.lastChoEgg), 'ChoEggTooltipPlaceholder')); } if (centEgg) { stats.appendChild(listing('Century Egg Multiplier', document.createTextNode((Math.round((CM.Cache.CentEgg - 1) * 10000) / 100) + '%'))); @@ -2371,7 +2314,7 @@ CM.Disp.AddMenuStats = function(title) { fortunes.push(CM.Data.Fortunes[i]); } } - if (fortunes.length != 0) stats.appendChild(listing('Fortune Upgrades Left to Buy', createMissDisp(fortunes))); + if (fortunes.length != 0) stats.appendChild(listing('Fortune Upgrades Left to Buy', CM.Disp.CreateStatsMissDisp(fortunes))); } stats.appendChild(listing('Missed Golden Cookies', document.createTextNode(Beautify(Game.missedGoldenClicks)))); if (Game.prefs.autosave) { @@ -2419,6 +2362,93 @@ CM.Disp.CreateStatsHeader = function(text, config) { return div; } +/** + * This function creates an stats-listing-object for the stats page + * It is called by CM.Disp.AddMenuStats() + * @param {string} type The type fo the listing + * @param {string} name The name of the option + * @param {object} text The text-object of the option + * @param {string} placeholder The id of the to-be displayed tooltip if applicable + * @returns {object} div The option object + */ +CM.Disp.CreateStatsListing = function(type, name, text, placeholder) { + var div = document.createElement('div'); + div.className = 'listing'; + + var listingName = document.createElement('span'); + listingName.textContent = name + ' ' + div.appendChild(listingName); + if (type == "withTooltip") { + div.className = 'listingWithTooltip'; + + var tooltip = document.createElement('span'); + tooltip.onmouseout = function() { Game.tooltip.hide(); }; + tooltip.onmouseover = function() {Game.tooltip.draw(this, escape(CM.Disp[placeholder].innerHTML));}; + tooltip.style.cursor = 'default'; + tooltip.style.display = 'inline-block'; + tooltip.style.height = '10px'; + tooltip.style.width = '10px'; + tooltip.style.borderRadius = '5px'; + tooltip.style.textAlign = 'center'; + tooltip.style.backgroundColor = '#C0C0C0'; + tooltip.style.color = 'black'; + tooltip.style.fontSize = '9px'; + tooltip.style.verticalAlign = 'bottom'; + tooltip.textContent = '?'; + div.appendChild(tooltip); + div.appendChild(document.createTextNode(' ')); + } + div.appendChild(document.createTextNode(': ')); + div.appendChild(text); + return div; +} + + +/** + * This function ? + * @param {string} theMissDisp The type fo the listing + * @returns {object} frag The option object + */ +CM.Disp.CreateStatsMissDisp = function(theMissDisp) { + var frag = document.createDocumentFragment(); + frag.appendChild(document.createTextNode(theMissDisp.length + ' ')); + var span = document.createElement('span'); + span.onmouseout = function() { Game.tooltip.hide(); }; + var placeholder = document.createElement('div'); + var missing = document.createElement('div'); + missing.style.minWidth = '140px'; + missing.style.marginBottom = '4px'; + var title = document.createElement('div'); + title.className = 'name'; + title.style.marginBottom = '4px'; + title.style.textAlign = 'center'; + title.textContent = 'Missing'; + missing.appendChild(title); + for (var i in theMissDisp) { + var div = document.createElement('div'); + div.style.textAlign = 'center'; + div.appendChild(document.createTextNode(theMissDisp[i])); + missing.appendChild(div); + } + placeholder.appendChild(missing); + span.onmouseover = function() {Game.tooltip.draw(this, escape(placeholder.innerHTML));}; + span.style.cursor = 'default'; + span.style.display = 'inline-block'; + span.style.height = '10px'; + span.style.width = '10px'; + span.style.borderRadius = '5px'; + span.style.textAlign = 'center'; + span.style.backgroundColor = '#C0C0C0'; + span.style.color = 'black'; + span.style.fontSize = '9px'; + span.style.verticalAlign = 'bottom'; + span.textContent = '?'; + frag.appendChild(span); + return frag; +} + + + CM.Disp.AddMissingUpgrades = function() { if (CM.Cache.UpgradesOwned != Game.UpgradesOwned) { CM.Cache.CalcMissingUpgrades(); From 7e101edf8259513f47760a6f7ceae5eb89e67fa2 Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Sat, 5 Dec 2020 23:13:53 +0100 Subject: [PATCH 034/106] Fix for challenge mode --- CookieMonster.js | 32 ++++++++++++++++---------------- src/Sim.js | 6 +++++- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index ac8d14e..62c2801 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -3260,17 +3260,15 @@ CM.Disp.CreateStatsHeader = function(text, config) { * @returns {object} div The option object */ CM.Disp.CreateStatsListing = function(type, name, text, placeholder) { + var div = document.createElement('div'); + div.className = 'listing'; + + var listingName = document.createElement('span'); + listingName.textContent = name + ' ' + div.appendChild(listingName); if (type == "withTooltip") { - var div = document.createElement('div'); div.className = 'listingWithTooltip'; - - - var listingName = document.createElement('span'); - listingName.textContent = name + ' ' - div.appendChild(listingName); - - var frag = document.createDocumentFragment(); var tooltip = document.createElement('span'); tooltip.onmouseout = function() { Game.tooltip.hide(); }; tooltip.onmouseover = function() {Game.tooltip.draw(this, escape(CM.Disp[placeholder].innerHTML));}; @@ -3285,14 +3283,12 @@ CM.Disp.CreateStatsListing = function(type, name, text, placeholder) { tooltip.style.fontSize = '9px'; tooltip.style.verticalAlign = 'bottom'; tooltip.textContent = '?'; - frag.appendChild(tooltip); - frag.appendChild(document.createTextNode(' : ')); - div.appendChild(frag); - - div.appendChild(text); - return div; + div.appendChild(tooltip); + div.appendChild(document.createTextNode(' ')); } - + div.appendChild(document.createTextNode(': ')); + div.appendChild(text); + return div; } @@ -4204,7 +4200,11 @@ CM.Sim.InitialBuildingData = function(buildingName) { * so this function just returns an empty object. */ CM.Sim.InitUpgrade = function(upgradeName) { - return {}; + var me = Game.Upgrades[upgradeName]; + var you = {}; + you.pool = me.pool; + you.name = me.name; + return you; } /* Similar to the previous function, but for achievements. diff --git a/src/Sim.js b/src/Sim.js index 17988c2..7037235 100644 --- a/src/Sim.js +++ b/src/Sim.js @@ -171,7 +171,11 @@ CM.Sim.InitialBuildingData = function(buildingName) { * so this function just returns an empty object. */ CM.Sim.InitUpgrade = function(upgradeName) { - return {}; + var me = Game.Upgrades[upgradeName]; + var you = {}; + you.pool = me.pool; + you.name = me.name; + return you; } /* Similar to the previous function, but for achievements. From 87a85bfc59a57b803cfda51aba36083468a2c0ab Mon Sep 17 00:00:00 2001 From: Chorizorro Date: Sat, 5 Dec 2020 23:14:12 +0100 Subject: [PATCH 035/106] Fix favicon not being reset with no GC left --- CookieMonster.js | 6 +++--- src/Disp.js | 2 +- src/Main.js | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index 49d8928..7ba14d7 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -1894,7 +1894,7 @@ CM.Disp.CreateFavicon = function() { * By relying on CM.Cache.spawnedGoldenShimmer it only changes for non-user spawned cookie */ CM.Disp.UpdateFavicon = function() { - if (CM.Config.Favicon == 1) { + if (CM.Config.Favicon == 1 && CM.Main.lastGoldenCookieState > 0) { if (CM.Cache.spawnedGoldenShimmer.wrath) CM.Disp.Favicon.href = 'https://aktanusa.github.io/CookieMonster/favicon/wrathCookie.ico'; else CM.Disp.Favicon.href = 'https://aktanusa.github.io/CookieMonster/favicon/goldenCookie.ico'; } @@ -3784,7 +3784,6 @@ CM.Main.CheckGoldenCookie = function() { CM.Disp.PlaySound(CM.Config.GCSoundURL, 'GCSound', 'GCVolume'); CM.Disp.Notification('GCNotification', "Golden Cookie Spawned", "A Golden Cookie has spawned. Click it now!") } - CM.Disp.UpdateFavicon(); for (var i in Game.shimmers) { if (typeof CM.Disp.GCTimers[Game.shimmers[i].id] == "undefined") { @@ -3792,7 +3791,8 @@ CM.Main.CheckGoldenCookie = function() { } } } - CM.Main.lastSpawnedGoldenCookieState = CM.Main.currSpawnedGoldenCookieState + CM.Disp.UpdateFavicon(); + CM.Main.lastSpawnedGoldenCookieState = CM.Main.currSpawnedGoldenCookieState; if (CM.Main.currSpawnedGoldenCookieState == 0) CM.Cache.spawnedGoldenShimmer = 0; } else if (CM.Config.GCTimer == 1 && CM.Main.lastGoldenCookieState) { diff --git a/src/Disp.js b/src/Disp.js index 7816777..ec02a1e 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -1006,7 +1006,7 @@ CM.Disp.CreateFavicon = function() { * By relying on CM.Cache.spawnedGoldenShimmer it only changes for non-user spawned cookie */ CM.Disp.UpdateFavicon = function() { - if (CM.Config.Favicon == 1) { + if (CM.Config.Favicon == 1 && CM.Main.lastGoldenCookieState > 0) { if (CM.Cache.spawnedGoldenShimmer.wrath) CM.Disp.Favicon.href = 'https://aktanusa.github.io/CookieMonster/favicon/wrathCookie.ico'; else CM.Disp.Favicon.href = 'https://aktanusa.github.io/CookieMonster/favicon/goldenCookie.ico'; } diff --git a/src/Main.js b/src/Main.js index 3b336d7..23519fa 100644 --- a/src/Main.js +++ b/src/Main.js @@ -305,7 +305,6 @@ CM.Main.CheckGoldenCookie = function() { CM.Disp.PlaySound(CM.Config.GCSoundURL, 'GCSound', 'GCVolume'); CM.Disp.Notification('GCNotification', "Golden Cookie Spawned", "A Golden Cookie has spawned. Click it now!") } - CM.Disp.UpdateFavicon(); for (var i in Game.shimmers) { if (typeof CM.Disp.GCTimers[Game.shimmers[i].id] == "undefined") { @@ -313,7 +312,8 @@ CM.Main.CheckGoldenCookie = function() { } } } - CM.Main.lastSpawnedGoldenCookieState = CM.Main.currSpawnedGoldenCookieState + CM.Disp.UpdateFavicon(); + CM.Main.lastSpawnedGoldenCookieState = CM.Main.currSpawnedGoldenCookieState; if (CM.Main.currSpawnedGoldenCookieState == 0) CM.Cache.spawnedGoldenShimmer = 0; } else if (CM.Config.GCTimer == 1 && CM.Main.lastGoldenCookieState) { From b6370c187343ae7570dea583bfa2b60ea7e7faa1 Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Sat, 5 Dec 2020 23:13:28 +0100 Subject: [PATCH 036/106] First version of stats page --- CookieMonster.js | 208 +++++++++++++++++++++++++++-------------------- src/Disp.js | 204 ++++++++++++++++++++++++++-------------------- 2 files changed, 238 insertions(+), 174 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index 49d8928..fecfa67 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -891,7 +891,7 @@ CM.ConfigData.Scale = {type: 'bool', group: 'Other', label: ['Game\'s Setting Sc ********/ /******** - * Please make sure to annotate your code correctly using JSDoc. See the options page section for some examples. + * Please make sure to annotate your code correctly using JSDoc. * Only put functions related to graphics and displays in this file. * All calculations and data should preferrably be put in other files. */ @@ -2889,7 +2889,6 @@ CM.Disp.AddMenuStats = function(title) { var stats = document.createElement('div'); stats.className = 'subsection'; stats.appendChild(title()); - var listing = function(name, text) { var div = document.createElement('div'); div.className = 'listing'; @@ -2902,65 +2901,6 @@ CM.Disp.AddMenuStats = function(title) { return div; } - var listingQuest = function(text, placeholder) { - var frag = document.createDocumentFragment(); - frag.appendChild(document.createTextNode(text + ' ')); - var span = document.createElement('span'); - span.onmouseout = function() { Game.tooltip.hide(); }; - span.onmouseover = function() {Game.tooltip.draw(this, escape(CM.Disp[placeholder].innerHTML));}; - span.style.cursor = 'default'; - span.style.display = 'inline-block'; - span.style.height = '10px'; - span.style.width = '10px'; - span.style.borderRadius = '5px'; - span.style.textAlign = 'center'; - span.style.backgroundColor = '#C0C0C0'; - span.style.color = 'black'; - span.style.fontSize = '9px'; - span.style.verticalAlign = 'bottom'; - span.textContent = '?'; - frag.appendChild(span); - return frag; - } - - var createMissDisp = function(theMissDisp) { - var frag = document.createDocumentFragment(); - frag.appendChild(document.createTextNode(theMissDisp.length + ' ')); - var span = document.createElement('span'); - span.onmouseout = function() { Game.tooltip.hide(); }; - var placeholder = document.createElement('div'); - var missing = document.createElement('div'); - missing.style.minWidth = '140px'; - missing.style.marginBottom = '4px'; - var title = document.createElement('div'); - title.className = 'name'; - title.style.marginBottom = '4px'; - title.style.textAlign = 'center'; - title.textContent = 'Missing'; - missing.appendChild(title); - for (var i in theMissDisp) { - var div = document.createElement('div'); - div.style.textAlign = 'center'; - div.appendChild(document.createTextNode(theMissDisp[i])); - missing.appendChild(div); - } - placeholder.appendChild(missing); - span.onmouseover = function() {Game.tooltip.draw(this, escape(placeholder.innerHTML));}; - span.style.cursor = 'default'; - span.style.display = 'inline-block'; - span.style.height = '10px'; - span.style.width = '10px'; - span.style.borderRadius = '5px'; - span.style.textAlign = 'center'; - span.style.backgroundColor = '#C0C0C0'; - span.style.color = 'black'; - span.style.fontSize = '9px'; - span.style.verticalAlign = 'bottom'; - span.textContent = '?'; - frag.appendChild(span); - return frag; - } - var goldCookTooltip = CM.Sim.auraMult('Dragon\'s Fortune') ? 'GoldCookDragonsFortuneTooltipPlaceholder' : 'GoldCookTooltipPlaceholder'; stats.appendChild(CM.Disp.CreateStatsHeader('Lucky Cookies', 'Lucky')); @@ -2989,7 +2929,10 @@ CM.Disp.AddMenuStats = function(title) { luckyReqSmall.textContent = ' (' + luckyTime + ')'; luckyReqFrag.appendChild(luckyReqSmall); } - stats.appendChild(listing(listingQuest('\"Lucky!\" Cookies Required', goldCookTooltip), luckyReqFrag)); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Lucky!\" Cookies Required', Beautify(CM.Cache.Lucky), goldCookTooltip)); + + + var luckyReqFrenFrag = document.createDocumentFragment(); var luckyReqFrenSpan = document.createElement('span'); luckyReqFrenSpan.style.fontWeight = 'bold'; @@ -3001,10 +2944,10 @@ CM.Disp.AddMenuStats = function(title) { luckyReqFrenSmall.textContent = ' (' + luckyTimeFrenzy + ')'; luckyReqFrenFrag.appendChild(luckyReqFrenSmall); } - stats.appendChild(listing(listingQuest('\"Lucky!\" Cookies Required (Frenzy)', goldCookTooltip), luckyReqFrenFrag)); - stats.appendChild(listing(listingQuest('\"Lucky!\" Reward (MAX)' + (luckySplit ? ' (Golden / Wrath)' : ''), goldCookTooltip), document.createTextNode(Beautify(luckyRewardMax) + (luckySplit ? (' / ' + Beautify(luckyRewardMaxWrath)) : '')))); - stats.appendChild(listing(listingQuest('\"Lucky!\" Reward (MAX) (Frenzy)' + (luckySplit ? ' (Golden / Wrath)' : ''), goldCookTooltip), document.createTextNode(Beautify(luckyRewardFrenzyMax) + (luckySplit ? (' / ' + Beautify(luckyRewardFrenzyMaxWrath)) : '')))); - stats.appendChild(listing(listingQuest('\"Lucky!\" Reward (CUR)' + (luckySplit ? ' (Golden / Wrath)' : ''), goldCookTooltip), document.createTextNode(Beautify(luckyCur) + (luckySplit ? (' / ' + Beautify(luckyCurWrath)) : '')))); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Lucky!\" Cookies Required (Frenzy)', luckyReqFrenFrag, goldCookTooltip)); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Lucky!\" Reward (MAX)' + (luckySplit ? ' (Golden / Wrath)' : ''), Beautify(luckyRewardMax) + (luckySplit ? (' / ' + Beautify(luckyRewardMaxWrath)) : ''), goldCookTooltip)); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Lucky!\" Reward (MAX) (Frenzy)' + (luckySplit ? ' (Golden / Wrath)' : ''), Beautify(luckyRewardFrenzyMax) + (luckySplit ? (' / ' + Beautify(luckyRewardFrenzyMaxWrath)) : ''), goldCookTooltip)); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Lucky!\" Reward (CUR)' + (luckySplit ? ' (Golden / Wrath)' : ''), Beautify(luckyCur) + (luckySplit ? (' / ' + Beautify(luckyCurWrath)) : ''), goldCookTooltip)); } stats.appendChild(CM.Disp.CreateStatsHeader('Chain Cookies', 'Chain')); @@ -3037,7 +2980,7 @@ CM.Disp.AddMenuStats = function(title) { chainReqSmall.textContent = ' (' + chainTime + ')'; chainReqFrag.appendChild(chainReqSmall); } - stats.appendChild(listing(listingQuest('\"Chain\" Cookies Required', goldCookTooltip), chainReqFrag)); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Chain\" Cookies Required', chainReqFrag, goldCookTooltip)); var chainWrathReqFrag = document.createDocumentFragment(); var chainWrathReqSpan = document.createElement('span'); chainWrathReqSpan.style.fontWeight = 'bold'; @@ -3049,7 +2992,7 @@ CM.Disp.AddMenuStats = function(title) { chainWrathReqSmall.textContent = ' (' + chainWrathTime + ')'; chainWrathReqFrag.appendChild(chainWrathReqSmall); } - stats.appendChild(listing(listingQuest('\"Chain\" Cookies Required (Wrath)', goldCookTooltip), chainWrathReqFrag)); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Chain\" Cookies Required (Wrath)', chainWrathReqFrag, goldCookTooltip)); var chainReqFrenFrag = document.createDocumentFragment(); var chainReqFrenSpan = document.createElement('span'); chainReqFrenSpan.style.fontWeight = 'bold'; @@ -3061,7 +3004,7 @@ CM.Disp.AddMenuStats = function(title) { chainReqFrenSmall.textContent = ' (' + chainTimeFrenzy + ')'; chainReqFrenFrag.appendChild(chainReqFrenSmall); } - stats.appendChild(listing(listingQuest('\"Chain\" Cookies Required (Frenzy)', goldCookTooltip), chainReqFrenFrag)); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Chain\" Cookies Required (Frenzy)', chainReqFrenFrag, goldCookTooltip)); var chainWrathReqFrenFrag = document.createDocumentFragment(); var chainWrathReqFrenFrag = document.createDocumentFragment(); var chainWrathReqFrenSpan = document.createElement('span'); @@ -3074,10 +3017,10 @@ CM.Disp.AddMenuStats = function(title) { chainWrathReqFrenSmall.textContent = ' (' + chainWrathTimeFrenzy + ')'; chainWrathReqFrenFrag.appendChild(chainWrathReqFrenSmall); } - stats.appendChild(listing(listingQuest('\"Chain\" Cookies Required (Frenzy) (Wrath)', goldCookTooltip), chainWrathReqFrenFrag)); - stats.appendChild(listing(listingQuest('\"Chain\" Reward (MAX) (Golden / Wrath)', goldCookTooltip), document.createTextNode(Beautify(chainRewardMax) + ' / ' + Beautify(chainWrathRewardMax)))); - stats.appendChild(listing(listingQuest('\"Chain\" Reward (MAX) (Frenzy) (Golden / Wrath)', goldCookTooltip), document.createTextNode(Beautify(chainFrenzyRewardMax) + ' / ' + Beautify(chainFrenzyWrathRewardMax)))); - stats.appendChild(listing(listingQuest('\"Chain\" Reward (CUR) (Golden / Wrath)', goldCookTooltip), document.createTextNode(Beautify(chainCur) + ' / ' + Beautify(chainCurWrath)))); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Chain\" Cookies Required (Frenzy) (Wrath)', chainWrathReqFrenFrag, goldCookTooltip)); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Chain\" Reward (MAX) (Golden / Wrath)', Beautify(chainRewardMax) + ' / ' + Beautify(chainWrathRewardMax), goldCookTooltip)); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Chain\" Reward (MAX) (Frenzy) (Golden / Wrath)', Beautify(chainFrenzyRewardMax) + ' / ' + Beautify(chainFrenzyWrathRewardMax), goldCookTooltip)); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Chain\" Reward (CUR) (Golden / Wrath)', Beautify(chainCur) + ' / ' + Beautify(chainCurWrath), goldCookTooltip)); } stats.appendChild(CM.Disp.CreateStatsHeader('Conjure Baked Goods', 'Conjure')); @@ -3098,9 +3041,9 @@ CM.Disp.AddMenuStats = function(title) { conjureReqSmall.textContent = ' (' + conjureTime + ')'; conjureReqFrag.appendChild(conjureReqSmall); } - stats.appendChild(listing(listingQuest('\"Conjure Baked Goods\" Cookies Required', 'GoldCookTooltipPlaceholder'), conjureReqFrag)); - stats.appendChild(listing(listingQuest('\"Conjure Baked Goods\" Reward (MAX)', 'GoldCookTooltipPlaceholder'), document.createTextNode(Beautify(conjureRewardMax)))); - stats.appendChild(listing(listingQuest('\"Conjure Baked Goods\" Reward (CUR)', 'GoldCookTooltipPlaceholder'), document.createTextNode(Beautify(conjureCur)))); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Conjure Baked Goods\" Cookies Required', conjureReqFrag, 'GoldCookTooltipPlaceholder')); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Conjure Baked Goods\" Reward (MAX)', conjureRewardMax, 'GoldCookTooltipPlaceholder')); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Conjure Baked Goods\" Reward (CUR)', conjureCur, 'GoldCookTooltipPlaceholder')); } var choEgg = (Game.HasUnlocked('Chocolate egg') && !Game.Has('Chocolate egg')); // Needs to be done for the checking below @@ -3109,15 +3052,15 @@ CM.Disp.AddMenuStats = function(title) { if (CM.Config.StatsPref.Prestige) { var possiblePresMax = Math.floor(Game.HowMuchPrestige(CM.Cache.RealCookiesEarned + Game.cookiesReset + CM.Cache.WrinkGodBank + (choEgg ? CM.Cache.lastChoEgg : 0))); var neededCook = Game.HowManyCookiesReset(possiblePresMax + 1) - (CM.Cache.RealCookiesEarned + Game.cookiesReset + CM.Cache.WrinkGodBank + (choEgg ? CM.Cache.lastChoEgg : 0)); - stats.appendChild(listing(listingQuest('Prestige Level (CUR / MAX)', 'PrestMaxTooltipPlaceholder'), document.createTextNode(Beautify(Game.prestige) + ' / ' + Beautify(possiblePresMax)))); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", 'Prestige Level (CUR / MAX)', Beautify(Game.prestige) + ' / ' + Beautify(possiblePresMax), 'PrestMaxTooltipPlaceholder')); var cookiesNextFrag = document.createDocumentFragment(); cookiesNextFrag.appendChild(document.createTextNode(Beautify(neededCook))); var cookiesNextSmall = document.createElement('small'); cookiesNextSmall.textContent = ' (' + (CM.Disp.FormatTime(neededCook / CM.Cache.AvgCPSChoEgg, 1)) + ')'; cookiesNextFrag.appendChild(cookiesNextSmall); - stats.appendChild(listing(listingQuest('Cookies To Next Level', 'NextPrestTooltipPlaceholder'), cookiesNextFrag)); - stats.appendChild(listing(listingQuest('Heavenly Chips (CUR / MAX)', 'HeavenChipMaxTooltipPlaceholder'), document.createTextNode(Beautify(Game.heavenlyChips) + ' / ' + Beautify((possiblePresMax - Game.prestige) + Game.heavenlyChips)))); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", 'Cookies To Next Level', cookiesNextFrag, 'NextPrestTooltipPlaceholder')); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", 'Heavenly Chips (CUR / MAX)', Beautify(Game.heavenlyChips) + ' / ' + Beautify((possiblePresMax - Game.prestige) + Game.heavenlyChips), 'HeavenChipMaxTooltipPlaceholder')); var resetBonus = CM.Sim.ResetBonus(possiblePresMax); var resetFrag = document.createDocumentFragment(); @@ -3128,7 +3071,7 @@ CM.Disp.AddMenuStats = function(title) { resetSmall.textContent = ' (' + (increase / 100) + '% of income)'; resetFrag.appendChild(resetSmall); } - stats.appendChild(listing(listingQuest('Reset Bonus Income', 'ResetTooltipPlaceholder'), resetFrag)); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", 'Reset Bonus Income', resetFrag, 'ResetTooltipPlaceholder')); var currentPrestige = Math.floor(Game.HowMuchPrestige(Game.cookiesReset)); var willHave = Math.floor(Game.HowMuchPrestige(Game.cookiesReset + Game.cookiesEarned)); @@ -3248,16 +3191,16 @@ CM.Disp.AddMenuStats = function(title) { stats.appendChild(CM.Disp.CreateStatsHeader('Season Specials', 'Sea')); if (CM.Config.StatsPref.Sea) { if (specDisp) { - if (halloCook.length != 0) stats.appendChild(listing('Halloween Cookies Left to Buy', createMissDisp(halloCook))); - if (christCook.length != 0) stats.appendChild(listing('Christmas Cookies Left to Buy', createMissDisp(christCook))); - if (valCook.length != 0) stats.appendChild(listing('Valentine Cookies Left to Buy', createMissDisp(valCook))); - if (normEggs.length != 0) stats.appendChild(listing('Normal Easter Eggs Left to Unlock', createMissDisp(normEggs))); - if (rareEggs.length != 0) stats.appendChild(listing('Rare Easter Eggs Left to Unlock', createMissDisp(rareEggs))); + if (halloCook.length != 0) stats.appendChild(listing('Halloween Cookies Left to Buy', CM.Disp.CreateStatsMissDisp(halloCook))); + if (christCook.length != 0) stats.appendChild(listing('Christmas Cookies Left to Buy', CM.Disp.CreateStatsMissDisp(christCook))); + if (valCook.length != 0) stats.appendChild(listing('Valentine Cookies Left to Buy', CM.Disp.CreateStatsMissDisp(valCook))); + if (normEggs.length != 0) stats.appendChild(listing('Normal Easter Eggs Left to Unlock', CM.Disp.CreateStatsMissDisp(normEggs))); + if (rareEggs.length != 0) stats.appendChild(listing('Rare Easter Eggs Left to Unlock', CM.Disp.CreateStatsMissDisp(rareEggs))); } if (Game.season == 'christmas') stats.appendChild(listing('Reindeer Reward', document.createTextNode(Beautify(CM.Cache.SeaSpec)))); if (choEgg) { - stats.appendChild(listing(listingQuest('Chocolate Egg Cookies', 'ChoEggTooltipPlaceholder'), document.createTextNode(Beautify(CM.Cache.lastChoEgg)))); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", 'Chocolate Egg Cookies', Beautify(CM.Cache.lastChoEgg), 'ChoEggTooltipPlaceholder')); } if (centEgg) { stats.appendChild(listing('Century Egg Multiplier', document.createTextNode((Math.round((CM.Cache.CentEgg - 1) * 10000) / 100) + '%'))); @@ -3279,7 +3222,7 @@ CM.Disp.AddMenuStats = function(title) { fortunes.push(CM.Data.Fortunes[i]); } } - if (fortunes.length != 0) stats.appendChild(listing('Fortune Upgrades Left to Buy', createMissDisp(fortunes))); + if (fortunes.length != 0) stats.appendChild(listing('Fortune Upgrades Left to Buy', CM.Disp.CreateStatsMissDisp(fortunes))); } stats.appendChild(listing('Missed Golden Cookies', document.createTextNode(Beautify(Game.missedGoldenClicks)))); if (Game.prefs.autosave) { @@ -3329,6 +3272,97 @@ CM.Disp.CreateStatsHeader = function(text, config) { return div; } +/** + * This function creates an stats-listing-object for the stats page + * It is called by CM.Disp.AddMenuStats() + * @param {string} type The type fo the listing + * @param {string} name The name of the option + * @param {object} text The text-object of the option + * @param {string} placeholder The id of the to-be displayed tooltip if applicable + * @returns {object} div The option object + */ +CM.Disp.CreateStatsListing = function(type, name, text, placeholder) { + if (type == "withTooltip") { + var div = document.createElement('div'); + div.className = 'listingWithTooltip'; + + + + var listingName = document.createElement('span'); + listingName.textContent = name + ' ' + div.appendChild(listingName); + + var frag = document.createDocumentFragment(); + var tooltip = document.createElement('span'); + tooltip.onmouseout = function() { Game.tooltip.hide(); }; + tooltip.onmouseover = function() {Game.tooltip.draw(this, escape(CM.Disp[placeholder].innerHTML));}; + tooltip.style.cursor = 'default'; + tooltip.style.display = 'inline-block'; + tooltip.style.height = '10px'; + tooltip.style.width = '10px'; + tooltip.style.borderRadius = '5px'; + tooltip.style.textAlign = 'center'; + tooltip.style.backgroundColor = '#C0C0C0'; + tooltip.style.color = 'black'; + tooltip.style.fontSize = '9px'; + tooltip.style.verticalAlign = 'bottom'; + tooltip.textContent = '?'; + frag.appendChild(tooltip); + frag.appendChild(document.createTextNode(' : ')); + div.appendChild(frag); + + div.appendChild(text); + return div; + } + +} + + +/** + * This function ? + * @param {string} theMissDisp The type fo the listing + * @returns {object} frag The option object + */ +CM.Disp.CreateStatsMissDisp = function(theMissDisp) { + var frag = document.createDocumentFragment(); + frag.appendChild(document.createTextNode(theMissDisp.length + ' ')); + var span = document.createElement('span'); + span.onmouseout = function() { Game.tooltip.hide(); }; + var placeholder = document.createElement('div'); + var missing = document.createElement('div'); + missing.style.minWidth = '140px'; + missing.style.marginBottom = '4px'; + var title = document.createElement('div'); + title.className = 'name'; + title.style.marginBottom = '4px'; + title.style.textAlign = 'center'; + title.textContent = 'Missing'; + missing.appendChild(title); + for (var i in theMissDisp) { + var div = document.createElement('div'); + div.style.textAlign = 'center'; + div.appendChild(document.createTextNode(theMissDisp[i])); + missing.appendChild(div); + } + placeholder.appendChild(missing); + span.onmouseover = function() {Game.tooltip.draw(this, escape(placeholder.innerHTML));}; + span.style.cursor = 'default'; + span.style.display = 'inline-block'; + span.style.height = '10px'; + span.style.width = '10px'; + span.style.borderRadius = '5px'; + span.style.textAlign = 'center'; + span.style.backgroundColor = '#C0C0C0'; + span.style.color = 'black'; + span.style.fontSize = '9px'; + span.style.verticalAlign = 'bottom'; + span.textContent = '?'; + frag.appendChild(span); + return frag; +} + + + CM.Disp.AddMissingUpgrades = function() { if (CM.Cache.UpgradesOwned != Game.UpgradesOwned) { CM.Cache.CalcMissingUpgrades(); diff --git a/src/Disp.js b/src/Disp.js index 7816777..36120cb 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -3,7 +3,7 @@ ********/ /******** - * Please make sure to annotate your code correctly using JSDoc. See the options page section for some examples. + * Please make sure to annotate your code correctly using JSDoc. * Only put functions related to graphics and displays in this file. * All calculations and data should preferrably be put in other files. */ @@ -2001,7 +2001,6 @@ CM.Disp.AddMenuStats = function(title) { var stats = document.createElement('div'); stats.className = 'subsection'; stats.appendChild(title()); - var listing = function(name, text) { var div = document.createElement('div'); div.className = 'listing'; @@ -2014,65 +2013,6 @@ CM.Disp.AddMenuStats = function(title) { return div; } - var listingQuest = function(text, placeholder) { - var frag = document.createDocumentFragment(); - frag.appendChild(document.createTextNode(text + ' ')); - var span = document.createElement('span'); - span.onmouseout = function() { Game.tooltip.hide(); }; - span.onmouseover = function() {Game.tooltip.draw(this, escape(CM.Disp[placeholder].innerHTML));}; - span.style.cursor = 'default'; - span.style.display = 'inline-block'; - span.style.height = '10px'; - span.style.width = '10px'; - span.style.borderRadius = '5px'; - span.style.textAlign = 'center'; - span.style.backgroundColor = '#C0C0C0'; - span.style.color = 'black'; - span.style.fontSize = '9px'; - span.style.verticalAlign = 'bottom'; - span.textContent = '?'; - frag.appendChild(span); - return frag; - } - - var createMissDisp = function(theMissDisp) { - var frag = document.createDocumentFragment(); - frag.appendChild(document.createTextNode(theMissDisp.length + ' ')); - var span = document.createElement('span'); - span.onmouseout = function() { Game.tooltip.hide(); }; - var placeholder = document.createElement('div'); - var missing = document.createElement('div'); - missing.style.minWidth = '140px'; - missing.style.marginBottom = '4px'; - var title = document.createElement('div'); - title.className = 'name'; - title.style.marginBottom = '4px'; - title.style.textAlign = 'center'; - title.textContent = 'Missing'; - missing.appendChild(title); - for (var i in theMissDisp) { - var div = document.createElement('div'); - div.style.textAlign = 'center'; - div.appendChild(document.createTextNode(theMissDisp[i])); - missing.appendChild(div); - } - placeholder.appendChild(missing); - span.onmouseover = function() {Game.tooltip.draw(this, escape(placeholder.innerHTML));}; - span.style.cursor = 'default'; - span.style.display = 'inline-block'; - span.style.height = '10px'; - span.style.width = '10px'; - span.style.borderRadius = '5px'; - span.style.textAlign = 'center'; - span.style.backgroundColor = '#C0C0C0'; - span.style.color = 'black'; - span.style.fontSize = '9px'; - span.style.verticalAlign = 'bottom'; - span.textContent = '?'; - frag.appendChild(span); - return frag; - } - var goldCookTooltip = CM.Sim.auraMult('Dragon\'s Fortune') ? 'GoldCookDragonsFortuneTooltipPlaceholder' : 'GoldCookTooltipPlaceholder'; stats.appendChild(CM.Disp.CreateStatsHeader('Lucky Cookies', 'Lucky')); @@ -2101,7 +2041,10 @@ CM.Disp.AddMenuStats = function(title) { luckyReqSmall.textContent = ' (' + luckyTime + ')'; luckyReqFrag.appendChild(luckyReqSmall); } - stats.appendChild(listing(listingQuest('\"Lucky!\" Cookies Required', goldCookTooltip), luckyReqFrag)); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Lucky!\" Cookies Required', Beautify(CM.Cache.Lucky), goldCookTooltip)); + + + var luckyReqFrenFrag = document.createDocumentFragment(); var luckyReqFrenSpan = document.createElement('span'); luckyReqFrenSpan.style.fontWeight = 'bold'; @@ -2113,10 +2056,10 @@ CM.Disp.AddMenuStats = function(title) { luckyReqFrenSmall.textContent = ' (' + luckyTimeFrenzy + ')'; luckyReqFrenFrag.appendChild(luckyReqFrenSmall); } - stats.appendChild(listing(listingQuest('\"Lucky!\" Cookies Required (Frenzy)', goldCookTooltip), luckyReqFrenFrag)); - stats.appendChild(listing(listingQuest('\"Lucky!\" Reward (MAX)' + (luckySplit ? ' (Golden / Wrath)' : ''), goldCookTooltip), document.createTextNode(Beautify(luckyRewardMax) + (luckySplit ? (' / ' + Beautify(luckyRewardMaxWrath)) : '')))); - stats.appendChild(listing(listingQuest('\"Lucky!\" Reward (MAX) (Frenzy)' + (luckySplit ? ' (Golden / Wrath)' : ''), goldCookTooltip), document.createTextNode(Beautify(luckyRewardFrenzyMax) + (luckySplit ? (' / ' + Beautify(luckyRewardFrenzyMaxWrath)) : '')))); - stats.appendChild(listing(listingQuest('\"Lucky!\" Reward (CUR)' + (luckySplit ? ' (Golden / Wrath)' : ''), goldCookTooltip), document.createTextNode(Beautify(luckyCur) + (luckySplit ? (' / ' + Beautify(luckyCurWrath)) : '')))); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Lucky!\" Cookies Required (Frenzy)', luckyReqFrenFrag, goldCookTooltip)); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Lucky!\" Reward (MAX)' + (luckySplit ? ' (Golden / Wrath)' : ''), Beautify(luckyRewardMax) + (luckySplit ? (' / ' + Beautify(luckyRewardMaxWrath)) : ''), goldCookTooltip)); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Lucky!\" Reward (MAX) (Frenzy)' + (luckySplit ? ' (Golden / Wrath)' : ''), Beautify(luckyRewardFrenzyMax) + (luckySplit ? (' / ' + Beautify(luckyRewardFrenzyMaxWrath)) : ''), goldCookTooltip)); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Lucky!\" Reward (CUR)' + (luckySplit ? ' (Golden / Wrath)' : ''), Beautify(luckyCur) + (luckySplit ? (' / ' + Beautify(luckyCurWrath)) : ''), goldCookTooltip)); } stats.appendChild(CM.Disp.CreateStatsHeader('Chain Cookies', 'Chain')); @@ -2149,7 +2092,7 @@ CM.Disp.AddMenuStats = function(title) { chainReqSmall.textContent = ' (' + chainTime + ')'; chainReqFrag.appendChild(chainReqSmall); } - stats.appendChild(listing(listingQuest('\"Chain\" Cookies Required', goldCookTooltip), chainReqFrag)); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Chain\" Cookies Required', chainReqFrag, goldCookTooltip)); var chainWrathReqFrag = document.createDocumentFragment(); var chainWrathReqSpan = document.createElement('span'); chainWrathReqSpan.style.fontWeight = 'bold'; @@ -2161,7 +2104,7 @@ CM.Disp.AddMenuStats = function(title) { chainWrathReqSmall.textContent = ' (' + chainWrathTime + ')'; chainWrathReqFrag.appendChild(chainWrathReqSmall); } - stats.appendChild(listing(listingQuest('\"Chain\" Cookies Required (Wrath)', goldCookTooltip), chainWrathReqFrag)); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Chain\" Cookies Required (Wrath)', chainWrathReqFrag, goldCookTooltip)); var chainReqFrenFrag = document.createDocumentFragment(); var chainReqFrenSpan = document.createElement('span'); chainReqFrenSpan.style.fontWeight = 'bold'; @@ -2173,7 +2116,7 @@ CM.Disp.AddMenuStats = function(title) { chainReqFrenSmall.textContent = ' (' + chainTimeFrenzy + ')'; chainReqFrenFrag.appendChild(chainReqFrenSmall); } - stats.appendChild(listing(listingQuest('\"Chain\" Cookies Required (Frenzy)', goldCookTooltip), chainReqFrenFrag)); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Chain\" Cookies Required (Frenzy)', chainReqFrenFrag, goldCookTooltip)); var chainWrathReqFrenFrag = document.createDocumentFragment(); var chainWrathReqFrenFrag = document.createDocumentFragment(); var chainWrathReqFrenSpan = document.createElement('span'); @@ -2186,10 +2129,10 @@ CM.Disp.AddMenuStats = function(title) { chainWrathReqFrenSmall.textContent = ' (' + chainWrathTimeFrenzy + ')'; chainWrathReqFrenFrag.appendChild(chainWrathReqFrenSmall); } - stats.appendChild(listing(listingQuest('\"Chain\" Cookies Required (Frenzy) (Wrath)', goldCookTooltip), chainWrathReqFrenFrag)); - stats.appendChild(listing(listingQuest('\"Chain\" Reward (MAX) (Golden / Wrath)', goldCookTooltip), document.createTextNode(Beautify(chainRewardMax) + ' / ' + Beautify(chainWrathRewardMax)))); - stats.appendChild(listing(listingQuest('\"Chain\" Reward (MAX) (Frenzy) (Golden / Wrath)', goldCookTooltip), document.createTextNode(Beautify(chainFrenzyRewardMax) + ' / ' + Beautify(chainFrenzyWrathRewardMax)))); - stats.appendChild(listing(listingQuest('\"Chain\" Reward (CUR) (Golden / Wrath)', goldCookTooltip), document.createTextNode(Beautify(chainCur) + ' / ' + Beautify(chainCurWrath)))); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Chain\" Cookies Required (Frenzy) (Wrath)', chainWrathReqFrenFrag, goldCookTooltip)); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Chain\" Reward (MAX) (Golden / Wrath)', Beautify(chainRewardMax) + ' / ' + Beautify(chainWrathRewardMax), goldCookTooltip)); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Chain\" Reward (MAX) (Frenzy) (Golden / Wrath)', Beautify(chainFrenzyRewardMax) + ' / ' + Beautify(chainFrenzyWrathRewardMax), goldCookTooltip)); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Chain\" Reward (CUR) (Golden / Wrath)', Beautify(chainCur) + ' / ' + Beautify(chainCurWrath), goldCookTooltip)); } stats.appendChild(CM.Disp.CreateStatsHeader('Conjure Baked Goods', 'Conjure')); @@ -2210,9 +2153,9 @@ CM.Disp.AddMenuStats = function(title) { conjureReqSmall.textContent = ' (' + conjureTime + ')'; conjureReqFrag.appendChild(conjureReqSmall); } - stats.appendChild(listing(listingQuest('\"Conjure Baked Goods\" Cookies Required', 'GoldCookTooltipPlaceholder'), conjureReqFrag)); - stats.appendChild(listing(listingQuest('\"Conjure Baked Goods\" Reward (MAX)', 'GoldCookTooltipPlaceholder'), document.createTextNode(Beautify(conjureRewardMax)))); - stats.appendChild(listing(listingQuest('\"Conjure Baked Goods\" Reward (CUR)', 'GoldCookTooltipPlaceholder'), document.createTextNode(Beautify(conjureCur)))); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Conjure Baked Goods\" Cookies Required', conjureReqFrag, 'GoldCookTooltipPlaceholder')); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Conjure Baked Goods\" Reward (MAX)', conjureRewardMax, 'GoldCookTooltipPlaceholder')); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Conjure Baked Goods\" Reward (CUR)', conjureCur, 'GoldCookTooltipPlaceholder')); } var choEgg = (Game.HasUnlocked('Chocolate egg') && !Game.Has('Chocolate egg')); // Needs to be done for the checking below @@ -2221,15 +2164,15 @@ CM.Disp.AddMenuStats = function(title) { if (CM.Config.StatsPref.Prestige) { var possiblePresMax = Math.floor(Game.HowMuchPrestige(CM.Cache.RealCookiesEarned + Game.cookiesReset + CM.Cache.WrinkGodBank + (choEgg ? CM.Cache.lastChoEgg : 0))); var neededCook = Game.HowManyCookiesReset(possiblePresMax + 1) - (CM.Cache.RealCookiesEarned + Game.cookiesReset + CM.Cache.WrinkGodBank + (choEgg ? CM.Cache.lastChoEgg : 0)); - stats.appendChild(listing(listingQuest('Prestige Level (CUR / MAX)', 'PrestMaxTooltipPlaceholder'), document.createTextNode(Beautify(Game.prestige) + ' / ' + Beautify(possiblePresMax)))); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", 'Prestige Level (CUR / MAX)', Beautify(Game.prestige) + ' / ' + Beautify(possiblePresMax), 'PrestMaxTooltipPlaceholder')); var cookiesNextFrag = document.createDocumentFragment(); cookiesNextFrag.appendChild(document.createTextNode(Beautify(neededCook))); var cookiesNextSmall = document.createElement('small'); cookiesNextSmall.textContent = ' (' + (CM.Disp.FormatTime(neededCook / CM.Cache.AvgCPSChoEgg, 1)) + ')'; cookiesNextFrag.appendChild(cookiesNextSmall); - stats.appendChild(listing(listingQuest('Cookies To Next Level', 'NextPrestTooltipPlaceholder'), cookiesNextFrag)); - stats.appendChild(listing(listingQuest('Heavenly Chips (CUR / MAX)', 'HeavenChipMaxTooltipPlaceholder'), document.createTextNode(Beautify(Game.heavenlyChips) + ' / ' + Beautify((possiblePresMax - Game.prestige) + Game.heavenlyChips)))); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", 'Cookies To Next Level', cookiesNextFrag, 'NextPrestTooltipPlaceholder')); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", 'Heavenly Chips (CUR / MAX)', Beautify(Game.heavenlyChips) + ' / ' + Beautify((possiblePresMax - Game.prestige) + Game.heavenlyChips), 'HeavenChipMaxTooltipPlaceholder')); var resetBonus = CM.Sim.ResetBonus(possiblePresMax); var resetFrag = document.createDocumentFragment(); @@ -2240,7 +2183,7 @@ CM.Disp.AddMenuStats = function(title) { resetSmall.textContent = ' (' + (increase / 100) + '% of income)'; resetFrag.appendChild(resetSmall); } - stats.appendChild(listing(listingQuest('Reset Bonus Income', 'ResetTooltipPlaceholder'), resetFrag)); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", 'Reset Bonus Income', resetFrag, 'ResetTooltipPlaceholder')); var currentPrestige = Math.floor(Game.HowMuchPrestige(Game.cookiesReset)); var willHave = Math.floor(Game.HowMuchPrestige(Game.cookiesReset + Game.cookiesEarned)); @@ -2360,16 +2303,16 @@ CM.Disp.AddMenuStats = function(title) { stats.appendChild(CM.Disp.CreateStatsHeader('Season Specials', 'Sea')); if (CM.Config.StatsPref.Sea) { if (specDisp) { - if (halloCook.length != 0) stats.appendChild(listing('Halloween Cookies Left to Buy', createMissDisp(halloCook))); - if (christCook.length != 0) stats.appendChild(listing('Christmas Cookies Left to Buy', createMissDisp(christCook))); - if (valCook.length != 0) stats.appendChild(listing('Valentine Cookies Left to Buy', createMissDisp(valCook))); - if (normEggs.length != 0) stats.appendChild(listing('Normal Easter Eggs Left to Unlock', createMissDisp(normEggs))); - if (rareEggs.length != 0) stats.appendChild(listing('Rare Easter Eggs Left to Unlock', createMissDisp(rareEggs))); + if (halloCook.length != 0) stats.appendChild(listing('Halloween Cookies Left to Buy', CM.Disp.CreateStatsMissDisp(halloCook))); + if (christCook.length != 0) stats.appendChild(listing('Christmas Cookies Left to Buy', CM.Disp.CreateStatsMissDisp(christCook))); + if (valCook.length != 0) stats.appendChild(listing('Valentine Cookies Left to Buy', CM.Disp.CreateStatsMissDisp(valCook))); + if (normEggs.length != 0) stats.appendChild(listing('Normal Easter Eggs Left to Unlock', CM.Disp.CreateStatsMissDisp(normEggs))); + if (rareEggs.length != 0) stats.appendChild(listing('Rare Easter Eggs Left to Unlock', CM.Disp.CreateStatsMissDisp(rareEggs))); } if (Game.season == 'christmas') stats.appendChild(listing('Reindeer Reward', document.createTextNode(Beautify(CM.Cache.SeaSpec)))); if (choEgg) { - stats.appendChild(listing(listingQuest('Chocolate Egg Cookies', 'ChoEggTooltipPlaceholder'), document.createTextNode(Beautify(CM.Cache.lastChoEgg)))); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", 'Chocolate Egg Cookies', Beautify(CM.Cache.lastChoEgg), 'ChoEggTooltipPlaceholder')); } if (centEgg) { stats.appendChild(listing('Century Egg Multiplier', document.createTextNode((Math.round((CM.Cache.CentEgg - 1) * 10000) / 100) + '%'))); @@ -2391,7 +2334,7 @@ CM.Disp.AddMenuStats = function(title) { fortunes.push(CM.Data.Fortunes[i]); } } - if (fortunes.length != 0) stats.appendChild(listing('Fortune Upgrades Left to Buy', createMissDisp(fortunes))); + if (fortunes.length != 0) stats.appendChild(listing('Fortune Upgrades Left to Buy', CM.Disp.CreateStatsMissDisp(fortunes))); } stats.appendChild(listing('Missed Golden Cookies', document.createTextNode(Beautify(Game.missedGoldenClicks)))); if (Game.prefs.autosave) { @@ -2441,6 +2384,93 @@ CM.Disp.CreateStatsHeader = function(text, config) { return div; } +/** + * This function creates an stats-listing-object for the stats page + * It is called by CM.Disp.AddMenuStats() + * @param {string} type The type fo the listing + * @param {string} name The name of the option + * @param {object} text The text-object of the option + * @param {string} placeholder The id of the to-be displayed tooltip if applicable + * @returns {object} div The option object + */ +CM.Disp.CreateStatsListing = function(type, name, text, placeholder) { + var div = document.createElement('div'); + div.className = 'listing'; + + var listingName = document.createElement('span'); + listingName.textContent = name + ' ' + div.appendChild(listingName); + if (type == "withTooltip") { + div.className = 'listingWithTooltip'; + + var tooltip = document.createElement('span'); + tooltip.onmouseout = function() { Game.tooltip.hide(); }; + tooltip.onmouseover = function() {Game.tooltip.draw(this, escape(CM.Disp[placeholder].innerHTML));}; + tooltip.style.cursor = 'default'; + tooltip.style.display = 'inline-block'; + tooltip.style.height = '10px'; + tooltip.style.width = '10px'; + tooltip.style.borderRadius = '5px'; + tooltip.style.textAlign = 'center'; + tooltip.style.backgroundColor = '#C0C0C0'; + tooltip.style.color = 'black'; + tooltip.style.fontSize = '9px'; + tooltip.style.verticalAlign = 'bottom'; + tooltip.textContent = '?'; + div.appendChild(tooltip); + div.appendChild(document.createTextNode(' ')); + } + div.appendChild(document.createTextNode(': ')); + div.appendChild(text); + return div; +} + + +/** + * This function ? + * @param {string} theMissDisp The type fo the listing + * @returns {object} frag The option object + */ +CM.Disp.CreateStatsMissDisp = function(theMissDisp) { + var frag = document.createDocumentFragment(); + frag.appendChild(document.createTextNode(theMissDisp.length + ' ')); + var span = document.createElement('span'); + span.onmouseout = function() { Game.tooltip.hide(); }; + var placeholder = document.createElement('div'); + var missing = document.createElement('div'); + missing.style.minWidth = '140px'; + missing.style.marginBottom = '4px'; + var title = document.createElement('div'); + title.className = 'name'; + title.style.marginBottom = '4px'; + title.style.textAlign = 'center'; + title.textContent = 'Missing'; + missing.appendChild(title); + for (var i in theMissDisp) { + var div = document.createElement('div'); + div.style.textAlign = 'center'; + div.appendChild(document.createTextNode(theMissDisp[i])); + missing.appendChild(div); + } + placeholder.appendChild(missing); + span.onmouseover = function() {Game.tooltip.draw(this, escape(placeholder.innerHTML));}; + span.style.cursor = 'default'; + span.style.display = 'inline-block'; + span.style.height = '10px'; + span.style.width = '10px'; + span.style.borderRadius = '5px'; + span.style.textAlign = 'center'; + span.style.backgroundColor = '#C0C0C0'; + span.style.color = 'black'; + span.style.fontSize = '9px'; + span.style.verticalAlign = 'bottom'; + span.textContent = '?'; + frag.appendChild(span); + return frag; +} + + + CM.Disp.AddMissingUpgrades = function() { if (CM.Cache.UpgradesOwned != Game.UpgradesOwned) { CM.Cache.CalcMissingUpgrades(); From bbc2fdf29fab12c60586e960db8b6c7d25fabf81 Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Sat, 5 Dec 2020 23:13:53 +0100 Subject: [PATCH 037/106] Fix for challenge mode --- CookieMonster.js | 32 ++++++++++++++++---------------- src/Sim.js | 6 +++++- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index fecfa67..5cb3579 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -3282,17 +3282,15 @@ CM.Disp.CreateStatsHeader = function(text, config) { * @returns {object} div The option object */ CM.Disp.CreateStatsListing = function(type, name, text, placeholder) { + var div = document.createElement('div'); + div.className = 'listing'; + + var listingName = document.createElement('span'); + listingName.textContent = name + ' ' + div.appendChild(listingName); if (type == "withTooltip") { - var div = document.createElement('div'); div.className = 'listingWithTooltip'; - - - var listingName = document.createElement('span'); - listingName.textContent = name + ' ' - div.appendChild(listingName); - - var frag = document.createDocumentFragment(); var tooltip = document.createElement('span'); tooltip.onmouseout = function() { Game.tooltip.hide(); }; tooltip.onmouseover = function() {Game.tooltip.draw(this, escape(CM.Disp[placeholder].innerHTML));}; @@ -3307,14 +3305,12 @@ CM.Disp.CreateStatsListing = function(type, name, text, placeholder) { tooltip.style.fontSize = '9px'; tooltip.style.verticalAlign = 'bottom'; tooltip.textContent = '?'; - frag.appendChild(tooltip); - frag.appendChild(document.createTextNode(' : ')); - div.appendChild(frag); - - div.appendChild(text); - return div; + div.appendChild(tooltip); + div.appendChild(document.createTextNode(' ')); } - + div.appendChild(document.createTextNode(': ')); + div.appendChild(text); + return div; } @@ -4235,7 +4231,11 @@ CM.Sim.InitialBuildingData = function(buildingName) { * so this function just returns an empty object. */ CM.Sim.InitUpgrade = function(upgradeName) { - return {}; + var me = Game.Upgrades[upgradeName]; + var you = {}; + you.pool = me.pool; + you.name = me.name; + return you; } /* Similar to the previous function, but for achievements. diff --git a/src/Sim.js b/src/Sim.js index 17988c2..7037235 100644 --- a/src/Sim.js +++ b/src/Sim.js @@ -171,7 +171,11 @@ CM.Sim.InitialBuildingData = function(buildingName) { * so this function just returns an empty object. */ CM.Sim.InitUpgrade = function(upgradeName) { - return {}; + var me = Game.Upgrades[upgradeName]; + var you = {}; + you.pool = me.pool; + you.name = me.name; + return you; } /* Similar to the previous function, but for achievements. From b462ed2cedae554bfe706aab33be6138fcf414fb Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Sun, 6 Dec 2020 19:37:34 +0100 Subject: [PATCH 038/106] Fix #416 on dev-branch --- CookieMonster.js | 2 +- src/Disp.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index 7ba14d7..134e22b 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -1567,7 +1567,7 @@ CM.Disp.UpdateBuildings = function() { l('productPrice' + Game.Objects[i].id).style.color = CM.Config.Colors[CM.Cache[target][i].color]; } } - else { + else if (Game.buyMode == -1) { for (var i in CM.Cache.Objects) { var o = Game.Objects[i]; l('productPrice' + o.id).style.color = ''; diff --git a/src/Disp.js b/src/Disp.js index ec02a1e..73b8cca 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -679,7 +679,7 @@ CM.Disp.UpdateBuildings = function() { l('productPrice' + Game.Objects[i].id).style.color = CM.Config.Colors[CM.Cache[target][i].color]; } } - else { + else if (Game.buyMode == -1) { for (var i in CM.Cache.Objects) { var o = Game.Objects[i]; l('productPrice' + o.id).style.color = ''; From 8805eacb0ea3f98dabdc486094c3d925ce041de4 Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Sun, 6 Dec 2020 20:51:04 +0100 Subject: [PATCH 039/106] Created CM.Disp.CreateStatsLuckySection --- CookieMonster.js | 133 ++++++++++++++++++++++++++--------------------- src/Disp.js | 133 ++++++++++++++++++++++++++--------------------- 2 files changed, 146 insertions(+), 120 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index 5cb3579..53d9236 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -2889,65 +2889,10 @@ CM.Disp.AddMenuStats = function(title) { var stats = document.createElement('div'); stats.className = 'subsection'; stats.appendChild(title()); - var listing = function(name, text) { - var div = document.createElement('div'); - div.className = 'listing'; - var b = document.createElement('b'); - if (typeof name == 'string') b.appendChild(document.createTextNode(name)); - else b.appendChild(name); // fragment - b.appendChild(document.createTextNode(' : ')); - div.appendChild(b); - div.appendChild(text); - return div; - } - - var goldCookTooltip = CM.Sim.auraMult('Dragon\'s Fortune') ? 'GoldCookDragonsFortuneTooltipPlaceholder' : 'GoldCookTooltipPlaceholder'; stats.appendChild(CM.Disp.CreateStatsHeader('Lucky Cookies', 'Lucky')); if (CM.Config.StatsPref.Lucky) { - var luckyColor = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.Lucky) ? CM.Disp.colorRed : CM.Disp.colorGreen; - var luckyTime = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.Lucky) ? CM.Disp.FormatTime((CM.Cache.Lucky - (Game.cookies + CM.Disp.GetWrinkConfigBank())) / CM.Disp.GetCPS()) : ''; - var luckyColorFrenzy = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.LuckyFrenzy) ? CM.Disp.colorRed : CM.Disp.colorGreen; - var luckyTimeFrenzy = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.LuckyFrenzy) ? CM.Disp.FormatTime((CM.Cache.LuckyFrenzy - (Game.cookies + CM.Disp.GetWrinkConfigBank())) / CM.Disp.GetCPS()) : ''; - var luckyCurBase = Math.min((Game.cookies + CM.Disp.GetWrinkConfigBank()) * 0.15, CM.Cache.NoGoldSwitchCookiesPS * CM.Cache.DragonsFortuneMultAdjustment * 60 * 15) + 13; - var luckyRewardMax = CM.Cache.LuckyReward; - var luckyRewardMaxWrath = CM.Cache.LuckyWrathReward; - var luckyRewardFrenzyMax = CM.Cache.LuckyRewardFrenzy; - var luckyRewardFrenzyMaxWrath = CM.Cache.LuckyWrathRewardFrenzy; - var luckyCur = CM.Cache.GoldenCookiesMult * luckyCurBase; - var luckyCurWrath = CM.Cache.WrathCookiesMult * luckyCurBase; - var luckySplit = luckyRewardMax != luckyRewardMaxWrath; - - var luckyReqFrag = document.createDocumentFragment(); - var luckyReqSpan = document.createElement('span'); - luckyReqSpan.style.fontWeight = 'bold'; - luckyReqSpan.className = CM.Disp.colorTextPre + luckyColor; - luckyReqSpan.textContent = Beautify(CM.Cache.Lucky); - luckyReqFrag.appendChild(luckyReqSpan); - if (luckyTime != '') { - var luckyReqSmall = document.createElement('small'); - luckyReqSmall.textContent = ' (' + luckyTime + ')'; - luckyReqFrag.appendChild(luckyReqSmall); - } - stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Lucky!\" Cookies Required', Beautify(CM.Cache.Lucky), goldCookTooltip)); - - - - var luckyReqFrenFrag = document.createDocumentFragment(); - var luckyReqFrenSpan = document.createElement('span'); - luckyReqFrenSpan.style.fontWeight = 'bold'; - luckyReqFrenSpan.className = CM.Disp.colorTextPre + luckyColorFrenzy; - luckyReqFrenSpan.textContent = Beautify(CM.Cache.LuckyFrenzy); - luckyReqFrenFrag.appendChild(luckyReqFrenSpan); - if (luckyTimeFrenzy != '') { - var luckyReqFrenSmall = document.createElement('small'); - luckyReqFrenSmall.textContent = ' (' + luckyTimeFrenzy + ')'; - luckyReqFrenFrag.appendChild(luckyReqFrenSmall); - } - stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Lucky!\" Cookies Required (Frenzy)', luckyReqFrenFrag, goldCookTooltip)); - stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Lucky!\" Reward (MAX)' + (luckySplit ? ' (Golden / Wrath)' : ''), Beautify(luckyRewardMax) + (luckySplit ? (' / ' + Beautify(luckyRewardMaxWrath)) : ''), goldCookTooltip)); - stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Lucky!\" Reward (MAX) (Frenzy)' + (luckySplit ? ' (Golden / Wrath)' : ''), Beautify(luckyRewardFrenzyMax) + (luckySplit ? (' / ' + Beautify(luckyRewardFrenzyMaxWrath)) : ''), goldCookTooltip)); - stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Lucky!\" Reward (CUR)' + (luckySplit ? ' (Golden / Wrath)' : ''), Beautify(luckyCur) + (luckySplit ? (' / ' + Beautify(luckyCurWrath)) : ''), goldCookTooltip)); + stats.appendChild(CM.Disp.CreateStatsLuckySection()); } stats.appendChild(CM.Disp.CreateStatsHeader('Chain Cookies', 'Chain')); @@ -3285,11 +3230,11 @@ CM.Disp.CreateStatsListing = function(type, name, text, placeholder) { var div = document.createElement('div'); div.className = 'listing'; - var listingName = document.createElement('span'); - listingName.textContent = name + ' ' + var listingName = document.createElement('b'); + listingName.textContent = name + ' '; div.appendChild(listingName); if (type == "withTooltip") { - div.className = 'listingWithTooltip'; + div.className = 'listing'; var tooltip = document.createElement('span'); tooltip.onmouseout = function() { Game.tooltip.hide(); }; @@ -3313,7 +3258,6 @@ CM.Disp.CreateStatsListing = function(type, name, text, placeholder) { return div; } - /** * This function ? * @param {string} theMissDisp The type fo the listing @@ -3357,6 +3301,75 @@ CM.Disp.CreateStatsMissDisp = function(theMissDisp) { return frag; } +/** + * This function creates the "Lucky" section of the stats page + * @returns {object} section The object contating the Lucky section + */ +CM.Disp.CreateStatsLuckySection = function() { + // TODO: Remove this and creater better tooltip!! + var goldCookTooltip = CM.Sim.auraMult('Dragon\'s Fortune') ? 'GoldCookDragonsFortuneTooltipPlaceholder' : 'GoldCookTooltipPlaceholder'; + var section = document.createElement('div'); + section.className = 'CMStatsLuckySection'; + + var luckyColor = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.Lucky) ? CM.Disp.colorRed : CM.Disp.colorGreen; + var luckyTime = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.Lucky) ? CM.Disp.FormatTime((CM.Cache.Lucky - (Game.cookies + CM.Disp.GetWrinkConfigBank())) / CM.Disp.GetCPS()) : ''; + var luckyReqFrag = document.createDocumentFragment(); + var luckyReqSpan = document.createElement('span'); + luckyReqSpan.style.fontWeight = 'bold'; + luckyReqSpan.className = CM.Disp.colorTextPre + luckyColor; + luckyReqSpan.textContent = Beautify(CM.Cache.Lucky); + luckyReqFrag.appendChild(luckyReqSpan); + if (luckyTime != '') { + var luckyReqSmall = document.createElement('small'); + luckyReqSmall.textContent = ' (' + luckyTime + ')'; + luckyReqFrag.appendChild(luckyReqSmall); + } + section.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Lucky!\" Cookies Required', luckyReqFrag, goldCookTooltip)); + + + var luckyColorFrenzy = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.LuckyFrenzy) ? CM.Disp.colorRed : CM.Disp.colorGreen; + var luckyTimeFrenzy = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.LuckyFrenzy) ? CM.Disp.FormatTime((CM.Cache.LuckyFrenzy - (Game.cookies + CM.Disp.GetWrinkConfigBank())) / CM.Disp.GetCPS()) : ''; + var luckyReqFrenFrag = document.createDocumentFragment(); + var luckyReqFrenSpan = document.createElement('span'); + luckyReqFrenSpan.style.fontWeight = 'bold'; + luckyReqFrenSpan.className = CM.Disp.colorTextPre + luckyColorFrenzy; + luckyReqFrenSpan.textContent = Beautify(CM.Cache.LuckyFrenzy); + luckyReqFrenFrag.appendChild(luckyReqFrenSpan); + if (luckyTimeFrenzy != '') { + var luckyReqFrenSmall = document.createElement('small'); + luckyReqFrenSmall.textContent = ' (' + luckyTimeFrenzy + ')'; + luckyReqFrenFrag.appendChild(luckyReqFrenSmall); + } + section.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Lucky!\" Cookies Required (Frenzy)', luckyReqFrenFrag, goldCookTooltip)); + + var luckySplit = luckyRewardMax != luckyRewardMaxWrath; + + var luckyRewardMax = CM.Cache.LuckyReward; + var luckyRewardMaxWrath = CM.Cache.LuckyWrathReward; + var luckyRewardMaxSpan = document.createElement('span'); + luckyRewardMaxSpan.style.fontWeight = 'bold'; + luckyRewardMaxSpan.className = CM.Disp.colorTextPre + luckyRewardMax; + luckyRewardMaxSpan.textContent = Beautify(luckyRewardMax) + (luckySplit ? (' / ' + Beautify(luckyRewardMaxWrath)) : ''); + section.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Lucky!\" Reward (MAX)' + (luckySplit ? ' (Golden / Wrath)' : ''), luckyRewardMaxSpan, goldCookTooltip)); + + var luckyRewardFrenzyMax = CM.Cache.LuckyRewardFrenzy; + var luckyRewardFrenzyMaxWrath = CM.Cache.LuckyWrathRewardFrenzy; + var luckyRewardFrenzyMaxSpan = document.createElement('span'); + luckyRewardFrenzyMaxSpan.style.fontWeight = 'bold'; + luckyRewardFrenzyMaxSpan.className = CM.Disp.colorTextPre + luckyRewardFrenzyMaxSpan; + luckyRewardFrenzyMaxSpan.textContent = Beautify(luckyRewardFrenzyMax) + (luckySplit ? (' / ' + Beautify(luckyRewardFrenzyMaxWrath)) : ''); + section.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Lucky!\" Reward (MAX) (Frenzy)' + (luckySplit ? ' (Golden / Wrath)' : ''), luckyRewardFrenzyMaxSpan , goldCookTooltip)); + + var luckyCurBase = Math.min((Game.cookies + CM.Disp.GetWrinkConfigBank()) * 0.15, CM.Cache.NoGoldSwitchCookiesPS * CM.Cache.DragonsFortuneMultAdjustment * 60 * 15) + 13; + var luckyCur = CM.Cache.GoldenCookiesMult * luckyCurBase; + var luckyCurWrath = CM.Cache.WrathCookiesMult * luckyCurBase; + var luckyCurSpan = document.createElement('span'); + luckyCurSpan.style.fontWeight = 'bold'; + luckyCurSpan.className = CM.Disp.colorTextPre + luckyCurSpan; + luckyCurSpan.textContent = Beautify(luckyCur) + (luckySplit ? (' / ' + Beautify(luckyCurWrath)) : '') + section.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Lucky!\" Reward (CUR)' + (luckySplit ? ' (Golden / Wrath)' : ''), luckyCurSpan, goldCookTooltip)); + return section; +} CM.Disp.AddMissingUpgrades = function() { diff --git a/src/Disp.js b/src/Disp.js index 36120cb..a3c3d39 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -2001,65 +2001,10 @@ CM.Disp.AddMenuStats = function(title) { var stats = document.createElement('div'); stats.className = 'subsection'; stats.appendChild(title()); - var listing = function(name, text) { - var div = document.createElement('div'); - div.className = 'listing'; - var b = document.createElement('b'); - if (typeof name == 'string') b.appendChild(document.createTextNode(name)); - else b.appendChild(name); // fragment - b.appendChild(document.createTextNode(' : ')); - div.appendChild(b); - div.appendChild(text); - return div; - } - - var goldCookTooltip = CM.Sim.auraMult('Dragon\'s Fortune') ? 'GoldCookDragonsFortuneTooltipPlaceholder' : 'GoldCookTooltipPlaceholder'; stats.appendChild(CM.Disp.CreateStatsHeader('Lucky Cookies', 'Lucky')); if (CM.Config.StatsPref.Lucky) { - var luckyColor = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.Lucky) ? CM.Disp.colorRed : CM.Disp.colorGreen; - var luckyTime = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.Lucky) ? CM.Disp.FormatTime((CM.Cache.Lucky - (Game.cookies + CM.Disp.GetWrinkConfigBank())) / CM.Disp.GetCPS()) : ''; - var luckyColorFrenzy = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.LuckyFrenzy) ? CM.Disp.colorRed : CM.Disp.colorGreen; - var luckyTimeFrenzy = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.LuckyFrenzy) ? CM.Disp.FormatTime((CM.Cache.LuckyFrenzy - (Game.cookies + CM.Disp.GetWrinkConfigBank())) / CM.Disp.GetCPS()) : ''; - var luckyCurBase = Math.min((Game.cookies + CM.Disp.GetWrinkConfigBank()) * 0.15, CM.Cache.NoGoldSwitchCookiesPS * CM.Cache.DragonsFortuneMultAdjustment * 60 * 15) + 13; - var luckyRewardMax = CM.Cache.LuckyReward; - var luckyRewardMaxWrath = CM.Cache.LuckyWrathReward; - var luckyRewardFrenzyMax = CM.Cache.LuckyRewardFrenzy; - var luckyRewardFrenzyMaxWrath = CM.Cache.LuckyWrathRewardFrenzy; - var luckyCur = CM.Cache.GoldenCookiesMult * luckyCurBase; - var luckyCurWrath = CM.Cache.WrathCookiesMult * luckyCurBase; - var luckySplit = luckyRewardMax != luckyRewardMaxWrath; - - var luckyReqFrag = document.createDocumentFragment(); - var luckyReqSpan = document.createElement('span'); - luckyReqSpan.style.fontWeight = 'bold'; - luckyReqSpan.className = CM.Disp.colorTextPre + luckyColor; - luckyReqSpan.textContent = Beautify(CM.Cache.Lucky); - luckyReqFrag.appendChild(luckyReqSpan); - if (luckyTime != '') { - var luckyReqSmall = document.createElement('small'); - luckyReqSmall.textContent = ' (' + luckyTime + ')'; - luckyReqFrag.appendChild(luckyReqSmall); - } - stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Lucky!\" Cookies Required', Beautify(CM.Cache.Lucky), goldCookTooltip)); - - - - var luckyReqFrenFrag = document.createDocumentFragment(); - var luckyReqFrenSpan = document.createElement('span'); - luckyReqFrenSpan.style.fontWeight = 'bold'; - luckyReqFrenSpan.className = CM.Disp.colorTextPre + luckyColorFrenzy; - luckyReqFrenSpan.textContent = Beautify(CM.Cache.LuckyFrenzy); - luckyReqFrenFrag.appendChild(luckyReqFrenSpan); - if (luckyTimeFrenzy != '') { - var luckyReqFrenSmall = document.createElement('small'); - luckyReqFrenSmall.textContent = ' (' + luckyTimeFrenzy + ')'; - luckyReqFrenFrag.appendChild(luckyReqFrenSmall); - } - stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Lucky!\" Cookies Required (Frenzy)', luckyReqFrenFrag, goldCookTooltip)); - stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Lucky!\" Reward (MAX)' + (luckySplit ? ' (Golden / Wrath)' : ''), Beautify(luckyRewardMax) + (luckySplit ? (' / ' + Beautify(luckyRewardMaxWrath)) : ''), goldCookTooltip)); - stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Lucky!\" Reward (MAX) (Frenzy)' + (luckySplit ? ' (Golden / Wrath)' : ''), Beautify(luckyRewardFrenzyMax) + (luckySplit ? (' / ' + Beautify(luckyRewardFrenzyMaxWrath)) : ''), goldCookTooltip)); - stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Lucky!\" Reward (CUR)' + (luckySplit ? ' (Golden / Wrath)' : ''), Beautify(luckyCur) + (luckySplit ? (' / ' + Beautify(luckyCurWrath)) : ''), goldCookTooltip)); + stats.appendChild(CM.Disp.CreateStatsLuckySection()); } stats.appendChild(CM.Disp.CreateStatsHeader('Chain Cookies', 'Chain')); @@ -2397,11 +2342,11 @@ CM.Disp.CreateStatsListing = function(type, name, text, placeholder) { var div = document.createElement('div'); div.className = 'listing'; - var listingName = document.createElement('span'); - listingName.textContent = name + ' ' + var listingName = document.createElement('b'); + listingName.textContent = name + ' '; div.appendChild(listingName); if (type == "withTooltip") { - div.className = 'listingWithTooltip'; + div.className = 'listing'; var tooltip = document.createElement('span'); tooltip.onmouseout = function() { Game.tooltip.hide(); }; @@ -2425,7 +2370,6 @@ CM.Disp.CreateStatsListing = function(type, name, text, placeholder) { return div; } - /** * This function ? * @param {string} theMissDisp The type fo the listing @@ -2469,6 +2413,75 @@ CM.Disp.CreateStatsMissDisp = function(theMissDisp) { return frag; } +/** + * This function creates the "Lucky" section of the stats page + * @returns {object} section The object contating the Lucky section + */ +CM.Disp.CreateStatsLuckySection = function() { + // TODO: Remove this and creater better tooltip!! + var goldCookTooltip = CM.Sim.auraMult('Dragon\'s Fortune') ? 'GoldCookDragonsFortuneTooltipPlaceholder' : 'GoldCookTooltipPlaceholder'; + var section = document.createElement('div'); + section.className = 'CMStatsLuckySection'; + + var luckyColor = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.Lucky) ? CM.Disp.colorRed : CM.Disp.colorGreen; + var luckyTime = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.Lucky) ? CM.Disp.FormatTime((CM.Cache.Lucky - (Game.cookies + CM.Disp.GetWrinkConfigBank())) / CM.Disp.GetCPS()) : ''; + var luckyReqFrag = document.createDocumentFragment(); + var luckyReqSpan = document.createElement('span'); + luckyReqSpan.style.fontWeight = 'bold'; + luckyReqSpan.className = CM.Disp.colorTextPre + luckyColor; + luckyReqSpan.textContent = Beautify(CM.Cache.Lucky); + luckyReqFrag.appendChild(luckyReqSpan); + if (luckyTime != '') { + var luckyReqSmall = document.createElement('small'); + luckyReqSmall.textContent = ' (' + luckyTime + ')'; + luckyReqFrag.appendChild(luckyReqSmall); + } + section.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Lucky!\" Cookies Required', luckyReqFrag, goldCookTooltip)); + + + var luckyColorFrenzy = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.LuckyFrenzy) ? CM.Disp.colorRed : CM.Disp.colorGreen; + var luckyTimeFrenzy = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.LuckyFrenzy) ? CM.Disp.FormatTime((CM.Cache.LuckyFrenzy - (Game.cookies + CM.Disp.GetWrinkConfigBank())) / CM.Disp.GetCPS()) : ''; + var luckyReqFrenFrag = document.createDocumentFragment(); + var luckyReqFrenSpan = document.createElement('span'); + luckyReqFrenSpan.style.fontWeight = 'bold'; + luckyReqFrenSpan.className = CM.Disp.colorTextPre + luckyColorFrenzy; + luckyReqFrenSpan.textContent = Beautify(CM.Cache.LuckyFrenzy); + luckyReqFrenFrag.appendChild(luckyReqFrenSpan); + if (luckyTimeFrenzy != '') { + var luckyReqFrenSmall = document.createElement('small'); + luckyReqFrenSmall.textContent = ' (' + luckyTimeFrenzy + ')'; + luckyReqFrenFrag.appendChild(luckyReqFrenSmall); + } + section.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Lucky!\" Cookies Required (Frenzy)', luckyReqFrenFrag, goldCookTooltip)); + + var luckySplit = luckyRewardMax != luckyRewardMaxWrath; + + var luckyRewardMax = CM.Cache.LuckyReward; + var luckyRewardMaxWrath = CM.Cache.LuckyWrathReward; + var luckyRewardMaxSpan = document.createElement('span'); + luckyRewardMaxSpan.style.fontWeight = 'bold'; + luckyRewardMaxSpan.className = CM.Disp.colorTextPre + luckyRewardMax; + luckyRewardMaxSpan.textContent = Beautify(luckyRewardMax) + (luckySplit ? (' / ' + Beautify(luckyRewardMaxWrath)) : ''); + section.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Lucky!\" Reward (MAX)' + (luckySplit ? ' (Golden / Wrath)' : ''), luckyRewardMaxSpan, goldCookTooltip)); + + var luckyRewardFrenzyMax = CM.Cache.LuckyRewardFrenzy; + var luckyRewardFrenzyMaxWrath = CM.Cache.LuckyWrathRewardFrenzy; + var luckyRewardFrenzyMaxSpan = document.createElement('span'); + luckyRewardFrenzyMaxSpan.style.fontWeight = 'bold'; + luckyRewardFrenzyMaxSpan.className = CM.Disp.colorTextPre + luckyRewardFrenzyMaxSpan; + luckyRewardFrenzyMaxSpan.textContent = Beautify(luckyRewardFrenzyMax) + (luckySplit ? (' / ' + Beautify(luckyRewardFrenzyMaxWrath)) : ''); + section.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Lucky!\" Reward (MAX) (Frenzy)' + (luckySplit ? ' (Golden / Wrath)' : ''), luckyRewardFrenzyMaxSpan , goldCookTooltip)); + + var luckyCurBase = Math.min((Game.cookies + CM.Disp.GetWrinkConfigBank()) * 0.15, CM.Cache.NoGoldSwitchCookiesPS * CM.Cache.DragonsFortuneMultAdjustment * 60 * 15) + 13; + var luckyCur = CM.Cache.GoldenCookiesMult * luckyCurBase; + var luckyCurWrath = CM.Cache.WrathCookiesMult * luckyCurBase; + var luckyCurSpan = document.createElement('span'); + luckyCurSpan.style.fontWeight = 'bold'; + luckyCurSpan.className = CM.Disp.colorTextPre + luckyCurSpan; + luckyCurSpan.textContent = Beautify(luckyCur) + (luckySplit ? (' / ' + Beautify(luckyCurWrath)) : '') + section.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Lucky!\" Reward (CUR)' + (luckySplit ? ' (Golden / Wrath)' : ''), luckyCurSpan, goldCookTooltip)); + return section; +} CM.Disp.AddMissingUpgrades = function() { From f30ebd081e28fd2f5a7728556c2acab62cec298e Mon Sep 17 00:00:00 2001 From: Chorizorro Date: Mon, 7 Dec 2020 10:11:07 +0100 Subject: [PATCH 040/106] Fix Dragon's Fortune mult in CalculateGains sim --- CookieMonster.js | 11 +++++------ src/Sim.js | 11 +++++------ 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index 134e22b..9e5378c 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -4436,13 +4436,12 @@ CM.Sim.CalculateGains = function() { if (rawCookiesPs >= Game.CpsAchievements[i].threshold) CM.Sim.Win(Game.CpsAchievements[i].name); } - CM.Sim.cookiesPsRaw=rawCookiesPs; + CM.Sim.cookiesPsRaw = rawCookiesPs; - if (CM.Sim.hasAura('Dragon\'s Fortune')) { - var n = Game.shimmerTypes['golden'].n; - for (var i = 0; i < n; i++) { - mult *= 1.23; - } + var n = Game.shimmerTypes['golden'].n; + var auraMult = CM.Sim.auraMult('Dragon\'s Fortune'); + for (var i = 0; i < n; i++){ + mult *= 1 + auraMult * 1.23; } var name = Game.bakeryName.toLowerCase(); diff --git a/src/Sim.js b/src/Sim.js index 17988c2..47dfc26 100644 --- a/src/Sim.js +++ b/src/Sim.js @@ -406,13 +406,12 @@ CM.Sim.CalculateGains = function() { if (rawCookiesPs >= Game.CpsAchievements[i].threshold) CM.Sim.Win(Game.CpsAchievements[i].name); } - CM.Sim.cookiesPsRaw=rawCookiesPs; + CM.Sim.cookiesPsRaw = rawCookiesPs; - if (CM.Sim.hasAura('Dragon\'s Fortune')) { - var n = Game.shimmerTypes['golden'].n; - for (var i = 0; i < n; i++) { - mult *= 1.23; - } + var n = Game.shimmerTypes['golden'].n; + var auraMult = CM.Sim.auraMult('Dragon\'s Fortune'); + for (var i = 0; i < n; i++){ + mult *= 1 + auraMult * 1.23; } var name = Game.bakeryName.toLowerCase(); From ea4776ae4b2ba4a7b16952113fbd552822b8ea26 Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Mon, 7 Dec 2020 21:25:02 +0100 Subject: [PATCH 041/106] Final rework of Disp.js --- CookieMonster.js | 466 +++++++++++++++++++++++++---------------------- src/Disp.js | 466 +++++++++++++++++++++++++---------------------- 2 files changed, 494 insertions(+), 438 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index 53d9236..d1ff682 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -910,6 +910,18 @@ CM.Disp.GetWrinkConfigBank = function() { return 0; } +/** + * This function pops all normal wrinklers + * It is called by a click of the 'pop all' button created by CM.Disp.AddMenuStats() + */ +CM.Disp.PopAllNormalWrinklers = function() { + for (var i in Game.wrinklers) { + if (Game.wrinklers[i].sucked > 0 && Game.wrinklers[i].type == 0) { + Game.wrinklers[i].hp = 0; + } + } +} + /** * This function returns the cps as either current or average CPS depending on CM.Config.CPSMode * @returns {number} The average or current cps @@ -1075,9 +1087,10 @@ CM.Disp.Beautify = function(num, frac, forced) { } else { var restOfNumber = (num / Math.pow(10, (timesTenToPowerThree * 3))).toString(); + // Check if number contains decimals numbersToAdd = (restOfNumber.indexOf('.') > -1 ? restOfNumber.indexOf('.') + 1 + decimals : (restOfNumber.length)) i = 0 - while (i < numbersToAdd - 1) { + while (i < numbersToAdd - 1 && i < restOfNumber.length - 1) { answer += restOfNumber[i]; i++ } @@ -1105,7 +1118,7 @@ CM.Disp.Beautify = function(num, frac, forced) { } } if (answer === '') { - console.log("Could not beautify number with CM.Disp.Beautify"); + console.log("Could not beautify number with CM.Disp.Beautify:" + num); answer = CM.Backup.Beautify(num, frac); } if (negative) answer = '-' + answer; @@ -1115,7 +1128,7 @@ CM.Disp.Beautify = function(num, frac, forced) { return "Infinity"; } else { - console.log("Could not beautify number with CM.Disp.Beautify"); + console.log("Could not beautify number with CM.Disp.Beautify:" + num); return CM.Backup.Beautify(num, frac); } } @@ -2883,8 +2896,13 @@ CM.Disp.UpdateColors = function() { /******** * Section: Functions related to the Stats page - * TODO: Annotate functions */ + * TODO: Annotate last functions */ +/** + * This function adds stats created by CookieMonster to the stats page + * It is called by CM.Disp.AddMenu + * @param {function} title A function that returns the title of CookieMonster pre-styled + */ CM.Disp.AddMenuStats = function(title) { var stats = document.createElement('div'); stats.className = 'subsection'; @@ -2897,186 +2915,17 @@ CM.Disp.AddMenuStats = function(title) { stats.appendChild(CM.Disp.CreateStatsHeader('Chain Cookies', 'Chain')); if (CM.Config.StatsPref.Chain) { - var chainColor = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.Chain) ? CM.Disp.colorRed : CM.Disp.colorGreen; - var chainTime = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.Chain) ? CM.Disp.FormatTime((CM.Cache.Chain - (Game.cookies + CM.Disp.GetWrinkConfigBank())) / CM.Disp.GetCPS()) : ''; - var chainColorFrenzy = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.ChainFrenzy) ? CM.Disp.colorRed : CM.Disp.colorGreen; - var chainTimeFrenzy = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.ChainFrenzy) ? CM.Disp.FormatTime((CM.Cache.ChainFrenzy - (Game.cookies + CM.Disp.GetWrinkConfigBank())) / CM.Disp.GetCPS()) : ''; - var chainWrathColor = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.ChainWrath) ? CM.Disp.colorRed : CM.Disp.colorGreen; - var chainWrathTime = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.ChainWrath) ? CM.Disp.FormatTime((CM.Cache.ChainWrath - (Game.cookies + CM.Disp.GetWrinkConfigBank())) / CM.Disp.GetCPS()) : ''; - var chainWrathColorFrenzy = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.ChainFrenzyWrath) ? CM.Disp.colorRed : CM.Disp.colorGreen; - var chainWrathTimeFrenzy = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.ChainFrenzyWrath) ? CM.Disp.FormatTime((CM.Cache.ChainFrenzyWrath - (Game.cookies + CM.Disp.GetWrinkConfigBank())) / CM.Disp.GetCPS()) : ''; - - var chainRewardMax = CM.Cache.ChainReward; - var chainWrathRewardMax = CM.Cache.ChainWrathReward; - var chainFrenzyRewardMax = CM.Cache.ChainFrenzyReward; - var chainFrenzyWrathRewardMax = CM.Cache.ChainFrenzyWrathReward; - var chainCurMax = Math.min(CM.Cache.NoGoldSwitchCookiesPS * CM.Cache.DragonsFortuneMultAdjustment * 60 * 60 * 6, (Game.cookies + CM.Disp.GetWrinkConfigBank()) * 0.5); - var chainCur = CM.Cache.MaxChainMoni(7, chainCurMax, CM.Cache.GoldenCookiesMult); - var chainCurWrath = CM.Cache.MaxChainMoni(6, chainCurMax, CM.Cache.WrathCookiesMult); - - var chainReqFrag = document.createDocumentFragment(); - var chainReqSpan = document.createElement('span'); - chainReqSpan.style.fontWeight = 'bold'; - chainReqSpan.className = CM.Disp.colorTextPre + chainColor; - chainReqSpan.textContent = Beautify(CM.Cache.Chain); - chainReqFrag.appendChild(chainReqSpan); - if (chainTime != '') { - var chainReqSmall = document.createElement('small'); - chainReqSmall.textContent = ' (' + chainTime + ')'; - chainReqFrag.appendChild(chainReqSmall); - } - stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Chain\" Cookies Required', chainReqFrag, goldCookTooltip)); - var chainWrathReqFrag = document.createDocumentFragment(); - var chainWrathReqSpan = document.createElement('span'); - chainWrathReqSpan.style.fontWeight = 'bold'; - chainWrathReqSpan.className = CM.Disp.colorTextPre + chainWrathColor; - chainWrathReqSpan.textContent = Beautify(CM.Cache.ChainWrath); - chainWrathReqFrag.appendChild(chainWrathReqSpan); - if (chainWrathTime != '') { - var chainWrathReqSmall = document.createElement('small'); - chainWrathReqSmall.textContent = ' (' + chainWrathTime + ')'; - chainWrathReqFrag.appendChild(chainWrathReqSmall); - } - stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Chain\" Cookies Required (Wrath)', chainWrathReqFrag, goldCookTooltip)); - var chainReqFrenFrag = document.createDocumentFragment(); - var chainReqFrenSpan = document.createElement('span'); - chainReqFrenSpan.style.fontWeight = 'bold'; - chainReqFrenSpan.className = CM.Disp.colorTextPre + chainColorFrenzy; - chainReqFrenSpan.textContent = Beautify(CM.Cache.ChainFrenzy); - chainReqFrenFrag.appendChild(chainReqFrenSpan); - if (chainTimeFrenzy != '') { - var chainReqFrenSmall = document.createElement('small'); - chainReqFrenSmall.textContent = ' (' + chainTimeFrenzy + ')'; - chainReqFrenFrag.appendChild(chainReqFrenSmall); - } - stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Chain\" Cookies Required (Frenzy)', chainReqFrenFrag, goldCookTooltip)); - var chainWrathReqFrenFrag = document.createDocumentFragment(); - var chainWrathReqFrenFrag = document.createDocumentFragment(); - var chainWrathReqFrenSpan = document.createElement('span'); - chainWrathReqFrenSpan.style.fontWeight = 'bold'; - chainWrathReqFrenSpan.className = CM.Disp.colorTextPre + chainWrathColorFrenzy; - chainWrathReqFrenSpan.textContent = Beautify(CM.Cache.ChainFrenzyWrath); - chainWrathReqFrenFrag.appendChild(chainWrathReqFrenSpan); - if (chainWrathTimeFrenzy != '') { - var chainWrathReqFrenSmall = document.createElement('small'); - chainWrathReqFrenSmall.textContent = ' (' + chainWrathTimeFrenzy + ')'; - chainWrathReqFrenFrag.appendChild(chainWrathReqFrenSmall); - } - stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Chain\" Cookies Required (Frenzy) (Wrath)', chainWrathReqFrenFrag, goldCookTooltip)); - stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Chain\" Reward (MAX) (Golden / Wrath)', Beautify(chainRewardMax) + ' / ' + Beautify(chainWrathRewardMax), goldCookTooltip)); - stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Chain\" Reward (MAX) (Frenzy) (Golden / Wrath)', Beautify(chainFrenzyRewardMax) + ' / ' + Beautify(chainFrenzyWrathRewardMax), goldCookTooltip)); - stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Chain\" Reward (CUR) (Golden / Wrath)', Beautify(chainCur) + ' / ' + Beautify(chainCurWrath), goldCookTooltip)); + stats.appendChild(CM.Disp.CreateStatsChainSection()); } stats.appendChild(CM.Disp.CreateStatsHeader('Conjure Baked Goods', 'Conjure')); if (CM.Config.StatsPref.Conjure) { - var conjureColor = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.Conjure) ? CM.Disp.colorRed : CM.Disp.colorGreen; - var conjureCur = Math.min((Game.cookies + CM.Disp.GetWrinkConfigBank()) * 0.15, CM.Cache.NoGoldSwitchCookiesPS * 60 * 30); - var conjureTime = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.Conjure) ? CM.Disp.FormatTime((CM.Cache.Conjure - (Game.cookies + CM.Disp.GetWrinkConfigBank())) / CM.Disp.GetCPS()) : ''; - var conjureRewardMax = CM.Cache.ConjureReward; - - var conjureReqFrag = document.createDocumentFragment(); - var conjureReqSpan = document.createElement('span'); - conjureReqSpan.style.fontWeight = 'bold'; - conjureReqSpan.className = CM.Disp.colorTextPre + conjureColor; - conjureReqSpan.textContent = Beautify(CM.Cache.Conjure); - conjureReqFrag.appendChild(conjureReqSpan); - if (conjureTime != '') { - var conjureReqSmall = document.createElement('small'); - conjureReqSmall.textContent = ' (' + conjureTime + ')'; - conjureReqFrag.appendChild(conjureReqSmall); - } - stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Conjure Baked Goods\" Cookies Required', conjureReqFrag, 'GoldCookTooltipPlaceholder')); - stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Conjure Baked Goods\" Reward (MAX)', conjureRewardMax, 'GoldCookTooltipPlaceholder')); - stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Conjure Baked Goods\" Reward (CUR)', conjureCur, 'GoldCookTooltipPlaceholder')); + stats.appendChild(CM.Disp.CreateStatsConjureSection()); } - - var choEgg = (Game.HasUnlocked('Chocolate egg') && !Game.Has('Chocolate egg')); // Needs to be done for the checking below stats.appendChild(CM.Disp.CreateStatsHeader('Prestige', 'Prestige')); if (CM.Config.StatsPref.Prestige) { - var possiblePresMax = Math.floor(Game.HowMuchPrestige(CM.Cache.RealCookiesEarned + Game.cookiesReset + CM.Cache.WrinkGodBank + (choEgg ? CM.Cache.lastChoEgg : 0))); - var neededCook = Game.HowManyCookiesReset(possiblePresMax + 1) - (CM.Cache.RealCookiesEarned + Game.cookiesReset + CM.Cache.WrinkGodBank + (choEgg ? CM.Cache.lastChoEgg : 0)); - stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", 'Prestige Level (CUR / MAX)', Beautify(Game.prestige) + ' / ' + Beautify(possiblePresMax), 'PrestMaxTooltipPlaceholder')); - - var cookiesNextFrag = document.createDocumentFragment(); - cookiesNextFrag.appendChild(document.createTextNode(Beautify(neededCook))); - var cookiesNextSmall = document.createElement('small'); - cookiesNextSmall.textContent = ' (' + (CM.Disp.FormatTime(neededCook / CM.Cache.AvgCPSChoEgg, 1)) + ')'; - cookiesNextFrag.appendChild(cookiesNextSmall); - stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", 'Cookies To Next Level', cookiesNextFrag, 'NextPrestTooltipPlaceholder')); - stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", 'Heavenly Chips (CUR / MAX)', Beautify(Game.heavenlyChips) + ' / ' + Beautify((possiblePresMax - Game.prestige) + Game.heavenlyChips), 'HeavenChipMaxTooltipPlaceholder')); - - var resetBonus = CM.Sim.ResetBonus(possiblePresMax); - var resetFrag = document.createDocumentFragment(); - resetFrag.appendChild(document.createTextNode(Beautify(resetBonus))); - var increase = Math.round(resetBonus / Game.cookiesPs * 10000); - if (isFinite(increase) && increase != 0) { - var resetSmall = document.createElement('small'); - resetSmall.textContent = ' (' + (increase / 100) + '% of income)'; - resetFrag.appendChild(resetSmall); - } - stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", 'Reset Bonus Income', resetFrag, 'ResetTooltipPlaceholder')); - - var currentPrestige = Math.floor(Game.HowMuchPrestige(Game.cookiesReset)); - var willHave = Math.floor(Game.HowMuchPrestige(Game.cookiesReset + Game.cookiesEarned)); - var willGet = willHave - currentPrestige; - var addCommas = (n) => - { - var s1 = n.toString(); - var s2 = ''; - for (var i in s1) - { - if ((s1.length - i) % 3 == 0 && i > 0) - s2 += ','; - - s2 += s1[i]; - } - - return s2; - }; - - if (!Game.Has('Lucky digit')) - { - var delta7 = 7 - (willHave % 10); - if (delta7 < 0) delta7 += 10; - var next7Reset = willGet + delta7; - var next7Total = willHave + delta7; - var frag7 = document.createDocumentFragment(); - frag7.appendChild(document.createTextNode(addCommas(next7Total) + " / " + addCommas(next7Reset) + " (+" + delta7 + ")")); - stats.appendChild(listing('Next "Lucky Digit" (total / reset)', frag7)); - } - - if (!Game.Has('Lucky number')) - { - var delta777 = 777 - (willHave % 1000); - if (delta777 < 0) delta777 += 1000; - var next777Reset = willGet + delta777; - var next777Total = willHave + delta777; - var frag777 = document.createDocumentFragment(); - frag777.appendChild(document.createTextNode(addCommas(next777Total) + " / " + addCommas(next777Reset) + " (+" + delta777 + ")")); - stats.appendChild(listing('Next "Lucky Number" (total / reset)', frag777)); - } - - if (!Game.Has('Lucky payout')) - { - var delta777777 = 777777 - (willHave % 1000000); - if (delta777777 < 0) delta777777 += 1000000; - var next777777Reset = willGet + delta777777; - var next777777Total = willHave + delta777777; - var frag777777 = document.createDocumentFragment(); - frag777777.appendChild(document.createTextNode(addCommas(next777777Total) + " / " + addCommas(next777777Reset) + " (+" + delta777777 + ")")); - stats.appendChild(listing('Next "Lucky Payout" (total / reset)', frag777777)); - } - } - - // TODO: Collapse this function and just write it as code - CM.Disp.CollectWrinklers = function() { - for (var i in Game.wrinklers) { - if (Game.wrinklers[i].sucked > 0 && Game.wrinklers[i].type == 0) { - Game.wrinklers[i].hp = 0; - } - } + stats.appendChild(CM.Disp.CreateStatsPrestigeSection()); } if (Game.cpsSucked > 0) { @@ -3089,77 +2938,78 @@ CM.Disp.AddMenuStats = function(title) { popAllA.className = 'option'; popAllA.onclick = function() { CM.Disp.CollectWrinklers(); }; popAllFrag.appendChild(popAllA); - stats.appendChild(listing('Rewards of Popping', popAllFrag)); + stats.appendChild(CM.Disp.CreateStatsListing("basic", 'Rewards of Popping', popAllFrag)); } } + var specDisp = false; - var halloCook = []; + var missingHalloweenCookies = []; for (var i in CM.Data.HalloCookies) { if (!Game.Has(CM.Data.HalloCookies[i])) { - halloCook.push(CM.Data.HalloCookies[i]); + missingHalloweenCookies.push(CM.Data.HalloCookies[i]); specDisp = true; } } - var christCook = []; + var missingChristmasCookies = []; for (var i in CM.Data.ChristCookies) { if (!Game.Has(CM.Data.ChristCookies[i])) { - christCook.push(CM.Data.ChristCookies[i]); + missingChristmasCookies.push(CM.Data.ChristCookies[i]); specDisp = true; } } - var valCook = []; + var missingValentineCookies = []; for (var i in CM.Data.ValCookies) { if (!Game.Has(CM.Data.ValCookies[i])) { - valCook.push(CM.Data.ValCookies[i]); + missingValentineCookies.push(CM.Data.ValCookies[i]); specDisp = true; } } - var normEggs = []; + var missingNormalEggs = []; for (var i in Game.eggDrops) { if (!Game.HasUnlocked(Game.eggDrops[i])) { - normEggs.push(Game.eggDrops[i]); + missingNormalEggs.push(Game.eggDrops[i]); specDisp = true; } } - var rareEggs = []; + var missingRareEggs = []; for (var i in Game.rareEggDrops) { if (!Game.HasUnlocked(Game.rareEggDrops[i])) { - rareEggs.push(Game.rareEggDrops[i]); + missingRareEggs.push(Game.rareEggDrops[i]); specDisp = true; } } - + var choEgg = (Game.HasUnlocked('Chocolate egg') && !Game.Has('Chocolate egg')); var centEgg = Game.Has('Century egg'); - + if (Game.season == 'christmas' || specDisp || choEgg || centEgg) { stats.appendChild(CM.Disp.CreateStatsHeader('Season Specials', 'Sea')); if (CM.Config.StatsPref.Sea) { if (specDisp) { - if (halloCook.length != 0) stats.appendChild(listing('Halloween Cookies Left to Buy', CM.Disp.CreateStatsMissDisp(halloCook))); - if (christCook.length != 0) stats.appendChild(listing('Christmas Cookies Left to Buy', CM.Disp.CreateStatsMissDisp(christCook))); - if (valCook.length != 0) stats.appendChild(listing('Valentine Cookies Left to Buy', CM.Disp.CreateStatsMissDisp(valCook))); - if (normEggs.length != 0) stats.appendChild(listing('Normal Easter Eggs Left to Unlock', CM.Disp.CreateStatsMissDisp(normEggs))); - if (rareEggs.length != 0) stats.appendChild(listing('Rare Easter Eggs Left to Unlock', CM.Disp.CreateStatsMissDisp(rareEggs))); + if (missingHalloweenCookies.length != 0) stats.appendChild(CM.Disp.CreateStatsListing("basic", 'Halloween Cookies Left to Buy', CM.Disp.CreateStatsMissDisp(missingHalloweenCookies))); + if (missingChristmasCookies.length != 0) stats.appendChild(CM.Disp.CreateStatsListing("basic", 'Christmas Cookies Left to Buy', CM.Disp.CreateStatsMissDisp(missingChristmasCookies))); + if (missingValentineCookies.length != 0) stats.appendChild(CM.Disp.CreateStatsListing("basic", 'Valentine Cookies Left to Buy', CM.Disp.CreateStatsMissDisp(missingValentineCookies))); + if (missingNormalEggs.length != 0) stats.appendChild(CM.Disp.CreateStatsListing("basic", 'Normal Easter Eggs Left to Unlock', CM.Disp.CreateStatsMissDisp(missingNormalEggs))); + if (missingRareEggs.length != 0) stats.appendChild(CM.Disp.CreateStatsListing("basic", 'Rare Easter Eggs Left to Unlock', CM.Disp.CreateStatsMissDisp(missingRareEggs))); } - if (Game.season == 'christmas') stats.appendChild(listing('Reindeer Reward', document.createTextNode(Beautify(CM.Cache.SeaSpec)))); + if (Game.season == 'christmas') stats.appendChild(CM.Disp.CreateStatsListing("basic", 'Reindeer Reward', document.createTextNode(Beautify(CM.Cache.SeaSpec)))); if (choEgg) { - stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", 'Chocolate Egg Cookies', Beautify(CM.Cache.lastChoEgg), 'ChoEggTooltipPlaceholder')); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", 'Chocolate Egg Cookies', document.createTextNode(Beautify(CM.Cache.lastChoEgg)), 'ChoEggTooltipPlaceholder')); } if (centEgg) { - stats.appendChild(listing('Century Egg Multiplier', document.createTextNode((Math.round((CM.Cache.CentEgg - 1) * 10000) / 100) + '%'))); + stats.appendChild(CM.Disp.CreateStatsListing("basic", 'Century Egg Multiplier', document.createTextNode((Math.round((CM.Cache.CentEgg - 1) * 10000) / 100) + '%'))); } } } stats.appendChild(CM.Disp.CreateStatsHeader('Miscellaneous', 'Misc')); if (CM.Config.StatsPref.Misc) { - stats.appendChild(listing( + stats.appendChild(CM.Disp.CreateStatsListing("basic", 'Average Cookies Per Second (Past ' + (CM.Disp.cookieTimes[CM.Config.AvgCPSHist] < 60 ? (CM.Disp.cookieTimes[CM.Config.AvgCPSHist] + ' seconds') : ((CM.Disp.cookieTimes[CM.Config.AvgCPSHist] / 60) + (CM.Config.AvgCPSHist == 3 ? ' minute' : ' minutes'))) + ')', document.createTextNode(Beautify(CM.Cache.AvgCPS, 3)) )); - stats.appendChild(listing('Average Cookie Clicks Per Second (Past ' + CM.Disp.clickTimes[CM.Config.AvgClicksHist] + (CM.Config.AvgClicksHist == 0 ? ' second' : ' seconds') + ')', document.createTextNode(Beautify(CM.Cache.AvgClicks, 1)))); + stats.appendChild(CM.Disp.CreateStatsListing("basic", 'Average Cookie Clicks Per Second (Past ' + CM.Disp.clickTimes[CM.Config.AvgClicksHist] + (CM.Config.AvgClicksHist == 0 ? ' second' : ' seconds') + ')', document.createTextNode(Beautify(CM.Cache.AvgClicks, 1)))); if (Game.Has('Fortune cookies')) { var fortunes = []; for (var i in CM.Data.Fortunes) { @@ -3167,14 +3017,14 @@ CM.Disp.AddMenuStats = function(title) { fortunes.push(CM.Data.Fortunes[i]); } } - if (fortunes.length != 0) stats.appendChild(listing('Fortune Upgrades Left to Buy', CM.Disp.CreateStatsMissDisp(fortunes))); + if (fortunes.length != 0) stats.appendChild(CM.Disp.CreateStatsListing("basic", 'Fortune Upgrades Left to Buy', CM.Disp.CreateStatsMissDisp(fortunes))); } - stats.appendChild(listing('Missed Golden Cookies', document.createTextNode(Beautify(Game.missedGoldenClicks)))); + stats.appendChild(CM.Disp.CreateStatsListing("basic", 'Missed Golden Cookies', document.createTextNode(Beautify(Game.missedGoldenClicks)))); if (Game.prefs.autosave) { var timer = document.createElement('span'); timer.id = 'CMStatsAutosaveTimer'; timer.innerText = Game.sayTime(Game.fps * 60 - (Game.OnAscend ? 0 : (Game.T % (Game.fps * 60))), 4); - stats.appendChild(listing('Time till autosave', timer)); + stats.appendChild(CM.Disp.CreateStatsListing("basic", 'Time till autosave', timer)); } } @@ -3231,7 +3081,7 @@ CM.Disp.CreateStatsListing = function(type, name, text, placeholder) { div.className = 'listing'; var listingName = document.createElement('b'); - listingName.textContent = name + ' '; + listingName.textContent = name; div.appendChild(listingName); if (type == "withTooltip") { div.className = 'listing'; @@ -3259,9 +3109,9 @@ CM.Disp.CreateStatsListing = function(type, name, text, placeholder) { } /** - * This function ? - * @param {string} theMissDisp The type fo the listing - * @returns {object} frag The option object + * This function creates a tooltip containing all missing holiday items contained in the list theMissDisp + * @param {list} theMissDisp A list of the missing holiday items + * @returns {object} frag The tooltip object */ CM.Disp.CreateStatsMissDisp = function(theMissDisp) { var frag = document.createDocumentFragment(); @@ -3305,9 +3155,10 @@ CM.Disp.CreateStatsMissDisp = function(theMissDisp) { * This function creates the "Lucky" section of the stats page * @returns {object} section The object contating the Lucky section */ -CM.Disp.CreateStatsLuckySection = function() { +CM.Disp.CreateStatsLuckySection = function() { // TODO: Remove this and creater better tooltip!! var goldCookTooltip = CM.Sim.auraMult('Dragon\'s Fortune') ? 'GoldCookDragonsFortuneTooltipPlaceholder' : 'GoldCookTooltipPlaceholder'; + var section = document.createElement('div'); section.className = 'CMStatsLuckySection'; @@ -3342,36 +3193,213 @@ CM.Disp.CreateStatsLuckySection = function() { } section.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Lucky!\" Cookies Required (Frenzy)', luckyReqFrenFrag, goldCookTooltip)); - var luckySplit = luckyRewardMax != luckyRewardMaxWrath; + var luckySplit = CM.Cache.LuckyReward != CM.Cache.LuckyWrathReward; - var luckyRewardMax = CM.Cache.LuckyReward; - var luckyRewardMaxWrath = CM.Cache.LuckyWrathReward; var luckyRewardMaxSpan = document.createElement('span'); luckyRewardMaxSpan.style.fontWeight = 'bold'; - luckyRewardMaxSpan.className = CM.Disp.colorTextPre + luckyRewardMax; - luckyRewardMaxSpan.textContent = Beautify(luckyRewardMax) + (luckySplit ? (' / ' + Beautify(luckyRewardMaxWrath)) : ''); + luckyRewardMaxSpan.className = CM.Disp.colorTextPre + CM.Cache.LuckyReward; + luckyRewardMaxSpan.textContent = Beautify(CM.Cache.LuckyReward) + (luckySplit ? (' / ' + Beautify(CM.Cache.LuckyWrathReward)) : ''); section.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Lucky!\" Reward (MAX)' + (luckySplit ? ' (Golden / Wrath)' : ''), luckyRewardMaxSpan, goldCookTooltip)); - var luckyRewardFrenzyMax = CM.Cache.LuckyRewardFrenzy; - var luckyRewardFrenzyMaxWrath = CM.Cache.LuckyWrathRewardFrenzy; var luckyRewardFrenzyMaxSpan = document.createElement('span'); luckyRewardFrenzyMaxSpan.style.fontWeight = 'bold'; luckyRewardFrenzyMaxSpan.className = CM.Disp.colorTextPre + luckyRewardFrenzyMaxSpan; - luckyRewardFrenzyMaxSpan.textContent = Beautify(luckyRewardFrenzyMax) + (luckySplit ? (' / ' + Beautify(luckyRewardFrenzyMaxWrath)) : ''); + luckyRewardFrenzyMaxSpan.textContent = Beautify(CM.Cache.LuckyRewardFrenzy) + (luckySplit ? (' / ' + Beautify(CM.Cache.LuckyWrathRewardFrenzy)) : ''); section.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Lucky!\" Reward (MAX) (Frenzy)' + (luckySplit ? ' (Golden / Wrath)' : ''), luckyRewardFrenzyMaxSpan , goldCookTooltip)); var luckyCurBase = Math.min((Game.cookies + CM.Disp.GetWrinkConfigBank()) * 0.15, CM.Cache.NoGoldSwitchCookiesPS * CM.Cache.DragonsFortuneMultAdjustment * 60 * 15) + 13; - var luckyCur = CM.Cache.GoldenCookiesMult * luckyCurBase; - var luckyCurWrath = CM.Cache.WrathCookiesMult * luckyCurBase; var luckyCurSpan = document.createElement('span'); luckyCurSpan.style.fontWeight = 'bold'; luckyCurSpan.className = CM.Disp.colorTextPre + luckyCurSpan; - luckyCurSpan.textContent = Beautify(luckyCur) + (luckySplit ? (' / ' + Beautify(luckyCurWrath)) : '') + luckyCurSpan.textContent = Beautify(CM.Cache.GoldenCookiesMult * luckyCurBase) + (luckySplit ? (' / ' + Beautify(CM.Cache.WrathCookiesMult * luckyCurBase)) : '') section.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Lucky!\" Reward (CUR)' + (luckySplit ? ' (Golden / Wrath)' : ''), luckyCurSpan, goldCookTooltip)); return section; } +/** + * This function creates the "Chain" section of the stats page + * @returns {object} section The object contating the Chain section + */ +CM.Disp.CreateStatsChainSection = function() { + // TODO: Remove this and creater better tooltip!! + var goldCookTooltip = CM.Sim.auraMult('Dragon\'s Fortune') ? 'GoldCookDragonsFortuneTooltipPlaceholder' : 'GoldCookTooltipPlaceholder'; + + var section = document.createElement('div'); + section.className = 'CMStatsChainSection'; + var chainColor = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.Chain) ? CM.Disp.colorRed : CM.Disp.colorGreen; + var chainTime = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.Chain) ? CM.Disp.FormatTime((CM.Cache.Chain - (Game.cookies + CM.Disp.GetWrinkConfigBank())) / CM.Disp.GetCPS()) : ''; + var chainReqFrag = document.createDocumentFragment(); + var chainReqSpan = document.createElement('span'); + chainReqSpan.style.fontWeight = 'bold'; + chainReqSpan.className = CM.Disp.colorTextPre + chainColor; + chainReqSpan.textContent = Beautify(CM.Cache.Chain); + chainReqFrag.appendChild(chainReqSpan); + if (chainTime != '') { + var chainReqSmall = document.createElement('small'); + chainReqSmall.textContent = ' (' + chainTime + ')'; + chainReqFrag.appendChild(chainReqSmall); + } + section.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Chain\" Cookies Required', chainReqFrag, goldCookTooltip)); + + var chainWrathColor = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.ChainWrath) ? CM.Disp.colorRed : CM.Disp.colorGreen; + var chainWrathTime = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.ChainWrath) ? CM.Disp.FormatTime((CM.Cache.ChainWrath - (Game.cookies + CM.Disp.GetWrinkConfigBank())) / CM.Disp.GetCPS()) : ''; + var chainWrathReqFrag = document.createDocumentFragment(); + var chainWrathReqSpan = document.createElement('span'); + chainWrathReqSpan.style.fontWeight = 'bold'; + chainWrathReqSpan.className = CM.Disp.colorTextPre + chainWrathColor; + chainWrathReqSpan.textContent = Beautify(CM.Cache.ChainWrath); + chainWrathReqFrag.appendChild(chainWrathReqSpan); + if (chainWrathTime != '') { + var chainWrathReqSmall = document.createElement('small'); + chainWrathReqSmall.textContent = ' (' + chainWrathTime + ')'; + chainWrathReqFrag.appendChild(chainWrathReqSmall); + } + section.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Chain\" Cookies Required (Wrath)', chainWrathReqFrag, goldCookTooltip)); + + var chainColorFrenzy = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.ChainFrenzy) ? CM.Disp.colorRed : CM.Disp.colorGreen; + var chainTimeFrenzy = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.ChainFrenzy) ? CM.Disp.FormatTime((CM.Cache.ChainFrenzy - (Game.cookies + CM.Disp.GetWrinkConfigBank())) / CM.Disp.GetCPS()) : ''; + var chainReqFrenFrag = document.createDocumentFragment(); + var chainReqFrenSpan = document.createElement('span'); + chainReqFrenSpan.style.fontWeight = 'bold'; + chainReqFrenSpan.className = CM.Disp.colorTextPre + chainColorFrenzy; + chainReqFrenSpan.textContent = Beautify(CM.Cache.ChainFrenzy); + chainReqFrenFrag.appendChild(chainReqFrenSpan); + if (chainTimeFrenzy != '') { + var chainReqFrenSmall = document.createElement('small'); + chainReqFrenSmall.textContent = ' (' + chainTimeFrenzy + ')'; + chainReqFrenFrag.appendChild(chainReqFrenSmall); + } + section.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Chain\" Cookies Required (Frenzy)', chainReqFrenFrag, goldCookTooltip)); + + var chainWrathColorFrenzy = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.ChainFrenzyWrath) ? CM.Disp.colorRed : CM.Disp.colorGreen; + var chainWrathTimeFrenzy = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.ChainFrenzyWrath) ? CM.Disp.FormatTime((CM.Cache.ChainFrenzyWrath - (Game.cookies + CM.Disp.GetWrinkConfigBank())) / CM.Disp.GetCPS()) : ''; + var chainWrathReqFrenFrag = document.createDocumentFragment(); + var chainWrathReqFrenSpan = document.createElement('span'); + chainWrathReqFrenSpan.style.fontWeight = 'bold'; + chainWrathReqFrenSpan.className = CM.Disp.colorTextPre + chainWrathColorFrenzy; + chainWrathReqFrenSpan.textContent = Beautify(CM.Cache.ChainFrenzyWrath); + chainWrathReqFrenFrag.appendChild(chainWrathReqFrenSpan); + if (chainWrathTimeFrenzy != '') { + var chainWrathReqFrenSmall = document.createElement('small'); + chainWrathReqFrenSmall.textContent = ' (' + chainWrathTimeFrenzy + ')'; + chainWrathReqFrenFrag.appendChild(chainWrathReqFrenSmall); + } + section.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Chain\" Cookies Required (Frenzy) (Wrath)', chainWrathReqFrenFrag, goldCookTooltip)); + + section.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Chain\" Reward (MAX) (Golden / Wrath)', document.createTextNode(Beautify(CM.Cache.ChainReward) + ' / ' + Beautify(CM.Cache.ChainWrathReward)), goldCookTooltip)); + + section.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Chain\" Reward (MAX) (Frenzy) (Golden / Wrath)', document.createTextNode((Beautify(CM.Cache.ChainFrenzyReward) + ' / ' + Beautify(CM.Cache.ChainFrenzyWrathReward))), goldCookTooltip)); + + // TODO: Place MaxChainMoni function into CM.Cache.RemakeChain and create global variables to store it + var chainCurMax = Math.min(CM.Cache.NoGoldSwitchCookiesPS * CM.Cache.DragonsFortuneMultAdjustment * 60 * 60 * 6, (Game.cookies + CM.Disp.GetWrinkConfigBank()) * 0.5); + var chainCur = CM.Cache.MaxChainMoni(7, chainCurMax, CM.Cache.GoldenCookiesMult); + var chainCurWrath = CM.Cache.MaxChainMoni(6, chainCurMax, CM.Cache.WrathCookiesMult); + section.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Chain\" Reward (CUR) (Golden / Wrath)', document.createTextNode((Beautify(chainCur) + ' / ' + Beautify(chainCurWrath))), goldCookTooltip)); + return section; +} + +/** + * This function creates the "Conjure" section of the stats page + * @returns {object} section The object contating the Conjure section + */ +CM.Disp.CreateStatsConjureSection = function() { + var section = document.createElement('div'); + section.className = 'CMStatsConjureSection'; + + var conjureColor = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.Conjure) ? CM.Disp.colorRed : CM.Disp.colorGreen; + var conjureCur = Math.min((Game.cookies + CM.Disp.GetWrinkConfigBank()) * 0.15, CM.Cache.NoGoldSwitchCookiesPS * 60 * 30); + var conjureTime = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.Conjure) ? CM.Disp.FormatTime((CM.Cache.Conjure - (Game.cookies + CM.Disp.GetWrinkConfigBank())) / CM.Disp.GetCPS()) : ''; + + var conjureReqFrag = document.createDocumentFragment(); + var conjureReqSpan = document.createElement('span'); + conjureReqSpan.style.fontWeight = 'bold'; + conjureReqSpan.className = CM.Disp.colorTextPre + conjureColor; + conjureReqSpan.textContent = Beautify(CM.Cache.Conjure); + conjureReqFrag.appendChild(conjureReqSpan); + if (conjureTime != '') { + var conjureReqSmall = document.createElement('small'); + conjureReqSmall.textContent = ' (' + conjureTime + ')'; + conjureReqFrag.appendChild(conjureReqSmall); + } + section.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Conjure Baked Goods\" Cookies Required', conjureReqFrag, 'GoldCookTooltipPlaceholder')); + section.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Conjure Baked Goods\" Reward (MAX)', document.createTextNode(CM.Disp.Beautify(CM.Cache.ConjureReward)), 'GoldCookTooltipPlaceholder')); + section.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Conjure Baked Goods\" Reward (CUR)', document.createTextNode(CM.Disp.Beautify(conjureCur)), 'GoldCookTooltipPlaceholder')); + return section; +} + +/** + * This function creates the "Prestige" section of the stats page + * @returns {object} section The object contating the Prestige section + */ +CM.Disp.CreateStatsPrestigeSection = function() { + var section = document.createElement('div'); + section.className = 'CMStatsPrestigeSection'; + + var possiblePresMax = Math.floor(Game.HowMuchPrestige(CM.Cache.RealCookiesEarned + + Game.cookiesReset + CM.Cache.WrinkGodBank + + (Game.HasUnlocked('Chocolate egg') && !Game.Has('Chocolate egg') ? CM.Cache.lastChoEgg : 0))); + section.appendChild(CM.Disp.CreateStatsListing("withTooltip", 'Prestige Level (CUR / MAX)', document.createTextNode(Beautify(Game.prestige) + ' / ' + Beautify(possiblePresMax)), 'PrestMaxTooltipPlaceholder')); + + var neededCook = Game.HowManyCookiesReset(possiblePresMax + 1) - (CM.Cache.RealCookiesEarned + Game.cookiesReset + CM.Cache.WrinkGodBank + ((Game.HasUnlocked('Chocolate egg') && !Game.Has('Chocolate egg') ? CM.Cache.lastChoEgg : 0) ? CM.Cache.lastChoEgg : 0)); + var cookiesNextFrag = document.createDocumentFragment(); + cookiesNextFrag.appendChild(document.createTextNode(Beautify(neededCook))); + var cookiesNextSmall = document.createElement('small'); + cookiesNextSmall.textContent = ' (' + (CM.Disp.FormatTime(neededCook / CM.Cache.AvgCPSChoEgg, 1)) + ')'; + cookiesNextFrag.appendChild(cookiesNextSmall); + section.appendChild(CM.Disp.CreateStatsListing("withTooltip", 'Cookies To Next Level', cookiesNextFrag, 'NextPrestTooltipPlaceholder')); + + section.appendChild(CM.Disp.CreateStatsListing("withTooltip", 'Heavenly Chips (CUR / MAX)', document.createTextNode(Beautify(Game.heavenlyChips) + ' / ' + Beautify((possiblePresMax - Game.prestige) + Game.heavenlyChips)), 'HeavenChipMaxTooltipPlaceholder')); + + var resetBonus = CM.Sim.ResetBonus(possiblePresMax); + var resetFrag = document.createDocumentFragment(); + resetFrag.appendChild(document.createTextNode(Beautify(resetBonus))); + var increase = Math.round(resetBonus / Game.cookiesPs * 10000); + if (isFinite(increase) && increase != 0) { + var resetSmall = document.createElement('small'); + resetSmall.textContent = ' (' + (increase / 100) + '% of income)'; + resetFrag.appendChild(resetSmall); + } + section.appendChild(CM.Disp.CreateStatsListing("withTooltip", 'Reset Bonus Income', resetFrag, 'ResetTooltipPlaceholder')); + + var currentPrestige = Math.floor(Game.HowMuchPrestige(Game.cookiesReset)); + var willHave = Math.floor(Game.HowMuchPrestige(Game.cookiesReset + Game.cookiesEarned)); + var willGet = willHave - currentPrestige; + if (!Game.Has('Lucky digit')) { + var delta7 = 7 - (willHave % 10); + if (delta7 < 0) delta7 += 10; + var next7Reset = willGet + delta7; + var next7Total = willHave + delta7; + var frag7 = document.createDocumentFragment(); + frag7.appendChild(document.createTextNode(next7Total.toLocaleString() + " / " + next7Reset.toLocaleString() + " (+" + delta7 + ")")); + section.appendChild(CM.Disp.CreateStatsListing("basic", 'Next "Lucky Digit" (total / reset)', frag7)); + } + + if (!Game.Has('Lucky number')) { + var delta777 = 777 - (willHave % 1000); + if (delta777 < 0) delta777 += 1000; + var next777Reset = willGet + delta777; + var next777Total = willHave + delta777; + var frag777 = document.createDocumentFragment(); + frag777.appendChild(document.createTextNode(next777Total.toLocaleString() + " / " + next777Reset.toLocaleString() + " (+" + delta777 + ")")); + section.appendChild(CM.Disp.CreateStatsListing("basic", 'Next "Lucky Number" (total / reset)', frag777)); + } + + if (!Game.Has('Lucky payout')) { + var delta777777 = 777777 - (willHave % 1000000); + if (delta777777 < 0) delta777777 += 1000000; + var next777777Reset = willGet + delta777777; + var next777777Total = willHave + delta777777; + var frag777777 = document.createDocumentFragment(); + frag777777.appendChild(document.createTextNode(next777777Total.toLocaleString() + " / " + next777777Reset.toLocaleString() + " (+" + delta777777 + ")")); + section.appendChild(CM.Disp.CreateStatsListing("basic", 'Next "Lucky Payout" (total / reset)', frag777777)); + } + + return section; +} + +// TODO: Fix and annotate this function. +/** CM.Disp.AddMissingUpgrades = function() { if (CM.Cache.UpgradesOwned != Game.UpgradesOwned) { CM.Cache.CalcMissingUpgrades(); @@ -3447,7 +3475,7 @@ CM.Disp.AddMissingUpgrades = function() { } upgradesMenu.appendChild(CM.Cache.MissingCookiesString); } -} +} */ /******** * Section: Variables used in Disp functions diff --git a/src/Disp.js b/src/Disp.js index a3c3d39..1cf5812 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -22,6 +22,18 @@ CM.Disp.GetWrinkConfigBank = function() { return 0; } +/** + * This function pops all normal wrinklers + * It is called by a click of the 'pop all' button created by CM.Disp.AddMenuStats() + */ +CM.Disp.PopAllNormalWrinklers = function() { + for (var i in Game.wrinklers) { + if (Game.wrinklers[i].sucked > 0 && Game.wrinklers[i].type == 0) { + Game.wrinklers[i].hp = 0; + } + } +} + /** * This function returns the cps as either current or average CPS depending on CM.Config.CPSMode * @returns {number} The average or current cps @@ -187,9 +199,10 @@ CM.Disp.Beautify = function(num, frac, forced) { } else { var restOfNumber = (num / Math.pow(10, (timesTenToPowerThree * 3))).toString(); + // Check if number contains decimals numbersToAdd = (restOfNumber.indexOf('.') > -1 ? restOfNumber.indexOf('.') + 1 + decimals : (restOfNumber.length)) i = 0 - while (i < numbersToAdd - 1) { + while (i < numbersToAdd - 1 && i < restOfNumber.length - 1) { answer += restOfNumber[i]; i++ } @@ -217,7 +230,7 @@ CM.Disp.Beautify = function(num, frac, forced) { } } if (answer === '') { - console.log("Could not beautify number with CM.Disp.Beautify"); + console.log("Could not beautify number with CM.Disp.Beautify:" + num); answer = CM.Backup.Beautify(num, frac); } if (negative) answer = '-' + answer; @@ -227,7 +240,7 @@ CM.Disp.Beautify = function(num, frac, forced) { return "Infinity"; } else { - console.log("Could not beautify number with CM.Disp.Beautify"); + console.log("Could not beautify number with CM.Disp.Beautify:" + num); return CM.Backup.Beautify(num, frac); } } @@ -1995,8 +2008,13 @@ CM.Disp.UpdateColors = function() { /******** * Section: Functions related to the Stats page - * TODO: Annotate functions */ + * TODO: Annotate last functions */ +/** + * This function adds stats created by CookieMonster to the stats page + * It is called by CM.Disp.AddMenu + * @param {function} title A function that returns the title of CookieMonster pre-styled + */ CM.Disp.AddMenuStats = function(title) { var stats = document.createElement('div'); stats.className = 'subsection'; @@ -2009,186 +2027,17 @@ CM.Disp.AddMenuStats = function(title) { stats.appendChild(CM.Disp.CreateStatsHeader('Chain Cookies', 'Chain')); if (CM.Config.StatsPref.Chain) { - var chainColor = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.Chain) ? CM.Disp.colorRed : CM.Disp.colorGreen; - var chainTime = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.Chain) ? CM.Disp.FormatTime((CM.Cache.Chain - (Game.cookies + CM.Disp.GetWrinkConfigBank())) / CM.Disp.GetCPS()) : ''; - var chainColorFrenzy = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.ChainFrenzy) ? CM.Disp.colorRed : CM.Disp.colorGreen; - var chainTimeFrenzy = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.ChainFrenzy) ? CM.Disp.FormatTime((CM.Cache.ChainFrenzy - (Game.cookies + CM.Disp.GetWrinkConfigBank())) / CM.Disp.GetCPS()) : ''; - var chainWrathColor = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.ChainWrath) ? CM.Disp.colorRed : CM.Disp.colorGreen; - var chainWrathTime = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.ChainWrath) ? CM.Disp.FormatTime((CM.Cache.ChainWrath - (Game.cookies + CM.Disp.GetWrinkConfigBank())) / CM.Disp.GetCPS()) : ''; - var chainWrathColorFrenzy = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.ChainFrenzyWrath) ? CM.Disp.colorRed : CM.Disp.colorGreen; - var chainWrathTimeFrenzy = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.ChainFrenzyWrath) ? CM.Disp.FormatTime((CM.Cache.ChainFrenzyWrath - (Game.cookies + CM.Disp.GetWrinkConfigBank())) / CM.Disp.GetCPS()) : ''; - - var chainRewardMax = CM.Cache.ChainReward; - var chainWrathRewardMax = CM.Cache.ChainWrathReward; - var chainFrenzyRewardMax = CM.Cache.ChainFrenzyReward; - var chainFrenzyWrathRewardMax = CM.Cache.ChainFrenzyWrathReward; - var chainCurMax = Math.min(CM.Cache.NoGoldSwitchCookiesPS * CM.Cache.DragonsFortuneMultAdjustment * 60 * 60 * 6, (Game.cookies + CM.Disp.GetWrinkConfigBank()) * 0.5); - var chainCur = CM.Cache.MaxChainMoni(7, chainCurMax, CM.Cache.GoldenCookiesMult); - var chainCurWrath = CM.Cache.MaxChainMoni(6, chainCurMax, CM.Cache.WrathCookiesMult); - - var chainReqFrag = document.createDocumentFragment(); - var chainReqSpan = document.createElement('span'); - chainReqSpan.style.fontWeight = 'bold'; - chainReqSpan.className = CM.Disp.colorTextPre + chainColor; - chainReqSpan.textContent = Beautify(CM.Cache.Chain); - chainReqFrag.appendChild(chainReqSpan); - if (chainTime != '') { - var chainReqSmall = document.createElement('small'); - chainReqSmall.textContent = ' (' + chainTime + ')'; - chainReqFrag.appendChild(chainReqSmall); - } - stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Chain\" Cookies Required', chainReqFrag, goldCookTooltip)); - var chainWrathReqFrag = document.createDocumentFragment(); - var chainWrathReqSpan = document.createElement('span'); - chainWrathReqSpan.style.fontWeight = 'bold'; - chainWrathReqSpan.className = CM.Disp.colorTextPre + chainWrathColor; - chainWrathReqSpan.textContent = Beautify(CM.Cache.ChainWrath); - chainWrathReqFrag.appendChild(chainWrathReqSpan); - if (chainWrathTime != '') { - var chainWrathReqSmall = document.createElement('small'); - chainWrathReqSmall.textContent = ' (' + chainWrathTime + ')'; - chainWrathReqFrag.appendChild(chainWrathReqSmall); - } - stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Chain\" Cookies Required (Wrath)', chainWrathReqFrag, goldCookTooltip)); - var chainReqFrenFrag = document.createDocumentFragment(); - var chainReqFrenSpan = document.createElement('span'); - chainReqFrenSpan.style.fontWeight = 'bold'; - chainReqFrenSpan.className = CM.Disp.colorTextPre + chainColorFrenzy; - chainReqFrenSpan.textContent = Beautify(CM.Cache.ChainFrenzy); - chainReqFrenFrag.appendChild(chainReqFrenSpan); - if (chainTimeFrenzy != '') { - var chainReqFrenSmall = document.createElement('small'); - chainReqFrenSmall.textContent = ' (' + chainTimeFrenzy + ')'; - chainReqFrenFrag.appendChild(chainReqFrenSmall); - } - stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Chain\" Cookies Required (Frenzy)', chainReqFrenFrag, goldCookTooltip)); - var chainWrathReqFrenFrag = document.createDocumentFragment(); - var chainWrathReqFrenFrag = document.createDocumentFragment(); - var chainWrathReqFrenSpan = document.createElement('span'); - chainWrathReqFrenSpan.style.fontWeight = 'bold'; - chainWrathReqFrenSpan.className = CM.Disp.colorTextPre + chainWrathColorFrenzy; - chainWrathReqFrenSpan.textContent = Beautify(CM.Cache.ChainFrenzyWrath); - chainWrathReqFrenFrag.appendChild(chainWrathReqFrenSpan); - if (chainWrathTimeFrenzy != '') { - var chainWrathReqFrenSmall = document.createElement('small'); - chainWrathReqFrenSmall.textContent = ' (' + chainWrathTimeFrenzy + ')'; - chainWrathReqFrenFrag.appendChild(chainWrathReqFrenSmall); - } - stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Chain\" Cookies Required (Frenzy) (Wrath)', chainWrathReqFrenFrag, goldCookTooltip)); - stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Chain\" Reward (MAX) (Golden / Wrath)', Beautify(chainRewardMax) + ' / ' + Beautify(chainWrathRewardMax), goldCookTooltip)); - stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Chain\" Reward (MAX) (Frenzy) (Golden / Wrath)', Beautify(chainFrenzyRewardMax) + ' / ' + Beautify(chainFrenzyWrathRewardMax), goldCookTooltip)); - stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Chain\" Reward (CUR) (Golden / Wrath)', Beautify(chainCur) + ' / ' + Beautify(chainCurWrath), goldCookTooltip)); + stats.appendChild(CM.Disp.CreateStatsChainSection()); } stats.appendChild(CM.Disp.CreateStatsHeader('Conjure Baked Goods', 'Conjure')); if (CM.Config.StatsPref.Conjure) { - var conjureColor = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.Conjure) ? CM.Disp.colorRed : CM.Disp.colorGreen; - var conjureCur = Math.min((Game.cookies + CM.Disp.GetWrinkConfigBank()) * 0.15, CM.Cache.NoGoldSwitchCookiesPS * 60 * 30); - var conjureTime = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.Conjure) ? CM.Disp.FormatTime((CM.Cache.Conjure - (Game.cookies + CM.Disp.GetWrinkConfigBank())) / CM.Disp.GetCPS()) : ''; - var conjureRewardMax = CM.Cache.ConjureReward; - - var conjureReqFrag = document.createDocumentFragment(); - var conjureReqSpan = document.createElement('span'); - conjureReqSpan.style.fontWeight = 'bold'; - conjureReqSpan.className = CM.Disp.colorTextPre + conjureColor; - conjureReqSpan.textContent = Beautify(CM.Cache.Conjure); - conjureReqFrag.appendChild(conjureReqSpan); - if (conjureTime != '') { - var conjureReqSmall = document.createElement('small'); - conjureReqSmall.textContent = ' (' + conjureTime + ')'; - conjureReqFrag.appendChild(conjureReqSmall); - } - stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Conjure Baked Goods\" Cookies Required', conjureReqFrag, 'GoldCookTooltipPlaceholder')); - stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Conjure Baked Goods\" Reward (MAX)', conjureRewardMax, 'GoldCookTooltipPlaceholder')); - stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Conjure Baked Goods\" Reward (CUR)', conjureCur, 'GoldCookTooltipPlaceholder')); + stats.appendChild(CM.Disp.CreateStatsConjureSection()); } - - var choEgg = (Game.HasUnlocked('Chocolate egg') && !Game.Has('Chocolate egg')); // Needs to be done for the checking below stats.appendChild(CM.Disp.CreateStatsHeader('Prestige', 'Prestige')); if (CM.Config.StatsPref.Prestige) { - var possiblePresMax = Math.floor(Game.HowMuchPrestige(CM.Cache.RealCookiesEarned + Game.cookiesReset + CM.Cache.WrinkGodBank + (choEgg ? CM.Cache.lastChoEgg : 0))); - var neededCook = Game.HowManyCookiesReset(possiblePresMax + 1) - (CM.Cache.RealCookiesEarned + Game.cookiesReset + CM.Cache.WrinkGodBank + (choEgg ? CM.Cache.lastChoEgg : 0)); - stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", 'Prestige Level (CUR / MAX)', Beautify(Game.prestige) + ' / ' + Beautify(possiblePresMax), 'PrestMaxTooltipPlaceholder')); - - var cookiesNextFrag = document.createDocumentFragment(); - cookiesNextFrag.appendChild(document.createTextNode(Beautify(neededCook))); - var cookiesNextSmall = document.createElement('small'); - cookiesNextSmall.textContent = ' (' + (CM.Disp.FormatTime(neededCook / CM.Cache.AvgCPSChoEgg, 1)) + ')'; - cookiesNextFrag.appendChild(cookiesNextSmall); - stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", 'Cookies To Next Level', cookiesNextFrag, 'NextPrestTooltipPlaceholder')); - stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", 'Heavenly Chips (CUR / MAX)', Beautify(Game.heavenlyChips) + ' / ' + Beautify((possiblePresMax - Game.prestige) + Game.heavenlyChips), 'HeavenChipMaxTooltipPlaceholder')); - - var resetBonus = CM.Sim.ResetBonus(possiblePresMax); - var resetFrag = document.createDocumentFragment(); - resetFrag.appendChild(document.createTextNode(Beautify(resetBonus))); - var increase = Math.round(resetBonus / Game.cookiesPs * 10000); - if (isFinite(increase) && increase != 0) { - var resetSmall = document.createElement('small'); - resetSmall.textContent = ' (' + (increase / 100) + '% of income)'; - resetFrag.appendChild(resetSmall); - } - stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", 'Reset Bonus Income', resetFrag, 'ResetTooltipPlaceholder')); - - var currentPrestige = Math.floor(Game.HowMuchPrestige(Game.cookiesReset)); - var willHave = Math.floor(Game.HowMuchPrestige(Game.cookiesReset + Game.cookiesEarned)); - var willGet = willHave - currentPrestige; - var addCommas = (n) => - { - var s1 = n.toString(); - var s2 = ''; - for (var i in s1) - { - if ((s1.length - i) % 3 == 0 && i > 0) - s2 += ','; - - s2 += s1[i]; - } - - return s2; - }; - - if (!Game.Has('Lucky digit')) - { - var delta7 = 7 - (willHave % 10); - if (delta7 < 0) delta7 += 10; - var next7Reset = willGet + delta7; - var next7Total = willHave + delta7; - var frag7 = document.createDocumentFragment(); - frag7.appendChild(document.createTextNode(addCommas(next7Total) + " / " + addCommas(next7Reset) + " (+" + delta7 + ")")); - stats.appendChild(listing('Next "Lucky Digit" (total / reset)', frag7)); - } - - if (!Game.Has('Lucky number')) - { - var delta777 = 777 - (willHave % 1000); - if (delta777 < 0) delta777 += 1000; - var next777Reset = willGet + delta777; - var next777Total = willHave + delta777; - var frag777 = document.createDocumentFragment(); - frag777.appendChild(document.createTextNode(addCommas(next777Total) + " / " + addCommas(next777Reset) + " (+" + delta777 + ")")); - stats.appendChild(listing('Next "Lucky Number" (total / reset)', frag777)); - } - - if (!Game.Has('Lucky payout')) - { - var delta777777 = 777777 - (willHave % 1000000); - if (delta777777 < 0) delta777777 += 1000000; - var next777777Reset = willGet + delta777777; - var next777777Total = willHave + delta777777; - var frag777777 = document.createDocumentFragment(); - frag777777.appendChild(document.createTextNode(addCommas(next777777Total) + " / " + addCommas(next777777Reset) + " (+" + delta777777 + ")")); - stats.appendChild(listing('Next "Lucky Payout" (total / reset)', frag777777)); - } - } - - // TODO: Collapse this function and just write it as code - CM.Disp.CollectWrinklers = function() { - for (var i in Game.wrinklers) { - if (Game.wrinklers[i].sucked > 0 && Game.wrinklers[i].type == 0) { - Game.wrinklers[i].hp = 0; - } - } + stats.appendChild(CM.Disp.CreateStatsPrestigeSection()); } if (Game.cpsSucked > 0) { @@ -2201,77 +2050,78 @@ CM.Disp.AddMenuStats = function(title) { popAllA.className = 'option'; popAllA.onclick = function() { CM.Disp.CollectWrinklers(); }; popAllFrag.appendChild(popAllA); - stats.appendChild(listing('Rewards of Popping', popAllFrag)); + stats.appendChild(CM.Disp.CreateStatsListing("basic", 'Rewards of Popping', popAllFrag)); } } + var specDisp = false; - var halloCook = []; + var missingHalloweenCookies = []; for (var i in CM.Data.HalloCookies) { if (!Game.Has(CM.Data.HalloCookies[i])) { - halloCook.push(CM.Data.HalloCookies[i]); + missingHalloweenCookies.push(CM.Data.HalloCookies[i]); specDisp = true; } } - var christCook = []; + var missingChristmasCookies = []; for (var i in CM.Data.ChristCookies) { if (!Game.Has(CM.Data.ChristCookies[i])) { - christCook.push(CM.Data.ChristCookies[i]); + missingChristmasCookies.push(CM.Data.ChristCookies[i]); specDisp = true; } } - var valCook = []; + var missingValentineCookies = []; for (var i in CM.Data.ValCookies) { if (!Game.Has(CM.Data.ValCookies[i])) { - valCook.push(CM.Data.ValCookies[i]); + missingValentineCookies.push(CM.Data.ValCookies[i]); specDisp = true; } } - var normEggs = []; + var missingNormalEggs = []; for (var i in Game.eggDrops) { if (!Game.HasUnlocked(Game.eggDrops[i])) { - normEggs.push(Game.eggDrops[i]); + missingNormalEggs.push(Game.eggDrops[i]); specDisp = true; } } - var rareEggs = []; + var missingRareEggs = []; for (var i in Game.rareEggDrops) { if (!Game.HasUnlocked(Game.rareEggDrops[i])) { - rareEggs.push(Game.rareEggDrops[i]); + missingRareEggs.push(Game.rareEggDrops[i]); specDisp = true; } } - + var choEgg = (Game.HasUnlocked('Chocolate egg') && !Game.Has('Chocolate egg')); var centEgg = Game.Has('Century egg'); - + if (Game.season == 'christmas' || specDisp || choEgg || centEgg) { stats.appendChild(CM.Disp.CreateStatsHeader('Season Specials', 'Sea')); if (CM.Config.StatsPref.Sea) { if (specDisp) { - if (halloCook.length != 0) stats.appendChild(listing('Halloween Cookies Left to Buy', CM.Disp.CreateStatsMissDisp(halloCook))); - if (christCook.length != 0) stats.appendChild(listing('Christmas Cookies Left to Buy', CM.Disp.CreateStatsMissDisp(christCook))); - if (valCook.length != 0) stats.appendChild(listing('Valentine Cookies Left to Buy', CM.Disp.CreateStatsMissDisp(valCook))); - if (normEggs.length != 0) stats.appendChild(listing('Normal Easter Eggs Left to Unlock', CM.Disp.CreateStatsMissDisp(normEggs))); - if (rareEggs.length != 0) stats.appendChild(listing('Rare Easter Eggs Left to Unlock', CM.Disp.CreateStatsMissDisp(rareEggs))); + if (missingHalloweenCookies.length != 0) stats.appendChild(CM.Disp.CreateStatsListing("basic", 'Halloween Cookies Left to Buy', CM.Disp.CreateStatsMissDisp(missingHalloweenCookies))); + if (missingChristmasCookies.length != 0) stats.appendChild(CM.Disp.CreateStatsListing("basic", 'Christmas Cookies Left to Buy', CM.Disp.CreateStatsMissDisp(missingChristmasCookies))); + if (missingValentineCookies.length != 0) stats.appendChild(CM.Disp.CreateStatsListing("basic", 'Valentine Cookies Left to Buy', CM.Disp.CreateStatsMissDisp(missingValentineCookies))); + if (missingNormalEggs.length != 0) stats.appendChild(CM.Disp.CreateStatsListing("basic", 'Normal Easter Eggs Left to Unlock', CM.Disp.CreateStatsMissDisp(missingNormalEggs))); + if (missingRareEggs.length != 0) stats.appendChild(CM.Disp.CreateStatsListing("basic", 'Rare Easter Eggs Left to Unlock', CM.Disp.CreateStatsMissDisp(missingRareEggs))); } - if (Game.season == 'christmas') stats.appendChild(listing('Reindeer Reward', document.createTextNode(Beautify(CM.Cache.SeaSpec)))); + if (Game.season == 'christmas') stats.appendChild(CM.Disp.CreateStatsListing("basic", 'Reindeer Reward', document.createTextNode(Beautify(CM.Cache.SeaSpec)))); if (choEgg) { - stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", 'Chocolate Egg Cookies', Beautify(CM.Cache.lastChoEgg), 'ChoEggTooltipPlaceholder')); + stats.appendChild(CM.Disp.CreateStatsListing("withTooltip", 'Chocolate Egg Cookies', document.createTextNode(Beautify(CM.Cache.lastChoEgg)), 'ChoEggTooltipPlaceholder')); } if (centEgg) { - stats.appendChild(listing('Century Egg Multiplier', document.createTextNode((Math.round((CM.Cache.CentEgg - 1) * 10000) / 100) + '%'))); + stats.appendChild(CM.Disp.CreateStatsListing("basic", 'Century Egg Multiplier', document.createTextNode((Math.round((CM.Cache.CentEgg - 1) * 10000) / 100) + '%'))); } } } stats.appendChild(CM.Disp.CreateStatsHeader('Miscellaneous', 'Misc')); if (CM.Config.StatsPref.Misc) { - stats.appendChild(listing( + stats.appendChild(CM.Disp.CreateStatsListing("basic", 'Average Cookies Per Second (Past ' + (CM.Disp.cookieTimes[CM.Config.AvgCPSHist] < 60 ? (CM.Disp.cookieTimes[CM.Config.AvgCPSHist] + ' seconds') : ((CM.Disp.cookieTimes[CM.Config.AvgCPSHist] / 60) + (CM.Config.AvgCPSHist == 3 ? ' minute' : ' minutes'))) + ')', document.createTextNode(Beautify(CM.Cache.AvgCPS, 3)) )); - stats.appendChild(listing('Average Cookie Clicks Per Second (Past ' + CM.Disp.clickTimes[CM.Config.AvgClicksHist] + (CM.Config.AvgClicksHist == 0 ? ' second' : ' seconds') + ')', document.createTextNode(Beautify(CM.Cache.AvgClicks, 1)))); + stats.appendChild(CM.Disp.CreateStatsListing("basic", 'Average Cookie Clicks Per Second (Past ' + CM.Disp.clickTimes[CM.Config.AvgClicksHist] + (CM.Config.AvgClicksHist == 0 ? ' second' : ' seconds') + ')', document.createTextNode(Beautify(CM.Cache.AvgClicks, 1)))); if (Game.Has('Fortune cookies')) { var fortunes = []; for (var i in CM.Data.Fortunes) { @@ -2279,14 +2129,14 @@ CM.Disp.AddMenuStats = function(title) { fortunes.push(CM.Data.Fortunes[i]); } } - if (fortunes.length != 0) stats.appendChild(listing('Fortune Upgrades Left to Buy', CM.Disp.CreateStatsMissDisp(fortunes))); + if (fortunes.length != 0) stats.appendChild(CM.Disp.CreateStatsListing("basic", 'Fortune Upgrades Left to Buy', CM.Disp.CreateStatsMissDisp(fortunes))); } - stats.appendChild(listing('Missed Golden Cookies', document.createTextNode(Beautify(Game.missedGoldenClicks)))); + stats.appendChild(CM.Disp.CreateStatsListing("basic", 'Missed Golden Cookies', document.createTextNode(Beautify(Game.missedGoldenClicks)))); if (Game.prefs.autosave) { var timer = document.createElement('span'); timer.id = 'CMStatsAutosaveTimer'; timer.innerText = Game.sayTime(Game.fps * 60 - (Game.OnAscend ? 0 : (Game.T % (Game.fps * 60))), 4); - stats.appendChild(listing('Time till autosave', timer)); + stats.appendChild(CM.Disp.CreateStatsListing("basic", 'Time till autosave', timer)); } } @@ -2343,7 +2193,7 @@ CM.Disp.CreateStatsListing = function(type, name, text, placeholder) { div.className = 'listing'; var listingName = document.createElement('b'); - listingName.textContent = name + ' '; + listingName.textContent = name; div.appendChild(listingName); if (type == "withTooltip") { div.className = 'listing'; @@ -2371,9 +2221,9 @@ CM.Disp.CreateStatsListing = function(type, name, text, placeholder) { } /** - * This function ? - * @param {string} theMissDisp The type fo the listing - * @returns {object} frag The option object + * This function creates a tooltip containing all missing holiday items contained in the list theMissDisp + * @param {list} theMissDisp A list of the missing holiday items + * @returns {object} frag The tooltip object */ CM.Disp.CreateStatsMissDisp = function(theMissDisp) { var frag = document.createDocumentFragment(); @@ -2417,9 +2267,10 @@ CM.Disp.CreateStatsMissDisp = function(theMissDisp) { * This function creates the "Lucky" section of the stats page * @returns {object} section The object contating the Lucky section */ -CM.Disp.CreateStatsLuckySection = function() { +CM.Disp.CreateStatsLuckySection = function() { // TODO: Remove this and creater better tooltip!! var goldCookTooltip = CM.Sim.auraMult('Dragon\'s Fortune') ? 'GoldCookDragonsFortuneTooltipPlaceholder' : 'GoldCookTooltipPlaceholder'; + var section = document.createElement('div'); section.className = 'CMStatsLuckySection'; @@ -2454,36 +2305,213 @@ CM.Disp.CreateStatsLuckySection = function() { } section.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Lucky!\" Cookies Required (Frenzy)', luckyReqFrenFrag, goldCookTooltip)); - var luckySplit = luckyRewardMax != luckyRewardMaxWrath; + var luckySplit = CM.Cache.LuckyReward != CM.Cache.LuckyWrathReward; - var luckyRewardMax = CM.Cache.LuckyReward; - var luckyRewardMaxWrath = CM.Cache.LuckyWrathReward; var luckyRewardMaxSpan = document.createElement('span'); luckyRewardMaxSpan.style.fontWeight = 'bold'; - luckyRewardMaxSpan.className = CM.Disp.colorTextPre + luckyRewardMax; - luckyRewardMaxSpan.textContent = Beautify(luckyRewardMax) + (luckySplit ? (' / ' + Beautify(luckyRewardMaxWrath)) : ''); + luckyRewardMaxSpan.className = CM.Disp.colorTextPre + CM.Cache.LuckyReward; + luckyRewardMaxSpan.textContent = Beautify(CM.Cache.LuckyReward) + (luckySplit ? (' / ' + Beautify(CM.Cache.LuckyWrathReward)) : ''); section.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Lucky!\" Reward (MAX)' + (luckySplit ? ' (Golden / Wrath)' : ''), luckyRewardMaxSpan, goldCookTooltip)); - var luckyRewardFrenzyMax = CM.Cache.LuckyRewardFrenzy; - var luckyRewardFrenzyMaxWrath = CM.Cache.LuckyWrathRewardFrenzy; var luckyRewardFrenzyMaxSpan = document.createElement('span'); luckyRewardFrenzyMaxSpan.style.fontWeight = 'bold'; luckyRewardFrenzyMaxSpan.className = CM.Disp.colorTextPre + luckyRewardFrenzyMaxSpan; - luckyRewardFrenzyMaxSpan.textContent = Beautify(luckyRewardFrenzyMax) + (luckySplit ? (' / ' + Beautify(luckyRewardFrenzyMaxWrath)) : ''); + luckyRewardFrenzyMaxSpan.textContent = Beautify(CM.Cache.LuckyRewardFrenzy) + (luckySplit ? (' / ' + Beautify(CM.Cache.LuckyWrathRewardFrenzy)) : ''); section.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Lucky!\" Reward (MAX) (Frenzy)' + (luckySplit ? ' (Golden / Wrath)' : ''), luckyRewardFrenzyMaxSpan , goldCookTooltip)); var luckyCurBase = Math.min((Game.cookies + CM.Disp.GetWrinkConfigBank()) * 0.15, CM.Cache.NoGoldSwitchCookiesPS * CM.Cache.DragonsFortuneMultAdjustment * 60 * 15) + 13; - var luckyCur = CM.Cache.GoldenCookiesMult * luckyCurBase; - var luckyCurWrath = CM.Cache.WrathCookiesMult * luckyCurBase; var luckyCurSpan = document.createElement('span'); luckyCurSpan.style.fontWeight = 'bold'; luckyCurSpan.className = CM.Disp.colorTextPre + luckyCurSpan; - luckyCurSpan.textContent = Beautify(luckyCur) + (luckySplit ? (' / ' + Beautify(luckyCurWrath)) : '') + luckyCurSpan.textContent = Beautify(CM.Cache.GoldenCookiesMult * luckyCurBase) + (luckySplit ? (' / ' + Beautify(CM.Cache.WrathCookiesMult * luckyCurBase)) : '') section.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Lucky!\" Reward (CUR)' + (luckySplit ? ' (Golden / Wrath)' : ''), luckyCurSpan, goldCookTooltip)); return section; } +/** + * This function creates the "Chain" section of the stats page + * @returns {object} section The object contating the Chain section + */ +CM.Disp.CreateStatsChainSection = function() { + // TODO: Remove this and creater better tooltip!! + var goldCookTooltip = CM.Sim.auraMult('Dragon\'s Fortune') ? 'GoldCookDragonsFortuneTooltipPlaceholder' : 'GoldCookTooltipPlaceholder'; + + var section = document.createElement('div'); + section.className = 'CMStatsChainSection'; + var chainColor = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.Chain) ? CM.Disp.colorRed : CM.Disp.colorGreen; + var chainTime = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.Chain) ? CM.Disp.FormatTime((CM.Cache.Chain - (Game.cookies + CM.Disp.GetWrinkConfigBank())) / CM.Disp.GetCPS()) : ''; + var chainReqFrag = document.createDocumentFragment(); + var chainReqSpan = document.createElement('span'); + chainReqSpan.style.fontWeight = 'bold'; + chainReqSpan.className = CM.Disp.colorTextPre + chainColor; + chainReqSpan.textContent = Beautify(CM.Cache.Chain); + chainReqFrag.appendChild(chainReqSpan); + if (chainTime != '') { + var chainReqSmall = document.createElement('small'); + chainReqSmall.textContent = ' (' + chainTime + ')'; + chainReqFrag.appendChild(chainReqSmall); + } + section.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Chain\" Cookies Required', chainReqFrag, goldCookTooltip)); + + var chainWrathColor = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.ChainWrath) ? CM.Disp.colorRed : CM.Disp.colorGreen; + var chainWrathTime = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.ChainWrath) ? CM.Disp.FormatTime((CM.Cache.ChainWrath - (Game.cookies + CM.Disp.GetWrinkConfigBank())) / CM.Disp.GetCPS()) : ''; + var chainWrathReqFrag = document.createDocumentFragment(); + var chainWrathReqSpan = document.createElement('span'); + chainWrathReqSpan.style.fontWeight = 'bold'; + chainWrathReqSpan.className = CM.Disp.colorTextPre + chainWrathColor; + chainWrathReqSpan.textContent = Beautify(CM.Cache.ChainWrath); + chainWrathReqFrag.appendChild(chainWrathReqSpan); + if (chainWrathTime != '') { + var chainWrathReqSmall = document.createElement('small'); + chainWrathReqSmall.textContent = ' (' + chainWrathTime + ')'; + chainWrathReqFrag.appendChild(chainWrathReqSmall); + } + section.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Chain\" Cookies Required (Wrath)', chainWrathReqFrag, goldCookTooltip)); + + var chainColorFrenzy = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.ChainFrenzy) ? CM.Disp.colorRed : CM.Disp.colorGreen; + var chainTimeFrenzy = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.ChainFrenzy) ? CM.Disp.FormatTime((CM.Cache.ChainFrenzy - (Game.cookies + CM.Disp.GetWrinkConfigBank())) / CM.Disp.GetCPS()) : ''; + var chainReqFrenFrag = document.createDocumentFragment(); + var chainReqFrenSpan = document.createElement('span'); + chainReqFrenSpan.style.fontWeight = 'bold'; + chainReqFrenSpan.className = CM.Disp.colorTextPre + chainColorFrenzy; + chainReqFrenSpan.textContent = Beautify(CM.Cache.ChainFrenzy); + chainReqFrenFrag.appendChild(chainReqFrenSpan); + if (chainTimeFrenzy != '') { + var chainReqFrenSmall = document.createElement('small'); + chainReqFrenSmall.textContent = ' (' + chainTimeFrenzy + ')'; + chainReqFrenFrag.appendChild(chainReqFrenSmall); + } + section.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Chain\" Cookies Required (Frenzy)', chainReqFrenFrag, goldCookTooltip)); + + var chainWrathColorFrenzy = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.ChainFrenzyWrath) ? CM.Disp.colorRed : CM.Disp.colorGreen; + var chainWrathTimeFrenzy = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.ChainFrenzyWrath) ? CM.Disp.FormatTime((CM.Cache.ChainFrenzyWrath - (Game.cookies + CM.Disp.GetWrinkConfigBank())) / CM.Disp.GetCPS()) : ''; + var chainWrathReqFrenFrag = document.createDocumentFragment(); + var chainWrathReqFrenSpan = document.createElement('span'); + chainWrathReqFrenSpan.style.fontWeight = 'bold'; + chainWrathReqFrenSpan.className = CM.Disp.colorTextPre + chainWrathColorFrenzy; + chainWrathReqFrenSpan.textContent = Beautify(CM.Cache.ChainFrenzyWrath); + chainWrathReqFrenFrag.appendChild(chainWrathReqFrenSpan); + if (chainWrathTimeFrenzy != '') { + var chainWrathReqFrenSmall = document.createElement('small'); + chainWrathReqFrenSmall.textContent = ' (' + chainWrathTimeFrenzy + ')'; + chainWrathReqFrenFrag.appendChild(chainWrathReqFrenSmall); + } + section.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Chain\" Cookies Required (Frenzy) (Wrath)', chainWrathReqFrenFrag, goldCookTooltip)); + + section.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Chain\" Reward (MAX) (Golden / Wrath)', document.createTextNode(Beautify(CM.Cache.ChainReward) + ' / ' + Beautify(CM.Cache.ChainWrathReward)), goldCookTooltip)); + + section.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Chain\" Reward (MAX) (Frenzy) (Golden / Wrath)', document.createTextNode((Beautify(CM.Cache.ChainFrenzyReward) + ' / ' + Beautify(CM.Cache.ChainFrenzyWrathReward))), goldCookTooltip)); + + // TODO: Place MaxChainMoni function into CM.Cache.RemakeChain and create global variables to store it + var chainCurMax = Math.min(CM.Cache.NoGoldSwitchCookiesPS * CM.Cache.DragonsFortuneMultAdjustment * 60 * 60 * 6, (Game.cookies + CM.Disp.GetWrinkConfigBank()) * 0.5); + var chainCur = CM.Cache.MaxChainMoni(7, chainCurMax, CM.Cache.GoldenCookiesMult); + var chainCurWrath = CM.Cache.MaxChainMoni(6, chainCurMax, CM.Cache.WrathCookiesMult); + section.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Chain\" Reward (CUR) (Golden / Wrath)', document.createTextNode((Beautify(chainCur) + ' / ' + Beautify(chainCurWrath))), goldCookTooltip)); + return section; +} + +/** + * This function creates the "Conjure" section of the stats page + * @returns {object} section The object contating the Conjure section + */ +CM.Disp.CreateStatsConjureSection = function() { + var section = document.createElement('div'); + section.className = 'CMStatsConjureSection'; + + var conjureColor = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.Conjure) ? CM.Disp.colorRed : CM.Disp.colorGreen; + var conjureCur = Math.min((Game.cookies + CM.Disp.GetWrinkConfigBank()) * 0.15, CM.Cache.NoGoldSwitchCookiesPS * 60 * 30); + var conjureTime = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.Conjure) ? CM.Disp.FormatTime((CM.Cache.Conjure - (Game.cookies + CM.Disp.GetWrinkConfigBank())) / CM.Disp.GetCPS()) : ''; + + var conjureReqFrag = document.createDocumentFragment(); + var conjureReqSpan = document.createElement('span'); + conjureReqSpan.style.fontWeight = 'bold'; + conjureReqSpan.className = CM.Disp.colorTextPre + conjureColor; + conjureReqSpan.textContent = Beautify(CM.Cache.Conjure); + conjureReqFrag.appendChild(conjureReqSpan); + if (conjureTime != '') { + var conjureReqSmall = document.createElement('small'); + conjureReqSmall.textContent = ' (' + conjureTime + ')'; + conjureReqFrag.appendChild(conjureReqSmall); + } + section.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Conjure Baked Goods\" Cookies Required', conjureReqFrag, 'GoldCookTooltipPlaceholder')); + section.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Conjure Baked Goods\" Reward (MAX)', document.createTextNode(CM.Disp.Beautify(CM.Cache.ConjureReward)), 'GoldCookTooltipPlaceholder')); + section.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Conjure Baked Goods\" Reward (CUR)', document.createTextNode(CM.Disp.Beautify(conjureCur)), 'GoldCookTooltipPlaceholder')); + return section; +} + +/** + * This function creates the "Prestige" section of the stats page + * @returns {object} section The object contating the Prestige section + */ +CM.Disp.CreateStatsPrestigeSection = function() { + var section = document.createElement('div'); + section.className = 'CMStatsPrestigeSection'; + + var possiblePresMax = Math.floor(Game.HowMuchPrestige(CM.Cache.RealCookiesEarned + + Game.cookiesReset + CM.Cache.WrinkGodBank + + (Game.HasUnlocked('Chocolate egg') && !Game.Has('Chocolate egg') ? CM.Cache.lastChoEgg : 0))); + section.appendChild(CM.Disp.CreateStatsListing("withTooltip", 'Prestige Level (CUR / MAX)', document.createTextNode(Beautify(Game.prestige) + ' / ' + Beautify(possiblePresMax)), 'PrestMaxTooltipPlaceholder')); + + var neededCook = Game.HowManyCookiesReset(possiblePresMax + 1) - (CM.Cache.RealCookiesEarned + Game.cookiesReset + CM.Cache.WrinkGodBank + ((Game.HasUnlocked('Chocolate egg') && !Game.Has('Chocolate egg') ? CM.Cache.lastChoEgg : 0) ? CM.Cache.lastChoEgg : 0)); + var cookiesNextFrag = document.createDocumentFragment(); + cookiesNextFrag.appendChild(document.createTextNode(Beautify(neededCook))); + var cookiesNextSmall = document.createElement('small'); + cookiesNextSmall.textContent = ' (' + (CM.Disp.FormatTime(neededCook / CM.Cache.AvgCPSChoEgg, 1)) + ')'; + cookiesNextFrag.appendChild(cookiesNextSmall); + section.appendChild(CM.Disp.CreateStatsListing("withTooltip", 'Cookies To Next Level', cookiesNextFrag, 'NextPrestTooltipPlaceholder')); + + section.appendChild(CM.Disp.CreateStatsListing("withTooltip", 'Heavenly Chips (CUR / MAX)', document.createTextNode(Beautify(Game.heavenlyChips) + ' / ' + Beautify((possiblePresMax - Game.prestige) + Game.heavenlyChips)), 'HeavenChipMaxTooltipPlaceholder')); + + var resetBonus = CM.Sim.ResetBonus(possiblePresMax); + var resetFrag = document.createDocumentFragment(); + resetFrag.appendChild(document.createTextNode(Beautify(resetBonus))); + var increase = Math.round(resetBonus / Game.cookiesPs * 10000); + if (isFinite(increase) && increase != 0) { + var resetSmall = document.createElement('small'); + resetSmall.textContent = ' (' + (increase / 100) + '% of income)'; + resetFrag.appendChild(resetSmall); + } + section.appendChild(CM.Disp.CreateStatsListing("withTooltip", 'Reset Bonus Income', resetFrag, 'ResetTooltipPlaceholder')); + + var currentPrestige = Math.floor(Game.HowMuchPrestige(Game.cookiesReset)); + var willHave = Math.floor(Game.HowMuchPrestige(Game.cookiesReset + Game.cookiesEarned)); + var willGet = willHave - currentPrestige; + if (!Game.Has('Lucky digit')) { + var delta7 = 7 - (willHave % 10); + if (delta7 < 0) delta7 += 10; + var next7Reset = willGet + delta7; + var next7Total = willHave + delta7; + var frag7 = document.createDocumentFragment(); + frag7.appendChild(document.createTextNode(next7Total.toLocaleString() + " / " + next7Reset.toLocaleString() + " (+" + delta7 + ")")); + section.appendChild(CM.Disp.CreateStatsListing("basic", 'Next "Lucky Digit" (total / reset)', frag7)); + } + + if (!Game.Has('Lucky number')) { + var delta777 = 777 - (willHave % 1000); + if (delta777 < 0) delta777 += 1000; + var next777Reset = willGet + delta777; + var next777Total = willHave + delta777; + var frag777 = document.createDocumentFragment(); + frag777.appendChild(document.createTextNode(next777Total.toLocaleString() + " / " + next777Reset.toLocaleString() + " (+" + delta777 + ")")); + section.appendChild(CM.Disp.CreateStatsListing("basic", 'Next "Lucky Number" (total / reset)', frag777)); + } + + if (!Game.Has('Lucky payout')) { + var delta777777 = 777777 - (willHave % 1000000); + if (delta777777 < 0) delta777777 += 1000000; + var next777777Reset = willGet + delta777777; + var next777777Total = willHave + delta777777; + var frag777777 = document.createDocumentFragment(); + frag777777.appendChild(document.createTextNode(next777777Total.toLocaleString() + " / " + next777777Reset.toLocaleString() + " (+" + delta777777 + ")")); + section.appendChild(CM.Disp.CreateStatsListing("basic", 'Next "Lucky Payout" (total / reset)', frag777777)); + } + + return section; +} + +// TODO: Fix and annotate this function. +/** CM.Disp.AddMissingUpgrades = function() { if (CM.Cache.UpgradesOwned != Game.UpgradesOwned) { CM.Cache.CalcMissingUpgrades(); @@ -2559,7 +2587,7 @@ CM.Disp.AddMissingUpgrades = function() { } upgradesMenu.appendChild(CM.Cache.MissingCookiesString); } -} +} */ /******** * Section: Variables used in Disp functions From f9c4f68bb87cefdc5bdf58804e447bb162b90a72 Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Thu, 10 Dec 2020 22:13:26 +0100 Subject: [PATCH 042/106] Add config and replace-function for AuraInfo --- CookieMonster.js | 25 +++++++++++++++++++++++++ src/Data.js | 1 + src/Disp.js | 11 +++++++++++ src/Main.js | 13 +++++++++++++ 4 files changed, 50 insertions(+) diff --git a/CookieMonster.js b/CookieMonster.js index 88f9c03..143155e 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -874,6 +874,7 @@ CM.ConfigData.ToolWarnPos = {type: 'bool', group: 'Tooltip', label: ['Tooltip Wa CM.ConfigData.TooltipGrim = {type: 'bool', group: 'Tooltip', label: ['Grimoire Tooltip Information OFF', 'Grimoire Tooltip Information ON'], desc: 'Extra information in tooltip for grimoire', toggle: true}; CM.ConfigData.ToolWrink = {type: 'bool', group: 'Tooltip', label: ['Wrinkler Tooltip OFF', 'Wrinkler Tooltip ON'], desc: 'Shows the amount of cookies a wrinkler will give when popping it', toggle: true}; CM.ConfigData.TooltipLump = {type: 'bool', group: 'Tooltip', label: ['Sugar Lump Tooltip OFF', 'Sugar Lump Tooltip ON'], desc: 'Shows the current Sugar Lump type in Sugar lump tooltip.', toggle: true}; +CM.ConfigData.DragonAuraInfo = {type: 'bool', group: 'Tooltip', label: ['Extra Dragon Aura OFF', 'Extra Dragon Aura ON'], desc: 'Shows information about changes in CPS and costs in the dragon aura interface.', toggle: true}; // Statistics CM.ConfigData.Stats = {type: 'bool', group: 'Statistics', label: ['Statistics OFF', 'Statistics ON'], desc: 'Extra Cookie Monster statistics!', toggle: true}; @@ -2654,6 +2655,17 @@ CM.Disp.UpdateWrinklerTooltip = function() { } } +/******** + * Section: Functions related to the dragon aura interface */ + +CM.Disp.AddAuraInfo = function() { + if (CM.Config.DragonAuraInfo == 1) { + console.log("Yes!") + } else { + console.log("No!") + } +} + /******** * Section: General functions related to the Options/Stats pages @@ -3608,6 +3620,18 @@ CM.ReplaceNative = function() { Game.CalculateGains(); } + + CM.Backup.DescribeDragonAura = Game.DescribeDragonAura; + /** + * This functions adds the function CM.Disp.AddAuraInfo() to Game.DescribeDragonAura() + * This adds information about CPS differences and costs to the aura choosing interface + * @param {number} aura The number of the aura current selected by the mouse/user + */ + Game.DescribeDragonAura = function(aura) { + CM.Backup.DescribeDragonAura(aura); + CM.Disp.AddAuraInfo(); + } + CM.Backup.UpdateMenu = Game.UpdateMenu; Game.UpdateMenu = function() { if (typeof jscolor.picker === 'undefined' || typeof jscolor.picker.owner === 'undefined') { @@ -4081,6 +4105,7 @@ CM.ConfigDefault = { TooltipGrim:1, ToolWrink: 1, TooltipLump: 1, + DragonAuraInfo: 1, Stats: 1, MissingUpgrades: 0, UpStats: 1, diff --git a/src/Data.js b/src/Data.js index b005688..ec95b30 100644 --- a/src/Data.js +++ b/src/Data.js @@ -162,6 +162,7 @@ CM.ConfigData.ToolWarnPos = {type: 'bool', group: 'Tooltip', label: ['Tooltip Wa CM.ConfigData.TooltipGrim = {type: 'bool', group: 'Tooltip', label: ['Grimoire Tooltip Information OFF', 'Grimoire Tooltip Information ON'], desc: 'Extra information in tooltip for grimoire', toggle: true}; CM.ConfigData.ToolWrink = {type: 'bool', group: 'Tooltip', label: ['Wrinkler Tooltip OFF', 'Wrinkler Tooltip ON'], desc: 'Shows the amount of cookies a wrinkler will give when popping it', toggle: true}; CM.ConfigData.TooltipLump = {type: 'bool', group: 'Tooltip', label: ['Sugar Lump Tooltip OFF', 'Sugar Lump Tooltip ON'], desc: 'Shows the current Sugar Lump type in Sugar lump tooltip.', toggle: true}; +CM.ConfigData.DragonAuraInfo = {type: 'bool', group: 'Tooltip', label: ['Extra Dragon Aura OFF', 'Extra Dragon Aura ON'], desc: 'Shows information about changes in CPS and costs in the dragon aura interface.', toggle: true}; // Statistics CM.ConfigData.Stats = {type: 'bool', group: 'Statistics', label: ['Statistics OFF', 'Statistics ON'], desc: 'Extra Cookie Monster statistics!', toggle: true}; diff --git a/src/Disp.js b/src/Disp.js index df69041..065517c 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -1766,6 +1766,17 @@ CM.Disp.UpdateWrinklerTooltip = function() { } } +/******** + * Section: Functions related to the dragon aura interface */ + +CM.Disp.AddAuraInfo = function() { + if (CM.Config.DragonAuraInfo == 1) { + console.log("Yes!") + } else { + console.log("No!") + } +} + /******** * Section: General functions related to the Options/Stats pages diff --git a/src/Main.js b/src/Main.js index 23519fa..2067cd7 100644 --- a/src/Main.js +++ b/src/Main.js @@ -58,6 +58,18 @@ CM.ReplaceNative = function() { Game.CalculateGains(); } + + CM.Backup.DescribeDragonAura = Game.DescribeDragonAura; + /** + * This functions adds the function CM.Disp.AddAuraInfo() to Game.DescribeDragonAura() + * This adds information about CPS differences and costs to the aura choosing interface + * @param {number} aura The number of the aura current selected by the mouse/user + */ + Game.DescribeDragonAura = function(aura) { + CM.Backup.DescribeDragonAura(aura); + CM.Disp.AddAuraInfo(); + } + CM.Backup.UpdateMenu = Game.UpdateMenu; Game.UpdateMenu = function() { if (typeof jscolor.picker === 'undefined' || typeof jscolor.picker.owner === 'undefined') { @@ -531,6 +543,7 @@ CM.ConfigDefault = { TooltipGrim:1, ToolWrink: 1, TooltipLump: 1, + DragonAuraInfo: 1, Stats: 1, MissingUpgrades: 0, UpStats: 1, From 8ffc0a2664ea5ad399a1e77275af343a55ad0839 Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Thu, 10 Dec 2020 22:30:07 +0100 Subject: [PATCH 043/106] Added CM.Disp.AddAuraInfo() --- CookieMonster.js | 24 ++++++++++++++++++------ src/Disp.js | 20 ++++++++++++++++---- src/Main.js | 4 ++-- 3 files changed, 36 insertions(+), 12 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index 143155e..1dfc4bf 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -2657,12 +2657,24 @@ CM.Disp.UpdateWrinklerTooltip = function() { /******** * Section: Functions related to the dragon aura interface */ - +/** + * This functions adds the two extra lines about CPS and time to recover to the aura picker infoscreen + * This adds information about CPS differences and costs to the aura choosing interface + * @param {number} aura The number of the aura currently selected by the mouse/user + */ CM.Disp.AddAuraInfo = function() { if (CM.Config.DragonAuraInfo == 1) { - console.log("Yes!") - } else { - console.log("No!") + console.log("called") + var bonusCPS = "TESTCPS"; + var bonusCPSPercentage = "TESTCPS%"; + var timeToRecover = "TESTTIME"; + l('dragonAuraInfo').style.minHeight = "90px" + l('dragonAuraInfo').appendChild(document.createElement("div")).className = "line" + var div = document.createElement("div"); + div.style.minWidth = "200px"; + div.style.textAlign = "center"; + div.textContent = "Picking this aura will change CPS by " + bonusCPS + " (" + bonusCPSPercentage + "% of current cps). It will take " + timeToRecover + " to recover the cost."; + l('dragonAuraInfo').appendChild(div); } } @@ -3625,11 +3637,11 @@ CM.ReplaceNative = function() { /** * This functions adds the function CM.Disp.AddAuraInfo() to Game.DescribeDragonAura() * This adds information about CPS differences and costs to the aura choosing interface - * @param {number} aura The number of the aura current selected by the mouse/user + * @param {number} aura The number of the aura currently selected by the mouse/user */ Game.DescribeDragonAura = function(aura) { CM.Backup.DescribeDragonAura(aura); - CM.Disp.AddAuraInfo(); + CM.Disp.AddAuraInfo(aura); } CM.Backup.UpdateMenu = Game.UpdateMenu; diff --git a/src/Disp.js b/src/Disp.js index 065517c..946dd25 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -1768,12 +1768,24 @@ CM.Disp.UpdateWrinklerTooltip = function() { /******** * Section: Functions related to the dragon aura interface */ - +/** + * This functions adds the two extra lines about CPS and time to recover to the aura picker infoscreen + * This adds information about CPS differences and costs to the aura choosing interface + * @param {number} aura The number of the aura currently selected by the mouse/user + */ CM.Disp.AddAuraInfo = function() { if (CM.Config.DragonAuraInfo == 1) { - console.log("Yes!") - } else { - console.log("No!") + console.log("called") + var bonusCPS = "TESTCPS"; + var bonusCPSPercentage = "TESTCPS%"; + var timeToRecover = "TESTTIME"; + l('dragonAuraInfo').style.minHeight = "90px" + l('dragonAuraInfo').appendChild(document.createElement("div")).className = "line" + var div = document.createElement("div"); + div.style.minWidth = "200px"; + div.style.textAlign = "center"; + div.textContent = "Picking this aura will change CPS by " + bonusCPS + " (" + bonusCPSPercentage + "% of current cps). It will take " + timeToRecover + " to recover the cost."; + l('dragonAuraInfo').appendChild(div); } } diff --git a/src/Main.js b/src/Main.js index 2067cd7..efc9e5c 100644 --- a/src/Main.js +++ b/src/Main.js @@ -63,11 +63,11 @@ CM.ReplaceNative = function() { /** * This functions adds the function CM.Disp.AddAuraInfo() to Game.DescribeDragonAura() * This adds information about CPS differences and costs to the aura choosing interface - * @param {number} aura The number of the aura current selected by the mouse/user + * @param {number} aura The number of the aura currently selected by the mouse/user */ Game.DescribeDragonAura = function(aura) { CM.Backup.DescribeDragonAura(aura); - CM.Disp.AddAuraInfo(); + CM.Disp.AddAuraInfo(aura); } CM.Backup.UpdateMenu = Game.UpdateMenu; From f72e95301c10a428ce94d62f748462542ebee5d3 Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Thu, 10 Dec 2020 22:31:26 +0100 Subject: [PATCH 044/106] Fixed some annotations in Sim.js --- CookieMonster.js | 9 ++++++--- src/Sim.js | 9 ++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index 1dfc4bf..7c69fee 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -4280,7 +4280,8 @@ CM.Sim.getCPSBuffMult = function() { return mult; } -/* Constructs an object with the static properties of a building, +/** + * Constructs an object with the static properties of a building, * but with a 'cps' method changed to use 'CM.Sim.Has' instead of 'Game.Has' * (and similar to 'hasAura', 'Objects', 'GetTieredCpsMult' and 'auraMult'). * @@ -4304,7 +4305,8 @@ CM.Sim.InitialBuildingData = function(buildingName) { return you; } -/* Similar to the previous function, but for upgrades. +/** + * Similar to the previous function, but for upgrades. * Note: currently no static data is used by Cookie Monster, * so this function just returns an empty object. */ @@ -4316,7 +4318,8 @@ CM.Sim.InitUpgrade = function(upgradeName) { return you; } -/* Similar to the previous function, but for achievements. +/** + * Similar to the previous function, but for achievements. * Note: currently no static data is used by Cookie Monster, * so this function just returns an empty object. */ diff --git a/src/Sim.js b/src/Sim.js index 8eb7f83..95fe7d5 100644 --- a/src/Sim.js +++ b/src/Sim.js @@ -142,7 +142,8 @@ CM.Sim.getCPSBuffMult = function() { return mult; } -/* Constructs an object with the static properties of a building, +/** + * Constructs an object with the static properties of a building, * but with a 'cps' method changed to use 'CM.Sim.Has' instead of 'Game.Has' * (and similar to 'hasAura', 'Objects', 'GetTieredCpsMult' and 'auraMult'). * @@ -166,7 +167,8 @@ CM.Sim.InitialBuildingData = function(buildingName) { return you; } -/* Similar to the previous function, but for upgrades. +/** + * Similar to the previous function, but for upgrades. * Note: currently no static data is used by Cookie Monster, * so this function just returns an empty object. */ @@ -178,7 +180,8 @@ CM.Sim.InitUpgrade = function(upgradeName) { return you; } -/* Similar to the previous function, but for achievements. +/** + * Similar to the previous function, but for achievements. * Note: currently no static data is used by Cookie Monster, * so this function just returns an empty object. */ From f13c9fb02d2e9565fd766e4388017501feffad6d Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Sun, 13 Dec 2020 21:50:04 +0100 Subject: [PATCH 045/106] Added Aura caching and changing --- CookieMonster.js | 87 ++++++++++++++++++++++++++++++++++++++++++------ src/Cache.js | 16 +++++++++ src/Disp.js | 24 ++++++++----- src/Sim.js | 46 +++++++++++++++++++++++-- 4 files changed, 152 insertions(+), 21 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index 7c69fee..7785723 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -29,6 +29,16 @@ if (typeof CM == "undefined") { * Cache * *********/ +/** + * This functions caches the currently selected Dragon Auras + * It is called by CM.Sim.CopyData() and CM.Sim.InitData() + * Uncapitalized dragon follows Game-naming + */ +CM.Cache.CacheDragonAuras = function() { + CM.Cache.dragonAura = Game.dragonAura; + CM.Cache.dragonAura2 = Game.dragonAura2; +} + /******** * Section: UNSORTED */ @@ -557,7 +567,12 @@ CM.Cache.MissingCookiesString = null; CM.Cache.seasonPopShimmer; CM.Cache.goldenShimmersByID = {}; CM.Cache.spawnedGoldenShimmer = 0; -/********** + +/** + * This variables are used by CM.Cache.CacheDragonAuras(), naming follows naming in Game + */ +CM.Cache.dragonAura = 0; +CM.Cache.dragonAura2 = 0;/********** * Config * **********/ @@ -2657,24 +2672,32 @@ CM.Disp.UpdateWrinklerTooltip = function() { /******** * Section: Functions related to the dragon aura interface */ + /** * This functions adds the two extra lines about CPS and time to recover to the aura picker infoscreen - * This adds information about CPS differences and costs to the aura choosing interface + * It is called by Game.DescribeDragonAura() after CM.ReplaceNative() * @param {number} aura The number of the aura currently selected by the mouse/user */ -CM.Disp.AddAuraInfo = function() { +CM.Disp.AddAuraInfo = function(aura) { if (CM.Config.DragonAuraInfo == 1) { - console.log("called") - var bonusCPS = "TESTCPS"; - var bonusCPSPercentage = "TESTCPS%"; - var timeToRecover = "TESTTIME"; - l('dragonAuraInfo').style.minHeight = "90px" + var [bonusCPS, priceOfChange] = CM.Sim.CalculateChangeAura(aura); + var timeToRecover = CM.Disp.FormatTime(priceOfChange / (bonusCPS + Game.cookiesPs)); + var bonusCPSPercentage = CM.Disp.Beautify(bonusCPS / Game.cookiesPs); + bonusCPS = CM.Disp.Beautify(bonusCPS); + + l('dragonAuraInfo').style.minHeight = "60px" + l('dragonAuraInfo').style.margin = "8px" l('dragonAuraInfo').appendChild(document.createElement("div")).className = "line" var div = document.createElement("div"); div.style.minWidth = "200px"; div.style.textAlign = "center"; - div.textContent = "Picking this aura will change CPS by " + bonusCPS + " (" + bonusCPSPercentage + "% of current cps). It will take " + timeToRecover + " to recover the cost."; + div.textContent = "Picking this aura will change CPS by " + bonusCPS + " (" + bonusCPSPercentage + "% of current CPS)."; l('dragonAuraInfo').appendChild(div); + var div2 = document.createElement("div"); + div2.style.minWidth = "200px"; + div2.style.textAlign = "center"; + div2.textContent = "It will take " + timeToRecover + " to recover the cost."; + l('dragonAuraInfo').appendChild(div2); } } @@ -4345,6 +4368,9 @@ CM.Sim.InitData = function() { for (var i in Game.Achievements) { CM.Sim.Achievements[i] = CM.Sim.InitAchievement(i); } + + // Auras + CM.Cache.CacheDragonAuras(); } CM.Sim.CopyData = function() { @@ -4354,8 +4380,6 @@ CM.Sim.CopyData = function() { CM.Sim.AchievementsOwned = Game.AchievementsOwned; CM.Sim.heavenlyPower = Game.heavenlyPower; // Unneeded? > Might be modded CM.Sim.prestige = Game.prestige; - CM.Sim.dragonAura = Game.dragonAura; - CM.Sim.dragonAura2 = Game.dragonAura2; // Buildings for (var i in Game.Objects) { @@ -4368,6 +4392,8 @@ CM.Sim.CopyData = function() { you.amount = me.amount; you.level = me.level; you.totalCookies = me.totalCookies; + you.basePrice = me.basePrice; + you.free = me.free; if (me.minigameLoaded) you.minigameLoaded = me.minigameLoaded; you.minigame = me.minigame; } @@ -4390,6 +4416,11 @@ CM.Sim.CopyData = function() { } you.won = me.won; } + + // Auras + CM.Cache.CacheDragonAuras(); + CM.Sim.dragonAura = CM.Cache.dragonAura; + CM.Sim.dragonAura2 = CM.Cache.dragonAura2; }; CM.Sim.CalculateGains = function() { @@ -4758,6 +4789,40 @@ CM.Sim.BuyUpgrades = function() { } } +CM.Sim.CalculateChangeAura = function(aura) { + CM.Sim.CopyData(); + + // Check if aura being changed is first or second aura + var auraToBeChanged = l('promptContent').children[0].innerHTML.includes("secondary") + if (auraToBeChanged) CM.Sim.dragonAura2 = aura; + else CM.Sim.dragonAura = aura; + + // Sell highest building but only if aura is different + if (CM.Sim.dragonAura != CM.Cache.dragonAura || CM.Sim.dragonAura2 != CM.Cache.dragonAura2) { + for (var i = Game.ObjectsById.length; i > -1, --i;) { + if (Game.ObjectsById[i].amount > 0) { + var highestBuilding = CM.Sim.Objects[Game.ObjectsById[i].name].name; + CM.Sim.Objects[highestBuilding].amount -=1; + CM.Sim.buildingsOwned -= 1; + break + } + } + // This calculates price of highest building + var price = CM.Sim.Objects[highestBuilding].basePrice * Math.pow(Game.priceIncrease, Math.max(0, CM.Sim.Objects[highestBuilding].amount - 1 -CM.Sim.Objects[highestBuilding].free)); + price = Game.modifyBuildingPrice(CM.Sim.Objects[highestBuilding], price); + price = Math.ceil(price); + } else var price = 0; + + var lastAchievementsOwned = CM.Sim.AchievementsOwned; + CM.Sim.CalculateGains(); + + CM.Sim.CheckOtherAchiev(); + if (lastAchievementsOwned != CM.Sim.AchievementsOwned) { + CM.Sim.CalculateGains(); + } + return [CM.Sim.cookiesPs - Game.cookiesPs, price] +} + CM.Sim.NoGoldSwitchCookiesPS = function() { if (Game.Has('Golden switch [off]')) { CM.Sim.CopyData(); diff --git a/src/Cache.js b/src/Cache.js index b3a08ed..84eb53a 100644 --- a/src/Cache.js +++ b/src/Cache.js @@ -2,6 +2,16 @@ * Cache * *********/ +/** + * This functions caches the currently selected Dragon Auras + * It is called by CM.Sim.CopyData() and CM.Sim.InitData() + * Uncapitalized dragon follows Game-naming + */ +CM.Cache.CacheDragonAuras = function() { + CM.Cache.dragonAura = Game.dragonAura; + CM.Cache.dragonAura2 = Game.dragonAura2; +} + /******** * Section: UNSORTED */ @@ -530,3 +540,9 @@ CM.Cache.MissingCookiesString = null; CM.Cache.seasonPopShimmer; CM.Cache.goldenShimmersByID = {}; CM.Cache.spawnedGoldenShimmer = 0; + +/** + * This variables are used by CM.Cache.CacheDragonAuras(), naming follows naming in Game + */ +CM.Cache.dragonAura = 0; +CM.Cache.dragonAura2 = 0; \ No newline at end of file diff --git a/src/Disp.js b/src/Disp.js index 946dd25..06f2399 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -1768,24 +1768,32 @@ CM.Disp.UpdateWrinklerTooltip = function() { /******** * Section: Functions related to the dragon aura interface */ + /** * This functions adds the two extra lines about CPS and time to recover to the aura picker infoscreen - * This adds information about CPS differences and costs to the aura choosing interface + * It is called by Game.DescribeDragonAura() after CM.ReplaceNative() * @param {number} aura The number of the aura currently selected by the mouse/user */ -CM.Disp.AddAuraInfo = function() { +CM.Disp.AddAuraInfo = function(aura) { if (CM.Config.DragonAuraInfo == 1) { - console.log("called") - var bonusCPS = "TESTCPS"; - var bonusCPSPercentage = "TESTCPS%"; - var timeToRecover = "TESTTIME"; - l('dragonAuraInfo').style.minHeight = "90px" + var [bonusCPS, priceOfChange] = CM.Sim.CalculateChangeAura(aura); + var timeToRecover = CM.Disp.FormatTime(priceOfChange / (bonusCPS + Game.cookiesPs)); + var bonusCPSPercentage = CM.Disp.Beautify(bonusCPS / Game.cookiesPs); + bonusCPS = CM.Disp.Beautify(bonusCPS); + + l('dragonAuraInfo').style.minHeight = "60px" + l('dragonAuraInfo').style.margin = "8px" l('dragonAuraInfo').appendChild(document.createElement("div")).className = "line" var div = document.createElement("div"); div.style.minWidth = "200px"; div.style.textAlign = "center"; - div.textContent = "Picking this aura will change CPS by " + bonusCPS + " (" + bonusCPSPercentage + "% of current cps). It will take " + timeToRecover + " to recover the cost."; + div.textContent = "Picking this aura will change CPS by " + bonusCPS + " (" + bonusCPSPercentage + "% of current CPS)."; l('dragonAuraInfo').appendChild(div); + var div2 = document.createElement("div"); + div2.style.minWidth = "200px"; + div2.style.textAlign = "center"; + div2.textContent = "It will take " + timeToRecover + " to recover the cost."; + l('dragonAuraInfo').appendChild(div2); } } diff --git a/src/Sim.js b/src/Sim.js index 95fe7d5..f32dbcc 100644 --- a/src/Sim.js +++ b/src/Sim.js @@ -207,6 +207,9 @@ CM.Sim.InitData = function() { for (var i in Game.Achievements) { CM.Sim.Achievements[i] = CM.Sim.InitAchievement(i); } + + // Auras + CM.Cache.CacheDragonAuras(); } CM.Sim.CopyData = function() { @@ -216,8 +219,6 @@ CM.Sim.CopyData = function() { CM.Sim.AchievementsOwned = Game.AchievementsOwned; CM.Sim.heavenlyPower = Game.heavenlyPower; // Unneeded? > Might be modded CM.Sim.prestige = Game.prestige; - CM.Sim.dragonAura = Game.dragonAura; - CM.Sim.dragonAura2 = Game.dragonAura2; // Buildings for (var i in Game.Objects) { @@ -230,6 +231,8 @@ CM.Sim.CopyData = function() { you.amount = me.amount; you.level = me.level; you.totalCookies = me.totalCookies; + you.basePrice = me.basePrice; + you.free = me.free; if (me.minigameLoaded) you.minigameLoaded = me.minigameLoaded; you.minigame = me.minigame; } @@ -252,6 +255,11 @@ CM.Sim.CopyData = function() { } you.won = me.won; } + + // Auras + CM.Cache.CacheDragonAuras(); + CM.Sim.dragonAura = CM.Cache.dragonAura; + CM.Sim.dragonAura2 = CM.Cache.dragonAura2; }; CM.Sim.CalculateGains = function() { @@ -620,6 +628,40 @@ CM.Sim.BuyUpgrades = function() { } } +CM.Sim.CalculateChangeAura = function(aura) { + CM.Sim.CopyData(); + + // Check if aura being changed is first or second aura + var auraToBeChanged = l('promptContent').children[0].innerHTML.includes("secondary") + if (auraToBeChanged) CM.Sim.dragonAura2 = aura; + else CM.Sim.dragonAura = aura; + + // Sell highest building but only if aura is different + if (CM.Sim.dragonAura != CM.Cache.dragonAura || CM.Sim.dragonAura2 != CM.Cache.dragonAura2) { + for (var i = Game.ObjectsById.length; i > -1, --i;) { + if (Game.ObjectsById[i].amount > 0) { + var highestBuilding = CM.Sim.Objects[Game.ObjectsById[i].name].name; + CM.Sim.Objects[highestBuilding].amount -=1; + CM.Sim.buildingsOwned -= 1; + break + } + } + // This calculates price of highest building + var price = CM.Sim.Objects[highestBuilding].basePrice * Math.pow(Game.priceIncrease, Math.max(0, CM.Sim.Objects[highestBuilding].amount - 1 -CM.Sim.Objects[highestBuilding].free)); + price = Game.modifyBuildingPrice(CM.Sim.Objects[highestBuilding], price); + price = Math.ceil(price); + } else var price = 0; + + var lastAchievementsOwned = CM.Sim.AchievementsOwned; + CM.Sim.CalculateGains(); + + CM.Sim.CheckOtherAchiev(); + if (lastAchievementsOwned != CM.Sim.AchievementsOwned) { + CM.Sim.CalculateGains(); + } + return [CM.Sim.cookiesPs - Game.cookiesPs, price] +} + CM.Sim.NoGoldSwitchCookiesPS = function() { if (Game.Has('Golden switch [off]')) { CM.Sim.CopyData(); From 15b859e8b9e1a0b737a2e0051233d124efe003f7 Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Sun, 13 Dec 2020 21:50:39 +0100 Subject: [PATCH 046/106] Changed display of DragonAuraInfo in options --- CookieMonster.js | 2 +- src/Data.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index 7785723..280ac51 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -889,7 +889,7 @@ CM.ConfigData.ToolWarnPos = {type: 'bool', group: 'Tooltip', label: ['Tooltip Wa CM.ConfigData.TooltipGrim = {type: 'bool', group: 'Tooltip', label: ['Grimoire Tooltip Information OFF', 'Grimoire Tooltip Information ON'], desc: 'Extra information in tooltip for grimoire', toggle: true}; CM.ConfigData.ToolWrink = {type: 'bool', group: 'Tooltip', label: ['Wrinkler Tooltip OFF', 'Wrinkler Tooltip ON'], desc: 'Shows the amount of cookies a wrinkler will give when popping it', toggle: true}; CM.ConfigData.TooltipLump = {type: 'bool', group: 'Tooltip', label: ['Sugar Lump Tooltip OFF', 'Sugar Lump Tooltip ON'], desc: 'Shows the current Sugar Lump type in Sugar lump tooltip.', toggle: true}; -CM.ConfigData.DragonAuraInfo = {type: 'bool', group: 'Tooltip', label: ['Extra Dragon Aura OFF', 'Extra Dragon Aura ON'], desc: 'Shows information about changes in CPS and costs in the dragon aura interface.', toggle: true}; +CM.ConfigData.DragonAuraInfo = {type: 'bool', group: 'Tooltip', label: ['Extra Dragon Aura Info OFF', 'Extra Dragon Aura Info ON'], desc: 'Shows information about changes in CPS and costs in the dragon aura interface.', toggle: true}; // Statistics CM.ConfigData.Stats = {type: 'bool', group: 'Statistics', label: ['Statistics OFF', 'Statistics ON'], desc: 'Extra Cookie Monster statistics!', toggle: true}; diff --git a/src/Data.js b/src/Data.js index ec95b30..21cba91 100644 --- a/src/Data.js +++ b/src/Data.js @@ -162,7 +162,7 @@ CM.ConfigData.ToolWarnPos = {type: 'bool', group: 'Tooltip', label: ['Tooltip Wa CM.ConfigData.TooltipGrim = {type: 'bool', group: 'Tooltip', label: ['Grimoire Tooltip Information OFF', 'Grimoire Tooltip Information ON'], desc: 'Extra information in tooltip for grimoire', toggle: true}; CM.ConfigData.ToolWrink = {type: 'bool', group: 'Tooltip', label: ['Wrinkler Tooltip OFF', 'Wrinkler Tooltip ON'], desc: 'Shows the amount of cookies a wrinkler will give when popping it', toggle: true}; CM.ConfigData.TooltipLump = {type: 'bool', group: 'Tooltip', label: ['Sugar Lump Tooltip OFF', 'Sugar Lump Tooltip ON'], desc: 'Shows the current Sugar Lump type in Sugar lump tooltip.', toggle: true}; -CM.ConfigData.DragonAuraInfo = {type: 'bool', group: 'Tooltip', label: ['Extra Dragon Aura OFF', 'Extra Dragon Aura ON'], desc: 'Shows information about changes in CPS and costs in the dragon aura interface.', toggle: true}; +CM.ConfigData.DragonAuraInfo = {type: 'bool', group: 'Tooltip', label: ['Extra Dragon Aura Info OFF', 'Extra Dragon Aura Info ON'], desc: 'Shows information about changes in CPS and costs in the dragon aura interface.', toggle: true}; // Statistics CM.ConfigData.Stats = {type: 'bool', group: 'Statistics', label: ['Statistics OFF', 'Statistics ON'], desc: 'Extra Cookie Monster statistics!', toggle: true}; From 6a6a27680f1fd220ca6599b71f083a930d64578f Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Sun, 13 Dec 2020 21:54:29 +0100 Subject: [PATCH 047/106] Annotated CM.Sim.CalculateChangeAura --- CookieMonster.js | 6 ++++++ src/Sim.js | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/CookieMonster.js b/CookieMonster.js index 280ac51..119ad03 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -4789,6 +4789,12 @@ CM.Sim.BuyUpgrades = function() { } } +/** + * This functions calculates the cps and cost of changing a Dragon Aura + * It is called by CM.Disp.AddAuraInfo() + * @param {number} aura The number of the aura currently selected by the mouse/user + * @returns {[number, number]} [CM.Sim.cookiesPs - Game.cookiesPs, price] The bonus cps and the price of the change + */ CM.Sim.CalculateChangeAura = function(aura) { CM.Sim.CopyData(); diff --git a/src/Sim.js b/src/Sim.js index f32dbcc..fe9bc60 100644 --- a/src/Sim.js +++ b/src/Sim.js @@ -628,6 +628,12 @@ CM.Sim.BuyUpgrades = function() { } } +/** + * This functions calculates the cps and cost of changing a Dragon Aura + * It is called by CM.Disp.AddAuraInfo() + * @param {number} aura The number of the aura currently selected by the mouse/user + * @returns {[number, number]} [CM.Sim.cookiesPs - Game.cookiesPs, price] The bonus cps and the price of the change + */ CM.Sim.CalculateChangeAura = function(aura) { CM.Sim.CopyData(); From a867d3d896a1bfba1d1fb9d932f184936535d51c Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Sun, 13 Dec 2020 22:10:06 +0100 Subject: [PATCH 048/106] Incorporated Game volume settings --- CookieMonster.js | 3 ++- src/Disp.js | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index 119ad03..d857628 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -1884,7 +1884,8 @@ CM.Disp.Flash = function(mode, config) { CM.Disp.PlaySound = function(url, sndConfig, volConfig) { if (CM.Config[sndConfig] == 1) { var sound = new realAudio(url); - sound.volume = CM.Config[volConfig] / 100; + // * 2 as the standard Game volume is 50%, which is quite low + sound.volume = (CM.Config[volConfig] / 100) * Game.volume * 2; sound.play(); } } diff --git a/src/Disp.js b/src/Disp.js index 06f2399..39d7275 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -980,7 +980,8 @@ CM.Disp.Flash = function(mode, config) { CM.Disp.PlaySound = function(url, sndConfig, volConfig) { if (CM.Config[sndConfig] == 1) { var sound = new realAudio(url); - sound.volume = CM.Config[volConfig] / 100; + // * 2 as the standard Game volume is 50%, which is quite low + sound.volume = (CM.Config[volConfig] / 100) * Game.volume * 2; sound.play(); } } From b80d2b63e82dee5a4f15c789a66f4e59158c9e17 Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Sun, 13 Dec 2020 22:12:53 +0100 Subject: [PATCH 049/106] Fixed bug with Sound of notifications --- CookieMonster.js | 3 +-- src/Disp.js | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index d857628..7536892 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -1884,8 +1884,7 @@ CM.Disp.Flash = function(mode, config) { CM.Disp.PlaySound = function(url, sndConfig, volConfig) { if (CM.Config[sndConfig] == 1) { var sound = new realAudio(url); - // * 2 as the standard Game volume is 50%, which is quite low - sound.volume = (CM.Config[volConfig] / 100) * Game.volume * 2; + sound.volume = (CM.Config[volConfig] / 100) * (Game.volume / 100); sound.play(); } } diff --git a/src/Disp.js b/src/Disp.js index 39d7275..5a01efa 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -980,8 +980,7 @@ CM.Disp.Flash = function(mode, config) { CM.Disp.PlaySound = function(url, sndConfig, volConfig) { if (CM.Config[sndConfig] == 1) { var sound = new realAudio(url); - // * 2 as the standard Game volume is 50%, which is quite low - sound.volume = (CM.Config[volConfig] / 100) * Game.volume * 2; + sound.volume = (CM.Config[volConfig] / 100) * (Game.volume / 100); sound.play(); } } From 08b30e9c620b33ee50d43d80ea09c6f486fe0b47 Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Tue, 15 Dec 2020 15:17:49 +0100 Subject: [PATCH 050/106] Changed Volume-options into sliders --- CookieMonster.js | 73 +++++++++++++++++++++++++++++++----------------- src/Config.js | 13 +++++++++ src/Data.js | 14 +++++----- src/Disp.js | 46 +++++++++++++++++------------- 4 files changed, 94 insertions(+), 52 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index 7536892..964fcb1 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -678,6 +678,19 @@ CM.ToggleConfigDown = function(config) { CM.SaveConfig(CM.Config); } +/** + * This function sets the value of the specified volume-option and updates the display in the options menu + * It is called by CM.Disp.CreatePrefOption() + * @param {string} config The name of the option + */ +CM.ToggleConfigVolume = function(config) { + if (l("slider" + config) != null) { + l("slider" + config + "right").innerHTML = l("slider" + config).value + "%"; + CM.Config[config] = Math.round(l("slider" + config).value); + } + CM.SaveConfig(CM.Config); +} + CM.ToggleStatsConfig = function(config) { if (CM.Config.StatsPref[config] == 0) { CM.Config.StatsPref[config]++; @@ -824,7 +837,7 @@ CM.ConfigData.ToolWarnBon = {type: 'bool', group: 'Calculation', label: ['Calcul CM.ConfigData.GCNotification = {type: 'bool', group: 'Notification', label: ['Golden Cookie Notification OFF', 'Golden Cookie Notification ON'], desc: 'Create a notification when Golden Cookie spawns', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Config.GCNotification);}}; CM.ConfigData.GCFlash = {type: 'bool', group: 'Notification', label: ['Golden Cookie Flash OFF', 'Golden Cookie Flash ON'], desc: 'Flash screen on Golden Cookie', toggle: true}; CM.ConfigData.GCSound = {type: 'bool', group: 'Notification', label: ['Golden Cookie Sound OFF', 'Golden Cookie Sound ON'], desc: 'Play a sound on Golden Cookie', toggle: true}; -CM.ConfigData.GCVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of the Golden Cookie sound'}; +CM.ConfigData.GCVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of Golden Cookie'}; for (var i = 0; i < 101; i++) { CM.ConfigData.GCVolume.label[i] = i + '%'; } @@ -834,7 +847,7 @@ CM.ConfigData.Favicon = {type: 'bool', group: 'Notification', label: ['Favicon O CM.ConfigData.FortuneNotification = {type: 'bool', group: 'Notification', label: ['Fortune Cookie Notification OFF', 'Fortune Cookie Notification ON'], desc: 'Create a notification when Fortune Cookie is on the Ticker', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Config.FortuneNotification);}}; CM.ConfigData.FortuneFlash = {type: 'bool', group: 'Notification', label: ['Fortune Cookie Flash OFF', 'Fortune Cookie Flash ON'], desc: 'Flash screen on Fortune Cookie', toggle: true}; CM.ConfigData.FortuneSound = {type: 'bool', group: 'Notification', label: ['Fortune Cookie Sound OFF', 'Fortune Cookie Sound ON'], desc: 'Play a sound on Fortune Cookie', toggle: true}; -CM.ConfigData.FortuneVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of the Fortune Cookie sound'}; +CM.ConfigData.FortuneVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of Fortune Cookie'}; for (var i = 0; i < 101; i++) { CM.ConfigData.FortuneVolume.label[i] = i + '%'; } @@ -842,14 +855,14 @@ CM.ConfigData.FortuneSoundURL = {type: 'url', group: 'Notification', label: 'For CM.ConfigData.SeaNotification = {type: 'bool', group: 'Notification', label: ['Season Special Notification OFF', 'Season Special Notification ON'], desc: 'Create a notification on Season Popup', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Config.SeaNotification);}}; CM.ConfigData.SeaFlash = {type: 'bool', group: 'Notification', label: ['Season Special Flash OFF', 'Season Special Flash ON'], desc: 'Flash screen on Season Popup', toggle: true}; CM.ConfigData.SeaSound = {type: 'bool', group: 'Notification', label: ['Season Special Sound OFF', 'Season Special Sound ON'], desc: 'Play a sound on Season Popup', toggle: true}; -CM.ConfigData.SeaVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of the Season Special sound'}; +CM.ConfigData.SeaVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of Season Special'}; for (var i = 0; i < 101; i++) { CM.ConfigData.SeaVolume.label[i] = i + '%'; } CM.ConfigData.SeaSoundURL = {type: 'url', group: 'Notification', label: 'Season Special Sound URL:', desc: 'URL of the sound to be played when a Season Special spawns'}; CM.ConfigData.GardFlash = {type: 'bool', group: 'Notification', label: ['Garden Tick Flash OFF', 'Garden Tick Flash ON'], desc: 'Flash screen on Garden Tick', toggle: true}; CM.ConfigData.GardSound = {type: 'bool', group: 'Notification', label: ['Garden Tick Sound OFF', 'Garden Tick Sound ON'], desc: 'Play a sound on Garden Tick', toggle: true}; -CM.ConfigData.GardVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of the Garden Tick sound'}; +CM.ConfigData.GardVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of Garden Tick'}; for (var i = 0; i < 101; i++) { CM.ConfigData.GardVolume.label[i] = i + '%'; } @@ -857,7 +870,7 @@ CM.ConfigData.GardSoundURL = {type: 'url', group: 'Notification', label: 'Garden CM.ConfigData.MagicNotification = {type: 'bool', group: 'Notification', label: ['Magic Max Notification OFF', 'Magic Max Notification ON'], desc: 'Create a notification when magic reaches maximum', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Config.MagicNotification);}}; CM.ConfigData.MagicFlash = {type: 'bool', group: 'Notification', label: ['Magic Max Flash OFF', 'Magic Max Flash ON'], desc: 'Flash screen when magic reaches maximum', toggle: true}; CM.ConfigData.MagicSound = {type: 'bool', group: 'Notification', label: ['Magic Max Sound OFF', 'Magic Max Sound ON'], desc: 'Play a sound when magic reaches maximum', toggle: true}; -CM.ConfigData.MagicVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of the Max Magic sound'}; +CM.ConfigData.MagicVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of Max Magic'}; for (var i = 0; i < 101; i++) { CM.ConfigData.MagicVolume.label[i] = i + '%'; } @@ -865,7 +878,7 @@ CM.ConfigData.MagicSoundURL = {type: 'url', group: 'Notification', label: 'Magic CM.ConfigData.WrinklerNotification = {type: 'bool', group: 'Notification', label: ['Wrinkler Notification OFF', 'Wrinkler Notification ON'], desc: 'Create a notification when a Wrinkler appears', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Config.WrinklerNotification);}}; CM.ConfigData.WrinklerFlash = {type: 'bool', group: 'Notification', label: ['Wrinkler Flash OFF', 'Wrinkler Flash ON'], desc: 'Flash screen when a Wrinkler appears', toggle: true}; CM.ConfigData.WrinklerSound = {type: 'bool', group: 'Notification', label: ['Wrinkler Sound OFF', 'Wrinkler Sound ON'], desc: 'Play a sound when a Wrinkler appears', toggle: true}; -CM.ConfigData.WrinklerVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of the Wrinkler sound'}; +CM.ConfigData.WrinklerVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of Wrinkler'}; for (var i = 0; i < 101; i++) { CM.ConfigData.WrinklerVolume.label[i] = i + '%'; } @@ -873,7 +886,7 @@ CM.ConfigData.WrinklerSoundURL = {type: 'url', group: 'Notification', label: 'Wr CM.ConfigData.WrinklerMaxNotification = {type: 'bool', group: 'Notification', label: ['Wrinkler Max Notification OFF', 'Wrinkler Max Notification ON'], desc: 'Create a notification when the maximum amount of Wrinklers has appeared', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Config.WrinklerMaxNotification);}}; CM.ConfigData.WrinklerMaxFlash = {type: 'bool', group: 'Notification', label: ['Wrinkler Max Flash OFF', 'Wrinkler Max Flash ON'], desc: 'Flash screen when the maximum amount of Wrinklers has appeared', toggle: true}; CM.ConfigData.WrinklerMaxSound = {type: 'bool', group: 'Notification', label: ['Wrinkler Max Sound OFF', 'Wrinkler Max Sound ON'], desc: 'Play a sound when the maximum amount of Wrinklers has appeared', toggle: true}; -CM.ConfigData.WrinklerMaxVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of the Wrinkler Max sound'}; +CM.ConfigData.WrinklerMaxVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of Wrinkler Max'}; for (var i = 0; i < 101; i++) { CM.ConfigData.WrinklerMaxVolume.label[i] = i + '%'; } @@ -2827,27 +2840,35 @@ CM.Disp.CreatePrefOption = function(config) { return div; } else if (CM.ConfigData[config].type == "vol") { + var div = document.createElement('div'); + div.className = 'listing'; var volume = document.createElement('div'); - volume.className = 'listing'; - var minus = document.createElement('a'); - minus.className = 'option'; - minus.onclick = function() {CM.ToggleConfigDown(config);}; - minus.textContent = '-'; - volume.appendChild(minus); - var volText = document.createElement('span'); - volText.id = CM.ConfigPrefix + config; - volText.textContent = CM.ConfigData[config].label[CM.Config[config]]; - volume.appendChild(volText); - var plus = document.createElement('a'); - plus.className = 'option'; - plus.onclick = function() {CM.ToggleConfigUp(config);}; - plus.textContent = '+'; - volume.appendChild(plus); - var volLabel = document.createElement('label'); - volLabel.textContent = CM.ConfigData[config].desc; - volume.appendChild(volLabel); - return volume; + volume.className = 'sliderBox'; + var title = document.createElement('div'); + title.style.float = "left"; + title.innerHTML = CM.ConfigData[config].desc; + volume.appendChild(title); + var percent = title = document.createElement('div'); + percent.id = "slider" + config + "right"; + percent.style.float = "right"; + percent.innerHTML = CM.Config[config] + "%"; + volume.appendChild(percent); + var slider = document.createElement('input'); + slider.className = "slider"; + slider.id = "slider" + config; + slider.style.clear = "both"; + slider.type = "range"; + slider.min = "0"; + slider.max = "100"; + slider.step = "1"; + slider.value = CM.Config[config]; + slider.oninput = function() {CM.ToggleConfigVolume(config)}; + slider.onchange = function() {CM.ToggleConfigVolume(config)}; + volume.appendChild(slider); + div.appendChild(volume); + return div; } + else if (CM.ConfigData[config].type == "url") { var div = document.createElement('div'); div.className = 'listing'; diff --git a/src/Config.js b/src/Config.js index 38d6d49..582cafe 100644 --- a/src/Config.js +++ b/src/Config.js @@ -104,6 +104,19 @@ CM.ToggleConfigDown = function(config) { CM.SaveConfig(CM.Config); } +/** + * This function sets the value of the specified volume-option and updates the display in the options menu + * It is called by CM.Disp.CreatePrefOption() + * @param {string} config The name of the option + */ +CM.ToggleConfigVolume = function(config) { + if (l("slider" + config) != null) { + l("slider" + config + "right").innerHTML = l("slider" + config).value + "%"; + CM.Config[config] = Math.round(l("slider" + config).value); + } + CM.SaveConfig(CM.Config); +} + CM.ToggleStatsConfig = function(config) { if (CM.Config.StatsPref[config] == 0) { CM.Config.StatsPref[config]++; diff --git a/src/Data.js b/src/Data.js index 21cba91..8abbdd1 100644 --- a/src/Data.js +++ b/src/Data.js @@ -97,7 +97,7 @@ CM.ConfigData.ToolWarnBon = {type: 'bool', group: 'Calculation', label: ['Calcul CM.ConfigData.GCNotification = {type: 'bool', group: 'Notification', label: ['Golden Cookie Notification OFF', 'Golden Cookie Notification ON'], desc: 'Create a notification when Golden Cookie spawns', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Config.GCNotification);}}; CM.ConfigData.GCFlash = {type: 'bool', group: 'Notification', label: ['Golden Cookie Flash OFF', 'Golden Cookie Flash ON'], desc: 'Flash screen on Golden Cookie', toggle: true}; CM.ConfigData.GCSound = {type: 'bool', group: 'Notification', label: ['Golden Cookie Sound OFF', 'Golden Cookie Sound ON'], desc: 'Play a sound on Golden Cookie', toggle: true}; -CM.ConfigData.GCVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of the Golden Cookie sound'}; +CM.ConfigData.GCVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of Golden Cookie'}; for (var i = 0; i < 101; i++) { CM.ConfigData.GCVolume.label[i] = i + '%'; } @@ -107,7 +107,7 @@ CM.ConfigData.Favicon = {type: 'bool', group: 'Notification', label: ['Favicon O CM.ConfigData.FortuneNotification = {type: 'bool', group: 'Notification', label: ['Fortune Cookie Notification OFF', 'Fortune Cookie Notification ON'], desc: 'Create a notification when Fortune Cookie is on the Ticker', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Config.FortuneNotification);}}; CM.ConfigData.FortuneFlash = {type: 'bool', group: 'Notification', label: ['Fortune Cookie Flash OFF', 'Fortune Cookie Flash ON'], desc: 'Flash screen on Fortune Cookie', toggle: true}; CM.ConfigData.FortuneSound = {type: 'bool', group: 'Notification', label: ['Fortune Cookie Sound OFF', 'Fortune Cookie Sound ON'], desc: 'Play a sound on Fortune Cookie', toggle: true}; -CM.ConfigData.FortuneVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of the Fortune Cookie sound'}; +CM.ConfigData.FortuneVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of Fortune Cookie'}; for (var i = 0; i < 101; i++) { CM.ConfigData.FortuneVolume.label[i] = i + '%'; } @@ -115,14 +115,14 @@ CM.ConfigData.FortuneSoundURL = {type: 'url', group: 'Notification', label: 'For CM.ConfigData.SeaNotification = {type: 'bool', group: 'Notification', label: ['Season Special Notification OFF', 'Season Special Notification ON'], desc: 'Create a notification on Season Popup', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Config.SeaNotification);}}; CM.ConfigData.SeaFlash = {type: 'bool', group: 'Notification', label: ['Season Special Flash OFF', 'Season Special Flash ON'], desc: 'Flash screen on Season Popup', toggle: true}; CM.ConfigData.SeaSound = {type: 'bool', group: 'Notification', label: ['Season Special Sound OFF', 'Season Special Sound ON'], desc: 'Play a sound on Season Popup', toggle: true}; -CM.ConfigData.SeaVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of the Season Special sound'}; +CM.ConfigData.SeaVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of Season Special'}; for (var i = 0; i < 101; i++) { CM.ConfigData.SeaVolume.label[i] = i + '%'; } CM.ConfigData.SeaSoundURL = {type: 'url', group: 'Notification', label: 'Season Special Sound URL:', desc: 'URL of the sound to be played when a Season Special spawns'}; CM.ConfigData.GardFlash = {type: 'bool', group: 'Notification', label: ['Garden Tick Flash OFF', 'Garden Tick Flash ON'], desc: 'Flash screen on Garden Tick', toggle: true}; CM.ConfigData.GardSound = {type: 'bool', group: 'Notification', label: ['Garden Tick Sound OFF', 'Garden Tick Sound ON'], desc: 'Play a sound on Garden Tick', toggle: true}; -CM.ConfigData.GardVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of the Garden Tick sound'}; +CM.ConfigData.GardVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of Garden Tick'}; for (var i = 0; i < 101; i++) { CM.ConfigData.GardVolume.label[i] = i + '%'; } @@ -130,7 +130,7 @@ CM.ConfigData.GardSoundURL = {type: 'url', group: 'Notification', label: 'Garden CM.ConfigData.MagicNotification = {type: 'bool', group: 'Notification', label: ['Magic Max Notification OFF', 'Magic Max Notification ON'], desc: 'Create a notification when magic reaches maximum', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Config.MagicNotification);}}; CM.ConfigData.MagicFlash = {type: 'bool', group: 'Notification', label: ['Magic Max Flash OFF', 'Magic Max Flash ON'], desc: 'Flash screen when magic reaches maximum', toggle: true}; CM.ConfigData.MagicSound = {type: 'bool', group: 'Notification', label: ['Magic Max Sound OFF', 'Magic Max Sound ON'], desc: 'Play a sound when magic reaches maximum', toggle: true}; -CM.ConfigData.MagicVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of the Max Magic sound'}; +CM.ConfigData.MagicVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of Max Magic'}; for (var i = 0; i < 101; i++) { CM.ConfigData.MagicVolume.label[i] = i + '%'; } @@ -138,7 +138,7 @@ CM.ConfigData.MagicSoundURL = {type: 'url', group: 'Notification', label: 'Magic CM.ConfigData.WrinklerNotification = {type: 'bool', group: 'Notification', label: ['Wrinkler Notification OFF', 'Wrinkler Notification ON'], desc: 'Create a notification when a Wrinkler appears', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Config.WrinklerNotification);}}; CM.ConfigData.WrinklerFlash = {type: 'bool', group: 'Notification', label: ['Wrinkler Flash OFF', 'Wrinkler Flash ON'], desc: 'Flash screen when a Wrinkler appears', toggle: true}; CM.ConfigData.WrinklerSound = {type: 'bool', group: 'Notification', label: ['Wrinkler Sound OFF', 'Wrinkler Sound ON'], desc: 'Play a sound when a Wrinkler appears', toggle: true}; -CM.ConfigData.WrinklerVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of the Wrinkler sound'}; +CM.ConfigData.WrinklerVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of Wrinkler'}; for (var i = 0; i < 101; i++) { CM.ConfigData.WrinklerVolume.label[i] = i + '%'; } @@ -146,7 +146,7 @@ CM.ConfigData.WrinklerSoundURL = {type: 'url', group: 'Notification', label: 'Wr CM.ConfigData.WrinklerMaxNotification = {type: 'bool', group: 'Notification', label: ['Wrinkler Max Notification OFF', 'Wrinkler Max Notification ON'], desc: 'Create a notification when the maximum amount of Wrinklers has appeared', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Config.WrinklerMaxNotification);}}; CM.ConfigData.WrinklerMaxFlash = {type: 'bool', group: 'Notification', label: ['Wrinkler Max Flash OFF', 'Wrinkler Max Flash ON'], desc: 'Flash screen when the maximum amount of Wrinklers has appeared', toggle: true}; CM.ConfigData.WrinklerMaxSound = {type: 'bool', group: 'Notification', label: ['Wrinkler Max Sound OFF', 'Wrinkler Max Sound ON'], desc: 'Play a sound when the maximum amount of Wrinklers has appeared', toggle: true}; -CM.ConfigData.WrinklerMaxVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of the Wrinkler Max sound'}; +CM.ConfigData.WrinklerMaxVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of Wrinkler Max'}; for (var i = 0; i < 101; i++) { CM.ConfigData.WrinklerMaxVolume.label[i] = i + '%'; } diff --git a/src/Disp.js b/src/Disp.js index 5a01efa..7c72c1f 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -1923,27 +1923,35 @@ CM.Disp.CreatePrefOption = function(config) { return div; } else if (CM.ConfigData[config].type == "vol") { + var div = document.createElement('div'); + div.className = 'listing'; var volume = document.createElement('div'); - volume.className = 'listing'; - var minus = document.createElement('a'); - minus.className = 'option'; - minus.onclick = function() {CM.ToggleConfigDown(config);}; - minus.textContent = '-'; - volume.appendChild(minus); - var volText = document.createElement('span'); - volText.id = CM.ConfigPrefix + config; - volText.textContent = CM.ConfigData[config].label[CM.Config[config]]; - volume.appendChild(volText); - var plus = document.createElement('a'); - plus.className = 'option'; - plus.onclick = function() {CM.ToggleConfigUp(config);}; - plus.textContent = '+'; - volume.appendChild(plus); - var volLabel = document.createElement('label'); - volLabel.textContent = CM.ConfigData[config].desc; - volume.appendChild(volLabel); - return volume; + volume.className = 'sliderBox'; + var title = document.createElement('div'); + title.style.float = "left"; + title.innerHTML = CM.ConfigData[config].desc; + volume.appendChild(title); + var percent = title = document.createElement('div'); + percent.id = "slider" + config + "right"; + percent.style.float = "right"; + percent.innerHTML = CM.Config[config] + "%"; + volume.appendChild(percent); + var slider = document.createElement('input'); + slider.className = "slider"; + slider.id = "slider" + config; + slider.style.clear = "both"; + slider.type = "range"; + slider.min = "0"; + slider.max = "100"; + slider.step = "1"; + slider.value = CM.Config[config]; + slider.oninput = function() {CM.ToggleConfigVolume(config)}; + slider.onchange = function() {CM.ToggleConfigVolume(config)}; + volume.appendChild(slider); + div.appendChild(volume); + return div; } + else if (CM.ConfigData[config].type == "url") { var div = document.createElement('div'); div.className = 'listing'; From 10482dfd2d39aa52941541be340e4157da8608c3 Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Tue, 15 Dec 2020 15:19:50 +0100 Subject: [PATCH 051/106] Fixed lay-out issue --- CookieMonster.js | 1 - src/Disp.js | 1 - 2 files changed, 2 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index 964fcb1..495b981 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -2868,7 +2868,6 @@ CM.Disp.CreatePrefOption = function(config) { div.appendChild(volume); return div; } - else if (CM.ConfigData[config].type == "url") { var div = document.createElement('div'); div.className = 'listing'; diff --git a/src/Disp.js b/src/Disp.js index 7c72c1f..b652ee8 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -1951,7 +1951,6 @@ CM.Disp.CreatePrefOption = function(config) { div.appendChild(volume); return div; } - else if (CM.ConfigData[config].type == "url") { var div = document.createElement('div'); div.className = 'listing'; From cff7377789edc7c1f1cc48681b301a62aaf28435 Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Wed, 16 Dec 2020 13:31:49 +0100 Subject: [PATCH 052/106] Created ScaleDecimals as option --- CookieMonster.js | 4 +++- src/Data.js | 1 + src/Disp.js | 2 +- src/Main.js | 1 + 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index 495b981..04acb85 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -914,6 +914,7 @@ CM.ConfigData.GrimoireBar = {type: 'bool', group: 'Statistics', label: ['Grimoir // Statistics CM.ConfigData.Scale = {type: 'bool', group: 'Other', label: ['Game\'s Setting Scale', 'Metric', 'Short Scale', 'Scientific Notation', 'Engineering Notation'], desc: 'Change how long numbers are handled', toggle: false, func: function() {CM.Disp.RefreshScale();}}; +CM.ConfigData.ScaleDecimals = {type: 'bool', group: 'Other', label: ['0 decimals', '1 decimals', '2 decimals', '3 decimals'], desc: 'Set the number of decimals used when applicable', toggle: false, func: function() {CM.Disp.RefreshScale();}}; /******** * Disp * @@ -2930,7 +2931,7 @@ CM.Disp.ToggleDetailedTime = function() { /** * This function refreshes all numbers after a change in scale-setting - * It is therefore called by a change in CM.Config.Scale + * It is therefore called by a change in CM.Config.Scale and CM.Config.ScaleDecimals */ CM.Disp.RefreshScale = function() { BeautifyAll(); @@ -4168,6 +4169,7 @@ CM.ConfigDefault = { DetailedTime: 1, GrimoireBar: 1, Scale: 2, + ScaleDecimals: 2, OptionsPref: {BarsColors: 1, Calculation: 1, Notification: 1, Tooltip: 1, Statistics: 1, Other: 1}, StatsPref: {Lucky: 1, Conjure: 1, Chain: 1, Prestige: 1, Wrink: 1, Sea: 1, Misc: 1}, Colors : {Blue: '#4bb8f0', Green: '#00ff00', Yellow: '#ffff00', Orange: '#ff7f00', Red: '#ff0000', Purple: '#ff00ff', Gray: '#b3b3b3', Pink: '#ff1493', Brown: '#8b4513'}, diff --git a/src/Data.js b/src/Data.js index 8abbdd1..5c93d86 100644 --- a/src/Data.js +++ b/src/Data.js @@ -174,4 +174,5 @@ CM.ConfigData.GrimoireBar = {type: 'bool', group: 'Statistics', label: ['Grimoir // Statistics CM.ConfigData.Scale = {type: 'bool', group: 'Other', label: ['Game\'s Setting Scale', 'Metric', 'Short Scale', 'Scientific Notation', 'Engineering Notation'], desc: 'Change how long numbers are handled', toggle: false, func: function() {CM.Disp.RefreshScale();}}; +CM.ConfigData.ScaleDecimals = {type: 'bool', group: 'Other', label: ['0 decimals', '1 decimals', '2 decimals', '3 decimals'], desc: 'Set the number of decimals used when applicable', toggle: false, func: function() {CM.Disp.RefreshScale();}}; diff --git a/src/Disp.js b/src/Disp.js index b652ee8..e71cd2c 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -2013,7 +2013,7 @@ CM.Disp.ToggleDetailedTime = function() { /** * This function refreshes all numbers after a change in scale-setting - * It is therefore called by a change in CM.Config.Scale + * It is therefore called by a change in CM.Config.Scale and CM.Config.ScaleDecimals */ CM.Disp.RefreshScale = function() { BeautifyAll(); diff --git a/src/Main.js b/src/Main.js index efc9e5c..c18b3dd 100644 --- a/src/Main.js +++ b/src/Main.js @@ -551,6 +551,7 @@ CM.ConfigDefault = { DetailedTime: 1, GrimoireBar: 1, Scale: 2, + ScaleDecimals: 2, OptionsPref: {BarsColors: 1, Calculation: 1, Notification: 1, Tooltip: 1, Statistics: 1, Other: 1}, StatsPref: {Lucky: 1, Conjure: 1, Chain: 1, Prestige: 1, Wrink: 1, Sea: 1, Misc: 1}, Colors : {Blue: '#4bb8f0', Green: '#00ff00', Yellow: '#ffff00', Orange: '#ff7f00', Red: '#ff0000', Purple: '#ff00ff', Gray: '#b3b3b3', Pink: '#ff1493', Brown: '#8b4513'}, From 2fbbd39118454425b497b0fac4d148e77235b8b8 Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Wed, 16 Dec 2020 14:10:11 +0100 Subject: [PATCH 053/106] Added CM.Config.ScaleDecimals to CM.Disp.Beautify --- CookieMonster.js | 16 +++++++++++++--- src/Data.js | 2 +- src/Disp.js | 14 ++++++++++++-- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index 04acb85..913e278 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -914,7 +914,7 @@ CM.ConfigData.GrimoireBar = {type: 'bool', group: 'Statistics', label: ['Grimoir // Statistics CM.ConfigData.Scale = {type: 'bool', group: 'Other', label: ['Game\'s Setting Scale', 'Metric', 'Short Scale', 'Scientific Notation', 'Engineering Notation'], desc: 'Change how long numbers are handled', toggle: false, func: function() {CM.Disp.RefreshScale();}}; -CM.ConfigData.ScaleDecimals = {type: 'bool', group: 'Other', label: ['0 decimals', '1 decimals', '2 decimals', '3 decimals'], desc: 'Set the number of decimals used when applicable', toggle: false, func: function() {CM.Disp.RefreshScale();}}; +CM.ConfigData.ScaleDecimals = {type: 'bool', group: 'Other', label: ['1 decimals', '2 decimals', '3 decimals'], desc: 'Set the number of decimals used when applicable', toggle: false, func: function() {CM.Disp.RefreshScale();}}; /******** * Disp * @@ -1087,7 +1087,7 @@ CM.Disp.GetTimeColor = function(time) { * TODO: Add functionality to choose amount of decimals and separators */ CM.Disp.Beautify = function(num, frac, forced) { - var decimals = 3; // This can be used to implement function to let user choose amount of decimals + var decimals = CM.Config.ScaleDecimals + 1; if (CM.Config.Scale == 0) { return CM.Backup.Beautify(num, frac); } @@ -1112,7 +1112,17 @@ CM.Disp.Beautify = function(num, frac, forced) { answer += num[i + 2]; // num has a 0-based index and [1] is a '.' i++; } - answer += Math.round(num[i + 2] + '.' + num[i + 3]); + lastNumber = Math.round(num[i + 2] + '.' + num[i + 3]); + while (lastNumber >= 10) { + if (answer[answer.length - 1] != ".") { + lastNumber = Math.round((answer[answer.length - 1] * 10) + lastNumber) / 10; + answer = answer.slice(0,-1) + } else { + lastNumber = Math.round((answer[answer.length - 2] * 10) + lastNumber) / 10; + answer = answer.slice(0,-2) + } + } + answer += lastNumber; answer += 'E+' + Math.trunc(Math.log10(num)); } else { diff --git a/src/Data.js b/src/Data.js index 5c93d86..ece1ac3 100644 --- a/src/Data.js +++ b/src/Data.js @@ -174,5 +174,5 @@ CM.ConfigData.GrimoireBar = {type: 'bool', group: 'Statistics', label: ['Grimoir // Statistics CM.ConfigData.Scale = {type: 'bool', group: 'Other', label: ['Game\'s Setting Scale', 'Metric', 'Short Scale', 'Scientific Notation', 'Engineering Notation'], desc: 'Change how long numbers are handled', toggle: false, func: function() {CM.Disp.RefreshScale();}}; -CM.ConfigData.ScaleDecimals = {type: 'bool', group: 'Other', label: ['0 decimals', '1 decimals', '2 decimals', '3 decimals'], desc: 'Set the number of decimals used when applicable', toggle: false, func: function() {CM.Disp.RefreshScale();}}; +CM.ConfigData.ScaleDecimals = {type: 'bool', group: 'Other', label: ['1 decimals', '2 decimals', '3 decimals'], desc: 'Set the number of decimals used when applicable', toggle: false, func: function() {CM.Disp.RefreshScale();}}; diff --git a/src/Disp.js b/src/Disp.js index e71cd2c..5c02c48 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -169,7 +169,7 @@ CM.Disp.GetTimeColor = function(time) { * TODO: Add functionality to choose amount of decimals and separators */ CM.Disp.Beautify = function(num, frac, forced) { - var decimals = 3; // This can be used to implement function to let user choose amount of decimals + var decimals = CM.Config.ScaleDecimals + 1; if (CM.Config.Scale == 0) { return CM.Backup.Beautify(num, frac); } @@ -194,7 +194,17 @@ CM.Disp.Beautify = function(num, frac, forced) { answer += num[i + 2]; // num has a 0-based index and [1] is a '.' i++; } - answer += Math.round(num[i + 2] + '.' + num[i + 3]); + lastNumber = Math.round(num[i + 2] + '.' + num[i + 3]); + while (lastNumber >= 10) { + if (answer[answer.length - 1] != ".") { + lastNumber = Math.round((answer[answer.length - 1] * 10) + lastNumber) / 10; + answer = answer.slice(0,-1) + } else { + lastNumber = Math.round((answer[answer.length - 2] * 10) + lastNumber) / 10; + answer = answer.slice(0,-2) + } + } + answer += lastNumber; answer += 'E+' + Math.trunc(Math.log10(num)); } else { From fcadf1cc18bef1c74dfd4b11a6694c648bd27d55 Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Thu, 17 Dec 2020 17:41:25 +0100 Subject: [PATCH 054/106] Added Config.ScaleSeparator --- CookieMonster.js | 1 + src/Data.js | 1 + 2 files changed, 2 insertions(+) diff --git a/CookieMonster.js b/CookieMonster.js index 913e278..2ba8446 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -915,6 +915,7 @@ CM.ConfigData.GrimoireBar = {type: 'bool', group: 'Statistics', label: ['Grimoir // Statistics CM.ConfigData.Scale = {type: 'bool', group: 'Other', label: ['Game\'s Setting Scale', 'Metric', 'Short Scale', 'Scientific Notation', 'Engineering Notation'], desc: 'Change how long numbers are handled', toggle: false, func: function() {CM.Disp.RefreshScale();}}; CM.ConfigData.ScaleDecimals = {type: 'bool', group: 'Other', label: ['1 decimals', '2 decimals', '3 decimals'], desc: 'Set the number of decimals used when applicable', toggle: false, func: function() {CM.Disp.RefreshScale();}}; +CM.ConfigData.ScaleSeparator = {type: 'bool', group: 'Other', label: ['. for decimals', '. for thousands'], desc: 'Set the separator used for decimals and thousands', toggle: false, func: function() {CM.Disp.RefreshScale();}}; /******** * Disp * diff --git a/src/Data.js b/src/Data.js index ece1ac3..d88e167 100644 --- a/src/Data.js +++ b/src/Data.js @@ -175,4 +175,5 @@ CM.ConfigData.GrimoireBar = {type: 'bool', group: 'Statistics', label: ['Grimoir // Statistics CM.ConfigData.Scale = {type: 'bool', group: 'Other', label: ['Game\'s Setting Scale', 'Metric', 'Short Scale', 'Scientific Notation', 'Engineering Notation'], desc: 'Change how long numbers are handled', toggle: false, func: function() {CM.Disp.RefreshScale();}}; CM.ConfigData.ScaleDecimals = {type: 'bool', group: 'Other', label: ['1 decimals', '2 decimals', '3 decimals'], desc: 'Set the number of decimals used when applicable', toggle: false, func: function() {CM.Disp.RefreshScale();}}; +CM.ConfigData.ScaleSeparator = {type: 'bool', group: 'Other', label: ['. for decimals', '. for thousands'], desc: 'Set the separator used for decimals and thousands', toggle: false, func: function() {CM.Disp.RefreshScale();}}; From 8037615659245f0afb7d8b78be7faa8198a6274c Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Thu, 17 Dec 2020 18:07:34 +0100 Subject: [PATCH 055/106] Added functionality for ScaleSeparator --- CookieMonster.js | 19 ++++++++++--------- src/Data.js | 10 +++++----- src/Disp.js | 6 +++--- src/Main.js | 3 ++- 4 files changed, 20 insertions(+), 18 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index 2ba8446..5005890 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -786,7 +786,7 @@ CM.ConfigGroups = { Notification: "Notification", Tooltip: "Tooltips", Statistics: "Statitics", - Other: "Other"}, + Notation: "Notation"}, /******** * Section: An array (CM.ConfigData) containing all Config options @@ -912,10 +912,10 @@ CM.ConfigData.TimeFormat = {type: 'bool', group: 'Statistics', label: ['Time XXd CM.ConfigData.DetailedTime = {type: 'bool', group: 'Statistics', label: ['Detailed Time OFF', 'Detailed Time ON'], desc: 'Change how time is displayed in certain statistics and tooltips', toggle: true, func: function() {CM.Disp.ToggleDetailedTime();}}; CM.ConfigData.GrimoireBar = {type: 'bool', group: 'Statistics', label: ['Grimoire Magic Meter Timer OFF', 'Grimoire Magic Meter Timer ON'], desc: 'A timer on how long before the Grimoire magic meter is full', toggle: true}; -// Statistics -CM.ConfigData.Scale = {type: 'bool', group: 'Other', label: ['Game\'s Setting Scale', 'Metric', 'Short Scale', 'Scientific Notation', 'Engineering Notation'], desc: 'Change how long numbers are handled', toggle: false, func: function() {CM.Disp.RefreshScale();}}; -CM.ConfigData.ScaleDecimals = {type: 'bool', group: 'Other', label: ['1 decimals', '2 decimals', '3 decimals'], desc: 'Set the number of decimals used when applicable', toggle: false, func: function() {CM.Disp.RefreshScale();}}; -CM.ConfigData.ScaleSeparator = {type: 'bool', group: 'Other', label: ['. for decimals', '. for thousands'], desc: 'Set the separator used for decimals and thousands', toggle: false, func: function() {CM.Disp.RefreshScale();}}; +// Notation +CM.ConfigData.Scale = {type: 'bool', group: 'Notation', label: ['Game\'s Setting Scale', 'Metric', 'Short Scale', 'Scientific Notation', 'Engineering Notation'], desc: 'Change how long numbers are handled', toggle: false, func: function() {CM.Disp.RefreshScale();}}; +CM.ConfigData.ScaleDecimals = {type: 'bool', group: 'Notation', label: ['1 decimals', '2 decimals', '3 decimals'], desc: 'Set the number of decimals used when applicable', toggle: false, func: function() {CM.Disp.RefreshScale();}}; +CM.ConfigData.ScaleSeparator = {type: 'bool', group: 'Notation', label: ['. for decimals (Standard)', '. for thousands'], desc: 'Set the separator used for decimals and thousands', toggle: false, func: function() {CM.Disp.RefreshScale();}}; /******** * Disp * @@ -1085,7 +1085,6 @@ CM.Disp.GetTimeColor = function(time) { * @param {any} frac Used in some scenario's by CM.Backup.Beautify (Game's original function) * @param {number} forced Used to force (type 3) in certains cases * @returns {string} Formatted number - * TODO: Add functionality to choose amount of decimals and separators */ CM.Disp.Beautify = function(num, frac, forced) { var decimals = CM.Config.ScaleDecimals + 1; @@ -1104,10 +1103,11 @@ CM.Disp.Beautify = function(num, frac, forced) { return num } else if (-1 < timesTenToPowerThree && timesTenToPowerThree < 2) { + // TODO: Add changing separators of thousands and making this cut-off user configurable answer = Math.round(num * 100) / 100; } else if (CM.Config.Scale == 3 && !forced || forced == 3) { // Scientific notation, 123456789 => 1.235E+8 - answer = num[0] + '.' + answer = num[0] + (CM.Config.ScaleSeparator ? ',' : '.'); i = 0; while (i < decimals - 1) { answer += num[i + 2]; // num has a 0-based index and [1] is a '.' @@ -1132,7 +1132,7 @@ CM.Disp.Beautify = function(num, frac, forced) { numbersToAdd = (restOfNumber.indexOf('.') > -1 ? restOfNumber.indexOf('.') + 1 + decimals : (restOfNumber.length)) i = 0 while (i < numbersToAdd - 1 && i < restOfNumber.length - 1) { - answer += restOfNumber[i]; + answer += (CM.Config.ScaleSeparator && restOfNumber[i] == '.' ? ',' : restOfNumber[i]); i++ } answer += (i + 1 < restOfNumber.length ? Math.round(restOfNumber[i] + '.' + restOfNumber[i + 1]) : restOfNumber[i]); @@ -4181,7 +4181,8 @@ CM.ConfigDefault = { GrimoireBar: 1, Scale: 2, ScaleDecimals: 2, - OptionsPref: {BarsColors: 1, Calculation: 1, Notification: 1, Tooltip: 1, Statistics: 1, Other: 1}, + ScaleSeparator: 0, + OptionsPref: {BarsColors: 1, Calculation: 1, Notification: 1, Tooltip: 1, Statistics: 1, Notation: 1}, StatsPref: {Lucky: 1, Conjure: 1, Chain: 1, Prestige: 1, Wrink: 1, Sea: 1, Misc: 1}, Colors : {Blue: '#4bb8f0', Green: '#00ff00', Yellow: '#ffff00', Orange: '#ff7f00', Red: '#ff0000', Purple: '#ff00ff', Gray: '#b3b3b3', Pink: '#ff1493', Brown: '#8b4513'}, SortBuildings: 0, diff --git a/src/Data.js b/src/Data.js index d88e167..ee0eff1 100644 --- a/src/Data.js +++ b/src/Data.js @@ -46,7 +46,7 @@ CM.ConfigGroups = { Notification: "Notification", Tooltip: "Tooltips", Statistics: "Statitics", - Other: "Other"}, + Notation: "Notation"}, /******** * Section: An array (CM.ConfigData) containing all Config options @@ -172,8 +172,8 @@ CM.ConfigData.TimeFormat = {type: 'bool', group: 'Statistics', label: ['Time XXd CM.ConfigData.DetailedTime = {type: 'bool', group: 'Statistics', label: ['Detailed Time OFF', 'Detailed Time ON'], desc: 'Change how time is displayed in certain statistics and tooltips', toggle: true, func: function() {CM.Disp.ToggleDetailedTime();}}; CM.ConfigData.GrimoireBar = {type: 'bool', group: 'Statistics', label: ['Grimoire Magic Meter Timer OFF', 'Grimoire Magic Meter Timer ON'], desc: 'A timer on how long before the Grimoire magic meter is full', toggle: true}; -// Statistics -CM.ConfigData.Scale = {type: 'bool', group: 'Other', label: ['Game\'s Setting Scale', 'Metric', 'Short Scale', 'Scientific Notation', 'Engineering Notation'], desc: 'Change how long numbers are handled', toggle: false, func: function() {CM.Disp.RefreshScale();}}; -CM.ConfigData.ScaleDecimals = {type: 'bool', group: 'Other', label: ['1 decimals', '2 decimals', '3 decimals'], desc: 'Set the number of decimals used when applicable', toggle: false, func: function() {CM.Disp.RefreshScale();}}; -CM.ConfigData.ScaleSeparator = {type: 'bool', group: 'Other', label: ['. for decimals', '. for thousands'], desc: 'Set the separator used for decimals and thousands', toggle: false, func: function() {CM.Disp.RefreshScale();}}; +// Notation +CM.ConfigData.Scale = {type: 'bool', group: 'Notation', label: ['Game\'s Setting Scale', 'Metric', 'Short Scale', 'Scientific Notation', 'Engineering Notation'], desc: 'Change how long numbers are handled', toggle: false, func: function() {CM.Disp.RefreshScale();}}; +CM.ConfigData.ScaleDecimals = {type: 'bool', group: 'Notation', label: ['1 decimals', '2 decimals', '3 decimals'], desc: 'Set the number of decimals used when applicable', toggle: false, func: function() {CM.Disp.RefreshScale();}}; +CM.ConfigData.ScaleSeparator = {type: 'bool', group: 'Notation', label: ['. for decimals (Standard)', '. for thousands'], desc: 'Set the separator used for decimals and thousands', toggle: false, func: function() {CM.Disp.RefreshScale();}}; diff --git a/src/Disp.js b/src/Disp.js index 5c02c48..1db11f2 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -166,7 +166,6 @@ CM.Disp.GetTimeColor = function(time) { * @param {any} frac Used in some scenario's by CM.Backup.Beautify (Game's original function) * @param {number} forced Used to force (type 3) in certains cases * @returns {string} Formatted number - * TODO: Add functionality to choose amount of decimals and separators */ CM.Disp.Beautify = function(num, frac, forced) { var decimals = CM.Config.ScaleDecimals + 1; @@ -185,10 +184,11 @@ CM.Disp.Beautify = function(num, frac, forced) { return num } else if (-1 < timesTenToPowerThree && timesTenToPowerThree < 2) { + // TODO: Add changing separators of thousands and making this cut-off user configurable answer = Math.round(num * 100) / 100; } else if (CM.Config.Scale == 3 && !forced || forced == 3) { // Scientific notation, 123456789 => 1.235E+8 - answer = num[0] + '.' + answer = num[0] + (CM.Config.ScaleSeparator ? ',' : '.'); i = 0; while (i < decimals - 1) { answer += num[i + 2]; // num has a 0-based index and [1] is a '.' @@ -213,7 +213,7 @@ CM.Disp.Beautify = function(num, frac, forced) { numbersToAdd = (restOfNumber.indexOf('.') > -1 ? restOfNumber.indexOf('.') + 1 + decimals : (restOfNumber.length)) i = 0 while (i < numbersToAdd - 1 && i < restOfNumber.length - 1) { - answer += restOfNumber[i]; + answer += (CM.Config.ScaleSeparator && restOfNumber[i] == '.' ? ',' : restOfNumber[i]); i++ } answer += (i + 1 < restOfNumber.length ? Math.round(restOfNumber[i] + '.' + restOfNumber[i + 1]) : restOfNumber[i]); diff --git a/src/Main.js b/src/Main.js index c18b3dd..9a37183 100644 --- a/src/Main.js +++ b/src/Main.js @@ -552,7 +552,8 @@ CM.ConfigDefault = { GrimoireBar: 1, Scale: 2, ScaleDecimals: 2, - OptionsPref: {BarsColors: 1, Calculation: 1, Notification: 1, Tooltip: 1, Statistics: 1, Other: 1}, + ScaleSeparator: 0, + OptionsPref: {BarsColors: 1, Calculation: 1, Notification: 1, Tooltip: 1, Statistics: 1, Notation: 1}, StatsPref: {Lucky: 1, Conjure: 1, Chain: 1, Prestige: 1, Wrink: 1, Sea: 1, Misc: 1}, Colors : {Blue: '#4bb8f0', Green: '#00ff00', Yellow: '#ffff00', Orange: '#ff7f00', Red: '#ff0000', Purple: '#ff00ff', Gray: '#b3b3b3', Pink: '#ff1493', Brown: '#8b4513'}, SortBuildings: 0, From 556e71434d94a0d9fcb4fd86bfdae3c600be0e4a Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Thu, 17 Dec 2020 18:18:58 +0100 Subject: [PATCH 056/106] Changed structure of Data.js --- CookieMonster.js | 185 ++++++++++++++++++++++++----------------------- src/Config.js | 20 ++--- src/Data.js | 89 ++++++++++++++++++++++- src/Main.js | 75 ------------------- 4 files changed, 190 insertions(+), 179 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index 5005890..557fb22 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -586,45 +586,45 @@ CM.LoadConfig = function() { // Check values var mod = false; - for (var i in CM.ConfigDefault) { + for (var i in CM.Data.ConfigDefault) { if (typeof CM.Config[i] === 'undefined') { mod = true; - CM.Config[i] = CM.ConfigDefault[i]; + CM.Config[i] = CM.Data.ConfigDefault[i]; } else if (i != 'StatsPref' && i != 'Colors') { if (i.indexOf('SoundURL') == -1) { if (!(CM.Config[i] > -1 && CM.Config[i] < CM.ConfigData[i].label.length)) { mod = true; - CM.Config[i] = CM.ConfigDefault[i]; + CM.Config[i] = CM.Data.ConfigDefault[i]; } } else { // Sound URLs if (typeof CM.Config[i] != 'string') { mod = true; - CM.Config[i] = CM.ConfigDefault[i]; + CM.Config[i] = CM.Data.ConfigDefault[i]; } } } else if (i == 'StatsPref') { - for (var j in CM.ConfigDefault.StatsPref) { + for (var j in CM.Data.ConfigDefault.StatsPref) { if (typeof CM.Config[i][j] === 'undefined' || !(CM.Config[i][j] > -1 && CM.Config[i][j] < 2)) { mod = true; - CM.Config[i][j] = CM.ConfigDefault[i][j]; + CM.Config[i][j] = CM.Data.ConfigDefault[i][j]; } } } else { // Colors - for (var j in CM.ConfigDefault.Colors) { + for (var j in CM.Data.ConfigDefault.Colors) { if (typeof CM.Config[i][j] === 'undefined' || typeof CM.Config[i][j] != 'string') { mod = true; - CM.Config[i][j] = CM.ConfigDefault[i][j]; + CM.Config[i][j] = CM.Data.ConfigDefault[i][j]; } } } } if (mod) CM.SaveConfig(CM.Config); CM.Loop(); // Do loop once - for (var i in CM.ConfigDefault) { + for (var i in CM.Data.ConfigDefault) { if (i != 'StatsPref' && i != 'OptionsPref' && typeof CM.ConfigData[i].func !== 'undefined') { CM.ConfigData[i].func(); } @@ -637,7 +637,7 @@ CM.LoadConfig = function() { CM.RestoreDefault = function() { CM.Config = {}; - CM.SaveConfig(CM.ConfigDefault); + CM.SaveConfig(CM.Data.ConfigDefault); CM.LoadConfig(); Game.UpdateMenu(); } @@ -774,6 +774,7 @@ CM.Data.ValCookies = ['Pure heart biscuits', 'Ardent heart biscuits', 'Sour hear /******** * Section: Data for the various scales used by CookieMonster */ + CM.Data.metric = ['', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y']; CM.Data.shortScale = ['', 'M', 'B', 'Tr', 'Quadr', 'Quint', 'Sext', 'Sept', 'Oct', 'Non', 'Dec', 'Undec', 'Duodec', 'Tredec', 'Quattuordec', 'Quindec', 'Sexdec', 'Septendec', 'Octodec', 'Novemdec', 'Vigint', 'Unvigint', 'Duovigint', 'Trevigint', 'Quattuorvigint']; @@ -789,9 +790,11 @@ CM.ConfigGroups = { Notation: "Notation"}, /******** - * Section: An array (CM.ConfigData) containing all Config options - * - * Each array has the following items + * Section: An array (CM.ConfigData) containing all Config options and an array of default settings */ + +/** + * This includes all options of CookieMonster and relevant data + * Each individual option-array in the has the following items * @item {string} type The type of option (bool(ean), vol(ume), url or color) * @item {string} group The options-group the option belongs to * @item {[string, ...]} label A list of the various configurations of the option @@ -799,7 +802,6 @@ CM.ConfigGroups = { * @item {boolean} toggle Whether it should be displayed as a grey/white toggle in the options menu * @item {function} func A function to be called when the option is toggled */ - // Barscolors CM.ConfigData.BotBar = {type: 'bool', group: 'BarsColors', label: ['Bottom Bar OFF', 'Bottom Bar ON'], desc: 'Building Information', toggle: true, func: function() {CM.Disp.ToggleBotBar();}}; CM.ConfigData.TimerBar = {type: 'bool', group: 'BarsColors', label: ['Timer Bar OFF', 'Timer Bar ON'], desc: 'Timers of Golden Cookie, Season Popup, Frenzy (Normal, Clot, Elder), Click Frenzy', toggle: true, func: function() {CM.Disp.ToggleTimerBar();}}; @@ -917,7 +919,85 @@ CM.ConfigData.Scale = {type: 'bool', group: 'Notation', label: ['Game\'s Setting CM.ConfigData.ScaleDecimals = {type: 'bool', group: 'Notation', label: ['1 decimals', '2 decimals', '3 decimals'], desc: 'Set the number of decimals used when applicable', toggle: false, func: function() {CM.Disp.RefreshScale();}}; CM.ConfigData.ScaleSeparator = {type: 'bool', group: 'Notation', label: ['. for decimals (Standard)', '. for thousands'], desc: 'Set the separator used for decimals and thousands', toggle: false, func: function() {CM.Disp.RefreshScale();}}; -/******** +/** + * This array describes all default settings + * It is used by CM.LoadConfig() and CM.RestoreDefault() + */ +CM.Data.ConfigDefault = { + BotBar: 1, + TimerBar: 1, + TimerBarPos: 0, + BuildColor: 1, + BulkBuildColor: 0, + ColorPPBulkMode: 0, + UpBarColor: 1, + UpgradeBarFixedPos: 1, + CalcWrink: 0, + CPSMode: 1, + AvgCPSHist: 3, + AvgClicksHist: 0, + ToolWarnBon: 0, + GCNotification: 0, + GCFlash: 1, + GCSound: 1, + GCVolume: 100, + GCSoundURL: 'https://freesound.org/data/previews/66/66717_931655-lq.mp3', + GCTimer: 1, + Favicon: 1, + FortuneNotification: 0, + FortuneFlash: 1, + FortuneSound: 1, + FortuneVolume: 100, + FortuneSoundURL: 'https://freesound.org/data/previews/174/174027_3242494-lq.mp3', + SeaNotification: 0, + SeaFlash: 1, + SeaSound: 1, + SeaVolume: 100, + SeaSoundURL: 'https://www.freesound.org/data/previews/121/121099_2193266-lq.mp3', + GardFlash: 1, + GardSound: 1, + GardVolume: 100, + GardSoundURL: 'https://freesound.org/data/previews/103/103046_861714-lq.mp3', + MagicNotification: 0, + MagicFlash: 1, + MagicSound: 1, + MagicVolume: 100, + MagicSoundURL: 'https://freesound.org/data/previews/221/221683_1015240-lq.mp3', + WrinklerNotification: 0, + WrinklerFlash: 1, + WrinklerSound: 1, + WrinklerVolume: 100, + WrinklerSoundURL: 'https://freesound.org/data/previews/124/124186_8043-lq.mp3', + WrinklerMaxNotification: 0, + WrinklerMaxFlash: 1, + WrinklerMaxSound: 1, + WrinklerMaxVolume: 100, + WrinklerMaxSoundURL: 'https://freesound.org/data/previews/152/152743_15663-lq.mp3', + Title: 1, + TooltipBuildUp: 1, + TooltipAmor: 0, + ToolWarnLucky: 1, + ToolWarnConjure: 1, + ToolWarnPos: 1, + TooltipGrim:1, + ToolWrink: 1, + TooltipLump: 1, + DragonAuraInfo: 1, + Stats: 1, + MissingUpgrades: 0, + UpStats: 1, + TimeFormat: 0, + DetailedTime: 1, + GrimoireBar: 1, + Scale: 2, + ScaleDecimals: 2, + ScaleSeparator: 0, + OptionsPref: {BarsColors: 1, Calculation: 1, Notification: 1, Tooltip: 1, Statistics: 1, Notation: 1}, + StatsPref: {Lucky: 1, Conjure: 1, Chain: 1, Prestige: 1, Wrink: 1, Sea: 1, Misc: 1}, + Colors : {Blue: '#4bb8f0', Green: '#00ff00', Yellow: '#ffff00', Orange: '#ff7f00', Red: '#ff0000', Purple: '#ff00ff', Gray: '#b3b3b3', Pink: '#ff1493', Brown: '#8b4513'}, + SortBuildings: 0, + SortUpgrades: 0 +};/******** * Disp * ********/ @@ -4113,81 +4193,6 @@ CM.Main.lastGardenNextStep = 0; CM.Main.lastMagicBarFull = 0; CM.Main.lastWrinklerCount = 0; -CM.ConfigDefault = { - BotBar: 1, - TimerBar: 1, - TimerBarPos: 0, - BuildColor: 1, - BulkBuildColor: 0, - ColorPPBulkMode: 0, - UpBarColor: 1, - UpgradeBarFixedPos: 1, - CalcWrink: 0, - CPSMode: 1, - AvgCPSHist: 3, - AvgClicksHist: 0, - ToolWarnBon: 0, - GCNotification: 0, - GCFlash: 1, - GCSound: 1, - GCVolume: 100, - GCSoundURL: 'https://freesound.org/data/previews/66/66717_931655-lq.mp3', - GCTimer: 1, - Favicon: 1, - FortuneNotification: 0, - FortuneFlash: 1, - FortuneSound: 1, - FortuneVolume: 100, - FortuneSoundURL: 'https://freesound.org/data/previews/174/174027_3242494-lq.mp3', - SeaNotification: 0, - SeaFlash: 1, - SeaSound: 1, - SeaVolume: 100, - SeaSoundURL: 'https://www.freesound.org/data/previews/121/121099_2193266-lq.mp3', - GardFlash: 1, - GardSound: 1, - GardVolume: 100, - GardSoundURL: 'https://freesound.org/data/previews/103/103046_861714-lq.mp3', - MagicNotification: 0, - MagicFlash: 1, - MagicSound: 1, - MagicVolume: 100, - MagicSoundURL: 'https://freesound.org/data/previews/221/221683_1015240-lq.mp3', - WrinklerNotification: 0, - WrinklerFlash: 1, - WrinklerSound: 1, - WrinklerVolume: 100, - WrinklerSoundURL: 'https://freesound.org/data/previews/124/124186_8043-lq.mp3', - WrinklerMaxNotification: 0, - WrinklerMaxFlash: 1, - WrinklerMaxSound: 1, - WrinklerMaxVolume: 100, - WrinklerMaxSoundURL: 'https://freesound.org/data/previews/152/152743_15663-lq.mp3', - Title: 1, - TooltipBuildUp: 1, - TooltipAmor: 0, - ToolWarnLucky: 1, - ToolWarnConjure: 1, - ToolWarnPos: 1, - TooltipGrim:1, - ToolWrink: 1, - TooltipLump: 1, - DragonAuraInfo: 1, - Stats: 1, - MissingUpgrades: 0, - UpStats: 1, - TimeFormat: 0, - DetailedTime: 1, - GrimoireBar: 1, - Scale: 2, - ScaleDecimals: 2, - ScaleSeparator: 0, - OptionsPref: {BarsColors: 1, Calculation: 1, Notification: 1, Tooltip: 1, Statistics: 1, Notation: 1}, - StatsPref: {Lucky: 1, Conjure: 1, Chain: 1, Prestige: 1, Wrink: 1, Sea: 1, Misc: 1}, - Colors : {Blue: '#4bb8f0', Green: '#00ff00', Yellow: '#ffff00', Orange: '#ff7f00', Red: '#ff0000', Purple: '#ff00ff', Gray: '#b3b3b3', Pink: '#ff1493', Brown: '#8b4513'}, - SortBuildings: 0, - SortUpgrades: 0 -}; CM.ConfigPrefix = 'CMConfig'; CM.VersionMajor = '2.031'; diff --git a/src/Config.js b/src/Config.js index 582cafe..e639651 100644 --- a/src/Config.js +++ b/src/Config.js @@ -12,45 +12,45 @@ CM.LoadConfig = function() { // Check values var mod = false; - for (var i in CM.ConfigDefault) { + for (var i in CM.Data.ConfigDefault) { if (typeof CM.Config[i] === 'undefined') { mod = true; - CM.Config[i] = CM.ConfigDefault[i]; + CM.Config[i] = CM.Data.ConfigDefault[i]; } else if (i != 'StatsPref' && i != 'Colors') { if (i.indexOf('SoundURL') == -1) { if (!(CM.Config[i] > -1 && CM.Config[i] < CM.ConfigData[i].label.length)) { mod = true; - CM.Config[i] = CM.ConfigDefault[i]; + CM.Config[i] = CM.Data.ConfigDefault[i]; } } else { // Sound URLs if (typeof CM.Config[i] != 'string') { mod = true; - CM.Config[i] = CM.ConfigDefault[i]; + CM.Config[i] = CM.Data.ConfigDefault[i]; } } } else if (i == 'StatsPref') { - for (var j in CM.ConfigDefault.StatsPref) { + for (var j in CM.Data.ConfigDefault.StatsPref) { if (typeof CM.Config[i][j] === 'undefined' || !(CM.Config[i][j] > -1 && CM.Config[i][j] < 2)) { mod = true; - CM.Config[i][j] = CM.ConfigDefault[i][j]; + CM.Config[i][j] = CM.Data.ConfigDefault[i][j]; } } } else { // Colors - for (var j in CM.ConfigDefault.Colors) { + for (var j in CM.Data.ConfigDefault.Colors) { if (typeof CM.Config[i][j] === 'undefined' || typeof CM.Config[i][j] != 'string') { mod = true; - CM.Config[i][j] = CM.ConfigDefault[i][j]; + CM.Config[i][j] = CM.Data.ConfigDefault[i][j]; } } } } if (mod) CM.SaveConfig(CM.Config); CM.Loop(); // Do loop once - for (var i in CM.ConfigDefault) { + for (var i in CM.Data.ConfigDefault) { if (i != 'StatsPref' && i != 'OptionsPref' && typeof CM.ConfigData[i].func !== 'undefined') { CM.ConfigData[i].func(); } @@ -63,7 +63,7 @@ CM.LoadConfig = function() { CM.RestoreDefault = function() { CM.Config = {}; - CM.SaveConfig(CM.ConfigDefault); + CM.SaveConfig(CM.Data.ConfigDefault); CM.LoadConfig(); Game.UpdateMenu(); } diff --git a/src/Data.js b/src/Data.js index ee0eff1..fd2b698 100644 --- a/src/Data.js +++ b/src/Data.js @@ -34,6 +34,7 @@ CM.Data.ValCookies = ['Pure heart biscuits', 'Ardent heart biscuits', 'Sour hear /******** * Section: Data for the various scales used by CookieMonster */ + CM.Data.metric = ['', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y']; CM.Data.shortScale = ['', 'M', 'B', 'Tr', 'Quadr', 'Quint', 'Sext', 'Sept', 'Oct', 'Non', 'Dec', 'Undec', 'Duodec', 'Tredec', 'Quattuordec', 'Quindec', 'Sexdec', 'Septendec', 'Octodec', 'Novemdec', 'Vigint', 'Unvigint', 'Duovigint', 'Trevigint', 'Quattuorvigint']; @@ -49,9 +50,11 @@ CM.ConfigGroups = { Notation: "Notation"}, /******** - * Section: An array (CM.ConfigData) containing all Config options - * - * Each array has the following items + * Section: An array (CM.ConfigData) containing all Config options and an array of default settings */ + +/** + * This includes all options of CookieMonster and relevant data + * Each individual option-array in the has the following items * @item {string} type The type of option (bool(ean), vol(ume), url or color) * @item {string} group The options-group the option belongs to * @item {[string, ...]} label A list of the various configurations of the option @@ -59,7 +62,6 @@ CM.ConfigGroups = { * @item {boolean} toggle Whether it should be displayed as a grey/white toggle in the options menu * @item {function} func A function to be called when the option is toggled */ - // Barscolors CM.ConfigData.BotBar = {type: 'bool', group: 'BarsColors', label: ['Bottom Bar OFF', 'Bottom Bar ON'], desc: 'Building Information', toggle: true, func: function() {CM.Disp.ToggleBotBar();}}; CM.ConfigData.TimerBar = {type: 'bool', group: 'BarsColors', label: ['Timer Bar OFF', 'Timer Bar ON'], desc: 'Timers of Golden Cookie, Season Popup, Frenzy (Normal, Clot, Elder), Click Frenzy', toggle: true, func: function() {CM.Disp.ToggleTimerBar();}}; @@ -177,3 +179,82 @@ CM.ConfigData.Scale = {type: 'bool', group: 'Notation', label: ['Game\'s Setting CM.ConfigData.ScaleDecimals = {type: 'bool', group: 'Notation', label: ['1 decimals', '2 decimals', '3 decimals'], desc: 'Set the number of decimals used when applicable', toggle: false, func: function() {CM.Disp.RefreshScale();}}; CM.ConfigData.ScaleSeparator = {type: 'bool', group: 'Notation', label: ['. for decimals (Standard)', '. for thousands'], desc: 'Set the separator used for decimals and thousands', toggle: false, func: function() {CM.Disp.RefreshScale();}}; +/** + * This array describes all default settings + * It is used by CM.LoadConfig() and CM.RestoreDefault() + */ +CM.Data.ConfigDefault = { + BotBar: 1, + TimerBar: 1, + TimerBarPos: 0, + BuildColor: 1, + BulkBuildColor: 0, + ColorPPBulkMode: 0, + UpBarColor: 1, + UpgradeBarFixedPos: 1, + CalcWrink: 0, + CPSMode: 1, + AvgCPSHist: 3, + AvgClicksHist: 0, + ToolWarnBon: 0, + GCNotification: 0, + GCFlash: 1, + GCSound: 1, + GCVolume: 100, + GCSoundURL: 'https://freesound.org/data/previews/66/66717_931655-lq.mp3', + GCTimer: 1, + Favicon: 1, + FortuneNotification: 0, + FortuneFlash: 1, + FortuneSound: 1, + FortuneVolume: 100, + FortuneSoundURL: 'https://freesound.org/data/previews/174/174027_3242494-lq.mp3', + SeaNotification: 0, + SeaFlash: 1, + SeaSound: 1, + SeaVolume: 100, + SeaSoundURL: 'https://www.freesound.org/data/previews/121/121099_2193266-lq.mp3', + GardFlash: 1, + GardSound: 1, + GardVolume: 100, + GardSoundURL: 'https://freesound.org/data/previews/103/103046_861714-lq.mp3', + MagicNotification: 0, + MagicFlash: 1, + MagicSound: 1, + MagicVolume: 100, + MagicSoundURL: 'https://freesound.org/data/previews/221/221683_1015240-lq.mp3', + WrinklerNotification: 0, + WrinklerFlash: 1, + WrinklerSound: 1, + WrinklerVolume: 100, + WrinklerSoundURL: 'https://freesound.org/data/previews/124/124186_8043-lq.mp3', + WrinklerMaxNotification: 0, + WrinklerMaxFlash: 1, + WrinklerMaxSound: 1, + WrinklerMaxVolume: 100, + WrinklerMaxSoundURL: 'https://freesound.org/data/previews/152/152743_15663-lq.mp3', + Title: 1, + TooltipBuildUp: 1, + TooltipAmor: 0, + ToolWarnLucky: 1, + ToolWarnConjure: 1, + ToolWarnPos: 1, + TooltipGrim:1, + ToolWrink: 1, + TooltipLump: 1, + DragonAuraInfo: 1, + Stats: 1, + MissingUpgrades: 0, + UpStats: 1, + TimeFormat: 0, + DetailedTime: 1, + GrimoireBar: 1, + Scale: 2, + ScaleDecimals: 2, + ScaleSeparator: 0, + OptionsPref: {BarsColors: 1, Calculation: 1, Notification: 1, Tooltip: 1, Statistics: 1, Notation: 1}, + StatsPref: {Lucky: 1, Conjure: 1, Chain: 1, Prestige: 1, Wrink: 1, Sea: 1, Misc: 1}, + Colors : {Blue: '#4bb8f0', Green: '#00ff00', Yellow: '#ffff00', Orange: '#ff7f00', Red: '#ff0000', Purple: '#ff00ff', Gray: '#b3b3b3', Pink: '#ff1493', Brown: '#8b4513'}, + SortBuildings: 0, + SortUpgrades: 0 +}; \ No newline at end of file diff --git a/src/Main.js b/src/Main.js index 9a37183..20705c2 100644 --- a/src/Main.js +++ b/src/Main.js @@ -484,81 +484,6 @@ CM.Main.lastGardenNextStep = 0; CM.Main.lastMagicBarFull = 0; CM.Main.lastWrinklerCount = 0; -CM.ConfigDefault = { - BotBar: 1, - TimerBar: 1, - TimerBarPos: 0, - BuildColor: 1, - BulkBuildColor: 0, - ColorPPBulkMode: 0, - UpBarColor: 1, - UpgradeBarFixedPos: 1, - CalcWrink: 0, - CPSMode: 1, - AvgCPSHist: 3, - AvgClicksHist: 0, - ToolWarnBon: 0, - GCNotification: 0, - GCFlash: 1, - GCSound: 1, - GCVolume: 100, - GCSoundURL: 'https://freesound.org/data/previews/66/66717_931655-lq.mp3', - GCTimer: 1, - Favicon: 1, - FortuneNotification: 0, - FortuneFlash: 1, - FortuneSound: 1, - FortuneVolume: 100, - FortuneSoundURL: 'https://freesound.org/data/previews/174/174027_3242494-lq.mp3', - SeaNotification: 0, - SeaFlash: 1, - SeaSound: 1, - SeaVolume: 100, - SeaSoundURL: 'https://www.freesound.org/data/previews/121/121099_2193266-lq.mp3', - GardFlash: 1, - GardSound: 1, - GardVolume: 100, - GardSoundURL: 'https://freesound.org/data/previews/103/103046_861714-lq.mp3', - MagicNotification: 0, - MagicFlash: 1, - MagicSound: 1, - MagicVolume: 100, - MagicSoundURL: 'https://freesound.org/data/previews/221/221683_1015240-lq.mp3', - WrinklerNotification: 0, - WrinklerFlash: 1, - WrinklerSound: 1, - WrinklerVolume: 100, - WrinklerSoundURL: 'https://freesound.org/data/previews/124/124186_8043-lq.mp3', - WrinklerMaxNotification: 0, - WrinklerMaxFlash: 1, - WrinklerMaxSound: 1, - WrinklerMaxVolume: 100, - WrinklerMaxSoundURL: 'https://freesound.org/data/previews/152/152743_15663-lq.mp3', - Title: 1, - TooltipBuildUp: 1, - TooltipAmor: 0, - ToolWarnLucky: 1, - ToolWarnConjure: 1, - ToolWarnPos: 1, - TooltipGrim:1, - ToolWrink: 1, - TooltipLump: 1, - DragonAuraInfo: 1, - Stats: 1, - MissingUpgrades: 0, - UpStats: 1, - TimeFormat: 0, - DetailedTime: 1, - GrimoireBar: 1, - Scale: 2, - ScaleDecimals: 2, - ScaleSeparator: 0, - OptionsPref: {BarsColors: 1, Calculation: 1, Notification: 1, Tooltip: 1, Statistics: 1, Notation: 1}, - StatsPref: {Lucky: 1, Conjure: 1, Chain: 1, Prestige: 1, Wrink: 1, Sea: 1, Misc: 1}, - Colors : {Blue: '#4bb8f0', Green: '#00ff00', Yellow: '#ffff00', Orange: '#ff7f00', Red: '#ff0000', Purple: '#ff00ff', Gray: '#b3b3b3', Pink: '#ff1493', Brown: '#8b4513'}, - SortBuildings: 0, - SortUpgrades: 0 -}; CM.ConfigPrefix = 'CMConfig'; CM.VersionMajor = '2.031'; From a8002f29e3fa2abd86609aa0e7fba065042749b7 Mon Sep 17 00:00:00 2001 From: DanielNoord Date: Fri, 18 Dec 2020 15:38:16 +0100 Subject: [PATCH 057/106] Update issue templates --- .github/ISSUE_TEMPLATE/bug_report.md | 23 +++++++++++++++++++++++ .github/ISSUE_TEMPLATE/feature_request.md | 14 ++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/bug_report.md create mode 100644 .github/ISSUE_TEMPLATE/feature_request.md diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..e42ac53 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,23 @@ +--- +name: Bug report +about: Please use this template to report bugs you might have found +title: '' +labels: Bug +assignees: '' + +--- + +**Describe the bug** +Please describe the bug and what you would have expected the mod to do + +**To Reproduce** +The steps needed to reproduce the behavior: +1. ... + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**Save file** +``` +If applicable please copy your save file here +``` diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..4daa125 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,14 @@ +--- +name: Feature request +about: Suggest an idea for CookieMonster +title: '' +labels: Enhancement +assignees: '' + +--- + +**Describe the function you'd like to see added to CookieMonster** +A clear and concise description of what you want to happen. + +**Additional files** +Add any other files such as save files or screenshots about the feature request here. From e230a3c89edfbd8860693066382bd438604d5613 Mon Sep 17 00:00:00 2001 From: DanielNoord Date: Fri, 18 Dec 2020 15:45:22 +0100 Subject: [PATCH 058/106] Update README.md --- README.md | 43 ++++++++----------------------------------- 1 file changed, 8 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index 570bff9..0a9ee61 100644 --- a/README.md +++ b/README.md @@ -4,15 +4,15 @@ This is a helper, and it is here to help you at *whichever* degree you want, if you only need some help shortening long numbers, it does that. If you need to be accompanied by hand to pick the best buildings to buy, it does that, but **everything is an option**. -## Current version - +### Current version You can see the current version, and a full history of all versions and what they changed by consulting the [releases page](https://github.com/Aktanusa/CookieMonster/releases). ## What it does -At its core, Cookie Monster computes an index on both buildings and upgrades: - -* **Payback Period (PP)**: Indicates how much a building is worth by using the formula max(cost - cookies in bank, 0)/cps + cost/Δ cps +At its core, Cookie Monster computes an index for both buildings and upgrades: the **Payback Period (PP)**. This indicates how much a building is worth by using the following formula: +``` +max(cost - cookies in bank, 0)/cps + cost/Δ cps +``` Cookie Monster also indicates the time left before being able to buy an upgrade or building, and takes it into consideration. It will take *everything* in consideration, meaning if buying a building also unlocks an achievement which boosts your income, which unlocks an achievement, it will know and highlight that building's value. @@ -60,14 +60,6 @@ javascript: (function () { If (for some reason) the above doesn't work, trying pasting everything after the javascript: bit into your browser's console. -For beta, use the following instead: - -```javascript -javascript: (function () { - Game.LoadMod('https://aktanusa.github.io/CookieMonster/CookieMonsterBeta.js'); -}()); -``` - ## Userscript If you'd rather use the addon as a script via per example *Greasemonkey* or *Tampermonkey*, you can use the following script, which will automatically load *Cookie Monster* every time the original game loads. You may need to specify http://orteil.dashnet.org/cookieclicker/ when asked for a *namespace* or *includes*. For how to add an userscript to your browser, refer to your browser/plugin's documentation as the method changes for each one. @@ -91,31 +83,10 @@ If you'd rather use the addon as a script via per example *Greasemonkey* or *Tam }, 1000); })(); ``` -If you are using the beta, use this instead: - -```javascript -// ==UserScript== -// @name Cookie Monster Beta -// @namespace Cookie -// @include http://orteil.dashnet.org/cookieclicker/beta/ -// @include https://orteil.dashnet.org/cookieclicker/beta/ -// @version 1 -// @grant none -// ==/UserScript== - -(function() { - const checkReady = setInterval(function() { - if (typeof Game.ready !== 'undefined' && Game.ready) { - Game.LoadMod('https://aktanusa.github.io/CookieMonster/CookieMonsterBeta.js'); - clearInterval(checkReady); - } - }, 1000); -})(); -``` # Bugs and suggestions -Any bug or suggestion should be **opened as an issue** [in the repository](https://github.com/Aktanusa/CookieMonster/issues) for easier tracking. This allows me to close issues once they're fixed. +Any bug or suggestion should be **opened as an issue** [in the repository](https://github.com/Aktanusa/CookieMonster/issues) for easier tracking. This allows us to close issues once they're fixed. Before submitting a bug, make sure to give a shot at the latest version of the addon on the dev branch. For this, use the following bookmarklet: @@ -138,3 +109,5 @@ All suggestions are welcome, even the smallest ones. * **[BlackenedGem](https://github.com/BlackenedGem)**: Golden/Wrath Cookie Favicons * **[Sandworm](https://github.com/svschouw)**: Modified PP calculation * **[Aktanusa](https://github.com/Aktanusa)**: Current maintainer +* **[DanielNoord](https://github.com/DanielNoord)**: Current maintainer +* **[bitsandbytes1708](https://github.com/bitsandbytes1708)**: Current maintainer From b65f31bee1550bd23f56d5a16bde3fd661601cc3 Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Fri, 18 Dec 2020 16:12:33 +0100 Subject: [PATCH 059/106] Stats displays reward pop all normal wrinkler --- CookieMonster.js | 25 ++++++++++++++----------- src/Cache.js | 15 +++++++++------ src/Disp.js | 10 +++++----- 3 files changed, 28 insertions(+), 22 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index 557fb22..e970519 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -80,6 +80,8 @@ CM.Cache.RemakeIncome = function() { } CM.Cache.RemakeWrinkBank = function() { + CM.Cache.WrinkBankTotal = 0; + CM.Cache.WrinkBankNormal = 0; var totalSucked = 0; for (var i in Game.wrinklers) { var sucked = Game.wrinklers[i].sucked; @@ -94,10 +96,10 @@ CM.Cache.RemakeWrinkBank = function() { else if (godLvl == 2) sucked *= 1.1; else if (godLvl == 3) sucked *= 1.05; } - totalSucked += sucked; + CM.Cache.WrinkBankTotal += sucked; + if (Game.wrinklers[i].type == 0) CM.Cache.WrinkBankNormal += sucked; } - CM.Cache.WrinkBank = totalSucked; - CM.Cache.WrinkGodBank = totalSucked; + CM.Cache.WrinkGodBank = CM.Cache.WrinkBankTotal; if (CM.Sim.Objects.Temple.minigameLoaded) { var godLvl = CM.Sim.hasGod('scorn'); if (godLvl == 2) CM.Cache.WrinkGodBank = CM.Cache.WrinkGodBank * 1.15 / 1.1; @@ -414,7 +416,7 @@ CM.Cache.UpdateAvgCPS = function() { if (CM.Cache.lastDate != -1) { var timeDiff = currDate - CM.Cache.lastDate var bankDiffAvg = Math.max(0, (Game.cookies - CM.Cache.lastCookies)) / timeDiff; - var wrinkDiffAvg = Math.max(0, (CM.Cache.WrinkBank - CM.Cache.lastWrinkCookies)) / timeDiff; + var wrinkDiffAvg = Math.max(0, (CM.Cache.WrinkBankTotal - CM.Cache.lastWrinkCookies)) / timeDiff; var choEggDiffAvg = Math.max(0,(choEggTotal - CM.Cache.lastChoEgg)) / timeDiff; var clicksDiffAvg = (Game.cookieClicks - CM.Cache.lastClicks) / timeDiff; for (var i = 0; i < timeDiff; i++) { @@ -436,7 +438,7 @@ CM.Cache.UpdateAvgCPS = function() { } CM.Cache.lastDate = currDate; CM.Cache.lastCookies = Game.cookies; - CM.Cache.lastWrinkCookies = CM.Cache.WrinkBank; + CM.Cache.lastWrinkCookies = CM.Cache.WrinkBankTotal; CM.Cache.lastChoEgg = choEggTotal; CM.Cache.lastClicks = Game.cookieClicks; @@ -519,7 +521,8 @@ CM.Cache.CalcMissingUpgrades = function() { CM.Cache.min = -1; CM.Cache.max = -1; CM.Cache.mid = -1; -CM.Cache.WrinkBank = -1; +CM.Cache.WrinkBankTotal = -1; +CM.Cache.WrinkBankNormal = -1; CM.Cache.WrinkGodBank = -1; CM.Cache.GoldenCookiesMult = 1; CM.Cache.WrathCookiesMult = 1; @@ -1012,11 +1015,11 @@ CM.Data.ConfigDefault = { /** * This function returns the total amount stored in the Wrinkler Bank * as calculated by CM.Cache.RemakeWrinkBank() if CM.Config.CalcWrink is set - * @returns {number} 0 or the amount of cookies stored (CM.Cache.WrinkBank) + * @returns {number} 0 or the amount of cookies stored (CM.Cache.WrinkBankTotal) */ CM.Disp.GetWrinkConfigBank = function() { if (CM.Config.CalcWrink) - return CM.Cache.WrinkBank; + return CM.Cache.WrinkBankTotal; else return 0; } @@ -3091,13 +3094,13 @@ CM.Disp.AddMenuStats = function(title) { stats.appendChild(CM.Disp.CreateStatsHeader('Wrinklers', 'Wrink')); if (CM.Config.StatsPref.Wrink) { var popAllFrag = document.createDocumentFragment(); - popAllFrag.appendChild(document.createTextNode(Beautify(CM.Cache.WrinkBank) + ' ')); + popAllFrag.appendChild(document.createTextNode(Beautify(CM.Cache.WrinkBankTotal) + ' / ' + Beautify(CM.Cache.WrinkBankNormal) + ' ')); var popAllA = document.createElement('a'); popAllA.textContent = 'Pop All Normal'; popAllA.className = 'option'; - popAllA.onclick = function() { CM.Disp.CollectWrinklers(); }; + popAllA.onclick = function() { CM.Disp.PopAllNormalWrinklers(); }; popAllFrag.appendChild(popAllA); - stats.appendChild(CM.Disp.CreateStatsListing("basic", 'Rewards of Popping', popAllFrag)); + stats.appendChild(CM.Disp.CreateStatsListing("basic", 'Rewards of Popping (All/Normal)', popAllFrag)); } } diff --git a/src/Cache.js b/src/Cache.js index 84eb53a..74764ab 100644 --- a/src/Cache.js +++ b/src/Cache.js @@ -53,6 +53,8 @@ CM.Cache.RemakeIncome = function() { } CM.Cache.RemakeWrinkBank = function() { + CM.Cache.WrinkBankTotal = 0; + CM.Cache.WrinkBankNormal = 0; var totalSucked = 0; for (var i in Game.wrinklers) { var sucked = Game.wrinklers[i].sucked; @@ -67,10 +69,10 @@ CM.Cache.RemakeWrinkBank = function() { else if (godLvl == 2) sucked *= 1.1; else if (godLvl == 3) sucked *= 1.05; } - totalSucked += sucked; + CM.Cache.WrinkBankTotal += sucked; + if (Game.wrinklers[i].type == 0) CM.Cache.WrinkBankNormal += sucked; } - CM.Cache.WrinkBank = totalSucked; - CM.Cache.WrinkGodBank = totalSucked; + CM.Cache.WrinkGodBank = CM.Cache.WrinkBankTotal; if (CM.Sim.Objects.Temple.minigameLoaded) { var godLvl = CM.Sim.hasGod('scorn'); if (godLvl == 2) CM.Cache.WrinkGodBank = CM.Cache.WrinkGodBank * 1.15 / 1.1; @@ -387,7 +389,7 @@ CM.Cache.UpdateAvgCPS = function() { if (CM.Cache.lastDate != -1) { var timeDiff = currDate - CM.Cache.lastDate var bankDiffAvg = Math.max(0, (Game.cookies - CM.Cache.lastCookies)) / timeDiff; - var wrinkDiffAvg = Math.max(0, (CM.Cache.WrinkBank - CM.Cache.lastWrinkCookies)) / timeDiff; + var wrinkDiffAvg = Math.max(0, (CM.Cache.WrinkBankTotal - CM.Cache.lastWrinkCookies)) / timeDiff; var choEggDiffAvg = Math.max(0,(choEggTotal - CM.Cache.lastChoEgg)) / timeDiff; var clicksDiffAvg = (Game.cookieClicks - CM.Cache.lastClicks) / timeDiff; for (var i = 0; i < timeDiff; i++) { @@ -409,7 +411,7 @@ CM.Cache.UpdateAvgCPS = function() { } CM.Cache.lastDate = currDate; CM.Cache.lastCookies = Game.cookies; - CM.Cache.lastWrinkCookies = CM.Cache.WrinkBank; + CM.Cache.lastWrinkCookies = CM.Cache.WrinkBankTotal; CM.Cache.lastChoEgg = choEggTotal; CM.Cache.lastClicks = Game.cookieClicks; @@ -492,7 +494,8 @@ CM.Cache.CalcMissingUpgrades = function() { CM.Cache.min = -1; CM.Cache.max = -1; CM.Cache.mid = -1; -CM.Cache.WrinkBank = -1; +CM.Cache.WrinkBankTotal = -1; +CM.Cache.WrinkBankNormal = -1; CM.Cache.WrinkGodBank = -1; CM.Cache.GoldenCookiesMult = 1; CM.Cache.WrathCookiesMult = 1; diff --git a/src/Disp.js b/src/Disp.js index 1db11f2..13cbcc9 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -13,11 +13,11 @@ /** * This function returns the total amount stored in the Wrinkler Bank * as calculated by CM.Cache.RemakeWrinkBank() if CM.Config.CalcWrink is set - * @returns {number} 0 or the amount of cookies stored (CM.Cache.WrinkBank) + * @returns {number} 0 or the amount of cookies stored (CM.Cache.WrinkBankTotal) */ CM.Disp.GetWrinkConfigBank = function() { if (CM.Config.CalcWrink) - return CM.Cache.WrinkBank; + return CM.Cache.WrinkBankTotal; else return 0; } @@ -2092,13 +2092,13 @@ CM.Disp.AddMenuStats = function(title) { stats.appendChild(CM.Disp.CreateStatsHeader('Wrinklers', 'Wrink')); if (CM.Config.StatsPref.Wrink) { var popAllFrag = document.createDocumentFragment(); - popAllFrag.appendChild(document.createTextNode(Beautify(CM.Cache.WrinkBank) + ' ')); + popAllFrag.appendChild(document.createTextNode(Beautify(CM.Cache.WrinkBankTotal) + ' / ' + Beautify(CM.Cache.WrinkBankNormal) + ' ')); var popAllA = document.createElement('a'); popAllA.textContent = 'Pop All Normal'; popAllA.className = 'option'; - popAllA.onclick = function() { CM.Disp.CollectWrinklers(); }; + popAllA.onclick = function() { CM.Disp.PopAllNormalWrinklers(); }; popAllFrag.appendChild(popAllA); - stats.appendChild(CM.Disp.CreateStatsListing("basic", 'Rewards of Popping', popAllFrag)); + stats.appendChild(CM.Disp.CreateStatsListing("basic", 'Rewards of Popping (All/Normal)', popAllFrag)); } } From f6f2f99966e2525ef208528a9e50801600d57af3 Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Fri, 18 Dec 2020 16:49:14 +0100 Subject: [PATCH 060/106] Choc egg tooltip shows cookies to be gained --- CookieMonster.js | 10 ++++++++++ src/Disp.js | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/CookieMonster.js b/CookieMonster.js index e970519..3dfdced 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -2526,6 +2526,16 @@ CM.Disp.UpdateTooltipUpgrade = function() { var timeColor = CM.Disp.GetTimeColor((CM.Disp.TooltipPrice - (Game.cookies + CM.Disp.GetWrinkConfigBank())) / CM.Disp.GetCPS()); l('CMTooltipTime').textContent = timeColor.text; l('CMTooltipTime').className = CM.Disp.colorTextPre + timeColor.color; + + // Add extra info to Chocolate egg tooltip + if (Game.UpgradesInStore[CM.Disp.tooltipName].name == "Chocolate egg") { + l('CMTooltipBorder').lastChild.style.marginBottom = '4px'; + l('CMTooltipBorder').appendChild(CM.Disp.TooltipCreateHeader('Cookies to be gained (Currently/Max)')); + var chocolate = document.createElement('div'); + chocolate.style.color = 'white'; + chocolate.textContent = CM.Disp.Beautify(Game.cookies * 0.05) + " / " + CM.Disp.Beautify(CM.Cache.lastChoEgg); + l('CMTooltipBorder').appendChild(chocolate); + } } } diff --git a/src/Disp.js b/src/Disp.js index 13cbcc9..5a6e8c3 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -1524,6 +1524,16 @@ CM.Disp.UpdateTooltipUpgrade = function() { var timeColor = CM.Disp.GetTimeColor((CM.Disp.TooltipPrice - (Game.cookies + CM.Disp.GetWrinkConfigBank())) / CM.Disp.GetCPS()); l('CMTooltipTime').textContent = timeColor.text; l('CMTooltipTime').className = CM.Disp.colorTextPre + timeColor.color; + + // Add extra info to Chocolate egg tooltip + if (Game.UpgradesInStore[CM.Disp.tooltipName].name == "Chocolate egg") { + l('CMTooltipBorder').lastChild.style.marginBottom = '4px'; + l('CMTooltipBorder').appendChild(CM.Disp.TooltipCreateHeader('Cookies to be gained (Currently/Max)')); + var chocolate = document.createElement('div'); + chocolate.style.color = 'white'; + chocolate.textContent = CM.Disp.Beautify(Game.cookies * 0.05) + " / " + CM.Disp.Beautify(CM.Cache.lastChoEgg); + l('CMTooltipBorder').appendChild(chocolate); + } } } From 73ca07a0e93cd526c0ea0cbbb724b3fa68a30075 Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Fri, 18 Dec 2020 17:17:54 +0100 Subject: [PATCH 061/106] Partial rewrite of Config.js --- CookieMonster.js | 48 +++++++++++++++++++++++++++++++----------------- src/Cache.js | 3 ++- src/Config.js | 40 +++++++++++++++++++++++++++------------- src/Disp.js | 4 +--- 4 files changed, 61 insertions(+), 34 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index 3dfdced..cbcb41d 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -575,14 +575,29 @@ CM.Cache.spawnedGoldenShimmer = 0; * This variables are used by CM.Cache.CacheDragonAuras(), naming follows naming in Game */ CM.Cache.dragonAura = 0; -CM.Cache.dragonAura2 = 0;/********** +CM.Cache.dragonAura2 = 0; + +/********** * Config * **********/ +/******** + * Section: Functions related to saving, loading and restoring configs */ + +/** + * This function saves the config of CookieMonster to localStorage + * It is called by CM.LoadConfig(), CM.RestoreDefault(), + * any of the CM.ToggleConfig() functions and upon changes to URL or volume settings + * @param {object} config The Config to be saved (normally CM.Config) + */ CM.SaveConfig = function(config) { localStorage.setItem(CM.ConfigPrefix, JSON.stringify(config)); } +/** + * This function loads the config of CookieMonster saved in localStorage and loads it into CM.Config + * It is called by CM.DelayInit() and CM.RestoreDefault() + */ CM.LoadConfig = function() { if (localStorage.getItem(CM.ConfigPrefix) != null) { CM.Config = JSON.parse(localStorage.getItem(CM.ConfigPrefix)); @@ -638,6 +653,10 @@ CM.LoadConfig = function() { } } +/** + * This function reloads and resaves the default config as stored in CM.Data.ConfigDefault + * It is called by resDefBut.onclick loaded in the options page or by CM.LoadConfig is no localStorage is found + */ CM.RestoreDefault = function() { CM.Config = {}; CM.SaveConfig(CM.Data.ConfigDefault); @@ -645,6 +664,15 @@ CM.RestoreDefault = function() { Game.UpdateMenu(); } +/******** + * Section: Functions related to toggling or changing configs */ + +/** + * This function toggles options which are considered "toggles" + * These have off (1) and on (1) states + * It is called by the onclick event of options of the "bool" type + * @param {string} config The name of the option + */ CM.ToggleConfig = function(config) { CM.ToggleConfigUp(config); if (CM.ConfigData[config].toggle) { @@ -669,22 +697,10 @@ CM.ToggleConfigUp = function(config) { CM.SaveConfig(CM.Config); } -CM.ToggleConfigDown = function(config) { - CM.Config[config]--; - if (CM.Config[config] < 0) { - CM.Config[config] = CM.ConfigData[config].label.length - 1; - } - if (typeof CM.ConfigData[config].func !== 'undefined') { - CM.ConfigData[config].func(); - } - l(CM.ConfigPrefix + config).innerHTML = CM.ConfigData[config].label[CM.Config[config]]; - CM.SaveConfig(CM.Config); -} - /** * This function sets the value of the specified volume-option and updates the display in the options menu * It is called by CM.Disp.CreatePrefOption() - * @param {string} config The name of the option + * @param {string} config The name of the option */ CM.ToggleConfigVolume = function(config) { if (l("slider" + config) != null) { @@ -2895,11 +2911,9 @@ CM.Disp.AddMenuPref = function(title) { */ CM.Disp.CreatePrefHeader = function(config, text) { var div = document.createElement('div'); - div.className = 'listing'; - div.style.padding = '5px 16px'; + div.className = 'title'; div.style.opacity = '0.7'; div.style.fontSize = '17px'; - div.style.fontFamily = '\"Kavoon\", Georgia, serif'; div.appendChild(document.createTextNode(text + ' ')); var span = document.createElement('span'); // Creates the +/- button span.style.cursor = 'pointer'; diff --git a/src/Cache.js b/src/Cache.js index 74764ab..f9dfa39 100644 --- a/src/Cache.js +++ b/src/Cache.js @@ -548,4 +548,5 @@ CM.Cache.spawnedGoldenShimmer = 0; * This variables are used by CM.Cache.CacheDragonAuras(), naming follows naming in Game */ CM.Cache.dragonAura = 0; -CM.Cache.dragonAura2 = 0; \ No newline at end of file +CM.Cache.dragonAura2 = 0; + diff --git a/src/Config.js b/src/Config.js index e639651..8438360 100644 --- a/src/Config.js +++ b/src/Config.js @@ -2,10 +2,23 @@ * Config * **********/ +/******** + * Section: Functions related to saving, loading and restoring configs */ + +/** + * This function saves the config of CookieMonster to localStorage + * It is called by CM.LoadConfig(), CM.RestoreDefault(), + * any of the CM.ToggleConfig() functions and upon changes to URL or volume settings + * @param {object} config The Config to be saved (normally CM.Config) + */ CM.SaveConfig = function(config) { localStorage.setItem(CM.ConfigPrefix, JSON.stringify(config)); } +/** + * This function loads the config of CookieMonster saved in localStorage and loads it into CM.Config + * It is called by CM.DelayInit() and CM.RestoreDefault() + */ CM.LoadConfig = function() { if (localStorage.getItem(CM.ConfigPrefix) != null) { CM.Config = JSON.parse(localStorage.getItem(CM.ConfigPrefix)); @@ -61,6 +74,10 @@ CM.LoadConfig = function() { } } +/** + * This function reloads and resaves the default config as stored in CM.Data.ConfigDefault + * It is called by resDefBut.onclick loaded in the options page or by CM.LoadConfig is no localStorage is found + */ CM.RestoreDefault = function() { CM.Config = {}; CM.SaveConfig(CM.Data.ConfigDefault); @@ -68,6 +85,15 @@ CM.RestoreDefault = function() { Game.UpdateMenu(); } +/******** + * Section: Functions related to toggling or changing configs */ + +/** + * This function toggles options which are considered "toggles" + * These have off (1) and on (1) states + * It is called by the onclick event of options of the "bool" type + * @param {string} config The name of the option + */ CM.ToggleConfig = function(config) { CM.ToggleConfigUp(config); if (CM.ConfigData[config].toggle) { @@ -92,22 +118,10 @@ CM.ToggleConfigUp = function(config) { CM.SaveConfig(CM.Config); } -CM.ToggleConfigDown = function(config) { - CM.Config[config]--; - if (CM.Config[config] < 0) { - CM.Config[config] = CM.ConfigData[config].label.length - 1; - } - if (typeof CM.ConfigData[config].func !== 'undefined') { - CM.ConfigData[config].func(); - } - l(CM.ConfigPrefix + config).innerHTML = CM.ConfigData[config].label[CM.Config[config]]; - CM.SaveConfig(CM.Config); -} - /** * This function sets the value of the specified volume-option and updates the display in the options menu * It is called by CM.Disp.CreatePrefOption() - * @param {string} config The name of the option + * @param {string} config The name of the option */ CM.ToggleConfigVolume = function(config) { if (l("slider" + config) != null) { diff --git a/src/Disp.js b/src/Disp.js index 5a6e8c3..d87eac7 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -1893,11 +1893,9 @@ CM.Disp.AddMenuPref = function(title) { */ CM.Disp.CreatePrefHeader = function(config, text) { var div = document.createElement('div'); - div.className = 'listing'; - div.style.padding = '5px 16px'; + div.className = 'title'; div.style.opacity = '0.7'; div.style.fontSize = '17px'; - div.style.fontFamily = '\"Kavoon\", Georgia, serif'; div.appendChild(document.createTextNode(text + ' ')); var span = document.createElement('span'); // Creates the +/- button span.style.cursor = 'pointer'; From 367702dc0028c3b726714cf1552ff6f25ad1ec2c Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Fri, 18 Dec 2020 17:26:59 +0100 Subject: [PATCH 062/106] Changed CM.Config into CM.Options --- CookieMonster.js | 329 ++++++++++++++++++++++++----------------------- src/Cache.js | 10 +- src/Config.js | 62 ++++----- src/Disp.js | 227 ++++++++++++++++---------------- src/Header.js | 2 + src/Main.js | 28 ++-- 6 files changed, 332 insertions(+), 326 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index cbcb41d..7239d5f 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -18,6 +18,8 @@ RunCookieMonsterHeader = function() { CM.Main = {}; + CM.Options = {}; + CM.Sim = {}; } @@ -113,7 +115,7 @@ CM.Cache.RemakeBuildingsPP = function() { CM.Cache.max = -1; CM.Cache.mid = -1; // Calculate PP and colors when compared to purchase of single optimal building - if (CM.Config.ColorPPBulkMode == 0) { + if (CM.Options.ColorPPBulkMode == 0) { for (var i in CM.Cache.Objects) { //CM.Cache.Objects[i].pp = Game.Objects[i].getPrice() / CM.Cache.Objects[i].bonus; if (Game.cookiesPs) { @@ -446,7 +448,7 @@ CM.Cache.UpdateAvgCPS = function() { var sortedGainWrink = new Array(); var sortedGainChoEgg = new Array(); - var cpsLength = Math.min(CM.Cache.CookiesDiff.getLength(), CM.Disp.cookieTimes[CM.Config.AvgCPSHist]); + var cpsLength = Math.min(CM.Cache.CookiesDiff.getLength(), CM.Disp.cookieTimes[CM.Options.AvgCPSHist]); // Assumes the queues are the same length for (var i = CM.Cache.CookiesDiff.getLength() - cpsLength; i < CM.Cache.CookiesDiff.getLength(); i++) { @@ -480,11 +482,11 @@ CM.Cache.UpdateAvgCPS = function() { totalGainWrink += sortedGainWrink[i]; totalGainChoEgg += sortedGainChoEgg[i]; } - CM.Cache.AvgCPS = (totalGainBank + (CM.Config.CalcWrink ? totalGainWrink : 0)) / sortedGainBank.length; + CM.Cache.AvgCPS = (totalGainBank + (CM.Options.CalcWrink ? totalGainWrink : 0)) / sortedGainBank.length; var choEgg = (Game.HasUnlocked('Chocolate egg') && !Game.Has('Chocolate egg')); - if (choEgg || CM.Config.CalcWrink == 0) { + if (choEgg || CM.Options.CalcWrink == 0) { CM.Cache.AvgCPSChoEgg = (totalGainBank + totalGainWrink + (choEgg ? totalGainChoEgg : 0)) / sortedGainBank.length; } else { @@ -492,7 +494,7 @@ CM.Cache.UpdateAvgCPS = function() { } var totalClicks = 0; - var clicksLength = Math.min(CM.Cache.ClicksDiff.getLength(), CM.Disp.clickTimes[CM.Config.AvgClicksHist]); + var clicksLength = Math.min(CM.Cache.ClicksDiff.getLength(), CM.Disp.clickTimes[CM.Options.AvgClicksHist]); for (var i = CM.Cache.ClicksDiff.getLength() - clicksLength; i < CM.Cache.ClicksDiff.getLength(); i++) { totalClicks += CM.Cache.ClicksDiff.get(i); } @@ -588,59 +590,59 @@ CM.Cache.dragonAura2 = 0; * This function saves the config of CookieMonster to localStorage * It is called by CM.LoadConfig(), CM.RestoreDefault(), * any of the CM.ToggleConfig() functions and upon changes to URL or volume settings - * @param {object} config The Config to be saved (normally CM.Config) + * @param {object} config The Config to be saved (normally CM.Options) */ CM.SaveConfig = function(config) { localStorage.setItem(CM.ConfigPrefix, JSON.stringify(config)); } /** - * This function loads the config of CookieMonster saved in localStorage and loads it into CM.Config + * This function loads the config of CookieMonster saved in localStorage and loads it into CM.Options * It is called by CM.DelayInit() and CM.RestoreDefault() */ CM.LoadConfig = function() { if (localStorage.getItem(CM.ConfigPrefix) != null) { - CM.Config = JSON.parse(localStorage.getItem(CM.ConfigPrefix)); + CM.Options = JSON.parse(localStorage.getItem(CM.ConfigPrefix)); // Check values var mod = false; for (var i in CM.Data.ConfigDefault) { - if (typeof CM.Config[i] === 'undefined') { + if (typeof CM.Options[i] === 'undefined') { mod = true; - CM.Config[i] = CM.Data.ConfigDefault[i]; + CM.Options[i] = CM.Data.ConfigDefault[i]; } else if (i != 'StatsPref' && i != 'Colors') { if (i.indexOf('SoundURL') == -1) { - if (!(CM.Config[i] > -1 && CM.Config[i] < CM.ConfigData[i].label.length)) { + if (!(CM.Options[i] > -1 && CM.Options[i] < CM.ConfigData[i].label.length)) { mod = true; - CM.Config[i] = CM.Data.ConfigDefault[i]; + CM.Options[i] = CM.Data.ConfigDefault[i]; } } else { // Sound URLs - if (typeof CM.Config[i] != 'string') { + if (typeof CM.Options[i] != 'string') { mod = true; - CM.Config[i] = CM.Data.ConfigDefault[i]; + CM.Options[i] = CM.Data.ConfigDefault[i]; } } } else if (i == 'StatsPref') { for (var j in CM.Data.ConfigDefault.StatsPref) { - if (typeof CM.Config[i][j] === 'undefined' || !(CM.Config[i][j] > -1 && CM.Config[i][j] < 2)) { + if (typeof CM.Options[i][j] === 'undefined' || !(CM.Options[i][j] > -1 && CM.Options[i][j] < 2)) { mod = true; - CM.Config[i][j] = CM.Data.ConfigDefault[i][j]; + CM.Options[i][j] = CM.Data.ConfigDefault[i][j]; } } } else { // Colors for (var j in CM.Data.ConfigDefault.Colors) { - if (typeof CM.Config[i][j] === 'undefined' || typeof CM.Config[i][j] != 'string') { + if (typeof CM.Options[i][j] === 'undefined' || typeof CM.Options[i][j] != 'string') { mod = true; - CM.Config[i][j] = CM.Data.ConfigDefault[i][j]; + CM.Options[i][j] = CM.Data.ConfigDefault[i][j]; } } } } - if (mod) CM.SaveConfig(CM.Config); + if (mod) CM.SaveConfig(CM.Options); CM.Loop(); // Do loop once for (var i in CM.Data.ConfigDefault) { if (i != 'StatsPref' && i != 'OptionsPref' && typeof CM.ConfigData[i].func !== 'undefined') { @@ -658,7 +660,7 @@ CM.LoadConfig = function() { * It is called by resDefBut.onclick loaded in the options page or by CM.LoadConfig is no localStorage is found */ CM.RestoreDefault = function() { - CM.Config = {}; + CM.Options = {}; CM.SaveConfig(CM.Data.ConfigDefault); CM.LoadConfig(); Game.UpdateMenu(); @@ -676,7 +678,7 @@ CM.RestoreDefault = function() { CM.ToggleConfig = function(config) { CM.ToggleConfigUp(config); if (CM.ConfigData[config].toggle) { - if (CM.Config[config] == 0) { + if (CM.Options[config] == 0) { l(CM.ConfigPrefix + config).className = 'option off'; } else { @@ -686,15 +688,15 @@ CM.ToggleConfig = function(config) { } CM.ToggleConfigUp = function(config) { - CM.Config[config]++; - if (CM.Config[config] == CM.ConfigData[config].label.length) { - CM.Config[config] = 0; + CM.Options[config]++; + if (CM.Options[config] == CM.ConfigData[config].label.length) { + CM.Options[config] = 0; } if (typeof CM.ConfigData[config].func !== 'undefined') { CM.ConfigData[config].func(); } - l(CM.ConfigPrefix + config).innerHTML = CM.ConfigData[config].label[CM.Config[config]]; - CM.SaveConfig(CM.Config); + l(CM.ConfigPrefix + config).innerHTML = CM.ConfigData[config].label[CM.Options[config]]; + CM.SaveConfig(CM.Options); } /** @@ -705,29 +707,29 @@ CM.ToggleConfigUp = function(config) { CM.ToggleConfigVolume = function(config) { if (l("slider" + config) != null) { l("slider" + config + "right").innerHTML = l("slider" + config).value + "%"; - CM.Config[config] = Math.round(l("slider" + config).value); + CM.Options[config] = Math.round(l("slider" + config).value); } - CM.SaveConfig(CM.Config); + CM.SaveConfig(CM.Options); } CM.ToggleStatsConfig = function(config) { - if (CM.Config.StatsPref[config] == 0) { - CM.Config.StatsPref[config]++; + if (CM.Options.StatsPref[config] == 0) { + CM.Options.StatsPref[config]++; } else { - CM.Config.StatsPref[config]--; + CM.Options.StatsPref[config]--; } - CM.SaveConfig(CM.Config); + CM.SaveConfig(CM.Options); } CM.ToggleOptionsConfig = function(config) { - if (CM.Config.OptionsPref[config] == 0) { - CM.Config.OptionsPref[config]++; + if (CM.Options.OptionsPref[config] == 0) { + CM.Options.OptionsPref[config]++; } else { - CM.Config.OptionsPref[config]--; + CM.Options.OptionsPref[config]--; } - CM.SaveConfig(CM.Config); + CM.SaveConfig(CM.Options); } // Checks if the browsers has permissions to produce notifications @@ -1030,11 +1032,11 @@ CM.Data.ConfigDefault = { /** * This function returns the total amount stored in the Wrinkler Bank - * as calculated by CM.Cache.RemakeWrinkBank() if CM.Config.CalcWrink is set + * as calculated by CM.Cache.RemakeWrinkBank() if CM.Options.CalcWrink is set * @returns {number} 0 or the amount of cookies stored (CM.Cache.WrinkBankTotal) */ CM.Disp.GetWrinkConfigBank = function() { - if (CM.Config.CalcWrink) + if (CM.Options.CalcWrink) return CM.Cache.WrinkBankTotal; else return 0; @@ -1053,11 +1055,11 @@ CM.Disp.PopAllNormalWrinklers = function() { } /** - * This function returns the cps as either current or average CPS depending on CM.Config.CPSMode + * This function returns the cps as either current or average CPS depending on CM.Options.CPSMode * @returns {number} The average or current cps */ CM.Disp.GetCPS = function() { - if (CM.Config.CPSMode) + if (CM.Options.CPSMode) return CM.Cache.AvgCPS; else return (Game.cookiesPs * (1 - Game.cpsSucked)); @@ -1139,7 +1141,7 @@ CM.Disp.FormatTime = function(time, longFormat) { var m = Math.floor(time % 3600 / 60); var s = Math.floor(time % 60); var str = ''; - if (CM.Config.TimeFormat) { + if (CM.Options.TimeFormat) { if (time > 3155760000) return 'XX:XX:XX:XX:XX'; str += (y < 10 ? '0' : '') + y + ':'; str += (d < 10 ? '0' : '') + d + ':'; @@ -1165,7 +1167,7 @@ CM.Disp.GetTimeColor = function(time) { var color; var text; if (time < 0) { - if (CM.Config.TimeFormat) text = '00:00:00:00:00'; + if (CM.Options.TimeFormat) text = '00:00:00:00:00'; else text = 'Done!'; color = CM.Disp.colorGreen; } @@ -1186,8 +1188,8 @@ CM.Disp.GetTimeColor = function(time) { * @returns {string} Formatted number */ CM.Disp.Beautify = function(num, frac, forced) { - var decimals = CM.Config.ScaleDecimals + 1; - if (CM.Config.Scale == 0) { + var decimals = CM.Options.ScaleDecimals + 1; + if (CM.Options.Scale == 0) { return CM.Backup.Beautify(num, frac); } else if (isFinite(num)) { @@ -1205,8 +1207,8 @@ CM.Disp.Beautify = function(num, frac, forced) { // TODO: Add changing separators of thousands and making this cut-off user configurable answer = Math.round(num * 100) / 100; } - else if (CM.Config.Scale == 3 && !forced || forced == 3) { // Scientific notation, 123456789 => 1.235E+8 - answer = num[0] + (CM.Config.ScaleSeparator ? ',' : '.'); + else if (CM.Options.Scale == 3 && !forced || forced == 3) { // Scientific notation, 123456789 => 1.235E+8 + answer = num[0] + (CM.Options.ScaleSeparator ? ',' : '.'); i = 0; while (i < decimals - 1) { answer += num[i + 2]; // num has a 0-based index and [1] is a '.' @@ -1231,13 +1233,13 @@ CM.Disp.Beautify = function(num, frac, forced) { numbersToAdd = (restOfNumber.indexOf('.') > -1 ? restOfNumber.indexOf('.') + 1 + decimals : (restOfNumber.length)) i = 0 while (i < numbersToAdd - 1 && i < restOfNumber.length - 1) { - answer += (CM.Config.ScaleSeparator && restOfNumber[i] == '.' ? ',' : restOfNumber[i]); + answer += (CM.Options.ScaleSeparator && restOfNumber[i] == '.' ? ',' : restOfNumber[i]); i++ } answer += (i + 1 < restOfNumber.length ? Math.round(restOfNumber[i] + '.' + restOfNumber[i + 1]) : restOfNumber[i]); // answer is now "xxx.xx" (e.g., 123456789 would be 123.46) - if (CM.Config.Scale == 1 && !forced || forced == 1) { // Metric scale, 123456789 => 123.457 M + if (CM.Options.Scale == 1 && !forced || forced == 1) { // Metric scale, 123456789 => 123.457 M if (timesTenToPowerThree - 1 < CM.Data.metric.length) { answer += ' ' + CM.Data.metric[timesTenToPowerThree - 1] } @@ -1245,7 +1247,7 @@ CM.Disp.Beautify = function(num, frac, forced) { return CM.Disp.Beautify(num, 0, 3); } } - else if (CM.Config.Scale == 2 && !forced || forced == 2) { // Short scale, 123456789 => 123.457 M + else if (CM.Options.Scale == 2 && !forced || forced == 2) { // Short scale, 123456789 => 123.457 M if (timesTenToPowerThree < CM.Data.shortScale.length + 1) { answer += ' ' + CM.Data.shortScale[timesTenToPowerThree - 1]; } @@ -1253,7 +1255,7 @@ CM.Disp.Beautify = function(num, frac, forced) { return CM.Disp.Beautify(num, 0, 3); } } - else if (CM.Config.Scale == 4 && !forced || forced == 4) { // Engineering notation, 123456789 => 123.457E+6 + else if (CM.Options.Scale == 4 && !forced || forced == 4) { // Engineering notation, 123456789 => 123.457E+6 answer += 'E+' + (timesTenToPowerThree * 3); } } @@ -1283,8 +1285,8 @@ CM.Disp.Beautify = function(num, frac, forced) { CM.Disp.UpdateAscendState = function() { if (Game.OnAscend) { l('game').style.bottom = '0px'; - if (CM.Config.BotBar == 1) CM.Disp.BotBar.style.display = 'none'; - if (CM.Config.TimerBar == 1) CM.Disp.TimerBar.style.display = 'none'; + if (CM.Options.BotBar == 1) CM.Disp.BotBar.style.display = 'none'; + if (CM.Options.TimerBar == 1) CM.Disp.TimerBar.style.display = 'none'; } else { CM.Disp.ToggleBotBar(); @@ -1335,7 +1337,7 @@ CM.Disp.Draw = function () { // Draw autosave timer in stats menu if ( (Game.prefs.autosave && Game.drawT % 10 == 0) && // with autosave ON and every 10 ticks - (Game.onMenu == 'stats' && CM.Config.Stats) // while being on the stats menu only + (Game.onMenu == 'stats' && CM.Options.Stats) // while being on the stats menu only ) { var timer = document.getElementById('CMStatsAutosaveTimer'); if (timer) { @@ -1349,10 +1351,10 @@ CM.Disp.Draw = function () { /** * This function toggle the bottom bar - * It is called by CM.Disp.UpdateAscendState() and a change in CM.Config.BotBar + * It is called by CM.Disp.UpdateAscendState() and a change in CM.Options.BotBar */ CM.Disp.ToggleBotBar = function() { - if (CM.Config.BotBar == 1) { + if (CM.Options.BotBar == 1) { CM.Disp.BotBar.style.display = ''; CM.Disp.UpdateBotBar(); } @@ -1364,7 +1366,7 @@ CM.Disp.ToggleBotBar = function() { /** * This function creates the bottom bar and appends it to l('wrapper') - * It is called by CM.DelayInit and a change in CM.Config.BotBar + * It is called by CM.DelayInit and a change in CM.Options.BotBar */ CM.Disp.CreateBotBar = function() { CM.Disp.BotBar = document.createElement('div'); @@ -1418,7 +1420,7 @@ CM.Disp.CreateBotBar = function() { * It is called by CM.Loop() */ CM.Disp.UpdateBotBar = function() { - if (CM.Config.BotBar == 1) { + if (CM.Options.BotBar == 1) { var count = 0; for (var i in CM.Cache.Objects) { var target = 'Objects'; @@ -1567,7 +1569,7 @@ CM.Disp.TimerBarCreateBar = function(id, name, bars) { * It is called by CM.Loop() */ CM.Disp.UpdateTimerBar = function() { - if (CM.Config.TimerBar == 1) { + if (CM.Options.TimerBar == 1) { // label width: 113, timer width: 26, div margin: 20 var maxWidth = CM.Disp.TimerBar.offsetWidth - 159; var numberOfTimers = 0; @@ -1642,20 +1644,20 @@ CM.Disp.UpdateTimerBar = function() { /** * This function changes the visibility of the timer bar - * It is called by CM.Disp.UpdateAscendState() or a change in CM.Config.TimerBar + * It is called by CM.Disp.UpdateAscendState() or a change in CM.Options.TimerBar */ CM.Disp.ToggleTimerBar = function() { - if (CM.Config.TimerBar == 1) CM.Disp.TimerBar.style.display = ''; + if (CM.Options.TimerBar == 1) CM.Disp.TimerBar.style.display = ''; else CM.Disp.TimerBar.style.display = 'none'; CM.Disp.UpdateBotTimerBarPosition(); } /** * This function changes the position of the timer bar - * It is called by a change in CM.Config.TimerBarPos + * It is called by a change in CM.Options.TimerBarPos */ CM.Disp.ToggleTimerBarPos = function() { - if (CM.Config.TimerBarPos == 0) { + if (CM.Options.TimerBarPos == 0) { CM.Disp.TimerBar.style.width = '30%'; CM.Disp.TimerBar.style.bottom = ''; l('game').insertBefore(CM.Disp.TimerBar, l('sectionLeft')); @@ -1676,22 +1678,22 @@ CM.Disp.ToggleTimerBarPos = function() { * It is called by CM.Disp.ToggleTimerBar(), CM.Disp.ToggleTimerBarPos() and CM.Disp.ToggleBotBar() */ CM.Disp.UpdateBotTimerBarPosition = function() { - if (CM.Config.BotBar == 1 && CM.Config.TimerBar == 1 && CM.Config.TimerBarPos == 1) { + if (CM.Options.BotBar == 1 && CM.Options.TimerBar == 1 && CM.Options.TimerBarPos == 1) { CM.Disp.BotBar.style.bottom = '48px'; l('game').style.bottom = '118px'; } - else if (CM.Config.BotBar == 1) { + else if (CM.Options.BotBar == 1) { CM.Disp.BotBar.style.bottom = '0px'; l('game').style.bottom = '70px'; } - else if (CM.Config.TimerBar == 1 && CM.Config.TimerBarPos == 1) { + else if (CM.Options.TimerBar == 1 && CM.Options.TimerBarPos == 1) { l('game').style.bottom = '48px'; } else { // No bars l('game').style.bottom = '0px'; } - if (CM.Config.TimerBar == 1 && CM.Config.TimerBarPos == 0) { + if (CM.Options.TimerBar == 1 && CM.Options.TimerBarPos == 0) { l('sectionLeft').style.top = '48px'; } else { @@ -1706,18 +1708,18 @@ CM.Disp.UpdateBotTimerBarPosition = function() { /** * This function adjusts some things in the column of buildings. - * It colours them, helps display the correct sell-price and shuffles the order when CM.Config.SortBuildings is set + * It colours them, helps display the correct sell-price and shuffles the order when CM.Options.SortBuildings is set * The function is called by CM.Loop(), CM.Disp.UpdateColors() & CM.Disp.RefreshScale() - * And by changes in CM.Config.BuildColor, CM.Config.SortBuild & CM.ConfigData.BulkBuildColor + * And by changes in CM.Options.BuildColor, CM.Options.SortBuild & CM.ConfigData.BulkBuildColor */ CM.Disp.UpdateBuildings = function() { - if (CM.Config.BuildColor == 1 && Game.buyMode == 1) { + if (CM.Options.BuildColor == 1 && Game.buyMode == 1) { var target = ''; - if (Game.buyBulk == 10 && CM.Config.BulkBuildColor == 1) target = 'Objects10'; - else if (Game.buyBulk == 100 && CM.Config.BulkBuildColor == 1) target = 'Objects100'; + if (Game.buyBulk == 10 && CM.Options.BulkBuildColor == 1) target = 'Objects10'; + else if (Game.buyBulk == 100 && CM.Options.BulkBuildColor == 1) target = 'Objects100'; else target = 'Objects'; for (var i in CM.Cache[target]) { - l('productPrice' + Game.Objects[i].id).style.color = CM.Config.Colors[CM.Cache[target][i].color]; + l('productPrice' + Game.Objects[i].id).style.color = CM.Options.Colors[CM.Cache[target][i].color]; } } else if (Game.buyMode == -1) { @@ -1739,7 +1741,7 @@ CM.Disp.UpdateBuildings = function() { // Build array of pointers, sort by pp, use array index (+2) as the grid row number // (grid rows are 1-based indexing, and row 1 is the bulk buy/sell options) // This regulates sorting of buildings - if (Game.buyMode == 1 && CM.Config.SortBuildings) { + if (Game.buyMode == 1 && CM.Options.SortBuildings) { var arr = Object.keys(CM.Cache[target]).map(k => { var o = CM.Cache[target][k]; @@ -1770,13 +1772,13 @@ CM.Disp.UpdateBuildings = function() { /** * This function adjusts some things in the upgrades section - * It colours them and shuffles the order when CM.Config.SortBuildings is set + * It colours them and shuffles the order when CM.Options.SortBuildings is set * The function is called by CM.Loop(), CM.Disp.ToggleUpgradeBarAndColor & CM.Disp.RefreshScale() - * And by changes in CM.Config.SortUpgrades + * And by changes in CM.Options.SortUpgrades */ CM.Disp.UpdateUpgrades = function() { // This counts the amount of upgrades for each pp group and updates the Upgrade Bar - if (CM.Config.UpBarColor > 0) { + if (CM.Options.UpBarColor > 0) { var blue = 0; var green = 0; var yellow = 0; @@ -1831,7 +1833,7 @@ CM.Disp.UpdateUpgrades = function() { arr.push(o); } - if (CM.Config.SortUpgrades) + if (CM.Options.SortUpgrades) arr.sort((a, b) => a.pp - b.pp); else arr.sort((a, b) => a.price - b.price); @@ -1846,14 +1848,14 @@ CM.Disp.UpdateUpgrades = function() { /** * This function toggles the upgrade bar and the colours of upgrades - * It is called by a change in CM.Config.UpBarColor + * It is called by a change in CM.Options.UpBarColor */ CM.Disp.ToggleUpgradeBarAndColor = function() { - if (CM.Config.UpBarColor == 1) { // Colours and bar on + if (CM.Options.UpBarColor == 1) { // Colours and bar on CM.Disp.UpgradeBar.style.display = ''; CM.Disp.UpdateUpgrades(); } - else if (CM.Config.UpBarColor == 2) {// Colours on and bar off + else if (CM.Options.UpBarColor == 2) {// Colours on and bar off CM.Disp.UpgradeBar.style.display = 'none'; CM.Disp.UpdateUpgrades(); } @@ -1865,10 +1867,10 @@ CM.Disp.ToggleUpgradeBarAndColor = function() { /** * This function toggles the position of the upgrade bar from fixed or non-fixed mode - * It is called by a change in CM.Config.UpgradeBarFixedPos + * It is called by a change in CM.Options.UpgradeBarFixedPos */ CM.Disp.ToggleUpgradeBarFixedPos = function() { - if (CM.Config.UpgradeBarFixedPos == 1) { // Fix to top of screen when scrolling + if (CM.Options.UpgradeBarFixedPos == 1) { // Fix to top of screen when scrolling CM.Disp.UpgradeBar.style.position = 'sticky'; CM.Disp.UpgradeBar.style.top = '0px'; } @@ -1978,10 +1980,10 @@ CM.Disp.CreateWhiteScreen = function() { * that check game-events and which have settings for Flashes (e.g., Golden Cookies appearing, Magic meter being full) * @param {number} mode Sets the intensity of the flash, used to recursively dim flash * All calls of function have use mode == 3 - * @param {string} config The setting in CM.Config that is checked before creating the flash + * @param {string} config The setting in CM.Options that is checked before creating the flash */ CM.Disp.Flash = function(mode, config) { - if ((CM.Config[config] == 1 && mode == 3) || mode == 1) { + if ((CM.Options[config] == 1 && mode == 3) || mode == 1) { CM.Disp.WhiteScreen.style.opacity = '0.5'; if (mode == 3) { CM.Disp.WhiteScreen.style.display = 'inline'; @@ -2001,14 +2003,14 @@ CM.Disp.Flash = function(mode, config) { /** * This function plays a sound depending on configs. It is called by all functions * that check game-events and which have settings for sound (e.g., Golden Cookies appearing, Magic meter being full) - * @param {variable} url A variable that gives the url for the sound (e.g., CM.Config.GCSoundURL) - * @param {string} sndConfig The setting in CM.Config that is checked before creating the sound - * @param {string} volConfig The setting in CM.Config that is checked to determine volume + * @param {variable} url A variable that gives the url for the sound (e.g., CM.Options.GCSoundURL) + * @param {string} sndConfig The setting in CM.Options that is checked before creating the sound + * @param {string} volConfig The setting in CM.Options that is checked to determine volume */ CM.Disp.PlaySound = function(url, sndConfig, volConfig) { - if (CM.Config[sndConfig] == 1) { + if (CM.Options[sndConfig] == 1) { var sound = new realAudio(url); - sound.volume = (CM.Config[volConfig] / 100) * (Game.volume / 100); + sound.volume = (CM.Options[volConfig] / 100) * (Game.volume / 100); sound.play(); } } @@ -2016,12 +2018,12 @@ CM.Disp.PlaySound = function(url, sndConfig, volConfig) { /** * This function creates a notifcation depending on configs. It is called by all functions * that check game-events and which have settings for notifications (e.g., Golden Cookies appearing, Magic meter being full) - * @param {string} notifyConfig The setting in CM.Config that is checked before creating the notification + * @param {string} notifyConfig The setting in CM.Options that is checked before creating the notification * @param {string} title The title of the to-be created notifications * @param {string} message The text of the to-be created notifications */ CM.Disp.Notification = function(notifyConfig, title, message) { - if (CM.Config[notifyConfig] == 1 && document.visibilityState == 'hidden') { + if (CM.Options[notifyConfig] == 1 && document.visibilityState == 'hidden') { var CookieIcon = 'https://orteil.dashnet.org/cookieclicker/favicon.ico' notification = new Notification(title, {body: message, badge: CookieIcon}); } @@ -2043,11 +2045,11 @@ CM.Disp.CreateFavicon = function() { /** * This function updates the Favicon depending on whether a Golden Cookie has spawned - * It is called on every loop by CM.Main.CheckGoldenCookie() or by a change in CM.Config.Favicon + * It is called on every loop by CM.Main.CheckGoldenCookie() or by a change in CM.Options.Favicon * By relying on CM.Cache.spawnedGoldenShimmer it only changes for non-user spawned cookie */ CM.Disp.UpdateFavicon = function() { - if (CM.Config.Favicon == 1 && CM.Main.lastGoldenCookieState > 0) { + if (CM.Options.Favicon == 1 && CM.Main.lastGoldenCookieState > 0) { if (CM.Cache.spawnedGoldenShimmer.wrath) CM.Disp.Favicon.href = 'https://aktanusa.github.io/CookieMonster/favicon/wrathCookie.ico'; else CM.Disp.Favicon.href = 'https://aktanusa.github.io/CookieMonster/favicon/goldenCookie.ico'; } @@ -2059,10 +2061,10 @@ CM.Disp.UpdateFavicon = function() { * It is called on every loop by Game.Logic() which also sets CM.Cache.Title to Game.cookies */ CM.Disp.UpdateTitle = function() { - if (Game.OnAscend || CM.Config.Title == 0) { + if (Game.OnAscend || CM.Options.Title == 0) { document.title = CM.Cache.Title; } - else if (CM.Config.Title == 1) { + else if (CM.Options.Title == 1) { var addFC = false; var addSP = false; var titleGC; @@ -2098,7 +2100,7 @@ CM.Disp.UpdateTitle = function() { } document.title = titleGC + (addFC ? titleFC : '') + (addSP ? titleSP : '') + ' ' + str; } - else if (CM.Config.Title == 2) { + else if (CM.Options.Title == 2) { var str = ''; var spawn = false; if (CM.Cache.spawnedGoldenShimmer) { @@ -2143,7 +2145,7 @@ CM.Disp.CreateGCTimer = function(cookie) { GCTimer.style.fontSize = '35px'; GCTimer.style.cursor = 'pointer'; GCTimer.style.display = 'block'; - if (CM.Config.GCTimer == 0) GCTimer.style.display = 'none'; + if (CM.Options.GCTimer == 0) GCTimer.style.display = 'none'; GCTimer.style.left = cookie.l.style.left; GCTimer.style.top = cookie.l.style.top; GCTimer.onclick = function () {cookie.pop();}; @@ -2156,10 +2158,10 @@ CM.Disp.CreateGCTimer = function(cookie) { /** * This function toggles GC Timers are visible - * It is called by a change in CM.Config.GCTimer + * It is called by a change in CM.Options.GCTimer */ CM.Disp.ToggleGCTimer = function() { - if (CM.Config.GCTimer == 1) { + if (CM.Options.GCTimer == 1) { for (var i in CM.Disp.GCTimers) { CM.Disp.GCTimers[i].style.display = 'block'; CM.Disp.GCTimers[i].style.left = CM.Cache.goldenShimmersByID[i].l.style.left; @@ -2275,7 +2277,7 @@ CM.Disp.Tooltip = function(type, name) { if (type == 'b') { // Buildings l('tooltip').innerHTML = Game.Objects[name].tooltip(); // Adds amortization info to the list of info per building - if (CM.Config.TooltipAmor == 1) { + if (CM.Options.TooltipAmor == 1) { var buildPrice = CM.Sim.BuildingGetPrice(Game.Objects[name], Game.Objects[name].basePrice, 0, Game.Objects[name].free, Game.Objects[name].amount); var amortizeAmount = buildPrice - Game.Objects[name].totalCookies; if (amortizeAmount > 0) { @@ -2470,7 +2472,7 @@ CM.Disp.UpdateTooltip = function() { * It is called when Building tooltips are created or refreshed by CM.Disp.UpdateTooltip() */ CM.Disp.UpdateTooltipBuilding = function() { - if (CM.Config.TooltipBuildUp == 1 && Game.buyMode == 1) { + if (CM.Options.TooltipBuildUp == 1 && Game.buyMode == 1) { tooltipBox = l('CMTooltipBorder'); CM.Disp.TooltipCreateCalculationSection(tooltipBox); @@ -2485,7 +2487,7 @@ CM.Disp.UpdateTooltipBuilding = function() { CM.Disp.TooltipBonusIncome = CM.Cache[target][CM.Disp.tooltipName].bonus; - if (CM.Config.TooltipBuildUp == 1 && Game.buyMode == 1) { + if (CM.Options.TooltipBuildUp == 1 && Game.buyMode == 1) { l('CMTooltipIncome').textContent = Beautify(CM.Disp.TooltipBonusIncome, 2); var increase = Math.round(CM.Disp.TooltipBonusIncome / Game.cookiesPs * 10000); if (isFinite(increase) && increase != 0) { @@ -2530,7 +2532,7 @@ CM.Disp.UpdateTooltipUpgrade = function() { CM.Disp.TooltipBonusIncome = CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].bonus; CM.Disp.TooltipPrice = Game.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].getPrice(); - if (CM.Config.TooltipBuildUp == 1) { + if (CM.Options.TooltipBuildUp == 1) { l('CMTooltipIncome').textContent = Beautify(CM.Disp.TooltipBonusIncome, 2); var increase = Math.round(CM.Disp.TooltipBonusIncome / Game.cookiesPs * 10000); if (isFinite(increase) && increase != 0) { @@ -2561,7 +2563,7 @@ CM.Disp.UpdateTooltipUpgrade = function() { * It adds to the additional information to l('CMTooltipArea') */ CM.Disp.UpdateTooltipSugarLump = function() { - if (CM.Config.TooltipLump === 1) { + if (CM.Options.TooltipLump === 1) { tooltipBox = l('CMTooltipBorder'); tooltipBox.appendChild(CM.Disp.TooltipCreateHeader('Current Sugar Lump')); @@ -2584,7 +2586,7 @@ CM.Disp.UpdateTooltipGrimoire = function() { var minigame = Game.Objects['Wizard tower'].minigame; var spellCost = minigame.getSpellCost(minigame.spellsById[CM.Disp.tooltipName]); - if (CM.Config.TooltipGrim == 1 && spellCost <= minigame.magicM) { + if (CM.Options.TooltipGrim == 1 && spellCost <= minigame.magicM) { tooltipBox = l('CMTooltipBorder'); // Time left till enough magic for spell @@ -2642,14 +2644,14 @@ CM.Disp.UpdateTooltipWarnings = function() { CM.Disp.ToggleToolWarnPos(); } - if (CM.Config.ToolWarnPos == 0) CM.Disp.TooltipWarn.style.right = '0px'; + if (CM.Options.ToolWarnPos == 0) CM.Disp.TooltipWarn.style.right = '0px'; else CM.Disp.TooltipWarn.style.top = (l('tooltip').offsetHeight) + 'px'; CM.Disp.TooltipWarn.style.width = (l('tooltip').offsetWidth - 6) + 'px'; - if (CM.Config.ToolWarnLucky == 1) { + if (CM.Options.ToolWarnLucky == 1) { var limitLucky = CM.Cache.Lucky; - if (CM.Config.ToolWarnBon == 1) { + if (CM.Options.ToolWarnBon == 1) { var bonusNoFren = CM.Disp.TooltipBonusIncome; bonusNoFren /= CM.Sim.getCPSBuffMult(); limitLucky += ((bonusNoFren * 60 * 15) / 0.15); @@ -2678,9 +2680,9 @@ CM.Disp.UpdateTooltipWarnings = function() { l('CMDispTooltipWarnLuckyFrenzy').style.display = 'none'; } - if (CM.Config.ToolWarnConjure == 1) { + if (CM.Options.ToolWarnConjure == 1) { var limitLucky = CM.Cache.Lucky; - if (CM.Config.ToolWarnBon == 1) { + if (CM.Options.ToolWarnBon == 1) { var bonusNoFren = CM.Disp.TooltipBonusIncome; bonusNoFren /= CM.Sim.getCPSBuffMult(); limitLucky += ((bonusNoFren * 60 * 15) / 0.15); @@ -2712,25 +2714,25 @@ CM.Disp.UpdateTooltipWarnings = function() { CM.Disp.UpdateTooltipLocation = function() { if (Game.tooltip.origin == 'store') { var warnOffset = 0; - if (CM.Config.ToolWarnLucky == 1 && CM.Config.ToolWarnPos == 1 && typeof CM.Disp.TooltipWarn != "undefined") { + if (CM.Options.ToolWarnLucky == 1 && CM.Options.ToolWarnPos == 1 && typeof CM.Disp.TooltipWarn != "undefined") { warnOffset = CM.Disp.TooltipWarn.clientHeight - 4; } Game.tooltip.tta.style.top = Math.min(parseInt(Game.tooltip.tta.style.top), (l('game').clientHeight + l('topBar').clientHeight) - Game.tooltip.tt.clientHeight - warnOffset - 46) + 'px'; } // Kept for future possible use if the code changes again - /*else if (!Game.onCrate && !Game.OnAscend && CM.Config.TimerBar == 1 && CM.Config.TimerBarPos == 0) { + /*else if (!Game.onCrate && !Game.OnAscend && CM.Options.TimerBar == 1 && CM.Options.TimerBarPos == 0) { Game.tooltip.tta.style.top = (parseInt(Game.tooltip.tta.style.top) + parseInt(CM.Disp.TimerBar.style.height)) + 'px'; }*/ } /** * This function toggles the position of the warnings created by CM.Disp.TooltipCreateWarningSection() - * It is called by a change in CM.Config.ToolWarnPos + * It is called by a change in CM.Options.ToolWarnPos * and upon creation of the warning tooltip by CM.Disp.UpdateTooltipWarnings() */ CM.Disp.ToggleToolWarnPos = function() { if (typeof CM.Disp.TooltipWarn != "undefined") { - if (CM.Config.ToolWarnPos == 0) { + if (CM.Options.ToolWarnPos == 0) { CM.Disp.TooltipWarn.style.top = 'auto'; CM.Disp.TooltipWarn.style.margin = '4px -4px'; CM.Disp.TooltipWarn.style.padding = '3px 4px'; @@ -2749,7 +2751,7 @@ CM.Disp.ToggleToolWarnPos = function() { * TODO: Change this code to be the same as other tooltips. (i.d., create tooltip with type "w") */ CM.Disp.CheckWrinklerTooltip = function() { - if (CM.Config.ToolWrink == 1 && CM.Disp.TooltipWrinklerArea == 1) { // Latter is set by CM.Main.AddWrinklerAreaDetect + if (CM.Options.ToolWrink == 1 && CM.Disp.TooltipWrinklerArea == 1) { // Latter is set by CM.Main.AddWrinklerAreaDetect var showingTooltip = false; for (var i in Game.wrinklers) { var me = Game.wrinklers[i]; @@ -2787,7 +2789,7 @@ CM.Disp.CheckWrinklerTooltip = function() { * TODO: Change this code to be the same as other tooltips. Fit this into CM.Disp.UpdateTooltip() */ CM.Disp.UpdateWrinklerTooltip = function() { - if (CM.Config.ToolWrink == 1 && l('CMTooltipWrinkler') != null) { + if (CM.Options.ToolWrink == 1 && l('CMTooltipWrinkler') != null) { var sucked = Game.wrinklers[CM.Disp.TooltipWrinkler].sucked; var toSuck = 1.1; if (Game.Has('Sacrilegious corruption')) toSuck *= 1.05; @@ -2813,7 +2815,7 @@ CM.Disp.UpdateWrinklerTooltip = function() { * @param {number} aura The number of the aura currently selected by the mouse/user */ CM.Disp.AddAuraInfo = function(aura) { - if (CM.Config.DragonAuraInfo == 1) { + if (CM.Options.DragonAuraInfo == 1) { var [bonusCPS, priceOfChange] = CM.Sim.CalculateChangeAura(aura); var timeToRecover = CM.Disp.FormatTime(priceOfChange / (bonusCPS + Game.cookiesPs)); var bonusCPSPercentage = CM.Disp.Beautify(bonusCPS / Game.cookiesPs); @@ -2854,18 +2856,18 @@ CM.Disp.AddMenu = function() { CM.Disp.AddMenuPref(title); } else if (Game.onMenu == 'stats') { - if (CM.Config.Stats) { + if (CM.Options.Stats) { CM.Disp.AddMenuStats(title); } } } /** - * This function refreshes the stats page, CM.Config.UpStats determines the rate at which that happens + * This function refreshes the stats page, CM.Options.UpStats determines the rate at which that happens * It is called by CM.Loop() */ CM.Disp.RefreshMenu = function() { - if (CM.Config.UpStats && Game.onMenu == 'stats' && (Game.drawT - 1) % (Game.fps * 5) != 0 && (Game.drawT - 1) % Game.fps == 0) Game.UpdateMenu(); + if (CM.Options.UpStats && Game.onMenu == 'stats' && (Game.drawT - 1) % (Game.fps * 5) != 0 && (Game.drawT - 1) % Game.fps == 0) Game.UpdateMenu(); } /******** @@ -2883,7 +2885,7 @@ CM.Disp.AddMenuPref = function(title) { for (var group in CM.ConfigGroups) { groupObject = CM.Disp.CreatePrefHeader(group, CM.ConfigGroups[group]) // (group, display-name of group) frag.appendChild(groupObject) - if (CM.Config.OptionsPref[group]) { // 0 is show, 1 is collapsed + if (CM.Options.OptionsPref[group]) { // 0 is show, 1 is collapsed for (var option in CM.ConfigData) { if (CM.ConfigData[option].group == group) frag.appendChild(CM.Disp.CreatePrefOption(option)) } @@ -2912,6 +2914,7 @@ CM.Disp.AddMenuPref = function(title) { CM.Disp.CreatePrefHeader = function(config, text) { var div = document.createElement('div'); div.className = 'title'; + div.style.opacity = '0.7'; div.style.fontSize = '17px'; div.appendChild(document.createTextNode(text + ' ')); @@ -2926,7 +2929,7 @@ CM.Disp.CreatePrefHeader = function(config, text) { span.style.color = 'black'; span.style.fontSize = '13px'; span.style.verticalAlign = 'middle'; - span.textContent = CM.Config.OptionsPref[config] ? '-' : '+'; + span.textContent = CM.Options.OptionsPref[config] ? '-' : '+'; span.onclick = function() {CM.ToggleOptionsConfig(config); Game.UpdateMenu();}; div.appendChild(span); return div; @@ -2943,7 +2946,7 @@ CM.Disp.CreatePrefOption = function(config) { var div = document.createElement('div'); div.className = 'listing'; var a = document.createElement('a'); - if (CM.ConfigData[config].toggle && CM.Config[config] == 0) { + if (CM.ConfigData[config].toggle && CM.Options[config] == 0) { a.className = 'option off'; } else { @@ -2951,7 +2954,7 @@ CM.Disp.CreatePrefOption = function(config) { } a.id = CM.ConfigPrefix + config; a.onclick = function() {CM.ToggleConfig(config);}; - a.textContent = CM.ConfigData[config].label[CM.Config[config]]; + a.textContent = CM.ConfigData[config].label[CM.Options[config]]; div.appendChild(a); var label = document.createElement('label'); label.textContent = CM.ConfigData[config].desc; @@ -2970,7 +2973,7 @@ CM.Disp.CreatePrefOption = function(config) { var percent = title = document.createElement('div'); percent.id = "slider" + config + "right"; percent.style.float = "right"; - percent.innerHTML = CM.Config[config] + "%"; + percent.innerHTML = CM.Options[config] + "%"; volume.appendChild(percent); var slider = document.createElement('input'); slider.className = "slider"; @@ -2980,7 +2983,7 @@ CM.Disp.CreatePrefOption = function(config) { slider.min = "0"; slider.max = "100"; slider.step = "1"; - slider.value = CM.Config[config]; + slider.value = CM.Options[config]; slider.oninput = function() {CM.ToggleConfigVolume(config)}; slider.onchange = function() {CM.ToggleConfigVolume(config)}; volume.appendChild(slider); @@ -2999,7 +3002,7 @@ CM.Disp.CreatePrefOption = function(config) { input.className = 'option'; input.type = 'text'; input.readOnly = true; - input.setAttribute('value', CM.Config[config]); + input.setAttribute('value', CM.Options[config]); input.style.width = '300px'; div.appendChild(input); div.appendChild(document.createTextNode(' ')); @@ -3007,10 +3010,10 @@ CM.Disp.CreatePrefOption = function(config) { inputPrompt.id = CM.ConfigPrefix + config + 'Prompt'; inputPrompt.className = 'option'; inputPrompt.type = 'text'; - inputPrompt.setAttribute('value', CM.Config[config]); + inputPrompt.setAttribute('value', CM.Options[config]); var a = document.createElement('a'); a.className = 'option'; - a.onclick = function() {Game.Prompt(inputPrompt.outerHTML, [['Save', 'CM.Config[\'' + config + '\'] = l(CM.ConfigPrefix + \'' + config + '\' + \'Prompt\').value; CM.SaveConfig(CM.Config); Game.ClosePrompt(); Game.UpdateMenu();'], 'Cancel']);}; + a.onclick = function() {Game.Prompt(inputPrompt.outerHTML, [['Save', 'CM.Options[\'' + config + '\'] = l(CM.ConfigPrefix + \'' + config + '\' + \'Prompt\').value; CM.SaveConfig(CM.Options); Game.ClosePrompt(); Game.UpdateMenu();'], 'Cancel']);}; a.textContent = 'Edit'; div.appendChild(a); var label = document.createElement('label'); @@ -3026,9 +3029,9 @@ CM.Disp.CreatePrefOption = function(config) { input.id = CM.ConfigPrefix + 'Color' + CM.Disp.colors[i]; input.className = 'option'; input.style.width = '65px'; - input.setAttribute('value', CM.Config.Colors[CM.Disp.colors[i]]); + input.setAttribute('value', CM.Options.Colors[CM.Disp.colors[i]]); div.appendChild(input); - eval('var change = function() {CM.Config.Colors[\'' + CM.Disp.colors[i] + '\'] = l(CM.ConfigPrefix + \'Color\' + \'' + CM.Disp.colors[i] + '\').value; CM.Disp.UpdateColors(); CM.SaveConfig(CM.Config);}'); + eval('var change = function() {CM.Options.Colors[\'' + CM.Disp.colors[i] + '\'] = l(CM.ConfigPrefix + \'Color\' + \'' + CM.Disp.colors[i] + '\').value; CM.Disp.UpdateColors(); CM.SaveConfig(CM.Options);}'); var jscolorpicker = new jscolor.color(input, {hash: true, caps: false, pickerZIndex: 1000000, pickerPosition: 'right', onImmediateChange: change}); var label = document.createElement('label'); label.textContent = CM.ConfigData.Colors.desc[CM.Disp.colors[i]]; @@ -3040,16 +3043,16 @@ CM.Disp.CreatePrefOption = function(config) { /** * This function changes some of the time-displays in the game to be more detailed - * It is called by a change in CM.Config.DetailedTime + * It is called by a change in CM.Options.DetailedTime */ CM.Disp.ToggleDetailedTime = function() { - if (CM.Config.DetailedTime == 1) Game.sayTime = CM.Disp.sayTime; + if (CM.Options.DetailedTime == 1) Game.sayTime = CM.Disp.sayTime; else Game.sayTime = CM.Backup.sayTime; } /** * This function refreshes all numbers after a change in scale-setting - * It is therefore called by a change in CM.Config.Scale and CM.Config.ScaleDecimals + * It is therefore called by a change in CM.Options.Scale and CM.Options.ScaleDecimals */ CM.Disp.RefreshScale = function() { BeautifyAll(); @@ -3063,18 +3066,18 @@ CM.Disp.RefreshScale = function() { /** * This function changes/refreshes colours if the user has set new standard colours - * The function is therefore called by a change in CM.Config.Colors + * The function is therefore called by a change in CM.Options.Colors */ CM.Disp.UpdateColors = function() { var str = ''; for (var i = 0; i < CM.Disp.colors.length; i++) { - str += '.' + CM.Disp.colorTextPre + CM.Disp.colors[i] + ' { color: ' + CM.Config.Colors[CM.Disp.colors[i]] + '; }\n'; + str += '.' + CM.Disp.colorTextPre + CM.Disp.colors[i] + ' { color: ' + CM.Options.Colors[CM.Disp.colors[i]] + '; }\n'; } for (var i = 0; i < CM.Disp.colors.length; i++) { - str += '.' + CM.Disp.colorBackPre + CM.Disp.colors[i] + ' { background-color: ' + CM.Config.Colors[CM.Disp.colors[i]] + '; }\n'; + str += '.' + CM.Disp.colorBackPre + CM.Disp.colors[i] + ' { background-color: ' + CM.Options.Colors[CM.Disp.colors[i]] + '; }\n'; } for (var i = 0; i < CM.Disp.colors.length; i++) { - str += '.' + CM.Disp.colorBorderPre + CM.Disp.colors[i] + ' { border: 1px solid ' + CM.Config.Colors[CM.Disp.colors[i]] + '; }\n'; + str += '.' + CM.Disp.colorBorderPre + CM.Disp.colors[i] + ' { border: 1px solid ' + CM.Options.Colors[CM.Disp.colors[i]] + '; }\n'; } CM.Disp.Css.textContent = str; CM.Disp.UpdateBuildings(); // Class has been already set @@ -3095,28 +3098,28 @@ CM.Disp.AddMenuStats = function(title) { stats.appendChild(title()); stats.appendChild(CM.Disp.CreateStatsHeader('Lucky Cookies', 'Lucky')); - if (CM.Config.StatsPref.Lucky) { + if (CM.Options.StatsPref.Lucky) { stats.appendChild(CM.Disp.CreateStatsLuckySection()); } stats.appendChild(CM.Disp.CreateStatsHeader('Chain Cookies', 'Chain')); - if (CM.Config.StatsPref.Chain) { + if (CM.Options.StatsPref.Chain) { stats.appendChild(CM.Disp.CreateStatsChainSection()); } stats.appendChild(CM.Disp.CreateStatsHeader('Conjure Baked Goods', 'Conjure')); - if (CM.Config.StatsPref.Conjure) { + if (CM.Options.StatsPref.Conjure) { stats.appendChild(CM.Disp.CreateStatsConjureSection()); } stats.appendChild(CM.Disp.CreateStatsHeader('Prestige', 'Prestige')); - if (CM.Config.StatsPref.Prestige) { + if (CM.Options.StatsPref.Prestige) { stats.appendChild(CM.Disp.CreateStatsPrestigeSection()); } if (Game.cpsSucked > 0) { stats.appendChild(CM.Disp.CreateStatsHeader('Wrinklers', 'Wrink')); - if (CM.Config.StatsPref.Wrink) { + if (CM.Options.StatsPref.Wrink) { var popAllFrag = document.createDocumentFragment(); popAllFrag.appendChild(document.createTextNode(Beautify(CM.Cache.WrinkBankTotal) + ' / ' + Beautify(CM.Cache.WrinkBankNormal) + ' ')); var popAllA = document.createElement('a'); @@ -3170,7 +3173,7 @@ CM.Disp.AddMenuStats = function(title) { if (Game.season == 'christmas' || specDisp || choEgg || centEgg) { stats.appendChild(CM.Disp.CreateStatsHeader('Season Specials', 'Sea')); - if (CM.Config.StatsPref.Sea) { + if (CM.Options.StatsPref.Sea) { if (specDisp) { if (missingHalloweenCookies.length != 0) stats.appendChild(CM.Disp.CreateStatsListing("basic", 'Halloween Cookies Left to Buy', CM.Disp.CreateStatsMissDisp(missingHalloweenCookies))); if (missingChristmasCookies.length != 0) stats.appendChild(CM.Disp.CreateStatsListing("basic", 'Christmas Cookies Left to Buy', CM.Disp.CreateStatsMissDisp(missingChristmasCookies))); @@ -3190,12 +3193,12 @@ CM.Disp.AddMenuStats = function(title) { } stats.appendChild(CM.Disp.CreateStatsHeader('Miscellaneous', 'Misc')); - if (CM.Config.StatsPref.Misc) { + if (CM.Options.StatsPref.Misc) { stats.appendChild(CM.Disp.CreateStatsListing("basic", - 'Average Cookies Per Second (Past ' + (CM.Disp.cookieTimes[CM.Config.AvgCPSHist] < 60 ? (CM.Disp.cookieTimes[CM.Config.AvgCPSHist] + ' seconds') : ((CM.Disp.cookieTimes[CM.Config.AvgCPSHist] / 60) + (CM.Config.AvgCPSHist == 3 ? ' minute' : ' minutes'))) + ')', + 'Average Cookies Per Second (Past ' + (CM.Disp.cookieTimes[CM.Options.AvgCPSHist] < 60 ? (CM.Disp.cookieTimes[CM.Options.AvgCPSHist] + ' seconds') : ((CM.Disp.cookieTimes[CM.Options.AvgCPSHist] / 60) + (CM.Options.AvgCPSHist == 3 ? ' minute' : ' minutes'))) + ')', document.createTextNode(Beautify(CM.Cache.AvgCPS, 3)) )); - stats.appendChild(CM.Disp.CreateStatsListing("basic", 'Average Cookie Clicks Per Second (Past ' + CM.Disp.clickTimes[CM.Config.AvgClicksHist] + (CM.Config.AvgClicksHist == 0 ? ' second' : ' seconds') + ')', document.createTextNode(Beautify(CM.Cache.AvgClicks, 1)))); + stats.appendChild(CM.Disp.CreateStatsListing("basic", 'Average Cookie Clicks Per Second (Past ' + CM.Disp.clickTimes[CM.Options.AvgClicksHist] + (CM.Options.AvgClicksHist == 0 ? ' second' : ' seconds') + ')', document.createTextNode(Beautify(CM.Cache.AvgClicks, 1)))); if (Game.Has('Fortune cookies')) { var fortunes = []; for (var i in CM.Data.Fortunes) { @@ -3216,7 +3219,7 @@ CM.Disp.AddMenuStats = function(title) { l('menu').insertBefore(stats, l('menu').childNodes[2]); - if (CM.Config.MissingUpgrades) { + if (CM.Options.MissingUpgrades) { CM.Disp.AddMissingUpgrades(); } } @@ -3247,7 +3250,7 @@ CM.Disp.CreateStatsHeader = function(text, config) { span.style.color = 'black'; span.style.fontSize = '13px'; span.style.verticalAlign = 'middle'; - span.textContent = CM.Config.StatsPref[config] ? '-' : '+'; + span.textContent = CM.Options.StatsPref[config] ? '-' : '+'; span.onclick = function() {CM.ToggleStatsConfig(config); Game.UpdateMenu();}; div.appendChild(span); return div; @@ -3862,7 +3865,7 @@ CM.ReplaceNativeGrimoireDraw = function() { CM.Backup.GrimoireDraw = minigame.draw; Game.Objects['Wizard tower'].minigame.draw = function() { CM.Backup.GrimoireDraw(); - if (CM.Config.GrimoireBar == 1 && minigame.magic < minigame.magicM) { + if (CM.Options.GrimoireBar == 1 && minigame.magic < minigame.magicM) { minigame.magicBarTextL.innerHTML += ' (' + CM.Disp.FormatTime(CM.Disp.CalculateGrimoireRefillTime(minigame.magic, minigame.magicM, minigame.magicM)) + ')'; } } @@ -4050,7 +4053,7 @@ CM.Main.CheckGoldenCookie = function() { if (CM.Main.lastGoldenCookieState) { if (CM.Main.lastSpawnedGoldenCookieState < CM.Main.currSpawnedGoldenCookieState) { CM.Disp.Flash(3, 'GCFlash'); - CM.Disp.PlaySound(CM.Config.GCSoundURL, 'GCSound', 'GCVolume'); + CM.Disp.PlaySound(CM.Options.GCSoundURL, 'GCSound', 'GCVolume'); CM.Disp.Notification('GCNotification', "Golden Cookie Spawned", "A Golden Cookie has spawned. Click it now!") } @@ -4064,7 +4067,7 @@ CM.Main.CheckGoldenCookie = function() { CM.Main.lastSpawnedGoldenCookieState = CM.Main.currSpawnedGoldenCookieState; if (CM.Main.currSpawnedGoldenCookieState == 0) CM.Cache.spawnedGoldenShimmer = 0; } - else if (CM.Config.GCTimer == 1 && CM.Main.lastGoldenCookieState) { + else if (CM.Options.GCTimer == 1 && CM.Main.lastGoldenCookieState) { for (var i in CM.Disp.GCTimers) { CM.Disp.GCTimers[i].style.opacity = CM.Cache.goldenShimmersByID[i].l.style.opacity; CM.Disp.GCTimers[i].style.transform = CM.Cache.goldenShimmersByID[i].l.style.transform; @@ -4087,7 +4090,7 @@ CM.Main.CheckSeasonPopup = function() { } } CM.Disp.Flash(3, 'SeaFlash'); - CM.Disp.PlaySound(CM.Config.SeaSoundURL, 'SeaSound', 'SeaVolume'); + CM.Disp.PlaySound(CM.Options.SeaSoundURL, 'SeaSound', 'SeaVolume'); CM.Disp.Notification('SeaNotification',"Reindeer sighted!", "A Reindeer has spawned. Click it now!") } } @@ -4101,7 +4104,7 @@ CM.Main.CheckTickerFortune = function() { CM.Main.lastTickerFortuneState = (Game.TickerEffect && Game.TickerEffect.type == 'fortune'); if (CM.Main.lastTickerFortuneState) { CM.Disp.Flash(3, 'FortuneFlash'); - CM.Disp.PlaySound(CM.Config.FortuneSoundURL, 'FortuneSound', 'FortuneVolume'); + CM.Disp.PlaySound(CM.Options.FortuneSoundURL, 'FortuneSound', 'FortuneVolume'); CM.Disp.Notification('FortuneNotification', "Fortune Cookie found", "A Fortune Cookie has appeared on the Ticker.") } } @@ -4115,7 +4118,7 @@ CM.Main.CheckGardenTick = function() { if (Game.Objects['Farm'].minigameLoaded && CM.Main.lastGardenNextStep != Game.Objects['Farm'].minigame.nextStep) { if (CM.Main.lastGardenNextStep != 0 && CM.Main.lastGardenNextStep < Date.now()) { CM.Disp.Flash(3, 'GardFlash'); - CM.Disp.PlaySound(CM.Config.GardSoundURL, 'GardSound', 'GardVolume'); + CM.Disp.PlaySound(CM.Options.GardSoundURL, 'GardSound', 'GardVolume'); } CM.Main.lastGardenNextStep = Game.Objects['Farm'].minigame.nextStep; } @@ -4126,13 +4129,13 @@ CM.Main.CheckGardenTick = function() { * It is called by CM.Loop */ CM.Main.CheckMagicMeter = function() { - if (Game.Objects['Wizard tower'].minigameLoaded && CM.Config.GrimoireBar == 1) { + if (Game.Objects['Wizard tower'].minigameLoaded && CM.Options.GrimoireBar == 1) { var minigame = Game.Objects['Wizard tower'].minigame; if (minigame.magic < minigame.magicM) CM.Main.lastMagicBarFull = false; else if (!CM.Main.lastMagicBarFull) { CM.Main.lastMagicBarFull = true; CM.Disp.Flash(3, 'MagicFlash'); - CM.Disp.PlaySound(CM.Config.MagicSoundURL, 'MagicSound', 'MagicVolume'); + CM.Disp.PlaySound(CM.Options.MagicSoundURL, 'MagicSound', 'MagicVolume'); CM.Disp.Notification('MagicNotification', "Magic Meter full", "Your Magic Meter is full. Cast a spell!") } } @@ -4150,17 +4153,17 @@ CM.Main.CheckWrinklerCount = function() { } if (CurrentWrinklers > CM.Main.lastWrinklerCount) { CM.Main.lastWrinklerCount = CurrentWrinklers - if (CurrentWrinklers == Game.getWrinklersMax() && CM.Config.WrinklerMaxFlash) { + if (CurrentWrinklers == Game.getWrinklersMax() && CM.Options.WrinklerMaxFlash) { CM.Disp.Flash(3, 'WrinklerMaxFlash'); } else { CM.Disp.Flash(3, 'WrinklerFlash'); } - if (CurrentWrinklers == Game.getWrinklersMax() && CM.Config.WrinklerMaxSound) { - CM.Disp.PlaySound(CM.Config.WrinklerMaxSoundURL, 'WrinklerMaxSound', 'WrinklerMaxVolume'); + if (CurrentWrinklers == Game.getWrinklersMax() && CM.Options.WrinklerMaxSound) { + CM.Disp.PlaySound(CM.Options.WrinklerMaxSoundURL, 'WrinklerMaxSound', 'WrinklerMaxVolume'); } else { - CM.Disp.PlaySound(CM.Config.WrinklerSoundURL, 'WrinklerSound', 'WrinklerVolume'); + CM.Disp.PlaySound(CM.Options.WrinklerSoundURL, 'WrinklerSound', 'WrinklerVolume'); } - if (CurrentWrinklers == Game.getWrinklersMax() && CM.Config.WrinklerMaxNotification) { + if (CurrentWrinklers == Game.getWrinklersMax() && CM.Options.WrinklerMaxNotification) { CM.Disp.Notification('WrinklerMaxNotification', "Maximum Wrinklers Reached", "You have reached your maximum ammount of wrinklers") } else { CM.Disp.Notification('WrinklerNotification', "A Wrinkler appeared", "A new wrinkler has appeared") @@ -4197,7 +4200,7 @@ CM.Main.AddWrinklerAreaDetect = function() { * before execution of their actual function */ CM.Main.FixMouseY = function(target) { - if (CM.Config.TimerBar == 1 && CM.Config.TimerBarPos == 0) { + if (CM.Options.TimerBar == 1 && CM.Options.TimerBarPos == 0) { var timerBarHeight = parseInt(CM.Disp.TimerBar.style.height); Game.mouseY -= timerBarHeight; target(); diff --git a/src/Cache.js b/src/Cache.js index f9dfa39..83416ad 100644 --- a/src/Cache.js +++ b/src/Cache.js @@ -86,7 +86,7 @@ CM.Cache.RemakeBuildingsPP = function() { CM.Cache.max = -1; CM.Cache.mid = -1; // Calculate PP and colors when compared to purchase of single optimal building - if (CM.Config.ColorPPBulkMode == 0) { + if (CM.Options.ColorPPBulkMode == 0) { for (var i in CM.Cache.Objects) { //CM.Cache.Objects[i].pp = Game.Objects[i].getPrice() / CM.Cache.Objects[i].bonus; if (Game.cookiesPs) { @@ -419,7 +419,7 @@ CM.Cache.UpdateAvgCPS = function() { var sortedGainWrink = new Array(); var sortedGainChoEgg = new Array(); - var cpsLength = Math.min(CM.Cache.CookiesDiff.getLength(), CM.Disp.cookieTimes[CM.Config.AvgCPSHist]); + var cpsLength = Math.min(CM.Cache.CookiesDiff.getLength(), CM.Disp.cookieTimes[CM.Options.AvgCPSHist]); // Assumes the queues are the same length for (var i = CM.Cache.CookiesDiff.getLength() - cpsLength; i < CM.Cache.CookiesDiff.getLength(); i++) { @@ -453,11 +453,11 @@ CM.Cache.UpdateAvgCPS = function() { totalGainWrink += sortedGainWrink[i]; totalGainChoEgg += sortedGainChoEgg[i]; } - CM.Cache.AvgCPS = (totalGainBank + (CM.Config.CalcWrink ? totalGainWrink : 0)) / sortedGainBank.length; + CM.Cache.AvgCPS = (totalGainBank + (CM.Options.CalcWrink ? totalGainWrink : 0)) / sortedGainBank.length; var choEgg = (Game.HasUnlocked('Chocolate egg') && !Game.Has('Chocolate egg')); - if (choEgg || CM.Config.CalcWrink == 0) { + if (choEgg || CM.Options.CalcWrink == 0) { CM.Cache.AvgCPSChoEgg = (totalGainBank + totalGainWrink + (choEgg ? totalGainChoEgg : 0)) / sortedGainBank.length; } else { @@ -465,7 +465,7 @@ CM.Cache.UpdateAvgCPS = function() { } var totalClicks = 0; - var clicksLength = Math.min(CM.Cache.ClicksDiff.getLength(), CM.Disp.clickTimes[CM.Config.AvgClicksHist]); + var clicksLength = Math.min(CM.Cache.ClicksDiff.getLength(), CM.Disp.clickTimes[CM.Options.AvgClicksHist]); for (var i = CM.Cache.ClicksDiff.getLength() - clicksLength; i < CM.Cache.ClicksDiff.getLength(); i++) { totalClicks += CM.Cache.ClicksDiff.get(i); } diff --git a/src/Config.js b/src/Config.js index 8438360..a4def30 100644 --- a/src/Config.js +++ b/src/Config.js @@ -9,59 +9,59 @@ * This function saves the config of CookieMonster to localStorage * It is called by CM.LoadConfig(), CM.RestoreDefault(), * any of the CM.ToggleConfig() functions and upon changes to URL or volume settings - * @param {object} config The Config to be saved (normally CM.Config) + * @param {object} config The Config to be saved (normally CM.Options) */ CM.SaveConfig = function(config) { localStorage.setItem(CM.ConfigPrefix, JSON.stringify(config)); } /** - * This function loads the config of CookieMonster saved in localStorage and loads it into CM.Config + * This function loads the config of CookieMonster saved in localStorage and loads it into CM.Options * It is called by CM.DelayInit() and CM.RestoreDefault() */ CM.LoadConfig = function() { if (localStorage.getItem(CM.ConfigPrefix) != null) { - CM.Config = JSON.parse(localStorage.getItem(CM.ConfigPrefix)); + CM.Options = JSON.parse(localStorage.getItem(CM.ConfigPrefix)); // Check values var mod = false; for (var i in CM.Data.ConfigDefault) { - if (typeof CM.Config[i] === 'undefined') { + if (typeof CM.Options[i] === 'undefined') { mod = true; - CM.Config[i] = CM.Data.ConfigDefault[i]; + CM.Options[i] = CM.Data.ConfigDefault[i]; } else if (i != 'StatsPref' && i != 'Colors') { if (i.indexOf('SoundURL') == -1) { - if (!(CM.Config[i] > -1 && CM.Config[i] < CM.ConfigData[i].label.length)) { + if (!(CM.Options[i] > -1 && CM.Options[i] < CM.ConfigData[i].label.length)) { mod = true; - CM.Config[i] = CM.Data.ConfigDefault[i]; + CM.Options[i] = CM.Data.ConfigDefault[i]; } } else { // Sound URLs - if (typeof CM.Config[i] != 'string') { + if (typeof CM.Options[i] != 'string') { mod = true; - CM.Config[i] = CM.Data.ConfigDefault[i]; + CM.Options[i] = CM.Data.ConfigDefault[i]; } } } else if (i == 'StatsPref') { for (var j in CM.Data.ConfigDefault.StatsPref) { - if (typeof CM.Config[i][j] === 'undefined' || !(CM.Config[i][j] > -1 && CM.Config[i][j] < 2)) { + if (typeof CM.Options[i][j] === 'undefined' || !(CM.Options[i][j] > -1 && CM.Options[i][j] < 2)) { mod = true; - CM.Config[i][j] = CM.Data.ConfigDefault[i][j]; + CM.Options[i][j] = CM.Data.ConfigDefault[i][j]; } } } else { // Colors for (var j in CM.Data.ConfigDefault.Colors) { - if (typeof CM.Config[i][j] === 'undefined' || typeof CM.Config[i][j] != 'string') { + if (typeof CM.Options[i][j] === 'undefined' || typeof CM.Options[i][j] != 'string') { mod = true; - CM.Config[i][j] = CM.Data.ConfigDefault[i][j]; + CM.Options[i][j] = CM.Data.ConfigDefault[i][j]; } } } } - if (mod) CM.SaveConfig(CM.Config); + if (mod) CM.SaveConfig(CM.Options); CM.Loop(); // Do loop once for (var i in CM.Data.ConfigDefault) { if (i != 'StatsPref' && i != 'OptionsPref' && typeof CM.ConfigData[i].func !== 'undefined') { @@ -79,7 +79,7 @@ CM.LoadConfig = function() { * It is called by resDefBut.onclick loaded in the options page or by CM.LoadConfig is no localStorage is found */ CM.RestoreDefault = function() { - CM.Config = {}; + CM.Options = {}; CM.SaveConfig(CM.Data.ConfigDefault); CM.LoadConfig(); Game.UpdateMenu(); @@ -97,7 +97,7 @@ CM.RestoreDefault = function() { CM.ToggleConfig = function(config) { CM.ToggleConfigUp(config); if (CM.ConfigData[config].toggle) { - if (CM.Config[config] == 0) { + if (CM.Options[config] == 0) { l(CM.ConfigPrefix + config).className = 'option off'; } else { @@ -107,15 +107,15 @@ CM.ToggleConfig = function(config) { } CM.ToggleConfigUp = function(config) { - CM.Config[config]++; - if (CM.Config[config] == CM.ConfigData[config].label.length) { - CM.Config[config] = 0; + CM.Options[config]++; + if (CM.Options[config] == CM.ConfigData[config].label.length) { + CM.Options[config] = 0; } if (typeof CM.ConfigData[config].func !== 'undefined') { CM.ConfigData[config].func(); } - l(CM.ConfigPrefix + config).innerHTML = CM.ConfigData[config].label[CM.Config[config]]; - CM.SaveConfig(CM.Config); + l(CM.ConfigPrefix + config).innerHTML = CM.ConfigData[config].label[CM.Options[config]]; + CM.SaveConfig(CM.Options); } /** @@ -126,29 +126,29 @@ CM.ToggleConfigUp = function(config) { CM.ToggleConfigVolume = function(config) { if (l("slider" + config) != null) { l("slider" + config + "right").innerHTML = l("slider" + config).value + "%"; - CM.Config[config] = Math.round(l("slider" + config).value); + CM.Options[config] = Math.round(l("slider" + config).value); } - CM.SaveConfig(CM.Config); + CM.SaveConfig(CM.Options); } CM.ToggleStatsConfig = function(config) { - if (CM.Config.StatsPref[config] == 0) { - CM.Config.StatsPref[config]++; + if (CM.Options.StatsPref[config] == 0) { + CM.Options.StatsPref[config]++; } else { - CM.Config.StatsPref[config]--; + CM.Options.StatsPref[config]--; } - CM.SaveConfig(CM.Config); + CM.SaveConfig(CM.Options); } CM.ToggleOptionsConfig = function(config) { - if (CM.Config.OptionsPref[config] == 0) { - CM.Config.OptionsPref[config]++; + if (CM.Options.OptionsPref[config] == 0) { + CM.Options.OptionsPref[config]++; } else { - CM.Config.OptionsPref[config]--; + CM.Options.OptionsPref[config]--; } - CM.SaveConfig(CM.Config); + CM.SaveConfig(CM.Options); } // Checks if the browsers has permissions to produce notifications diff --git a/src/Disp.js b/src/Disp.js index d87eac7..6d56715 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -12,11 +12,11 @@ /** * This function returns the total amount stored in the Wrinkler Bank - * as calculated by CM.Cache.RemakeWrinkBank() if CM.Config.CalcWrink is set + * as calculated by CM.Cache.RemakeWrinkBank() if CM.Options.CalcWrink is set * @returns {number} 0 or the amount of cookies stored (CM.Cache.WrinkBankTotal) */ CM.Disp.GetWrinkConfigBank = function() { - if (CM.Config.CalcWrink) + if (CM.Options.CalcWrink) return CM.Cache.WrinkBankTotal; else return 0; @@ -35,11 +35,11 @@ CM.Disp.PopAllNormalWrinklers = function() { } /** - * This function returns the cps as either current or average CPS depending on CM.Config.CPSMode + * This function returns the cps as either current or average CPS depending on CM.Options.CPSMode * @returns {number} The average or current cps */ CM.Disp.GetCPS = function() { - if (CM.Config.CPSMode) + if (CM.Options.CPSMode) return CM.Cache.AvgCPS; else return (Game.cookiesPs * (1 - Game.cpsSucked)); @@ -121,7 +121,7 @@ CM.Disp.FormatTime = function(time, longFormat) { var m = Math.floor(time % 3600 / 60); var s = Math.floor(time % 60); var str = ''; - if (CM.Config.TimeFormat) { + if (CM.Options.TimeFormat) { if (time > 3155760000) return 'XX:XX:XX:XX:XX'; str += (y < 10 ? '0' : '') + y + ':'; str += (d < 10 ? '0' : '') + d + ':'; @@ -147,7 +147,7 @@ CM.Disp.GetTimeColor = function(time) { var color; var text; if (time < 0) { - if (CM.Config.TimeFormat) text = '00:00:00:00:00'; + if (CM.Options.TimeFormat) text = '00:00:00:00:00'; else text = 'Done!'; color = CM.Disp.colorGreen; } @@ -168,8 +168,8 @@ CM.Disp.GetTimeColor = function(time) { * @returns {string} Formatted number */ CM.Disp.Beautify = function(num, frac, forced) { - var decimals = CM.Config.ScaleDecimals + 1; - if (CM.Config.Scale == 0) { + var decimals = CM.Options.ScaleDecimals + 1; + if (CM.Options.Scale == 0) { return CM.Backup.Beautify(num, frac); } else if (isFinite(num)) { @@ -187,8 +187,8 @@ CM.Disp.Beautify = function(num, frac, forced) { // TODO: Add changing separators of thousands and making this cut-off user configurable answer = Math.round(num * 100) / 100; } - else if (CM.Config.Scale == 3 && !forced || forced == 3) { // Scientific notation, 123456789 => 1.235E+8 - answer = num[0] + (CM.Config.ScaleSeparator ? ',' : '.'); + else if (CM.Options.Scale == 3 && !forced || forced == 3) { // Scientific notation, 123456789 => 1.235E+8 + answer = num[0] + (CM.Options.ScaleSeparator ? ',' : '.'); i = 0; while (i < decimals - 1) { answer += num[i + 2]; // num has a 0-based index and [1] is a '.' @@ -213,13 +213,13 @@ CM.Disp.Beautify = function(num, frac, forced) { numbersToAdd = (restOfNumber.indexOf('.') > -1 ? restOfNumber.indexOf('.') + 1 + decimals : (restOfNumber.length)) i = 0 while (i < numbersToAdd - 1 && i < restOfNumber.length - 1) { - answer += (CM.Config.ScaleSeparator && restOfNumber[i] == '.' ? ',' : restOfNumber[i]); + answer += (CM.Options.ScaleSeparator && restOfNumber[i] == '.' ? ',' : restOfNumber[i]); i++ } answer += (i + 1 < restOfNumber.length ? Math.round(restOfNumber[i] + '.' + restOfNumber[i + 1]) : restOfNumber[i]); // answer is now "xxx.xx" (e.g., 123456789 would be 123.46) - if (CM.Config.Scale == 1 && !forced || forced == 1) { // Metric scale, 123456789 => 123.457 M + if (CM.Options.Scale == 1 && !forced || forced == 1) { // Metric scale, 123456789 => 123.457 M if (timesTenToPowerThree - 1 < CM.Data.metric.length) { answer += ' ' + CM.Data.metric[timesTenToPowerThree - 1] } @@ -227,7 +227,7 @@ CM.Disp.Beautify = function(num, frac, forced) { return CM.Disp.Beautify(num, 0, 3); } } - else if (CM.Config.Scale == 2 && !forced || forced == 2) { // Short scale, 123456789 => 123.457 M + else if (CM.Options.Scale == 2 && !forced || forced == 2) { // Short scale, 123456789 => 123.457 M if (timesTenToPowerThree < CM.Data.shortScale.length + 1) { answer += ' ' + CM.Data.shortScale[timesTenToPowerThree - 1]; } @@ -235,7 +235,7 @@ CM.Disp.Beautify = function(num, frac, forced) { return CM.Disp.Beautify(num, 0, 3); } } - else if (CM.Config.Scale == 4 && !forced || forced == 4) { // Engineering notation, 123456789 => 123.457E+6 + else if (CM.Options.Scale == 4 && !forced || forced == 4) { // Engineering notation, 123456789 => 123.457E+6 answer += 'E+' + (timesTenToPowerThree * 3); } } @@ -265,8 +265,8 @@ CM.Disp.Beautify = function(num, frac, forced) { CM.Disp.UpdateAscendState = function() { if (Game.OnAscend) { l('game').style.bottom = '0px'; - if (CM.Config.BotBar == 1) CM.Disp.BotBar.style.display = 'none'; - if (CM.Config.TimerBar == 1) CM.Disp.TimerBar.style.display = 'none'; + if (CM.Options.BotBar == 1) CM.Disp.BotBar.style.display = 'none'; + if (CM.Options.TimerBar == 1) CM.Disp.TimerBar.style.display = 'none'; } else { CM.Disp.ToggleBotBar(); @@ -317,7 +317,7 @@ CM.Disp.Draw = function () { // Draw autosave timer in stats menu if ( (Game.prefs.autosave && Game.drawT % 10 == 0) && // with autosave ON and every 10 ticks - (Game.onMenu == 'stats' && CM.Config.Stats) // while being on the stats menu only + (Game.onMenu == 'stats' && CM.Options.Stats) // while being on the stats menu only ) { var timer = document.getElementById('CMStatsAutosaveTimer'); if (timer) { @@ -331,10 +331,10 @@ CM.Disp.Draw = function () { /** * This function toggle the bottom bar - * It is called by CM.Disp.UpdateAscendState() and a change in CM.Config.BotBar + * It is called by CM.Disp.UpdateAscendState() and a change in CM.Options.BotBar */ CM.Disp.ToggleBotBar = function() { - if (CM.Config.BotBar == 1) { + if (CM.Options.BotBar == 1) { CM.Disp.BotBar.style.display = ''; CM.Disp.UpdateBotBar(); } @@ -346,7 +346,7 @@ CM.Disp.ToggleBotBar = function() { /** * This function creates the bottom bar and appends it to l('wrapper') - * It is called by CM.DelayInit and a change in CM.Config.BotBar + * It is called by CM.DelayInit and a change in CM.Options.BotBar */ CM.Disp.CreateBotBar = function() { CM.Disp.BotBar = document.createElement('div'); @@ -400,7 +400,7 @@ CM.Disp.CreateBotBar = function() { * It is called by CM.Loop() */ CM.Disp.UpdateBotBar = function() { - if (CM.Config.BotBar == 1) { + if (CM.Options.BotBar == 1) { var count = 0; for (var i in CM.Cache.Objects) { var target = 'Objects'; @@ -549,7 +549,7 @@ CM.Disp.TimerBarCreateBar = function(id, name, bars) { * It is called by CM.Loop() */ CM.Disp.UpdateTimerBar = function() { - if (CM.Config.TimerBar == 1) { + if (CM.Options.TimerBar == 1) { // label width: 113, timer width: 26, div margin: 20 var maxWidth = CM.Disp.TimerBar.offsetWidth - 159; var numberOfTimers = 0; @@ -624,20 +624,20 @@ CM.Disp.UpdateTimerBar = function() { /** * This function changes the visibility of the timer bar - * It is called by CM.Disp.UpdateAscendState() or a change in CM.Config.TimerBar + * It is called by CM.Disp.UpdateAscendState() or a change in CM.Options.TimerBar */ CM.Disp.ToggleTimerBar = function() { - if (CM.Config.TimerBar == 1) CM.Disp.TimerBar.style.display = ''; + if (CM.Options.TimerBar == 1) CM.Disp.TimerBar.style.display = ''; else CM.Disp.TimerBar.style.display = 'none'; CM.Disp.UpdateBotTimerBarPosition(); } /** * This function changes the position of the timer bar - * It is called by a change in CM.Config.TimerBarPos + * It is called by a change in CM.Options.TimerBarPos */ CM.Disp.ToggleTimerBarPos = function() { - if (CM.Config.TimerBarPos == 0) { + if (CM.Options.TimerBarPos == 0) { CM.Disp.TimerBar.style.width = '30%'; CM.Disp.TimerBar.style.bottom = ''; l('game').insertBefore(CM.Disp.TimerBar, l('sectionLeft')); @@ -658,22 +658,22 @@ CM.Disp.ToggleTimerBarPos = function() { * It is called by CM.Disp.ToggleTimerBar(), CM.Disp.ToggleTimerBarPos() and CM.Disp.ToggleBotBar() */ CM.Disp.UpdateBotTimerBarPosition = function() { - if (CM.Config.BotBar == 1 && CM.Config.TimerBar == 1 && CM.Config.TimerBarPos == 1) { + if (CM.Options.BotBar == 1 && CM.Options.TimerBar == 1 && CM.Options.TimerBarPos == 1) { CM.Disp.BotBar.style.bottom = '48px'; l('game').style.bottom = '118px'; } - else if (CM.Config.BotBar == 1) { + else if (CM.Options.BotBar == 1) { CM.Disp.BotBar.style.bottom = '0px'; l('game').style.bottom = '70px'; } - else if (CM.Config.TimerBar == 1 && CM.Config.TimerBarPos == 1) { + else if (CM.Options.TimerBar == 1 && CM.Options.TimerBarPos == 1) { l('game').style.bottom = '48px'; } else { // No bars l('game').style.bottom = '0px'; } - if (CM.Config.TimerBar == 1 && CM.Config.TimerBarPos == 0) { + if (CM.Options.TimerBar == 1 && CM.Options.TimerBarPos == 0) { l('sectionLeft').style.top = '48px'; } else { @@ -688,18 +688,18 @@ CM.Disp.UpdateBotTimerBarPosition = function() { /** * This function adjusts some things in the column of buildings. - * It colours them, helps display the correct sell-price and shuffles the order when CM.Config.SortBuildings is set + * It colours them, helps display the correct sell-price and shuffles the order when CM.Options.SortBuildings is set * The function is called by CM.Loop(), CM.Disp.UpdateColors() & CM.Disp.RefreshScale() - * And by changes in CM.Config.BuildColor, CM.Config.SortBuild & CM.ConfigData.BulkBuildColor + * And by changes in CM.Options.BuildColor, CM.Options.SortBuild & CM.ConfigData.BulkBuildColor */ CM.Disp.UpdateBuildings = function() { - if (CM.Config.BuildColor == 1 && Game.buyMode == 1) { + if (CM.Options.BuildColor == 1 && Game.buyMode == 1) { var target = ''; - if (Game.buyBulk == 10 && CM.Config.BulkBuildColor == 1) target = 'Objects10'; - else if (Game.buyBulk == 100 && CM.Config.BulkBuildColor == 1) target = 'Objects100'; + if (Game.buyBulk == 10 && CM.Options.BulkBuildColor == 1) target = 'Objects10'; + else if (Game.buyBulk == 100 && CM.Options.BulkBuildColor == 1) target = 'Objects100'; else target = 'Objects'; for (var i in CM.Cache[target]) { - l('productPrice' + Game.Objects[i].id).style.color = CM.Config.Colors[CM.Cache[target][i].color]; + l('productPrice' + Game.Objects[i].id).style.color = CM.Options.Colors[CM.Cache[target][i].color]; } } else if (Game.buyMode == -1) { @@ -721,7 +721,7 @@ CM.Disp.UpdateBuildings = function() { // Build array of pointers, sort by pp, use array index (+2) as the grid row number // (grid rows are 1-based indexing, and row 1 is the bulk buy/sell options) // This regulates sorting of buildings - if (Game.buyMode == 1 && CM.Config.SortBuildings) { + if (Game.buyMode == 1 && CM.Options.SortBuildings) { var arr = Object.keys(CM.Cache[target]).map(k => { var o = CM.Cache[target][k]; @@ -752,13 +752,13 @@ CM.Disp.UpdateBuildings = function() { /** * This function adjusts some things in the upgrades section - * It colours them and shuffles the order when CM.Config.SortBuildings is set + * It colours them and shuffles the order when CM.Options.SortBuildings is set * The function is called by CM.Loop(), CM.Disp.ToggleUpgradeBarAndColor & CM.Disp.RefreshScale() - * And by changes in CM.Config.SortUpgrades + * And by changes in CM.Options.SortUpgrades */ CM.Disp.UpdateUpgrades = function() { // This counts the amount of upgrades for each pp group and updates the Upgrade Bar - if (CM.Config.UpBarColor > 0) { + if (CM.Options.UpBarColor > 0) { var blue = 0; var green = 0; var yellow = 0; @@ -813,7 +813,7 @@ CM.Disp.UpdateUpgrades = function() { arr.push(o); } - if (CM.Config.SortUpgrades) + if (CM.Options.SortUpgrades) arr.sort((a, b) => a.pp - b.pp); else arr.sort((a, b) => a.price - b.price); @@ -828,14 +828,14 @@ CM.Disp.UpdateUpgrades = function() { /** * This function toggles the upgrade bar and the colours of upgrades - * It is called by a change in CM.Config.UpBarColor + * It is called by a change in CM.Options.UpBarColor */ CM.Disp.ToggleUpgradeBarAndColor = function() { - if (CM.Config.UpBarColor == 1) { // Colours and bar on + if (CM.Options.UpBarColor == 1) { // Colours and bar on CM.Disp.UpgradeBar.style.display = ''; CM.Disp.UpdateUpgrades(); } - else if (CM.Config.UpBarColor == 2) {// Colours on and bar off + else if (CM.Options.UpBarColor == 2) {// Colours on and bar off CM.Disp.UpgradeBar.style.display = 'none'; CM.Disp.UpdateUpgrades(); } @@ -847,10 +847,10 @@ CM.Disp.ToggleUpgradeBarAndColor = function() { /** * This function toggles the position of the upgrade bar from fixed or non-fixed mode - * It is called by a change in CM.Config.UpgradeBarFixedPos + * It is called by a change in CM.Options.UpgradeBarFixedPos */ CM.Disp.ToggleUpgradeBarFixedPos = function() { - if (CM.Config.UpgradeBarFixedPos == 1) { // Fix to top of screen when scrolling + if (CM.Options.UpgradeBarFixedPos == 1) { // Fix to top of screen when scrolling CM.Disp.UpgradeBar.style.position = 'sticky'; CM.Disp.UpgradeBar.style.top = '0px'; } @@ -960,10 +960,10 @@ CM.Disp.CreateWhiteScreen = function() { * that check game-events and which have settings for Flashes (e.g., Golden Cookies appearing, Magic meter being full) * @param {number} mode Sets the intensity of the flash, used to recursively dim flash * All calls of function have use mode == 3 - * @param {string} config The setting in CM.Config that is checked before creating the flash + * @param {string} config The setting in CM.Options that is checked before creating the flash */ CM.Disp.Flash = function(mode, config) { - if ((CM.Config[config] == 1 && mode == 3) || mode == 1) { + if ((CM.Options[config] == 1 && mode == 3) || mode == 1) { CM.Disp.WhiteScreen.style.opacity = '0.5'; if (mode == 3) { CM.Disp.WhiteScreen.style.display = 'inline'; @@ -983,14 +983,14 @@ CM.Disp.Flash = function(mode, config) { /** * This function plays a sound depending on configs. It is called by all functions * that check game-events and which have settings for sound (e.g., Golden Cookies appearing, Magic meter being full) - * @param {variable} url A variable that gives the url for the sound (e.g., CM.Config.GCSoundURL) - * @param {string} sndConfig The setting in CM.Config that is checked before creating the sound - * @param {string} volConfig The setting in CM.Config that is checked to determine volume + * @param {variable} url A variable that gives the url for the sound (e.g., CM.Options.GCSoundURL) + * @param {string} sndConfig The setting in CM.Options that is checked before creating the sound + * @param {string} volConfig The setting in CM.Options that is checked to determine volume */ CM.Disp.PlaySound = function(url, sndConfig, volConfig) { - if (CM.Config[sndConfig] == 1) { + if (CM.Options[sndConfig] == 1) { var sound = new realAudio(url); - sound.volume = (CM.Config[volConfig] / 100) * (Game.volume / 100); + sound.volume = (CM.Options[volConfig] / 100) * (Game.volume / 100); sound.play(); } } @@ -998,12 +998,12 @@ CM.Disp.PlaySound = function(url, sndConfig, volConfig) { /** * This function creates a notifcation depending on configs. It is called by all functions * that check game-events and which have settings for notifications (e.g., Golden Cookies appearing, Magic meter being full) - * @param {string} notifyConfig The setting in CM.Config that is checked before creating the notification + * @param {string} notifyConfig The setting in CM.Options that is checked before creating the notification * @param {string} title The title of the to-be created notifications * @param {string} message The text of the to-be created notifications */ CM.Disp.Notification = function(notifyConfig, title, message) { - if (CM.Config[notifyConfig] == 1 && document.visibilityState == 'hidden') { + if (CM.Options[notifyConfig] == 1 && document.visibilityState == 'hidden') { var CookieIcon = 'https://orteil.dashnet.org/cookieclicker/favicon.ico' notification = new Notification(title, {body: message, badge: CookieIcon}); } @@ -1025,11 +1025,11 @@ CM.Disp.CreateFavicon = function() { /** * This function updates the Favicon depending on whether a Golden Cookie has spawned - * It is called on every loop by CM.Main.CheckGoldenCookie() or by a change in CM.Config.Favicon + * It is called on every loop by CM.Main.CheckGoldenCookie() or by a change in CM.Options.Favicon * By relying on CM.Cache.spawnedGoldenShimmer it only changes for non-user spawned cookie */ CM.Disp.UpdateFavicon = function() { - if (CM.Config.Favicon == 1 && CM.Main.lastGoldenCookieState > 0) { + if (CM.Options.Favicon == 1 && CM.Main.lastGoldenCookieState > 0) { if (CM.Cache.spawnedGoldenShimmer.wrath) CM.Disp.Favicon.href = 'https://aktanusa.github.io/CookieMonster/favicon/wrathCookie.ico'; else CM.Disp.Favicon.href = 'https://aktanusa.github.io/CookieMonster/favicon/goldenCookie.ico'; } @@ -1041,10 +1041,10 @@ CM.Disp.UpdateFavicon = function() { * It is called on every loop by Game.Logic() which also sets CM.Cache.Title to Game.cookies */ CM.Disp.UpdateTitle = function() { - if (Game.OnAscend || CM.Config.Title == 0) { + if (Game.OnAscend || CM.Options.Title == 0) { document.title = CM.Cache.Title; } - else if (CM.Config.Title == 1) { + else if (CM.Options.Title == 1) { var addFC = false; var addSP = false; var titleGC; @@ -1080,7 +1080,7 @@ CM.Disp.UpdateTitle = function() { } document.title = titleGC + (addFC ? titleFC : '') + (addSP ? titleSP : '') + ' ' + str; } - else if (CM.Config.Title == 2) { + else if (CM.Options.Title == 2) { var str = ''; var spawn = false; if (CM.Cache.spawnedGoldenShimmer) { @@ -1125,7 +1125,7 @@ CM.Disp.CreateGCTimer = function(cookie) { GCTimer.style.fontSize = '35px'; GCTimer.style.cursor = 'pointer'; GCTimer.style.display = 'block'; - if (CM.Config.GCTimer == 0) GCTimer.style.display = 'none'; + if (CM.Options.GCTimer == 0) GCTimer.style.display = 'none'; GCTimer.style.left = cookie.l.style.left; GCTimer.style.top = cookie.l.style.top; GCTimer.onclick = function () {cookie.pop();}; @@ -1138,10 +1138,10 @@ CM.Disp.CreateGCTimer = function(cookie) { /** * This function toggles GC Timers are visible - * It is called by a change in CM.Config.GCTimer + * It is called by a change in CM.Options.GCTimer */ CM.Disp.ToggleGCTimer = function() { - if (CM.Config.GCTimer == 1) { + if (CM.Options.GCTimer == 1) { for (var i in CM.Disp.GCTimers) { CM.Disp.GCTimers[i].style.display = 'block'; CM.Disp.GCTimers[i].style.left = CM.Cache.goldenShimmersByID[i].l.style.left; @@ -1257,7 +1257,7 @@ CM.Disp.Tooltip = function(type, name) { if (type == 'b') { // Buildings l('tooltip').innerHTML = Game.Objects[name].tooltip(); // Adds amortization info to the list of info per building - if (CM.Config.TooltipAmor == 1) { + if (CM.Options.TooltipAmor == 1) { var buildPrice = CM.Sim.BuildingGetPrice(Game.Objects[name], Game.Objects[name].basePrice, 0, Game.Objects[name].free, Game.Objects[name].amount); var amortizeAmount = buildPrice - Game.Objects[name].totalCookies; if (amortizeAmount > 0) { @@ -1452,7 +1452,7 @@ CM.Disp.UpdateTooltip = function() { * It is called when Building tooltips are created or refreshed by CM.Disp.UpdateTooltip() */ CM.Disp.UpdateTooltipBuilding = function() { - if (CM.Config.TooltipBuildUp == 1 && Game.buyMode == 1) { + if (CM.Options.TooltipBuildUp == 1 && Game.buyMode == 1) { tooltipBox = l('CMTooltipBorder'); CM.Disp.TooltipCreateCalculationSection(tooltipBox); @@ -1467,7 +1467,7 @@ CM.Disp.UpdateTooltipBuilding = function() { CM.Disp.TooltipBonusIncome = CM.Cache[target][CM.Disp.tooltipName].bonus; - if (CM.Config.TooltipBuildUp == 1 && Game.buyMode == 1) { + if (CM.Options.TooltipBuildUp == 1 && Game.buyMode == 1) { l('CMTooltipIncome').textContent = Beautify(CM.Disp.TooltipBonusIncome, 2); var increase = Math.round(CM.Disp.TooltipBonusIncome / Game.cookiesPs * 10000); if (isFinite(increase) && increase != 0) { @@ -1512,7 +1512,7 @@ CM.Disp.UpdateTooltipUpgrade = function() { CM.Disp.TooltipBonusIncome = CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].bonus; CM.Disp.TooltipPrice = Game.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].getPrice(); - if (CM.Config.TooltipBuildUp == 1) { + if (CM.Options.TooltipBuildUp == 1) { l('CMTooltipIncome').textContent = Beautify(CM.Disp.TooltipBonusIncome, 2); var increase = Math.round(CM.Disp.TooltipBonusIncome / Game.cookiesPs * 10000); if (isFinite(increase) && increase != 0) { @@ -1543,7 +1543,7 @@ CM.Disp.UpdateTooltipUpgrade = function() { * It adds to the additional information to l('CMTooltipArea') */ CM.Disp.UpdateTooltipSugarLump = function() { - if (CM.Config.TooltipLump === 1) { + if (CM.Options.TooltipLump === 1) { tooltipBox = l('CMTooltipBorder'); tooltipBox.appendChild(CM.Disp.TooltipCreateHeader('Current Sugar Lump')); @@ -1566,7 +1566,7 @@ CM.Disp.UpdateTooltipGrimoire = function() { var minigame = Game.Objects['Wizard tower'].minigame; var spellCost = minigame.getSpellCost(minigame.spellsById[CM.Disp.tooltipName]); - if (CM.Config.TooltipGrim == 1 && spellCost <= minigame.magicM) { + if (CM.Options.TooltipGrim == 1 && spellCost <= minigame.magicM) { tooltipBox = l('CMTooltipBorder'); // Time left till enough magic for spell @@ -1624,14 +1624,14 @@ CM.Disp.UpdateTooltipWarnings = function() { CM.Disp.ToggleToolWarnPos(); } - if (CM.Config.ToolWarnPos == 0) CM.Disp.TooltipWarn.style.right = '0px'; + if (CM.Options.ToolWarnPos == 0) CM.Disp.TooltipWarn.style.right = '0px'; else CM.Disp.TooltipWarn.style.top = (l('tooltip').offsetHeight) + 'px'; CM.Disp.TooltipWarn.style.width = (l('tooltip').offsetWidth - 6) + 'px'; - if (CM.Config.ToolWarnLucky == 1) { + if (CM.Options.ToolWarnLucky == 1) { var limitLucky = CM.Cache.Lucky; - if (CM.Config.ToolWarnBon == 1) { + if (CM.Options.ToolWarnBon == 1) { var bonusNoFren = CM.Disp.TooltipBonusIncome; bonusNoFren /= CM.Sim.getCPSBuffMult(); limitLucky += ((bonusNoFren * 60 * 15) / 0.15); @@ -1660,9 +1660,9 @@ CM.Disp.UpdateTooltipWarnings = function() { l('CMDispTooltipWarnLuckyFrenzy').style.display = 'none'; } - if (CM.Config.ToolWarnConjure == 1) { + if (CM.Options.ToolWarnConjure == 1) { var limitLucky = CM.Cache.Lucky; - if (CM.Config.ToolWarnBon == 1) { + if (CM.Options.ToolWarnBon == 1) { var bonusNoFren = CM.Disp.TooltipBonusIncome; bonusNoFren /= CM.Sim.getCPSBuffMult(); limitLucky += ((bonusNoFren * 60 * 15) / 0.15); @@ -1694,25 +1694,25 @@ CM.Disp.UpdateTooltipWarnings = function() { CM.Disp.UpdateTooltipLocation = function() { if (Game.tooltip.origin == 'store') { var warnOffset = 0; - if (CM.Config.ToolWarnLucky == 1 && CM.Config.ToolWarnPos == 1 && typeof CM.Disp.TooltipWarn != "undefined") { + if (CM.Options.ToolWarnLucky == 1 && CM.Options.ToolWarnPos == 1 && typeof CM.Disp.TooltipWarn != "undefined") { warnOffset = CM.Disp.TooltipWarn.clientHeight - 4; } Game.tooltip.tta.style.top = Math.min(parseInt(Game.tooltip.tta.style.top), (l('game').clientHeight + l('topBar').clientHeight) - Game.tooltip.tt.clientHeight - warnOffset - 46) + 'px'; } // Kept for future possible use if the code changes again - /*else if (!Game.onCrate && !Game.OnAscend && CM.Config.TimerBar == 1 && CM.Config.TimerBarPos == 0) { + /*else if (!Game.onCrate && !Game.OnAscend && CM.Options.TimerBar == 1 && CM.Options.TimerBarPos == 0) { Game.tooltip.tta.style.top = (parseInt(Game.tooltip.tta.style.top) + parseInt(CM.Disp.TimerBar.style.height)) + 'px'; }*/ } /** * This function toggles the position of the warnings created by CM.Disp.TooltipCreateWarningSection() - * It is called by a change in CM.Config.ToolWarnPos + * It is called by a change in CM.Options.ToolWarnPos * and upon creation of the warning tooltip by CM.Disp.UpdateTooltipWarnings() */ CM.Disp.ToggleToolWarnPos = function() { if (typeof CM.Disp.TooltipWarn != "undefined") { - if (CM.Config.ToolWarnPos == 0) { + if (CM.Options.ToolWarnPos == 0) { CM.Disp.TooltipWarn.style.top = 'auto'; CM.Disp.TooltipWarn.style.margin = '4px -4px'; CM.Disp.TooltipWarn.style.padding = '3px 4px'; @@ -1731,7 +1731,7 @@ CM.Disp.ToggleToolWarnPos = function() { * TODO: Change this code to be the same as other tooltips. (i.d., create tooltip with type "w") */ CM.Disp.CheckWrinklerTooltip = function() { - if (CM.Config.ToolWrink == 1 && CM.Disp.TooltipWrinklerArea == 1) { // Latter is set by CM.Main.AddWrinklerAreaDetect + if (CM.Options.ToolWrink == 1 && CM.Disp.TooltipWrinklerArea == 1) { // Latter is set by CM.Main.AddWrinklerAreaDetect var showingTooltip = false; for (var i in Game.wrinklers) { var me = Game.wrinklers[i]; @@ -1769,7 +1769,7 @@ CM.Disp.CheckWrinklerTooltip = function() { * TODO: Change this code to be the same as other tooltips. Fit this into CM.Disp.UpdateTooltip() */ CM.Disp.UpdateWrinklerTooltip = function() { - if (CM.Config.ToolWrink == 1 && l('CMTooltipWrinkler') != null) { + if (CM.Options.ToolWrink == 1 && l('CMTooltipWrinkler') != null) { var sucked = Game.wrinklers[CM.Disp.TooltipWrinkler].sucked; var toSuck = 1.1; if (Game.Has('Sacrilegious corruption')) toSuck *= 1.05; @@ -1795,7 +1795,7 @@ CM.Disp.UpdateWrinklerTooltip = function() { * @param {number} aura The number of the aura currently selected by the mouse/user */ CM.Disp.AddAuraInfo = function(aura) { - if (CM.Config.DragonAuraInfo == 1) { + if (CM.Options.DragonAuraInfo == 1) { var [bonusCPS, priceOfChange] = CM.Sim.CalculateChangeAura(aura); var timeToRecover = CM.Disp.FormatTime(priceOfChange / (bonusCPS + Game.cookiesPs)); var bonusCPSPercentage = CM.Disp.Beautify(bonusCPS / Game.cookiesPs); @@ -1836,18 +1836,18 @@ CM.Disp.AddMenu = function() { CM.Disp.AddMenuPref(title); } else if (Game.onMenu == 'stats') { - if (CM.Config.Stats) { + if (CM.Options.Stats) { CM.Disp.AddMenuStats(title); } } } /** - * This function refreshes the stats page, CM.Config.UpStats determines the rate at which that happens + * This function refreshes the stats page, CM.Options.UpStats determines the rate at which that happens * It is called by CM.Loop() */ CM.Disp.RefreshMenu = function() { - if (CM.Config.UpStats && Game.onMenu == 'stats' && (Game.drawT - 1) % (Game.fps * 5) != 0 && (Game.drawT - 1) % Game.fps == 0) Game.UpdateMenu(); + if (CM.Options.UpStats && Game.onMenu == 'stats' && (Game.drawT - 1) % (Game.fps * 5) != 0 && (Game.drawT - 1) % Game.fps == 0) Game.UpdateMenu(); } /******** @@ -1865,7 +1865,7 @@ CM.Disp.AddMenuPref = function(title) { for (var group in CM.ConfigGroups) { groupObject = CM.Disp.CreatePrefHeader(group, CM.ConfigGroups[group]) // (group, display-name of group) frag.appendChild(groupObject) - if (CM.Config.OptionsPref[group]) { // 0 is show, 1 is collapsed + if (CM.Options.OptionsPref[group]) { // 0 is show, 1 is collapsed for (var option in CM.ConfigData) { if (CM.ConfigData[option].group == group) frag.appendChild(CM.Disp.CreatePrefOption(option)) } @@ -1894,6 +1894,7 @@ CM.Disp.AddMenuPref = function(title) { CM.Disp.CreatePrefHeader = function(config, text) { var div = document.createElement('div'); div.className = 'title'; + div.style.opacity = '0.7'; div.style.fontSize = '17px'; div.appendChild(document.createTextNode(text + ' ')); @@ -1908,7 +1909,7 @@ CM.Disp.CreatePrefHeader = function(config, text) { span.style.color = 'black'; span.style.fontSize = '13px'; span.style.verticalAlign = 'middle'; - span.textContent = CM.Config.OptionsPref[config] ? '-' : '+'; + span.textContent = CM.Options.OptionsPref[config] ? '-' : '+'; span.onclick = function() {CM.ToggleOptionsConfig(config); Game.UpdateMenu();}; div.appendChild(span); return div; @@ -1925,7 +1926,7 @@ CM.Disp.CreatePrefOption = function(config) { var div = document.createElement('div'); div.className = 'listing'; var a = document.createElement('a'); - if (CM.ConfigData[config].toggle && CM.Config[config] == 0) { + if (CM.ConfigData[config].toggle && CM.Options[config] == 0) { a.className = 'option off'; } else { @@ -1933,7 +1934,7 @@ CM.Disp.CreatePrefOption = function(config) { } a.id = CM.ConfigPrefix + config; a.onclick = function() {CM.ToggleConfig(config);}; - a.textContent = CM.ConfigData[config].label[CM.Config[config]]; + a.textContent = CM.ConfigData[config].label[CM.Options[config]]; div.appendChild(a); var label = document.createElement('label'); label.textContent = CM.ConfigData[config].desc; @@ -1952,7 +1953,7 @@ CM.Disp.CreatePrefOption = function(config) { var percent = title = document.createElement('div'); percent.id = "slider" + config + "right"; percent.style.float = "right"; - percent.innerHTML = CM.Config[config] + "%"; + percent.innerHTML = CM.Options[config] + "%"; volume.appendChild(percent); var slider = document.createElement('input'); slider.className = "slider"; @@ -1962,7 +1963,7 @@ CM.Disp.CreatePrefOption = function(config) { slider.min = "0"; slider.max = "100"; slider.step = "1"; - slider.value = CM.Config[config]; + slider.value = CM.Options[config]; slider.oninput = function() {CM.ToggleConfigVolume(config)}; slider.onchange = function() {CM.ToggleConfigVolume(config)}; volume.appendChild(slider); @@ -1981,7 +1982,7 @@ CM.Disp.CreatePrefOption = function(config) { input.className = 'option'; input.type = 'text'; input.readOnly = true; - input.setAttribute('value', CM.Config[config]); + input.setAttribute('value', CM.Options[config]); input.style.width = '300px'; div.appendChild(input); div.appendChild(document.createTextNode(' ')); @@ -1989,10 +1990,10 @@ CM.Disp.CreatePrefOption = function(config) { inputPrompt.id = CM.ConfigPrefix + config + 'Prompt'; inputPrompt.className = 'option'; inputPrompt.type = 'text'; - inputPrompt.setAttribute('value', CM.Config[config]); + inputPrompt.setAttribute('value', CM.Options[config]); var a = document.createElement('a'); a.className = 'option'; - a.onclick = function() {Game.Prompt(inputPrompt.outerHTML, [['Save', 'CM.Config[\'' + config + '\'] = l(CM.ConfigPrefix + \'' + config + '\' + \'Prompt\').value; CM.SaveConfig(CM.Config); Game.ClosePrompt(); Game.UpdateMenu();'], 'Cancel']);}; + a.onclick = function() {Game.Prompt(inputPrompt.outerHTML, [['Save', 'CM.Options[\'' + config + '\'] = l(CM.ConfigPrefix + \'' + config + '\' + \'Prompt\').value; CM.SaveConfig(CM.Options); Game.ClosePrompt(); Game.UpdateMenu();'], 'Cancel']);}; a.textContent = 'Edit'; div.appendChild(a); var label = document.createElement('label'); @@ -2008,9 +2009,9 @@ CM.Disp.CreatePrefOption = function(config) { input.id = CM.ConfigPrefix + 'Color' + CM.Disp.colors[i]; input.className = 'option'; input.style.width = '65px'; - input.setAttribute('value', CM.Config.Colors[CM.Disp.colors[i]]); + input.setAttribute('value', CM.Options.Colors[CM.Disp.colors[i]]); div.appendChild(input); - eval('var change = function() {CM.Config.Colors[\'' + CM.Disp.colors[i] + '\'] = l(CM.ConfigPrefix + \'Color\' + \'' + CM.Disp.colors[i] + '\').value; CM.Disp.UpdateColors(); CM.SaveConfig(CM.Config);}'); + eval('var change = function() {CM.Options.Colors[\'' + CM.Disp.colors[i] + '\'] = l(CM.ConfigPrefix + \'Color\' + \'' + CM.Disp.colors[i] + '\').value; CM.Disp.UpdateColors(); CM.SaveConfig(CM.Options);}'); var jscolorpicker = new jscolor.color(input, {hash: true, caps: false, pickerZIndex: 1000000, pickerPosition: 'right', onImmediateChange: change}); var label = document.createElement('label'); label.textContent = CM.ConfigData.Colors.desc[CM.Disp.colors[i]]; @@ -2022,16 +2023,16 @@ CM.Disp.CreatePrefOption = function(config) { /** * This function changes some of the time-displays in the game to be more detailed - * It is called by a change in CM.Config.DetailedTime + * It is called by a change in CM.Options.DetailedTime */ CM.Disp.ToggleDetailedTime = function() { - if (CM.Config.DetailedTime == 1) Game.sayTime = CM.Disp.sayTime; + if (CM.Options.DetailedTime == 1) Game.sayTime = CM.Disp.sayTime; else Game.sayTime = CM.Backup.sayTime; } /** * This function refreshes all numbers after a change in scale-setting - * It is therefore called by a change in CM.Config.Scale and CM.Config.ScaleDecimals + * It is therefore called by a change in CM.Options.Scale and CM.Options.ScaleDecimals */ CM.Disp.RefreshScale = function() { BeautifyAll(); @@ -2045,18 +2046,18 @@ CM.Disp.RefreshScale = function() { /** * This function changes/refreshes colours if the user has set new standard colours - * The function is therefore called by a change in CM.Config.Colors + * The function is therefore called by a change in CM.Options.Colors */ CM.Disp.UpdateColors = function() { var str = ''; for (var i = 0; i < CM.Disp.colors.length; i++) { - str += '.' + CM.Disp.colorTextPre + CM.Disp.colors[i] + ' { color: ' + CM.Config.Colors[CM.Disp.colors[i]] + '; }\n'; + str += '.' + CM.Disp.colorTextPre + CM.Disp.colors[i] + ' { color: ' + CM.Options.Colors[CM.Disp.colors[i]] + '; }\n'; } for (var i = 0; i < CM.Disp.colors.length; i++) { - str += '.' + CM.Disp.colorBackPre + CM.Disp.colors[i] + ' { background-color: ' + CM.Config.Colors[CM.Disp.colors[i]] + '; }\n'; + str += '.' + CM.Disp.colorBackPre + CM.Disp.colors[i] + ' { background-color: ' + CM.Options.Colors[CM.Disp.colors[i]] + '; }\n'; } for (var i = 0; i < CM.Disp.colors.length; i++) { - str += '.' + CM.Disp.colorBorderPre + CM.Disp.colors[i] + ' { border: 1px solid ' + CM.Config.Colors[CM.Disp.colors[i]] + '; }\n'; + str += '.' + CM.Disp.colorBorderPre + CM.Disp.colors[i] + ' { border: 1px solid ' + CM.Options.Colors[CM.Disp.colors[i]] + '; }\n'; } CM.Disp.Css.textContent = str; CM.Disp.UpdateBuildings(); // Class has been already set @@ -2077,28 +2078,28 @@ CM.Disp.AddMenuStats = function(title) { stats.appendChild(title()); stats.appendChild(CM.Disp.CreateStatsHeader('Lucky Cookies', 'Lucky')); - if (CM.Config.StatsPref.Lucky) { + if (CM.Options.StatsPref.Lucky) { stats.appendChild(CM.Disp.CreateStatsLuckySection()); } stats.appendChild(CM.Disp.CreateStatsHeader('Chain Cookies', 'Chain')); - if (CM.Config.StatsPref.Chain) { + if (CM.Options.StatsPref.Chain) { stats.appendChild(CM.Disp.CreateStatsChainSection()); } stats.appendChild(CM.Disp.CreateStatsHeader('Conjure Baked Goods', 'Conjure')); - if (CM.Config.StatsPref.Conjure) { + if (CM.Options.StatsPref.Conjure) { stats.appendChild(CM.Disp.CreateStatsConjureSection()); } stats.appendChild(CM.Disp.CreateStatsHeader('Prestige', 'Prestige')); - if (CM.Config.StatsPref.Prestige) { + if (CM.Options.StatsPref.Prestige) { stats.appendChild(CM.Disp.CreateStatsPrestigeSection()); } if (Game.cpsSucked > 0) { stats.appendChild(CM.Disp.CreateStatsHeader('Wrinklers', 'Wrink')); - if (CM.Config.StatsPref.Wrink) { + if (CM.Options.StatsPref.Wrink) { var popAllFrag = document.createDocumentFragment(); popAllFrag.appendChild(document.createTextNode(Beautify(CM.Cache.WrinkBankTotal) + ' / ' + Beautify(CM.Cache.WrinkBankNormal) + ' ')); var popAllA = document.createElement('a'); @@ -2152,7 +2153,7 @@ CM.Disp.AddMenuStats = function(title) { if (Game.season == 'christmas' || specDisp || choEgg || centEgg) { stats.appendChild(CM.Disp.CreateStatsHeader('Season Specials', 'Sea')); - if (CM.Config.StatsPref.Sea) { + if (CM.Options.StatsPref.Sea) { if (specDisp) { if (missingHalloweenCookies.length != 0) stats.appendChild(CM.Disp.CreateStatsListing("basic", 'Halloween Cookies Left to Buy', CM.Disp.CreateStatsMissDisp(missingHalloweenCookies))); if (missingChristmasCookies.length != 0) stats.appendChild(CM.Disp.CreateStatsListing("basic", 'Christmas Cookies Left to Buy', CM.Disp.CreateStatsMissDisp(missingChristmasCookies))); @@ -2172,12 +2173,12 @@ CM.Disp.AddMenuStats = function(title) { } stats.appendChild(CM.Disp.CreateStatsHeader('Miscellaneous', 'Misc')); - if (CM.Config.StatsPref.Misc) { + if (CM.Options.StatsPref.Misc) { stats.appendChild(CM.Disp.CreateStatsListing("basic", - 'Average Cookies Per Second (Past ' + (CM.Disp.cookieTimes[CM.Config.AvgCPSHist] < 60 ? (CM.Disp.cookieTimes[CM.Config.AvgCPSHist] + ' seconds') : ((CM.Disp.cookieTimes[CM.Config.AvgCPSHist] / 60) + (CM.Config.AvgCPSHist == 3 ? ' minute' : ' minutes'))) + ')', + 'Average Cookies Per Second (Past ' + (CM.Disp.cookieTimes[CM.Options.AvgCPSHist] < 60 ? (CM.Disp.cookieTimes[CM.Options.AvgCPSHist] + ' seconds') : ((CM.Disp.cookieTimes[CM.Options.AvgCPSHist] / 60) + (CM.Options.AvgCPSHist == 3 ? ' minute' : ' minutes'))) + ')', document.createTextNode(Beautify(CM.Cache.AvgCPS, 3)) )); - stats.appendChild(CM.Disp.CreateStatsListing("basic", 'Average Cookie Clicks Per Second (Past ' + CM.Disp.clickTimes[CM.Config.AvgClicksHist] + (CM.Config.AvgClicksHist == 0 ? ' second' : ' seconds') + ')', document.createTextNode(Beautify(CM.Cache.AvgClicks, 1)))); + stats.appendChild(CM.Disp.CreateStatsListing("basic", 'Average Cookie Clicks Per Second (Past ' + CM.Disp.clickTimes[CM.Options.AvgClicksHist] + (CM.Options.AvgClicksHist == 0 ? ' second' : ' seconds') + ')', document.createTextNode(Beautify(CM.Cache.AvgClicks, 1)))); if (Game.Has('Fortune cookies')) { var fortunes = []; for (var i in CM.Data.Fortunes) { @@ -2198,7 +2199,7 @@ CM.Disp.AddMenuStats = function(title) { l('menu').insertBefore(stats, l('menu').childNodes[2]); - if (CM.Config.MissingUpgrades) { + if (CM.Options.MissingUpgrades) { CM.Disp.AddMissingUpgrades(); } } @@ -2229,7 +2230,7 @@ CM.Disp.CreateStatsHeader = function(text, config) { span.style.color = 'black'; span.style.fontSize = '13px'; span.style.verticalAlign = 'middle'; - span.textContent = CM.Config.StatsPref[config] ? '-' : '+'; + span.textContent = CM.Options.StatsPref[config] ? '-' : '+'; span.onclick = function() {CM.ToggleStatsConfig(config); Game.UpdateMenu();}; div.appendChild(span); return div; diff --git a/src/Header.js b/src/Header.js index 3731fa3..11f5e28 100644 --- a/src/Header.js +++ b/src/Header.js @@ -18,6 +18,8 @@ RunCookieMonsterHeader = function() { CM.Main = {}; + CM.Options = {}; + CM.Sim = {}; } diff --git a/src/Main.js b/src/Main.js index 20705c2..b15660c 100644 --- a/src/Main.js +++ b/src/Main.js @@ -126,7 +126,7 @@ CM.ReplaceNativeGrimoireDraw = function() { CM.Backup.GrimoireDraw = minigame.draw; Game.Objects['Wizard tower'].minigame.draw = function() { CM.Backup.GrimoireDraw(); - if (CM.Config.GrimoireBar == 1 && minigame.magic < minigame.magicM) { + if (CM.Options.GrimoireBar == 1 && minigame.magic < minigame.magicM) { minigame.magicBarTextL.innerHTML += ' (' + CM.Disp.FormatTime(CM.Disp.CalculateGrimoireRefillTime(minigame.magic, minigame.magicM, minigame.magicM)) + ')'; } } @@ -314,7 +314,7 @@ CM.Main.CheckGoldenCookie = function() { if (CM.Main.lastGoldenCookieState) { if (CM.Main.lastSpawnedGoldenCookieState < CM.Main.currSpawnedGoldenCookieState) { CM.Disp.Flash(3, 'GCFlash'); - CM.Disp.PlaySound(CM.Config.GCSoundURL, 'GCSound', 'GCVolume'); + CM.Disp.PlaySound(CM.Options.GCSoundURL, 'GCSound', 'GCVolume'); CM.Disp.Notification('GCNotification', "Golden Cookie Spawned", "A Golden Cookie has spawned. Click it now!") } @@ -328,7 +328,7 @@ CM.Main.CheckGoldenCookie = function() { CM.Main.lastSpawnedGoldenCookieState = CM.Main.currSpawnedGoldenCookieState; if (CM.Main.currSpawnedGoldenCookieState == 0) CM.Cache.spawnedGoldenShimmer = 0; } - else if (CM.Config.GCTimer == 1 && CM.Main.lastGoldenCookieState) { + else if (CM.Options.GCTimer == 1 && CM.Main.lastGoldenCookieState) { for (var i in CM.Disp.GCTimers) { CM.Disp.GCTimers[i].style.opacity = CM.Cache.goldenShimmersByID[i].l.style.opacity; CM.Disp.GCTimers[i].style.transform = CM.Cache.goldenShimmersByID[i].l.style.transform; @@ -351,7 +351,7 @@ CM.Main.CheckSeasonPopup = function() { } } CM.Disp.Flash(3, 'SeaFlash'); - CM.Disp.PlaySound(CM.Config.SeaSoundURL, 'SeaSound', 'SeaVolume'); + CM.Disp.PlaySound(CM.Options.SeaSoundURL, 'SeaSound', 'SeaVolume'); CM.Disp.Notification('SeaNotification',"Reindeer sighted!", "A Reindeer has spawned. Click it now!") } } @@ -365,7 +365,7 @@ CM.Main.CheckTickerFortune = function() { CM.Main.lastTickerFortuneState = (Game.TickerEffect && Game.TickerEffect.type == 'fortune'); if (CM.Main.lastTickerFortuneState) { CM.Disp.Flash(3, 'FortuneFlash'); - CM.Disp.PlaySound(CM.Config.FortuneSoundURL, 'FortuneSound', 'FortuneVolume'); + CM.Disp.PlaySound(CM.Options.FortuneSoundURL, 'FortuneSound', 'FortuneVolume'); CM.Disp.Notification('FortuneNotification', "Fortune Cookie found", "A Fortune Cookie has appeared on the Ticker.") } } @@ -379,7 +379,7 @@ CM.Main.CheckGardenTick = function() { if (Game.Objects['Farm'].minigameLoaded && CM.Main.lastGardenNextStep != Game.Objects['Farm'].minigame.nextStep) { if (CM.Main.lastGardenNextStep != 0 && CM.Main.lastGardenNextStep < Date.now()) { CM.Disp.Flash(3, 'GardFlash'); - CM.Disp.PlaySound(CM.Config.GardSoundURL, 'GardSound', 'GardVolume'); + CM.Disp.PlaySound(CM.Options.GardSoundURL, 'GardSound', 'GardVolume'); } CM.Main.lastGardenNextStep = Game.Objects['Farm'].minigame.nextStep; } @@ -390,13 +390,13 @@ CM.Main.CheckGardenTick = function() { * It is called by CM.Loop */ CM.Main.CheckMagicMeter = function() { - if (Game.Objects['Wizard tower'].minigameLoaded && CM.Config.GrimoireBar == 1) { + if (Game.Objects['Wizard tower'].minigameLoaded && CM.Options.GrimoireBar == 1) { var minigame = Game.Objects['Wizard tower'].minigame; if (minigame.magic < minigame.magicM) CM.Main.lastMagicBarFull = false; else if (!CM.Main.lastMagicBarFull) { CM.Main.lastMagicBarFull = true; CM.Disp.Flash(3, 'MagicFlash'); - CM.Disp.PlaySound(CM.Config.MagicSoundURL, 'MagicSound', 'MagicVolume'); + CM.Disp.PlaySound(CM.Options.MagicSoundURL, 'MagicSound', 'MagicVolume'); CM.Disp.Notification('MagicNotification', "Magic Meter full", "Your Magic Meter is full. Cast a spell!") } } @@ -414,17 +414,17 @@ CM.Main.CheckWrinklerCount = function() { } if (CurrentWrinklers > CM.Main.lastWrinklerCount) { CM.Main.lastWrinklerCount = CurrentWrinklers - if (CurrentWrinklers == Game.getWrinklersMax() && CM.Config.WrinklerMaxFlash) { + if (CurrentWrinklers == Game.getWrinklersMax() && CM.Options.WrinklerMaxFlash) { CM.Disp.Flash(3, 'WrinklerMaxFlash'); } else { CM.Disp.Flash(3, 'WrinklerFlash'); } - if (CurrentWrinklers == Game.getWrinklersMax() && CM.Config.WrinklerMaxSound) { - CM.Disp.PlaySound(CM.Config.WrinklerMaxSoundURL, 'WrinklerMaxSound', 'WrinklerMaxVolume'); + if (CurrentWrinklers == Game.getWrinklersMax() && CM.Options.WrinklerMaxSound) { + CM.Disp.PlaySound(CM.Options.WrinklerMaxSoundURL, 'WrinklerMaxSound', 'WrinklerMaxVolume'); } else { - CM.Disp.PlaySound(CM.Config.WrinklerSoundURL, 'WrinklerSound', 'WrinklerVolume'); + CM.Disp.PlaySound(CM.Options.WrinklerSoundURL, 'WrinklerSound', 'WrinklerVolume'); } - if (CurrentWrinklers == Game.getWrinklersMax() && CM.Config.WrinklerMaxNotification) { + if (CurrentWrinklers == Game.getWrinklersMax() && CM.Options.WrinklerMaxNotification) { CM.Disp.Notification('WrinklerMaxNotification', "Maximum Wrinklers Reached", "You have reached your maximum ammount of wrinklers") } else { CM.Disp.Notification('WrinklerNotification', "A Wrinkler appeared", "A new wrinkler has appeared") @@ -461,7 +461,7 @@ CM.Main.AddWrinklerAreaDetect = function() { * before execution of their actual function */ CM.Main.FixMouseY = function(target) { - if (CM.Config.TimerBar == 1 && CM.Config.TimerBarPos == 0) { + if (CM.Options.TimerBar == 1 && CM.Options.TimerBarPos == 0) { var timerBarHeight = parseInt(CM.Disp.TimerBar.style.height); Game.mouseY -= timerBarHeight; target(); From 0ae29ce2e8b9bd6d0739df622df0a476f2542a30 Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Fri, 18 Dec 2020 17:29:54 +0100 Subject: [PATCH 063/106] Missed some CM.Config's --- CookieMonster.js | 12 ++++++------ src/Data.js | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index 7239d5f..88f2402 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -857,7 +857,7 @@ CM.ConfigData.AvgClicksHist = {type: 'bool', group: 'Calculation', label: ['Aver CM.ConfigData.ToolWarnBon = {type: 'bool', group: 'Calculation', label: ['Calculate Tooltip Warning With Bonus CPS OFF', 'Calculate Tooltip Warning With Bonus CPS ON'], desc: 'Calculate the warning with or without the bonus CPS you get from buying', toggle: true}; // Notification -CM.ConfigData.GCNotification = {type: 'bool', group: 'Notification', label: ['Golden Cookie Notification OFF', 'Golden Cookie Notification ON'], desc: 'Create a notification when Golden Cookie spawns', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Config.GCNotification);}}; +CM.ConfigData.GCNotification = {type: 'bool', group: 'Notification', label: ['Golden Cookie Notification OFF', 'Golden Cookie Notification ON'], desc: 'Create a notification when Golden Cookie spawns', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Options.GCNotification);}}; CM.ConfigData.GCFlash = {type: 'bool', group: 'Notification', label: ['Golden Cookie Flash OFF', 'Golden Cookie Flash ON'], desc: 'Flash screen on Golden Cookie', toggle: true}; CM.ConfigData.GCSound = {type: 'bool', group: 'Notification', label: ['Golden Cookie Sound OFF', 'Golden Cookie Sound ON'], desc: 'Play a sound on Golden Cookie', toggle: true}; CM.ConfigData.GCVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of Golden Cookie'}; @@ -867,7 +867,7 @@ for (var i = 0; i < 101; i++) { CM.ConfigData.GCSoundURL = {type: 'url', group: 'Notification', label: 'Golden Cookie Sound URL:', desc: 'URL of the sound to be played when a Golden Cookie spawns'}; CM.ConfigData.GCTimer = {type: 'bool', group: 'Notification', label: ['Golden Cookie Timer OFF', 'Golden Cookie Timer ON'], desc: 'A timer on the Golden Cookie when it has been spawned', toggle: true, func: function() {CM.Disp.ToggleGCTimer();}}; CM.ConfigData.Favicon = {type: 'bool', group: 'Notification', label: ['Favicon OFF', 'Favicon ON'], desc: 'Update favicon with Golden/Wrath Cookie', toggle: true, func: function() {CM.Disp.UpdateFavicon();}}; -CM.ConfigData.FortuneNotification = {type: 'bool', group: 'Notification', label: ['Fortune Cookie Notification OFF', 'Fortune Cookie Notification ON'], desc: 'Create a notification when Fortune Cookie is on the Ticker', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Config.FortuneNotification);}}; +CM.ConfigData.FortuneNotification = {type: 'bool', group: 'Notification', label: ['Fortune Cookie Notification OFF', 'Fortune Cookie Notification ON'], desc: 'Create a notification when Fortune Cookie is on the Ticker', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Options.FortuneNotification);}}; CM.ConfigData.FortuneFlash = {type: 'bool', group: 'Notification', label: ['Fortune Cookie Flash OFF', 'Fortune Cookie Flash ON'], desc: 'Flash screen on Fortune Cookie', toggle: true}; CM.ConfigData.FortuneSound = {type: 'bool', group: 'Notification', label: ['Fortune Cookie Sound OFF', 'Fortune Cookie Sound ON'], desc: 'Play a sound on Fortune Cookie', toggle: true}; CM.ConfigData.FortuneVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of Fortune Cookie'}; @@ -875,7 +875,7 @@ for (var i = 0; i < 101; i++) { CM.ConfigData.FortuneVolume.label[i] = i + '%'; } CM.ConfigData.FortuneSoundURL = {type: 'url', group: 'Notification', label: 'Fortune Cookie Sound URL:', desc: 'URL of the sound to be played when the Ticker has a Fortune Cookie'}; -CM.ConfigData.SeaNotification = {type: 'bool', group: 'Notification', label: ['Season Special Notification OFF', 'Season Special Notification ON'], desc: 'Create a notification on Season Popup', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Config.SeaNotification);}}; +CM.ConfigData.SeaNotification = {type: 'bool', group: 'Notification', label: ['Season Special Notification OFF', 'Season Special Notification ON'], desc: 'Create a notification on Season Popup', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Options.SeaNotification);}}; CM.ConfigData.SeaFlash = {type: 'bool', group: 'Notification', label: ['Season Special Flash OFF', 'Season Special Flash ON'], desc: 'Flash screen on Season Popup', toggle: true}; CM.ConfigData.SeaSound = {type: 'bool', group: 'Notification', label: ['Season Special Sound OFF', 'Season Special Sound ON'], desc: 'Play a sound on Season Popup', toggle: true}; CM.ConfigData.SeaVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of Season Special'}; @@ -890,7 +890,7 @@ for (var i = 0; i < 101; i++) { CM.ConfigData.GardVolume.label[i] = i + '%'; } CM.ConfigData.GardSoundURL = {type: 'url', group: 'Notification', label: 'Garden Tick Sound URL:', desc: 'URL of the sound to be played when the garden ticks'}; -CM.ConfigData.MagicNotification = {type: 'bool', group: 'Notification', label: ['Magic Max Notification OFF', 'Magic Max Notification ON'], desc: 'Create a notification when magic reaches maximum', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Config.MagicNotification);}}; +CM.ConfigData.MagicNotification = {type: 'bool', group: 'Notification', label: ['Magic Max Notification OFF', 'Magic Max Notification ON'], desc: 'Create a notification when magic reaches maximum', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Options.MagicNotification);}}; CM.ConfigData.MagicFlash = {type: 'bool', group: 'Notification', label: ['Magic Max Flash OFF', 'Magic Max Flash ON'], desc: 'Flash screen when magic reaches maximum', toggle: true}; CM.ConfigData.MagicSound = {type: 'bool', group: 'Notification', label: ['Magic Max Sound OFF', 'Magic Max Sound ON'], desc: 'Play a sound when magic reaches maximum', toggle: true}; CM.ConfigData.MagicVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of Max Magic'}; @@ -898,7 +898,7 @@ for (var i = 0; i < 101; i++) { CM.ConfigData.MagicVolume.label[i] = i + '%'; } CM.ConfigData.MagicSoundURL = {type: 'url', group: 'Notification', label: 'Magic Max Sound URL:', desc: 'URL of the sound to be played when magic reaches maxium'}; -CM.ConfigData.WrinklerNotification = {type: 'bool', group: 'Notification', label: ['Wrinkler Notification OFF', 'Wrinkler Notification ON'], desc: 'Create a notification when a Wrinkler appears', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Config.WrinklerNotification);}}; +CM.ConfigData.WrinklerNotification = {type: 'bool', group: 'Notification', label: ['Wrinkler Notification OFF', 'Wrinkler Notification ON'], desc: 'Create a notification when a Wrinkler appears', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Options.WrinklerNotification);}}; CM.ConfigData.WrinklerFlash = {type: 'bool', group: 'Notification', label: ['Wrinkler Flash OFF', 'Wrinkler Flash ON'], desc: 'Flash screen when a Wrinkler appears', toggle: true}; CM.ConfigData.WrinklerSound = {type: 'bool', group: 'Notification', label: ['Wrinkler Sound OFF', 'Wrinkler Sound ON'], desc: 'Play a sound when a Wrinkler appears', toggle: true}; CM.ConfigData.WrinklerVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of Wrinkler'}; @@ -906,7 +906,7 @@ for (var i = 0; i < 101; i++) { CM.ConfigData.WrinklerVolume.label[i] = i + '%'; } CM.ConfigData.WrinklerSoundURL = {type: 'url', group: 'Notification', label: 'Wrinkler Sound URL:', desc: 'URL of the sound to be played when a Wrinkler appears'}; -CM.ConfigData.WrinklerMaxNotification = {type: 'bool', group: 'Notification', label: ['Wrinkler Max Notification OFF', 'Wrinkler Max Notification ON'], desc: 'Create a notification when the maximum amount of Wrinklers has appeared', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Config.WrinklerMaxNotification);}}; +CM.ConfigData.WrinklerMaxNotification = {type: 'bool', group: 'Notification', label: ['Wrinkler Max Notification OFF', 'Wrinkler Max Notification ON'], desc: 'Create a notification when the maximum amount of Wrinklers has appeared', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Options.WrinklerMaxNotification);}}; CM.ConfigData.WrinklerMaxFlash = {type: 'bool', group: 'Notification', label: ['Wrinkler Max Flash OFF', 'Wrinkler Max Flash ON'], desc: 'Flash screen when the maximum amount of Wrinklers has appeared', toggle: true}; CM.ConfigData.WrinklerMaxSound = {type: 'bool', group: 'Notification', label: ['Wrinkler Max Sound OFF', 'Wrinkler Max Sound ON'], desc: 'Play a sound when the maximum amount of Wrinklers has appeared', toggle: true}; CM.ConfigData.WrinklerMaxVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of Wrinkler Max'}; diff --git a/src/Data.js b/src/Data.js index fd2b698..792e0e9 100644 --- a/src/Data.js +++ b/src/Data.js @@ -96,7 +96,7 @@ CM.ConfigData.AvgClicksHist = {type: 'bool', group: 'Calculation', label: ['Aver CM.ConfigData.ToolWarnBon = {type: 'bool', group: 'Calculation', label: ['Calculate Tooltip Warning With Bonus CPS OFF', 'Calculate Tooltip Warning With Bonus CPS ON'], desc: 'Calculate the warning with or without the bonus CPS you get from buying', toggle: true}; // Notification -CM.ConfigData.GCNotification = {type: 'bool', group: 'Notification', label: ['Golden Cookie Notification OFF', 'Golden Cookie Notification ON'], desc: 'Create a notification when Golden Cookie spawns', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Config.GCNotification);}}; +CM.ConfigData.GCNotification = {type: 'bool', group: 'Notification', label: ['Golden Cookie Notification OFF', 'Golden Cookie Notification ON'], desc: 'Create a notification when Golden Cookie spawns', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Options.GCNotification);}}; CM.ConfigData.GCFlash = {type: 'bool', group: 'Notification', label: ['Golden Cookie Flash OFF', 'Golden Cookie Flash ON'], desc: 'Flash screen on Golden Cookie', toggle: true}; CM.ConfigData.GCSound = {type: 'bool', group: 'Notification', label: ['Golden Cookie Sound OFF', 'Golden Cookie Sound ON'], desc: 'Play a sound on Golden Cookie', toggle: true}; CM.ConfigData.GCVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of Golden Cookie'}; @@ -106,7 +106,7 @@ for (var i = 0; i < 101; i++) { CM.ConfigData.GCSoundURL = {type: 'url', group: 'Notification', label: 'Golden Cookie Sound URL:', desc: 'URL of the sound to be played when a Golden Cookie spawns'}; CM.ConfigData.GCTimer = {type: 'bool', group: 'Notification', label: ['Golden Cookie Timer OFF', 'Golden Cookie Timer ON'], desc: 'A timer on the Golden Cookie when it has been spawned', toggle: true, func: function() {CM.Disp.ToggleGCTimer();}}; CM.ConfigData.Favicon = {type: 'bool', group: 'Notification', label: ['Favicon OFF', 'Favicon ON'], desc: 'Update favicon with Golden/Wrath Cookie', toggle: true, func: function() {CM.Disp.UpdateFavicon();}}; -CM.ConfigData.FortuneNotification = {type: 'bool', group: 'Notification', label: ['Fortune Cookie Notification OFF', 'Fortune Cookie Notification ON'], desc: 'Create a notification when Fortune Cookie is on the Ticker', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Config.FortuneNotification);}}; +CM.ConfigData.FortuneNotification = {type: 'bool', group: 'Notification', label: ['Fortune Cookie Notification OFF', 'Fortune Cookie Notification ON'], desc: 'Create a notification when Fortune Cookie is on the Ticker', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Options.FortuneNotification);}}; CM.ConfigData.FortuneFlash = {type: 'bool', group: 'Notification', label: ['Fortune Cookie Flash OFF', 'Fortune Cookie Flash ON'], desc: 'Flash screen on Fortune Cookie', toggle: true}; CM.ConfigData.FortuneSound = {type: 'bool', group: 'Notification', label: ['Fortune Cookie Sound OFF', 'Fortune Cookie Sound ON'], desc: 'Play a sound on Fortune Cookie', toggle: true}; CM.ConfigData.FortuneVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of Fortune Cookie'}; @@ -114,7 +114,7 @@ for (var i = 0; i < 101; i++) { CM.ConfigData.FortuneVolume.label[i] = i + '%'; } CM.ConfigData.FortuneSoundURL = {type: 'url', group: 'Notification', label: 'Fortune Cookie Sound URL:', desc: 'URL of the sound to be played when the Ticker has a Fortune Cookie'}; -CM.ConfigData.SeaNotification = {type: 'bool', group: 'Notification', label: ['Season Special Notification OFF', 'Season Special Notification ON'], desc: 'Create a notification on Season Popup', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Config.SeaNotification);}}; +CM.ConfigData.SeaNotification = {type: 'bool', group: 'Notification', label: ['Season Special Notification OFF', 'Season Special Notification ON'], desc: 'Create a notification on Season Popup', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Options.SeaNotification);}}; CM.ConfigData.SeaFlash = {type: 'bool', group: 'Notification', label: ['Season Special Flash OFF', 'Season Special Flash ON'], desc: 'Flash screen on Season Popup', toggle: true}; CM.ConfigData.SeaSound = {type: 'bool', group: 'Notification', label: ['Season Special Sound OFF', 'Season Special Sound ON'], desc: 'Play a sound on Season Popup', toggle: true}; CM.ConfigData.SeaVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of Season Special'}; @@ -129,7 +129,7 @@ for (var i = 0; i < 101; i++) { CM.ConfigData.GardVolume.label[i] = i + '%'; } CM.ConfigData.GardSoundURL = {type: 'url', group: 'Notification', label: 'Garden Tick Sound URL:', desc: 'URL of the sound to be played when the garden ticks'}; -CM.ConfigData.MagicNotification = {type: 'bool', group: 'Notification', label: ['Magic Max Notification OFF', 'Magic Max Notification ON'], desc: 'Create a notification when magic reaches maximum', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Config.MagicNotification);}}; +CM.ConfigData.MagicNotification = {type: 'bool', group: 'Notification', label: ['Magic Max Notification OFF', 'Magic Max Notification ON'], desc: 'Create a notification when magic reaches maximum', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Options.MagicNotification);}}; CM.ConfigData.MagicFlash = {type: 'bool', group: 'Notification', label: ['Magic Max Flash OFF', 'Magic Max Flash ON'], desc: 'Flash screen when magic reaches maximum', toggle: true}; CM.ConfigData.MagicSound = {type: 'bool', group: 'Notification', label: ['Magic Max Sound OFF', 'Magic Max Sound ON'], desc: 'Play a sound when magic reaches maximum', toggle: true}; CM.ConfigData.MagicVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of Max Magic'}; @@ -137,7 +137,7 @@ for (var i = 0; i < 101; i++) { CM.ConfigData.MagicVolume.label[i] = i + '%'; } CM.ConfigData.MagicSoundURL = {type: 'url', group: 'Notification', label: 'Magic Max Sound URL:', desc: 'URL of the sound to be played when magic reaches maxium'}; -CM.ConfigData.WrinklerNotification = {type: 'bool', group: 'Notification', label: ['Wrinkler Notification OFF', 'Wrinkler Notification ON'], desc: 'Create a notification when a Wrinkler appears', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Config.WrinklerNotification);}}; +CM.ConfigData.WrinklerNotification = {type: 'bool', group: 'Notification', label: ['Wrinkler Notification OFF', 'Wrinkler Notification ON'], desc: 'Create a notification when a Wrinkler appears', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Options.WrinklerNotification);}}; CM.ConfigData.WrinklerFlash = {type: 'bool', group: 'Notification', label: ['Wrinkler Flash OFF', 'Wrinkler Flash ON'], desc: 'Flash screen when a Wrinkler appears', toggle: true}; CM.ConfigData.WrinklerSound = {type: 'bool', group: 'Notification', label: ['Wrinkler Sound OFF', 'Wrinkler Sound ON'], desc: 'Play a sound when a Wrinkler appears', toggle: true}; CM.ConfigData.WrinklerVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of Wrinkler'}; @@ -145,7 +145,7 @@ for (var i = 0; i < 101; i++) { CM.ConfigData.WrinklerVolume.label[i] = i + '%'; } CM.ConfigData.WrinklerSoundURL = {type: 'url', group: 'Notification', label: 'Wrinkler Sound URL:', desc: 'URL of the sound to be played when a Wrinkler appears'}; -CM.ConfigData.WrinklerMaxNotification = {type: 'bool', group: 'Notification', label: ['Wrinkler Max Notification OFF', 'Wrinkler Max Notification ON'], desc: 'Create a notification when the maximum amount of Wrinklers has appeared', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Config.WrinklerMaxNotification);}}; +CM.ConfigData.WrinklerMaxNotification = {type: 'bool', group: 'Notification', label: ['Wrinkler Max Notification OFF', 'Wrinkler Max Notification ON'], desc: 'Create a notification when the maximum amount of Wrinklers has appeared', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Options.WrinklerMaxNotification);}}; CM.ConfigData.WrinklerMaxFlash = {type: 'bool', group: 'Notification', label: ['Wrinkler Max Flash OFF', 'Wrinkler Max Flash ON'], desc: 'Flash screen when the maximum amount of Wrinklers has appeared', toggle: true}; CM.ConfigData.WrinklerMaxSound = {type: 'bool', group: 'Notification', label: ['Wrinkler Max Sound OFF', 'Wrinkler Max Sound ON'], desc: 'Play a sound when the maximum amount of Wrinklers has appeared', toggle: true}; CM.ConfigData.WrinklerMaxVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of Wrinkler Max'}; From 8aa8a7c878dcaebd46505b4c411e3f079558956e Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Fri, 18 Dec 2020 18:10:39 +0100 Subject: [PATCH 064/106] Fully annotated Config.js --- CookieMonster.js | 157 ++++++++++++++++++++++------------------------- src/Config.js | 98 +++++++++++++---------------- src/Data.js | 21 +++---- src/Disp.js | 36 +++++------ src/Main.js | 2 +- 5 files changed, 146 insertions(+), 168 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index 88f2402..40a24b7 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -588,19 +588,19 @@ CM.Cache.dragonAura2 = 0; /** * This function saves the config of CookieMonster to localStorage - * It is called by CM.LoadConfig(), CM.RestoreDefault(), - * any of the CM.ToggleConfig() functions and upon changes to URL or volume settings + * It is called by CM.Config.LoadConfig(), CM.Config.RestoreDefault(), CM.Config.ToggleConfig(), + * CM.ToggleConfigVolume() and changes in options with type "url" or "color" * @param {object} config The Config to be saved (normally CM.Options) */ -CM.SaveConfig = function(config) { +CM.Config.SaveConfig = function(config) { localStorage.setItem(CM.ConfigPrefix, JSON.stringify(config)); } /** * This function loads the config of CookieMonster saved in localStorage and loads it into CM.Options - * It is called by CM.DelayInit() and CM.RestoreDefault() + * It is called by CM.DelayInit() and CM.Config.RestoreDefault() */ -CM.LoadConfig = function() { +CM.Config.LoadConfig = function() { if (localStorage.getItem(CM.ConfigPrefix) != null) { CM.Options = JSON.parse(localStorage.getItem(CM.ConfigPrefix)); @@ -611,7 +611,7 @@ CM.LoadConfig = function() { mod = true; CM.Options[i] = CM.Data.ConfigDefault[i]; } - else if (i != 'StatsPref' && i != 'Colors') { + else if (i != 'Header' && i != 'Colors') { if (i.indexOf('SoundURL') == -1) { if (!(CM.Options[i] > -1 && CM.Options[i] < CM.ConfigData[i].label.length)) { mod = true; @@ -625,8 +625,8 @@ CM.LoadConfig = function() { } } } - else if (i == 'StatsPref') { - for (var j in CM.Data.ConfigDefault.StatsPref) { + else if (i == 'Header') { + for (var j in CM.Data.ConfigDefault.Header) { if (typeof CM.Options[i][j] === 'undefined' || !(CM.Options[i][j] > -1 && CM.Options[i][j] < 2)) { mod = true; CM.Options[i][j] = CM.Data.ConfigDefault[i][j]; @@ -642,27 +642,27 @@ CM.LoadConfig = function() { } } } - if (mod) CM.SaveConfig(CM.Options); + if (mod) CM.Config.SaveConfig(CM.Options); CM.Loop(); // Do loop once for (var i in CM.Data.ConfigDefault) { - if (i != 'StatsPref' && i != 'OptionsPref' && typeof CM.ConfigData[i].func !== 'undefined') { + if (i != 'Header' && typeof CM.ConfigData[i].func !== 'undefined') { CM.ConfigData[i].func(); } } } else { // Default values - CM.RestoreDefault(); + CM.Config.RestoreDefault(); } } /** * This function reloads and resaves the default config as stored in CM.Data.ConfigDefault - * It is called by resDefBut.onclick loaded in the options page or by CM.LoadConfig is no localStorage is found + * It is called by resDefBut.onclick loaded in the options page or by CM.Config.LoadConfig if no localStorage is found */ -CM.RestoreDefault = function() { +CM.Config.RestoreDefault = function() { CM.Options = {}; - CM.SaveConfig(CM.Data.ConfigDefault); - CM.LoadConfig(); + CM.Config.SaveConfig(CM.Data.ConfigDefault); + CM.Config.LoadConfig(); Game.UpdateMenu(); } @@ -670,71 +670,61 @@ CM.RestoreDefault = function() { * Section: Functions related to toggling or changing configs */ /** - * This function toggles options which are considered "toggles" - * These have off (1) and on (1) states + * This function toggles options by incrementing them with 1 and handling changes * It is called by the onclick event of options of the "bool" type * @param {string} config The name of the option */ -CM.ToggleConfig = function(config) { - CM.ToggleConfigUp(config); - if (CM.ConfigData[config].toggle) { - if (CM.Options[config] == 0) { - l(CM.ConfigPrefix + config).className = 'option off'; - } - else { - l(CM.ConfigPrefix + config).className = 'option'; - } - } -} - -CM.ToggleConfigUp = function(config) { +CM.Config.ToggleConfig = function(config) { CM.Options[config]++; + if (CM.Options[config] == CM.ConfigData[config].label.length) { CM.Options[config] = 0; + if (CM.ConfigData[config].toggle) l(CM.ConfigPrefix + config).className = 'option off'; } + else l(CM.ConfigPrefix + config).className = 'option'; + if (typeof CM.ConfigData[config].func !== 'undefined') { CM.ConfigData[config].func(); } + l(CM.ConfigPrefix + config).innerHTML = CM.ConfigData[config].label[CM.Options[config]]; - CM.SaveConfig(CM.Options); + CM.Config.SaveConfig(CM.Options); } /** * This function sets the value of the specified volume-option and updates the display in the options menu - * It is called by CM.Disp.CreatePrefOption() + * It is called by the oninput and onchange event of "vol" type options * @param {string} config The name of the option */ -CM.ToggleConfigVolume = function(config) { +CM.Config.ToggleConfigVolume = function(config) { if (l("slider" + config) != null) { l("slider" + config + "right").innerHTML = l("slider" + config).value + "%"; CM.Options[config] = Math.round(l("slider" + config).value); } - CM.SaveConfig(CM.Options); + CM.Config.SaveConfig(CM.Options); } -CM.ToggleStatsConfig = function(config) { - if (CM.Options.StatsPref[config] == 0) { - CM.Options.StatsPref[config]++; - } - else { - CM.Options.StatsPref[config]--; - } - CM.SaveConfig(CM.Options); +/** + * This function toggles header options by incrementing them with 1 and handling changes + * It is called by the onclick event of the +/- next to headers + * @param {string} config The name of the header + */ +CM.Config.ToggleHeader = function(config) { + CM.Options.Header[config]++; + if (CM.Options.Header[config] > 1) CM.Options.Header[config] = 0; + CM.Config.SaveConfig(CM.Options); } -CM.ToggleOptionsConfig = function(config) { - if (CM.Options.OptionsPref[config] == 0) { - CM.Options.OptionsPref[config]++; - } - else { - CM.Options.OptionsPref[config]--; - } - CM.SaveConfig(CM.Options); -} +/******** + * Section: Functions related to notifications */ -// Checks if the browsers has permissions to produce notifications -// Should be triggered when Config related to Notifications is toggled on -CM.CheckNotificationPermissions = function(ToggleOnOff) { +/** + * This function checks if the user has given permissions for notifications + * It is called by a change in any of the notification options + * Note that most browsers will stop asking if the user has ignored the prompt around 6 times + * @param {number} ToggleOnOff A number indicating whether the option has been turned off (0) or on (1) + */ +CM.Config.CheckNotificationPermissions = function(ToggleOnOff) { if (ToggleOnOff == 1) { // Check if browser support Promise version of Notification Permissions function checkNotificationPromise() { @@ -857,7 +847,7 @@ CM.ConfigData.AvgClicksHist = {type: 'bool', group: 'Calculation', label: ['Aver CM.ConfigData.ToolWarnBon = {type: 'bool', group: 'Calculation', label: ['Calculate Tooltip Warning With Bonus CPS OFF', 'Calculate Tooltip Warning With Bonus CPS ON'], desc: 'Calculate the warning with or without the bonus CPS you get from buying', toggle: true}; // Notification -CM.ConfigData.GCNotification = {type: 'bool', group: 'Notification', label: ['Golden Cookie Notification OFF', 'Golden Cookie Notification ON'], desc: 'Create a notification when Golden Cookie spawns', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Options.GCNotification);}}; +CM.ConfigData.GCNotification = {type: 'bool', group: 'Notification', label: ['Golden Cookie Notification OFF', 'Golden Cookie Notification ON'], desc: 'Create a notification when Golden Cookie spawns', toggle: true, func: function () {CM.Config.CheckNotificationPermissions(CM.Options.GCNotification);}}; CM.ConfigData.GCFlash = {type: 'bool', group: 'Notification', label: ['Golden Cookie Flash OFF', 'Golden Cookie Flash ON'], desc: 'Flash screen on Golden Cookie', toggle: true}; CM.ConfigData.GCSound = {type: 'bool', group: 'Notification', label: ['Golden Cookie Sound OFF', 'Golden Cookie Sound ON'], desc: 'Play a sound on Golden Cookie', toggle: true}; CM.ConfigData.GCVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of Golden Cookie'}; @@ -867,7 +857,7 @@ for (var i = 0; i < 101; i++) { CM.ConfigData.GCSoundURL = {type: 'url', group: 'Notification', label: 'Golden Cookie Sound URL:', desc: 'URL of the sound to be played when a Golden Cookie spawns'}; CM.ConfigData.GCTimer = {type: 'bool', group: 'Notification', label: ['Golden Cookie Timer OFF', 'Golden Cookie Timer ON'], desc: 'A timer on the Golden Cookie when it has been spawned', toggle: true, func: function() {CM.Disp.ToggleGCTimer();}}; CM.ConfigData.Favicon = {type: 'bool', group: 'Notification', label: ['Favicon OFF', 'Favicon ON'], desc: 'Update favicon with Golden/Wrath Cookie', toggle: true, func: function() {CM.Disp.UpdateFavicon();}}; -CM.ConfigData.FortuneNotification = {type: 'bool', group: 'Notification', label: ['Fortune Cookie Notification OFF', 'Fortune Cookie Notification ON'], desc: 'Create a notification when Fortune Cookie is on the Ticker', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Options.FortuneNotification);}}; +CM.ConfigData.FortuneNotification = {type: 'bool', group: 'Notification', label: ['Fortune Cookie Notification OFF', 'Fortune Cookie Notification ON'], desc: 'Create a notification when Fortune Cookie is on the Ticker', toggle: true, func: function () {CM.Config.CheckNotificationPermissions(CM.Options.FortuneNotification);}}; CM.ConfigData.FortuneFlash = {type: 'bool', group: 'Notification', label: ['Fortune Cookie Flash OFF', 'Fortune Cookie Flash ON'], desc: 'Flash screen on Fortune Cookie', toggle: true}; CM.ConfigData.FortuneSound = {type: 'bool', group: 'Notification', label: ['Fortune Cookie Sound OFF', 'Fortune Cookie Sound ON'], desc: 'Play a sound on Fortune Cookie', toggle: true}; CM.ConfigData.FortuneVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of Fortune Cookie'}; @@ -875,7 +865,7 @@ for (var i = 0; i < 101; i++) { CM.ConfigData.FortuneVolume.label[i] = i + '%'; } CM.ConfigData.FortuneSoundURL = {type: 'url', group: 'Notification', label: 'Fortune Cookie Sound URL:', desc: 'URL of the sound to be played when the Ticker has a Fortune Cookie'}; -CM.ConfigData.SeaNotification = {type: 'bool', group: 'Notification', label: ['Season Special Notification OFF', 'Season Special Notification ON'], desc: 'Create a notification on Season Popup', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Options.SeaNotification);}}; +CM.ConfigData.SeaNotification = {type: 'bool', group: 'Notification', label: ['Season Special Notification OFF', 'Season Special Notification ON'], desc: 'Create a notification on Season Popup', toggle: true, func: function () {CM.Config.CheckNotificationPermissions(CM.Options.SeaNotification);}}; CM.ConfigData.SeaFlash = {type: 'bool', group: 'Notification', label: ['Season Special Flash OFF', 'Season Special Flash ON'], desc: 'Flash screen on Season Popup', toggle: true}; CM.ConfigData.SeaSound = {type: 'bool', group: 'Notification', label: ['Season Special Sound OFF', 'Season Special Sound ON'], desc: 'Play a sound on Season Popup', toggle: true}; CM.ConfigData.SeaVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of Season Special'}; @@ -890,7 +880,7 @@ for (var i = 0; i < 101; i++) { CM.ConfigData.GardVolume.label[i] = i + '%'; } CM.ConfigData.GardSoundURL = {type: 'url', group: 'Notification', label: 'Garden Tick Sound URL:', desc: 'URL of the sound to be played when the garden ticks'}; -CM.ConfigData.MagicNotification = {type: 'bool', group: 'Notification', label: ['Magic Max Notification OFF', 'Magic Max Notification ON'], desc: 'Create a notification when magic reaches maximum', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Options.MagicNotification);}}; +CM.ConfigData.MagicNotification = {type: 'bool', group: 'Notification', label: ['Magic Max Notification OFF', 'Magic Max Notification ON'], desc: 'Create a notification when magic reaches maximum', toggle: true, func: function () {CM.Config.CheckNotificationPermissions(CM.Options.MagicNotification);}}; CM.ConfigData.MagicFlash = {type: 'bool', group: 'Notification', label: ['Magic Max Flash OFF', 'Magic Max Flash ON'], desc: 'Flash screen when magic reaches maximum', toggle: true}; CM.ConfigData.MagicSound = {type: 'bool', group: 'Notification', label: ['Magic Max Sound OFF', 'Magic Max Sound ON'], desc: 'Play a sound when magic reaches maximum', toggle: true}; CM.ConfigData.MagicVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of Max Magic'}; @@ -898,7 +888,7 @@ for (var i = 0; i < 101; i++) { CM.ConfigData.MagicVolume.label[i] = i + '%'; } CM.ConfigData.MagicSoundURL = {type: 'url', group: 'Notification', label: 'Magic Max Sound URL:', desc: 'URL of the sound to be played when magic reaches maxium'}; -CM.ConfigData.WrinklerNotification = {type: 'bool', group: 'Notification', label: ['Wrinkler Notification OFF', 'Wrinkler Notification ON'], desc: 'Create a notification when a Wrinkler appears', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Options.WrinklerNotification);}}; +CM.ConfigData.WrinklerNotification = {type: 'bool', group: 'Notification', label: ['Wrinkler Notification OFF', 'Wrinkler Notification ON'], desc: 'Create a notification when a Wrinkler appears', toggle: true, func: function () {CM.Config.CheckNotificationPermissions(CM.Options.WrinklerNotification);}}; CM.ConfigData.WrinklerFlash = {type: 'bool', group: 'Notification', label: ['Wrinkler Flash OFF', 'Wrinkler Flash ON'], desc: 'Flash screen when a Wrinkler appears', toggle: true}; CM.ConfigData.WrinklerSound = {type: 'bool', group: 'Notification', label: ['Wrinkler Sound OFF', 'Wrinkler Sound ON'], desc: 'Play a sound when a Wrinkler appears', toggle: true}; CM.ConfigData.WrinklerVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of Wrinkler'}; @@ -906,7 +896,7 @@ for (var i = 0; i < 101; i++) { CM.ConfigData.WrinklerVolume.label[i] = i + '%'; } CM.ConfigData.WrinklerSoundURL = {type: 'url', group: 'Notification', label: 'Wrinkler Sound URL:', desc: 'URL of the sound to be played when a Wrinkler appears'}; -CM.ConfigData.WrinklerMaxNotification = {type: 'bool', group: 'Notification', label: ['Wrinkler Max Notification OFF', 'Wrinkler Max Notification ON'], desc: 'Create a notification when the maximum amount of Wrinklers has appeared', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Options.WrinklerMaxNotification);}}; +CM.ConfigData.WrinklerMaxNotification = {type: 'bool', group: 'Notification', label: ['Wrinkler Max Notification OFF', 'Wrinkler Max Notification ON'], desc: 'Create a notification when the maximum amount of Wrinklers has appeared', toggle: true, func: function () {CM.Config.CheckNotificationPermissions(CM.Options.WrinklerMaxNotification);}}; CM.ConfigData.WrinklerMaxFlash = {type: 'bool', group: 'Notification', label: ['Wrinkler Max Flash OFF', 'Wrinkler Max Flash ON'], desc: 'Flash screen when the maximum amount of Wrinklers has appeared', toggle: true}; CM.ConfigData.WrinklerMaxSound = {type: 'bool', group: 'Notification', label: ['Wrinkler Max Sound OFF', 'Wrinkler Max Sound ON'], desc: 'Play a sound when the maximum amount of Wrinklers has appeared', toggle: true}; CM.ConfigData.WrinklerMaxVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of Wrinkler Max'}; @@ -942,7 +932,7 @@ CM.ConfigData.ScaleSeparator = {type: 'bool', group: 'Notation', label: ['. for /** * This array describes all default settings - * It is used by CM.LoadConfig() and CM.RestoreDefault() + * It is used by CM.LoadConfig() and CM.Config.RestoreDefault() */ CM.Data.ConfigDefault = { BotBar: 1, @@ -1013,11 +1003,10 @@ CM.Data.ConfigDefault = { Scale: 2, ScaleDecimals: 2, ScaleSeparator: 0, - OptionsPref: {BarsColors: 1, Calculation: 1, Notification: 1, Tooltip: 1, Statistics: 1, Notation: 1}, - StatsPref: {Lucky: 1, Conjure: 1, Chain: 1, Prestige: 1, Wrink: 1, Sea: 1, Misc: 1}, - Colors : {Blue: '#4bb8f0', Green: '#00ff00', Yellow: '#ffff00', Orange: '#ff7f00', Red: '#ff0000', Purple: '#ff00ff', Gray: '#b3b3b3', Pink: '#ff1493', Brown: '#8b4513'}, + Colors: {Blue: '#4bb8f0', Green: '#00ff00', Yellow: '#ffff00', Orange: '#ff7f00', Red: '#ff0000', Purple: '#ff00ff', Gray: '#b3b3b3', Pink: '#ff1493', Brown: '#8b4513'}, SortBuildings: 0, - SortUpgrades: 0 + SortUpgrades: 0, + Header: {BarsColors: 1, Calculation: 1, Notification: 1, Tooltip: 1, Statistics: 1, Notation: 1, Lucky: 1, Conjure: 1, Chain: 1, Prestige: 1, Wrink: 1, Sea: 1, Misc: 1}, };/******** * Disp * ********/ @@ -2885,7 +2874,7 @@ CM.Disp.AddMenuPref = function(title) { for (var group in CM.ConfigGroups) { groupObject = CM.Disp.CreatePrefHeader(group, CM.ConfigGroups[group]) // (group, display-name of group) frag.appendChild(groupObject) - if (CM.Options.OptionsPref[group]) { // 0 is show, 1 is collapsed + if (CM.Options.Header[group]) { // 0 is show, 1 is collapsed for (var option in CM.ConfigData) { if (CM.ConfigData[option].group == group) frag.appendChild(CM.Disp.CreatePrefOption(option)) } @@ -2896,7 +2885,7 @@ CM.Disp.AddMenuPref = function(title) { resDef.className = 'listing'; var resDefBut = document.createElement('a'); resDefBut.className = 'option'; - resDefBut.onclick = function() {CM.RestoreDefault();}; + resDefBut.onclick = function() {CM.Config.RestoreDefault();}; resDefBut.textContent = 'Restore Default'; resDef.appendChild(resDefBut); frag.appendChild(resDef); @@ -2929,8 +2918,8 @@ CM.Disp.CreatePrefHeader = function(config, text) { span.style.color = 'black'; span.style.fontSize = '13px'; span.style.verticalAlign = 'middle'; - span.textContent = CM.Options.OptionsPref[config] ? '-' : '+'; - span.onclick = function() {CM.ToggleOptionsConfig(config); Game.UpdateMenu();}; + span.textContent = CM.Options.Header[config] ? '-' : '+'; + span.onclick = function() {CM.Config.ToggleHeader(config); Game.UpdateMenu();}; div.appendChild(span); return div; } @@ -2953,7 +2942,7 @@ CM.Disp.CreatePrefOption = function(config) { a.className = 'option'; } a.id = CM.ConfigPrefix + config; - a.onclick = function() {CM.ToggleConfig(config);}; + a.onclick = function() {CM.Config.ToggleConfig(config);}; a.textContent = CM.ConfigData[config].label[CM.Options[config]]; div.appendChild(a); var label = document.createElement('label'); @@ -2984,8 +2973,8 @@ CM.Disp.CreatePrefOption = function(config) { slider.max = "100"; slider.step = "1"; slider.value = CM.Options[config]; - slider.oninput = function() {CM.ToggleConfigVolume(config)}; - slider.onchange = function() {CM.ToggleConfigVolume(config)}; + slider.oninput = function() {CM.Config.ToggleConfigVolume(config)}; + slider.onchange = function() {CM.Config.ToggleConfigVolume(config)}; volume.appendChild(slider); div.appendChild(volume); return div; @@ -3013,7 +3002,7 @@ CM.Disp.CreatePrefOption = function(config) { inputPrompt.setAttribute('value', CM.Options[config]); var a = document.createElement('a'); a.className = 'option'; - a.onclick = function() {Game.Prompt(inputPrompt.outerHTML, [['Save', 'CM.Options[\'' + config + '\'] = l(CM.ConfigPrefix + \'' + config + '\' + \'Prompt\').value; CM.SaveConfig(CM.Options); Game.ClosePrompt(); Game.UpdateMenu();'], 'Cancel']);}; + a.onclick = function() {Game.Prompt(inputPrompt.outerHTML, [['Save', 'CM.Options[\'' + config + '\'] = l(CM.ConfigPrefix + \'' + config + '\' + \'Prompt\').value; CM.Config.SaveConfig(CM.Options); Game.ClosePrompt(); Game.UpdateMenu();'], 'Cancel']);}; a.textContent = 'Edit'; div.appendChild(a); var label = document.createElement('label'); @@ -3031,7 +3020,7 @@ CM.Disp.CreatePrefOption = function(config) { input.style.width = '65px'; input.setAttribute('value', CM.Options.Colors[CM.Disp.colors[i]]); div.appendChild(input); - eval('var change = function() {CM.Options.Colors[\'' + CM.Disp.colors[i] + '\'] = l(CM.ConfigPrefix + \'Color\' + \'' + CM.Disp.colors[i] + '\').value; CM.Disp.UpdateColors(); CM.SaveConfig(CM.Options);}'); + eval('var change = function() {CM.Options.Colors[\'' + CM.Disp.colors[i] + '\'] = l(CM.ConfigPrefix + \'Color\' + \'' + CM.Disp.colors[i] + '\').value; CM.Disp.UpdateColors(); CM.Config.SaveConfig(CM.Options);}'); var jscolorpicker = new jscolor.color(input, {hash: true, caps: false, pickerZIndex: 1000000, pickerPosition: 'right', onImmediateChange: change}); var label = document.createElement('label'); label.textContent = CM.ConfigData.Colors.desc[CM.Disp.colors[i]]; @@ -3098,28 +3087,28 @@ CM.Disp.AddMenuStats = function(title) { stats.appendChild(title()); stats.appendChild(CM.Disp.CreateStatsHeader('Lucky Cookies', 'Lucky')); - if (CM.Options.StatsPref.Lucky) { + if (CM.Options.Header.Lucky) { stats.appendChild(CM.Disp.CreateStatsLuckySection()); } stats.appendChild(CM.Disp.CreateStatsHeader('Chain Cookies', 'Chain')); - if (CM.Options.StatsPref.Chain) { + if (CM.Options.Header.Chain) { stats.appendChild(CM.Disp.CreateStatsChainSection()); } stats.appendChild(CM.Disp.CreateStatsHeader('Conjure Baked Goods', 'Conjure')); - if (CM.Options.StatsPref.Conjure) { + if (CM.Options.Header.Conjure) { stats.appendChild(CM.Disp.CreateStatsConjureSection()); } stats.appendChild(CM.Disp.CreateStatsHeader('Prestige', 'Prestige')); - if (CM.Options.StatsPref.Prestige) { + if (CM.Options.Header.Prestige) { stats.appendChild(CM.Disp.CreateStatsPrestigeSection()); } if (Game.cpsSucked > 0) { stats.appendChild(CM.Disp.CreateStatsHeader('Wrinklers', 'Wrink')); - if (CM.Options.StatsPref.Wrink) { + if (CM.Options.Header.Wrink) { var popAllFrag = document.createDocumentFragment(); popAllFrag.appendChild(document.createTextNode(Beautify(CM.Cache.WrinkBankTotal) + ' / ' + Beautify(CM.Cache.WrinkBankNormal) + ' ')); var popAllA = document.createElement('a'); @@ -3173,7 +3162,7 @@ CM.Disp.AddMenuStats = function(title) { if (Game.season == 'christmas' || specDisp || choEgg || centEgg) { stats.appendChild(CM.Disp.CreateStatsHeader('Season Specials', 'Sea')); - if (CM.Options.StatsPref.Sea) { + if (CM.Options.Header.Sea) { if (specDisp) { if (missingHalloweenCookies.length != 0) stats.appendChild(CM.Disp.CreateStatsListing("basic", 'Halloween Cookies Left to Buy', CM.Disp.CreateStatsMissDisp(missingHalloweenCookies))); if (missingChristmasCookies.length != 0) stats.appendChild(CM.Disp.CreateStatsListing("basic", 'Christmas Cookies Left to Buy', CM.Disp.CreateStatsMissDisp(missingChristmasCookies))); @@ -3193,7 +3182,7 @@ CM.Disp.AddMenuStats = function(title) { } stats.appendChild(CM.Disp.CreateStatsHeader('Miscellaneous', 'Misc')); - if (CM.Options.StatsPref.Misc) { + if (CM.Options.Header.Misc) { stats.appendChild(CM.Disp.CreateStatsListing("basic", 'Average Cookies Per Second (Past ' + (CM.Disp.cookieTimes[CM.Options.AvgCPSHist] < 60 ? (CM.Disp.cookieTimes[CM.Options.AvgCPSHist] + ' seconds') : ((CM.Disp.cookieTimes[CM.Options.AvgCPSHist] / 60) + (CM.Options.AvgCPSHist == 3 ? ' minute' : ' minutes'))) + ')', document.createTextNode(Beautify(CM.Cache.AvgCPS, 3)) @@ -3250,8 +3239,8 @@ CM.Disp.CreateStatsHeader = function(text, config) { span.style.color = 'black'; span.style.fontSize = '13px'; span.style.verticalAlign = 'middle'; - span.textContent = CM.Options.StatsPref[config] ? '-' : '+'; - span.onclick = function() {CM.ToggleStatsConfig(config); Game.UpdateMenu();}; + span.textContent = CM.Options.Header[config] ? '-' : '+'; + span.onclick = function() {CM.Config.ToggleHeader(config); Game.UpdateMenu();}; div.appendChild(span); return div; } @@ -3985,7 +3974,7 @@ CM.DelayInit = function() { CM.ReplaceNative(); CM.ReplaceNativeGrimoire(); Game.CalculateGains(); - CM.LoadConfig(); // Must be after all things are created! + CM.Config.LoadConfig(); // Must be after all things are created! CM.Disp.lastAscendState = Game.OnAscend; CM.Disp.lastBuyMode = Game.buyMode; CM.Disp.lastBuyBulk = Game.buyBulk; diff --git a/src/Config.js b/src/Config.js index a4def30..c748b68 100644 --- a/src/Config.js +++ b/src/Config.js @@ -7,19 +7,19 @@ /** * This function saves the config of CookieMonster to localStorage - * It is called by CM.LoadConfig(), CM.RestoreDefault(), - * any of the CM.ToggleConfig() functions and upon changes to URL or volume settings + * It is called by CM.Config.LoadConfig(), CM.Config.RestoreDefault(), CM.Config.ToggleConfig(), + * CM.ToggleConfigVolume() and changes in options with type "url" or "color" * @param {object} config The Config to be saved (normally CM.Options) */ -CM.SaveConfig = function(config) { +CM.Config.SaveConfig = function(config) { localStorage.setItem(CM.ConfigPrefix, JSON.stringify(config)); } /** * This function loads the config of CookieMonster saved in localStorage and loads it into CM.Options - * It is called by CM.DelayInit() and CM.RestoreDefault() + * It is called by CM.DelayInit() and CM.Config.RestoreDefault() */ -CM.LoadConfig = function() { +CM.Config.LoadConfig = function() { if (localStorage.getItem(CM.ConfigPrefix) != null) { CM.Options = JSON.parse(localStorage.getItem(CM.ConfigPrefix)); @@ -30,7 +30,7 @@ CM.LoadConfig = function() { mod = true; CM.Options[i] = CM.Data.ConfigDefault[i]; } - else if (i != 'StatsPref' && i != 'Colors') { + else if (i != 'Header' && i != 'Colors') { if (i.indexOf('SoundURL') == -1) { if (!(CM.Options[i] > -1 && CM.Options[i] < CM.ConfigData[i].label.length)) { mod = true; @@ -44,8 +44,8 @@ CM.LoadConfig = function() { } } } - else if (i == 'StatsPref') { - for (var j in CM.Data.ConfigDefault.StatsPref) { + else if (i == 'Header') { + for (var j in CM.Data.ConfigDefault.Header) { if (typeof CM.Options[i][j] === 'undefined' || !(CM.Options[i][j] > -1 && CM.Options[i][j] < 2)) { mod = true; CM.Options[i][j] = CM.Data.ConfigDefault[i][j]; @@ -61,27 +61,27 @@ CM.LoadConfig = function() { } } } - if (mod) CM.SaveConfig(CM.Options); + if (mod) CM.Config.SaveConfig(CM.Options); CM.Loop(); // Do loop once for (var i in CM.Data.ConfigDefault) { - if (i != 'StatsPref' && i != 'OptionsPref' && typeof CM.ConfigData[i].func !== 'undefined') { + if (i != 'Header' && typeof CM.ConfigData[i].func !== 'undefined') { CM.ConfigData[i].func(); } } } else { // Default values - CM.RestoreDefault(); + CM.Config.RestoreDefault(); } } /** * This function reloads and resaves the default config as stored in CM.Data.ConfigDefault - * It is called by resDefBut.onclick loaded in the options page or by CM.LoadConfig is no localStorage is found + * It is called by resDefBut.onclick loaded in the options page or by CM.Config.LoadConfig if no localStorage is found */ -CM.RestoreDefault = function() { +CM.Config.RestoreDefault = function() { CM.Options = {}; - CM.SaveConfig(CM.Data.ConfigDefault); - CM.LoadConfig(); + CM.Config.SaveConfig(CM.Data.ConfigDefault); + CM.Config.LoadConfig(); Game.UpdateMenu(); } @@ -89,71 +89,61 @@ CM.RestoreDefault = function() { * Section: Functions related to toggling or changing configs */ /** - * This function toggles options which are considered "toggles" - * These have off (1) and on (1) states + * This function toggles options by incrementing them with 1 and handling changes * It is called by the onclick event of options of the "bool" type * @param {string} config The name of the option */ -CM.ToggleConfig = function(config) { - CM.ToggleConfigUp(config); - if (CM.ConfigData[config].toggle) { - if (CM.Options[config] == 0) { - l(CM.ConfigPrefix + config).className = 'option off'; - } - else { - l(CM.ConfigPrefix + config).className = 'option'; - } - } -} - -CM.ToggleConfigUp = function(config) { +CM.Config.ToggleConfig = function(config) { CM.Options[config]++; + if (CM.Options[config] == CM.ConfigData[config].label.length) { CM.Options[config] = 0; + if (CM.ConfigData[config].toggle) l(CM.ConfigPrefix + config).className = 'option off'; } + else l(CM.ConfigPrefix + config).className = 'option'; + if (typeof CM.ConfigData[config].func !== 'undefined') { CM.ConfigData[config].func(); } + l(CM.ConfigPrefix + config).innerHTML = CM.ConfigData[config].label[CM.Options[config]]; - CM.SaveConfig(CM.Options); + CM.Config.SaveConfig(CM.Options); } /** * This function sets the value of the specified volume-option and updates the display in the options menu - * It is called by CM.Disp.CreatePrefOption() + * It is called by the oninput and onchange event of "vol" type options * @param {string} config The name of the option */ -CM.ToggleConfigVolume = function(config) { +CM.Config.ToggleConfigVolume = function(config) { if (l("slider" + config) != null) { l("slider" + config + "right").innerHTML = l("slider" + config).value + "%"; CM.Options[config] = Math.round(l("slider" + config).value); } - CM.SaveConfig(CM.Options); + CM.Config.SaveConfig(CM.Options); } -CM.ToggleStatsConfig = function(config) { - if (CM.Options.StatsPref[config] == 0) { - CM.Options.StatsPref[config]++; - } - else { - CM.Options.StatsPref[config]--; - } - CM.SaveConfig(CM.Options); +/** + * This function toggles header options by incrementing them with 1 and handling changes + * It is called by the onclick event of the +/- next to headers + * @param {string} config The name of the header + */ +CM.Config.ToggleHeader = function(config) { + CM.Options.Header[config]++; + if (CM.Options.Header[config] > 1) CM.Options.Header[config] = 0; + CM.Config.SaveConfig(CM.Options); } -CM.ToggleOptionsConfig = function(config) { - if (CM.Options.OptionsPref[config] == 0) { - CM.Options.OptionsPref[config]++; - } - else { - CM.Options.OptionsPref[config]--; - } - CM.SaveConfig(CM.Options); -} +/******** + * Section: Functions related to notifications */ -// Checks if the browsers has permissions to produce notifications -// Should be triggered when Config related to Notifications is toggled on -CM.CheckNotificationPermissions = function(ToggleOnOff) { +/** + * This function checks if the user has given permissions for notifications + * It is called by a change in any of the notification options + * Note that most browsers will stop asking if the user has ignored the prompt around 6 times + * @param {number} ToggleOnOff A number indicating whether the option has been turned off (0) or on (1) + */ +CM.Config.CheckNotificationPermissions = function(ToggleOnOff) { if (ToggleOnOff == 1) { // Check if browser support Promise version of Notification Permissions function checkNotificationPromise() { diff --git a/src/Data.js b/src/Data.js index 792e0e9..74e2067 100644 --- a/src/Data.js +++ b/src/Data.js @@ -96,7 +96,7 @@ CM.ConfigData.AvgClicksHist = {type: 'bool', group: 'Calculation', label: ['Aver CM.ConfigData.ToolWarnBon = {type: 'bool', group: 'Calculation', label: ['Calculate Tooltip Warning With Bonus CPS OFF', 'Calculate Tooltip Warning With Bonus CPS ON'], desc: 'Calculate the warning with or without the bonus CPS you get from buying', toggle: true}; // Notification -CM.ConfigData.GCNotification = {type: 'bool', group: 'Notification', label: ['Golden Cookie Notification OFF', 'Golden Cookie Notification ON'], desc: 'Create a notification when Golden Cookie spawns', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Options.GCNotification);}}; +CM.ConfigData.GCNotification = {type: 'bool', group: 'Notification', label: ['Golden Cookie Notification OFF', 'Golden Cookie Notification ON'], desc: 'Create a notification when Golden Cookie spawns', toggle: true, func: function () {CM.Config.CheckNotificationPermissions(CM.Options.GCNotification);}}; CM.ConfigData.GCFlash = {type: 'bool', group: 'Notification', label: ['Golden Cookie Flash OFF', 'Golden Cookie Flash ON'], desc: 'Flash screen on Golden Cookie', toggle: true}; CM.ConfigData.GCSound = {type: 'bool', group: 'Notification', label: ['Golden Cookie Sound OFF', 'Golden Cookie Sound ON'], desc: 'Play a sound on Golden Cookie', toggle: true}; CM.ConfigData.GCVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of Golden Cookie'}; @@ -106,7 +106,7 @@ for (var i = 0; i < 101; i++) { CM.ConfigData.GCSoundURL = {type: 'url', group: 'Notification', label: 'Golden Cookie Sound URL:', desc: 'URL of the sound to be played when a Golden Cookie spawns'}; CM.ConfigData.GCTimer = {type: 'bool', group: 'Notification', label: ['Golden Cookie Timer OFF', 'Golden Cookie Timer ON'], desc: 'A timer on the Golden Cookie when it has been spawned', toggle: true, func: function() {CM.Disp.ToggleGCTimer();}}; CM.ConfigData.Favicon = {type: 'bool', group: 'Notification', label: ['Favicon OFF', 'Favicon ON'], desc: 'Update favicon with Golden/Wrath Cookie', toggle: true, func: function() {CM.Disp.UpdateFavicon();}}; -CM.ConfigData.FortuneNotification = {type: 'bool', group: 'Notification', label: ['Fortune Cookie Notification OFF', 'Fortune Cookie Notification ON'], desc: 'Create a notification when Fortune Cookie is on the Ticker', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Options.FortuneNotification);}}; +CM.ConfigData.FortuneNotification = {type: 'bool', group: 'Notification', label: ['Fortune Cookie Notification OFF', 'Fortune Cookie Notification ON'], desc: 'Create a notification when Fortune Cookie is on the Ticker', toggle: true, func: function () {CM.Config.CheckNotificationPermissions(CM.Options.FortuneNotification);}}; CM.ConfigData.FortuneFlash = {type: 'bool', group: 'Notification', label: ['Fortune Cookie Flash OFF', 'Fortune Cookie Flash ON'], desc: 'Flash screen on Fortune Cookie', toggle: true}; CM.ConfigData.FortuneSound = {type: 'bool', group: 'Notification', label: ['Fortune Cookie Sound OFF', 'Fortune Cookie Sound ON'], desc: 'Play a sound on Fortune Cookie', toggle: true}; CM.ConfigData.FortuneVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of Fortune Cookie'}; @@ -114,7 +114,7 @@ for (var i = 0; i < 101; i++) { CM.ConfigData.FortuneVolume.label[i] = i + '%'; } CM.ConfigData.FortuneSoundURL = {type: 'url', group: 'Notification', label: 'Fortune Cookie Sound URL:', desc: 'URL of the sound to be played when the Ticker has a Fortune Cookie'}; -CM.ConfigData.SeaNotification = {type: 'bool', group: 'Notification', label: ['Season Special Notification OFF', 'Season Special Notification ON'], desc: 'Create a notification on Season Popup', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Options.SeaNotification);}}; +CM.ConfigData.SeaNotification = {type: 'bool', group: 'Notification', label: ['Season Special Notification OFF', 'Season Special Notification ON'], desc: 'Create a notification on Season Popup', toggle: true, func: function () {CM.Config.CheckNotificationPermissions(CM.Options.SeaNotification);}}; CM.ConfigData.SeaFlash = {type: 'bool', group: 'Notification', label: ['Season Special Flash OFF', 'Season Special Flash ON'], desc: 'Flash screen on Season Popup', toggle: true}; CM.ConfigData.SeaSound = {type: 'bool', group: 'Notification', label: ['Season Special Sound OFF', 'Season Special Sound ON'], desc: 'Play a sound on Season Popup', toggle: true}; CM.ConfigData.SeaVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of Season Special'}; @@ -129,7 +129,7 @@ for (var i = 0; i < 101; i++) { CM.ConfigData.GardVolume.label[i] = i + '%'; } CM.ConfigData.GardSoundURL = {type: 'url', group: 'Notification', label: 'Garden Tick Sound URL:', desc: 'URL of the sound to be played when the garden ticks'}; -CM.ConfigData.MagicNotification = {type: 'bool', group: 'Notification', label: ['Magic Max Notification OFF', 'Magic Max Notification ON'], desc: 'Create a notification when magic reaches maximum', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Options.MagicNotification);}}; +CM.ConfigData.MagicNotification = {type: 'bool', group: 'Notification', label: ['Magic Max Notification OFF', 'Magic Max Notification ON'], desc: 'Create a notification when magic reaches maximum', toggle: true, func: function () {CM.Config.CheckNotificationPermissions(CM.Options.MagicNotification);}}; CM.ConfigData.MagicFlash = {type: 'bool', group: 'Notification', label: ['Magic Max Flash OFF', 'Magic Max Flash ON'], desc: 'Flash screen when magic reaches maximum', toggle: true}; CM.ConfigData.MagicSound = {type: 'bool', group: 'Notification', label: ['Magic Max Sound OFF', 'Magic Max Sound ON'], desc: 'Play a sound when magic reaches maximum', toggle: true}; CM.ConfigData.MagicVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of Max Magic'}; @@ -137,7 +137,7 @@ for (var i = 0; i < 101; i++) { CM.ConfigData.MagicVolume.label[i] = i + '%'; } CM.ConfigData.MagicSoundURL = {type: 'url', group: 'Notification', label: 'Magic Max Sound URL:', desc: 'URL of the sound to be played when magic reaches maxium'}; -CM.ConfigData.WrinklerNotification = {type: 'bool', group: 'Notification', label: ['Wrinkler Notification OFF', 'Wrinkler Notification ON'], desc: 'Create a notification when a Wrinkler appears', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Options.WrinklerNotification);}}; +CM.ConfigData.WrinklerNotification = {type: 'bool', group: 'Notification', label: ['Wrinkler Notification OFF', 'Wrinkler Notification ON'], desc: 'Create a notification when a Wrinkler appears', toggle: true, func: function () {CM.Config.CheckNotificationPermissions(CM.Options.WrinklerNotification);}}; CM.ConfigData.WrinklerFlash = {type: 'bool', group: 'Notification', label: ['Wrinkler Flash OFF', 'Wrinkler Flash ON'], desc: 'Flash screen when a Wrinkler appears', toggle: true}; CM.ConfigData.WrinklerSound = {type: 'bool', group: 'Notification', label: ['Wrinkler Sound OFF', 'Wrinkler Sound ON'], desc: 'Play a sound when a Wrinkler appears', toggle: true}; CM.ConfigData.WrinklerVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of Wrinkler'}; @@ -145,7 +145,7 @@ for (var i = 0; i < 101; i++) { CM.ConfigData.WrinklerVolume.label[i] = i + '%'; } CM.ConfigData.WrinklerSoundURL = {type: 'url', group: 'Notification', label: 'Wrinkler Sound URL:', desc: 'URL of the sound to be played when a Wrinkler appears'}; -CM.ConfigData.WrinklerMaxNotification = {type: 'bool', group: 'Notification', label: ['Wrinkler Max Notification OFF', 'Wrinkler Max Notification ON'], desc: 'Create a notification when the maximum amount of Wrinklers has appeared', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Options.WrinklerMaxNotification);}}; +CM.ConfigData.WrinklerMaxNotification = {type: 'bool', group: 'Notification', label: ['Wrinkler Max Notification OFF', 'Wrinkler Max Notification ON'], desc: 'Create a notification when the maximum amount of Wrinklers has appeared', toggle: true, func: function () {CM.Config.CheckNotificationPermissions(CM.Options.WrinklerMaxNotification);}}; CM.ConfigData.WrinklerMaxFlash = {type: 'bool', group: 'Notification', label: ['Wrinkler Max Flash OFF', 'Wrinkler Max Flash ON'], desc: 'Flash screen when the maximum amount of Wrinklers has appeared', toggle: true}; CM.ConfigData.WrinklerMaxSound = {type: 'bool', group: 'Notification', label: ['Wrinkler Max Sound OFF', 'Wrinkler Max Sound ON'], desc: 'Play a sound when the maximum amount of Wrinklers has appeared', toggle: true}; CM.ConfigData.WrinklerMaxVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of Wrinkler Max'}; @@ -181,7 +181,7 @@ CM.ConfigData.ScaleSeparator = {type: 'bool', group: 'Notation', label: ['. for /** * This array describes all default settings - * It is used by CM.LoadConfig() and CM.RestoreDefault() + * It is used by CM.LoadConfig() and CM.Config.RestoreDefault() */ CM.Data.ConfigDefault = { BotBar: 1, @@ -252,9 +252,8 @@ CM.Data.ConfigDefault = { Scale: 2, ScaleDecimals: 2, ScaleSeparator: 0, - OptionsPref: {BarsColors: 1, Calculation: 1, Notification: 1, Tooltip: 1, Statistics: 1, Notation: 1}, - StatsPref: {Lucky: 1, Conjure: 1, Chain: 1, Prestige: 1, Wrink: 1, Sea: 1, Misc: 1}, - Colors : {Blue: '#4bb8f0', Green: '#00ff00', Yellow: '#ffff00', Orange: '#ff7f00', Red: '#ff0000', Purple: '#ff00ff', Gray: '#b3b3b3', Pink: '#ff1493', Brown: '#8b4513'}, + Colors: {Blue: '#4bb8f0', Green: '#00ff00', Yellow: '#ffff00', Orange: '#ff7f00', Red: '#ff0000', Purple: '#ff00ff', Gray: '#b3b3b3', Pink: '#ff1493', Brown: '#8b4513'}, SortBuildings: 0, - SortUpgrades: 0 + SortUpgrades: 0, + Header: {BarsColors: 1, Calculation: 1, Notification: 1, Tooltip: 1, Statistics: 1, Notation: 1, Lucky: 1, Conjure: 1, Chain: 1, Prestige: 1, Wrink: 1, Sea: 1, Misc: 1}, }; \ No newline at end of file diff --git a/src/Disp.js b/src/Disp.js index 6d56715..ca0ae6e 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -1865,7 +1865,7 @@ CM.Disp.AddMenuPref = function(title) { for (var group in CM.ConfigGroups) { groupObject = CM.Disp.CreatePrefHeader(group, CM.ConfigGroups[group]) // (group, display-name of group) frag.appendChild(groupObject) - if (CM.Options.OptionsPref[group]) { // 0 is show, 1 is collapsed + if (CM.Options.Header[group]) { // 0 is show, 1 is collapsed for (var option in CM.ConfigData) { if (CM.ConfigData[option].group == group) frag.appendChild(CM.Disp.CreatePrefOption(option)) } @@ -1876,7 +1876,7 @@ CM.Disp.AddMenuPref = function(title) { resDef.className = 'listing'; var resDefBut = document.createElement('a'); resDefBut.className = 'option'; - resDefBut.onclick = function() {CM.RestoreDefault();}; + resDefBut.onclick = function() {CM.Config.RestoreDefault();}; resDefBut.textContent = 'Restore Default'; resDef.appendChild(resDefBut); frag.appendChild(resDef); @@ -1909,8 +1909,8 @@ CM.Disp.CreatePrefHeader = function(config, text) { span.style.color = 'black'; span.style.fontSize = '13px'; span.style.verticalAlign = 'middle'; - span.textContent = CM.Options.OptionsPref[config] ? '-' : '+'; - span.onclick = function() {CM.ToggleOptionsConfig(config); Game.UpdateMenu();}; + span.textContent = CM.Options.Header[config] ? '-' : '+'; + span.onclick = function() {CM.Config.ToggleHeader(config); Game.UpdateMenu();}; div.appendChild(span); return div; } @@ -1933,7 +1933,7 @@ CM.Disp.CreatePrefOption = function(config) { a.className = 'option'; } a.id = CM.ConfigPrefix + config; - a.onclick = function() {CM.ToggleConfig(config);}; + a.onclick = function() {CM.Config.ToggleConfig(config);}; a.textContent = CM.ConfigData[config].label[CM.Options[config]]; div.appendChild(a); var label = document.createElement('label'); @@ -1964,8 +1964,8 @@ CM.Disp.CreatePrefOption = function(config) { slider.max = "100"; slider.step = "1"; slider.value = CM.Options[config]; - slider.oninput = function() {CM.ToggleConfigVolume(config)}; - slider.onchange = function() {CM.ToggleConfigVolume(config)}; + slider.oninput = function() {CM.Config.ToggleConfigVolume(config)}; + slider.onchange = function() {CM.Config.ToggleConfigVolume(config)}; volume.appendChild(slider); div.appendChild(volume); return div; @@ -1993,7 +1993,7 @@ CM.Disp.CreatePrefOption = function(config) { inputPrompt.setAttribute('value', CM.Options[config]); var a = document.createElement('a'); a.className = 'option'; - a.onclick = function() {Game.Prompt(inputPrompt.outerHTML, [['Save', 'CM.Options[\'' + config + '\'] = l(CM.ConfigPrefix + \'' + config + '\' + \'Prompt\').value; CM.SaveConfig(CM.Options); Game.ClosePrompt(); Game.UpdateMenu();'], 'Cancel']);}; + a.onclick = function() {Game.Prompt(inputPrompt.outerHTML, [['Save', 'CM.Options[\'' + config + '\'] = l(CM.ConfigPrefix + \'' + config + '\' + \'Prompt\').value; CM.Config.SaveConfig(CM.Options); Game.ClosePrompt(); Game.UpdateMenu();'], 'Cancel']);}; a.textContent = 'Edit'; div.appendChild(a); var label = document.createElement('label'); @@ -2011,7 +2011,7 @@ CM.Disp.CreatePrefOption = function(config) { input.style.width = '65px'; input.setAttribute('value', CM.Options.Colors[CM.Disp.colors[i]]); div.appendChild(input); - eval('var change = function() {CM.Options.Colors[\'' + CM.Disp.colors[i] + '\'] = l(CM.ConfigPrefix + \'Color\' + \'' + CM.Disp.colors[i] + '\').value; CM.Disp.UpdateColors(); CM.SaveConfig(CM.Options);}'); + eval('var change = function() {CM.Options.Colors[\'' + CM.Disp.colors[i] + '\'] = l(CM.ConfigPrefix + \'Color\' + \'' + CM.Disp.colors[i] + '\').value; CM.Disp.UpdateColors(); CM.Config.SaveConfig(CM.Options);}'); var jscolorpicker = new jscolor.color(input, {hash: true, caps: false, pickerZIndex: 1000000, pickerPosition: 'right', onImmediateChange: change}); var label = document.createElement('label'); label.textContent = CM.ConfigData.Colors.desc[CM.Disp.colors[i]]; @@ -2078,28 +2078,28 @@ CM.Disp.AddMenuStats = function(title) { stats.appendChild(title()); stats.appendChild(CM.Disp.CreateStatsHeader('Lucky Cookies', 'Lucky')); - if (CM.Options.StatsPref.Lucky) { + if (CM.Options.Header.Lucky) { stats.appendChild(CM.Disp.CreateStatsLuckySection()); } stats.appendChild(CM.Disp.CreateStatsHeader('Chain Cookies', 'Chain')); - if (CM.Options.StatsPref.Chain) { + if (CM.Options.Header.Chain) { stats.appendChild(CM.Disp.CreateStatsChainSection()); } stats.appendChild(CM.Disp.CreateStatsHeader('Conjure Baked Goods', 'Conjure')); - if (CM.Options.StatsPref.Conjure) { + if (CM.Options.Header.Conjure) { stats.appendChild(CM.Disp.CreateStatsConjureSection()); } stats.appendChild(CM.Disp.CreateStatsHeader('Prestige', 'Prestige')); - if (CM.Options.StatsPref.Prestige) { + if (CM.Options.Header.Prestige) { stats.appendChild(CM.Disp.CreateStatsPrestigeSection()); } if (Game.cpsSucked > 0) { stats.appendChild(CM.Disp.CreateStatsHeader('Wrinklers', 'Wrink')); - if (CM.Options.StatsPref.Wrink) { + if (CM.Options.Header.Wrink) { var popAllFrag = document.createDocumentFragment(); popAllFrag.appendChild(document.createTextNode(Beautify(CM.Cache.WrinkBankTotal) + ' / ' + Beautify(CM.Cache.WrinkBankNormal) + ' ')); var popAllA = document.createElement('a'); @@ -2153,7 +2153,7 @@ CM.Disp.AddMenuStats = function(title) { if (Game.season == 'christmas' || specDisp || choEgg || centEgg) { stats.appendChild(CM.Disp.CreateStatsHeader('Season Specials', 'Sea')); - if (CM.Options.StatsPref.Sea) { + if (CM.Options.Header.Sea) { if (specDisp) { if (missingHalloweenCookies.length != 0) stats.appendChild(CM.Disp.CreateStatsListing("basic", 'Halloween Cookies Left to Buy', CM.Disp.CreateStatsMissDisp(missingHalloweenCookies))); if (missingChristmasCookies.length != 0) stats.appendChild(CM.Disp.CreateStatsListing("basic", 'Christmas Cookies Left to Buy', CM.Disp.CreateStatsMissDisp(missingChristmasCookies))); @@ -2173,7 +2173,7 @@ CM.Disp.AddMenuStats = function(title) { } stats.appendChild(CM.Disp.CreateStatsHeader('Miscellaneous', 'Misc')); - if (CM.Options.StatsPref.Misc) { + if (CM.Options.Header.Misc) { stats.appendChild(CM.Disp.CreateStatsListing("basic", 'Average Cookies Per Second (Past ' + (CM.Disp.cookieTimes[CM.Options.AvgCPSHist] < 60 ? (CM.Disp.cookieTimes[CM.Options.AvgCPSHist] + ' seconds') : ((CM.Disp.cookieTimes[CM.Options.AvgCPSHist] / 60) + (CM.Options.AvgCPSHist == 3 ? ' minute' : ' minutes'))) + ')', document.createTextNode(Beautify(CM.Cache.AvgCPS, 3)) @@ -2230,8 +2230,8 @@ CM.Disp.CreateStatsHeader = function(text, config) { span.style.color = 'black'; span.style.fontSize = '13px'; span.style.verticalAlign = 'middle'; - span.textContent = CM.Options.StatsPref[config] ? '-' : '+'; - span.onclick = function() {CM.ToggleStatsConfig(config); Game.UpdateMenu();}; + span.textContent = CM.Options.Header[config] ? '-' : '+'; + span.onclick = function() {CM.Config.ToggleHeader(config); Game.UpdateMenu();}; div.appendChild(span); return div; } diff --git a/src/Main.js b/src/Main.js index b15660c..12c0de1 100644 --- a/src/Main.js +++ b/src/Main.js @@ -246,7 +246,7 @@ CM.DelayInit = function() { CM.ReplaceNative(); CM.ReplaceNativeGrimoire(); Game.CalculateGains(); - CM.LoadConfig(); // Must be after all things are created! + CM.Config.LoadConfig(); // Must be after all things are created! CM.Disp.lastAscendState = Game.OnAscend; CM.Disp.lastBuyMode = Game.buyMode; CM.Disp.lastBuyBulk = Game.buyBulk; From 5e4471d9299aaa88ed7ee3f40a00e7cf4a9eff39 Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Fri, 18 Dec 2020 20:08:03 +0100 Subject: [PATCH 065/106] Fixed small numbers for Beautify --- CookieMonster.js | 75 ++++++++++++++---------------------------------- src/Disp.js | 75 ++++++++++++++---------------------------------- 2 files changed, 44 insertions(+), 106 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index 40a24b7..2a4107d 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -1172,95 +1172,64 @@ CM.Disp.GetTimeColor = function(time) { /** * This function returns formats number based on the Scale setting * @param {number} num Number to be beautified - * @param {any} frac Used in some scenario's by CM.Backup.Beautify (Game's original function) + * @param {any} floats Used in some scenario's by CM.Backup.Beautify (Game's original function) * @param {number} forced Used to force (type 3) in certains cases * @returns {string} Formatted number */ -CM.Disp.Beautify = function(num, frac, forced) { +CM.Disp.Beautify = function(num, floats, forced) { var decimals = CM.Options.ScaleDecimals + 1; if (CM.Options.Scale == 0) { - return CM.Backup.Beautify(num, frac); + return CM.Backup.Beautify(num, floats); } else if (isFinite(num)) { var answer = ''; - if (num < 0) { - num = Math.abs(num); - var negative = true; - } - num = num.toString(); var timesTenToPowerThree = Math.trunc(Math.log10(num) / 3) - if (num == "0") { - return num + if (num == 0) { + return num.toString() } else if (-1 < timesTenToPowerThree && timesTenToPowerThree < 2) { // TODO: Add changing separators of thousands and making this cut-off user configurable answer = Math.round(num * 100) / 100; } else if (CM.Options.Scale == 3 && !forced || forced == 3) { // Scientific notation, 123456789 => 1.235E+8 - answer = num[0] + (CM.Options.ScaleSeparator ? ',' : '.'); - i = 0; - while (i < decimals - 1) { - answer += num[i + 2]; // num has a 0-based index and [1] is a '.' - i++; - } - lastNumber = Math.round(num[i + 2] + '.' + num[i + 3]); - while (lastNumber >= 10) { - if (answer[answer.length - 1] != ".") { - lastNumber = Math.round((answer[answer.length - 1] * 10) + lastNumber) / 10; - answer = answer.slice(0,-1) - } else { - lastNumber = Math.round((answer[answer.length - 2] * 10) + lastNumber) / 10; - answer = answer.slice(0,-2) - } - } - answer += lastNumber; - answer += 'E+' + Math.trunc(Math.log10(num)); + answer = num.toExponential(decimals).toString().replace("e", "E"); } else { - var restOfNumber = (num / Math.pow(10, (timesTenToPowerThree * 3))).toString(); - // Check if number contains decimals - numbersToAdd = (restOfNumber.indexOf('.') > -1 ? restOfNumber.indexOf('.') + 1 + decimals : (restOfNumber.length)) - i = 0 - while (i < numbersToAdd - 1 && i < restOfNumber.length - 1) { - answer += (CM.Options.ScaleSeparator && restOfNumber[i] == '.' ? ',' : restOfNumber[i]); - i++ - } - answer += (i + 1 < restOfNumber.length ? Math.round(restOfNumber[i] + '.' + restOfNumber[i + 1]) : restOfNumber[i]); - + exponential = num.toExponential().toString(); + AmountOfTenPowerThree = Math.floor(exponential.slice(exponential.indexOf("e") + 1) / 3); + answer = (num / Number("1e" + (AmountOfTenPowerThree * 3))).toFixed(decimals) // answer is now "xxx.xx" (e.g., 123456789 would be 123.46) if (CM.Options.Scale == 1 && !forced || forced == 1) { // Metric scale, 123456789 => 123.457 M - if (timesTenToPowerThree - 1 < CM.Data.metric.length) { - answer += ' ' + CM.Data.metric[timesTenToPowerThree - 1] - } - else { // If number is too large, revert to scientific notation - return CM.Disp.Beautify(num, 0, 3); + if (num >= 0.01 && num < Number("1e" + CM.Data.metric.length * 3)) { + answer += ' ' + CM.Data.metric[AmountOfTenPowerThree - 1] } + // If number is too large or little, revert to scientific notation + else answer = CM.Disp.Beautify(num, 0, 3); } else if (CM.Options.Scale == 2 && !forced || forced == 2) { // Short scale, 123456789 => 123.457 M - if (timesTenToPowerThree < CM.Data.shortScale.length + 1) { - answer += ' ' + CM.Data.shortScale[timesTenToPowerThree - 1]; - } - else { // If number is too large, revert to scientific notation - return CM.Disp.Beautify(num, 0, 3); + if (num >= 0.01 && num < Number("1e" + CM.Data.shortScale.length * 3)) { + answer += ' ' + CM.Data.shortScale[AmountOfTenPowerThree - 1]; } + // If number is too large or little, revert to scientific notation + else answer = CM.Disp.Beautify(num, 0, 3); } else if (CM.Options.Scale == 4 && !forced || forced == 4) { // Engineering notation, 123456789 => 123.457E+6 - answer += 'E+' + (timesTenToPowerThree * 3); + answer += 'E' + AmountOfTenPowerThree * 3; } } if (answer === '') { console.log("Could not beautify number with CM.Disp.Beautify:" + num); - answer = CM.Backup.Beautify(num, frac); + answer = CM.Backup.Beautify(num, floats); } - if (negative) answer = '-' + answer; - return answer.toString(); + if (CM.Options.ScaleSeparator) answer = answer.replace('.', ','); + return answer; } else if (num == Infinity) { return "Infinity"; } else { console.log("Could not beautify number with CM.Disp.Beautify:" + num); - return CM.Backup.Beautify(num, frac); + return CM.Backup.Beautify(num, floats); } } diff --git a/src/Disp.js b/src/Disp.js index ca0ae6e..d4bbffc 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -163,95 +163,64 @@ CM.Disp.GetTimeColor = function(time) { /** * This function returns formats number based on the Scale setting * @param {number} num Number to be beautified - * @param {any} frac Used in some scenario's by CM.Backup.Beautify (Game's original function) + * @param {any} floats Used in some scenario's by CM.Backup.Beautify (Game's original function) * @param {number} forced Used to force (type 3) in certains cases * @returns {string} Formatted number */ -CM.Disp.Beautify = function(num, frac, forced) { +CM.Disp.Beautify = function(num, floats, forced) { var decimals = CM.Options.ScaleDecimals + 1; if (CM.Options.Scale == 0) { - return CM.Backup.Beautify(num, frac); + return CM.Backup.Beautify(num, floats); } else if (isFinite(num)) { var answer = ''; - if (num < 0) { - num = Math.abs(num); - var negative = true; - } - num = num.toString(); var timesTenToPowerThree = Math.trunc(Math.log10(num) / 3) - if (num == "0") { - return num + if (num == 0) { + return num.toString() } else if (-1 < timesTenToPowerThree && timesTenToPowerThree < 2) { // TODO: Add changing separators of thousands and making this cut-off user configurable answer = Math.round(num * 100) / 100; } else if (CM.Options.Scale == 3 && !forced || forced == 3) { // Scientific notation, 123456789 => 1.235E+8 - answer = num[0] + (CM.Options.ScaleSeparator ? ',' : '.'); - i = 0; - while (i < decimals - 1) { - answer += num[i + 2]; // num has a 0-based index and [1] is a '.' - i++; - } - lastNumber = Math.round(num[i + 2] + '.' + num[i + 3]); - while (lastNumber >= 10) { - if (answer[answer.length - 1] != ".") { - lastNumber = Math.round((answer[answer.length - 1] * 10) + lastNumber) / 10; - answer = answer.slice(0,-1) - } else { - lastNumber = Math.round((answer[answer.length - 2] * 10) + lastNumber) / 10; - answer = answer.slice(0,-2) - } - } - answer += lastNumber; - answer += 'E+' + Math.trunc(Math.log10(num)); + answer = num.toExponential(decimals).toString().replace("e", "E"); } else { - var restOfNumber = (num / Math.pow(10, (timesTenToPowerThree * 3))).toString(); - // Check if number contains decimals - numbersToAdd = (restOfNumber.indexOf('.') > -1 ? restOfNumber.indexOf('.') + 1 + decimals : (restOfNumber.length)) - i = 0 - while (i < numbersToAdd - 1 && i < restOfNumber.length - 1) { - answer += (CM.Options.ScaleSeparator && restOfNumber[i] == '.' ? ',' : restOfNumber[i]); - i++ - } - answer += (i + 1 < restOfNumber.length ? Math.round(restOfNumber[i] + '.' + restOfNumber[i + 1]) : restOfNumber[i]); - + exponential = num.toExponential().toString(); + AmountOfTenPowerThree = Math.floor(exponential.slice(exponential.indexOf("e") + 1) / 3); + answer = (num / Number("1e" + (AmountOfTenPowerThree * 3))).toFixed(decimals) // answer is now "xxx.xx" (e.g., 123456789 would be 123.46) if (CM.Options.Scale == 1 && !forced || forced == 1) { // Metric scale, 123456789 => 123.457 M - if (timesTenToPowerThree - 1 < CM.Data.metric.length) { - answer += ' ' + CM.Data.metric[timesTenToPowerThree - 1] - } - else { // If number is too large, revert to scientific notation - return CM.Disp.Beautify(num, 0, 3); + if (num >= 0.01 && num < Number("1e" + CM.Data.metric.length * 3)) { + answer += ' ' + CM.Data.metric[AmountOfTenPowerThree - 1] } + // If number is too large or little, revert to scientific notation + else answer = CM.Disp.Beautify(num, 0, 3); } else if (CM.Options.Scale == 2 && !forced || forced == 2) { // Short scale, 123456789 => 123.457 M - if (timesTenToPowerThree < CM.Data.shortScale.length + 1) { - answer += ' ' + CM.Data.shortScale[timesTenToPowerThree - 1]; - } - else { // If number is too large, revert to scientific notation - return CM.Disp.Beautify(num, 0, 3); + if (num >= 0.01 && num < Number("1e" + CM.Data.shortScale.length * 3)) { + answer += ' ' + CM.Data.shortScale[AmountOfTenPowerThree - 1]; } + // If number is too large or little, revert to scientific notation + else answer = CM.Disp.Beautify(num, 0, 3); } else if (CM.Options.Scale == 4 && !forced || forced == 4) { // Engineering notation, 123456789 => 123.457E+6 - answer += 'E+' + (timesTenToPowerThree * 3); + answer += 'E' + AmountOfTenPowerThree * 3; } } if (answer === '') { console.log("Could not beautify number with CM.Disp.Beautify:" + num); - answer = CM.Backup.Beautify(num, frac); + answer = CM.Backup.Beautify(num, floats); } - if (negative) answer = '-' + answer; - return answer.toString(); + if (CM.Options.ScaleSeparator) answer = answer.replace('.', ','); + return answer; } else if (num == Infinity) { return "Infinity"; } else { console.log("Could not beautify number with CM.Disp.Beautify:" + num); - return CM.Backup.Beautify(num, frac); + return CM.Backup.Beautify(num, floats); } } From 9542093f1be9ba0cfb0bb80921144ae893d550dd Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Fri, 18 Dec 2020 20:19:37 +0100 Subject: [PATCH 066/106] Split the options for Lucky/LuckyFrenzy warning --- CookieMonster.js | 63 ++++++++++++++++++++---------------------------- src/Data.js | 4 ++- src/Disp.js | 59 ++++++++++++++++++--------------------------- 3 files changed, 52 insertions(+), 74 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index 2a4107d..c5147ed 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -909,7 +909,8 @@ CM.ConfigData.Title = {type: 'bool', group: 'Notification', label: ['Title OFF', // Tooltip CM.ConfigData.TooltipBuildUp = {type: 'bool', group: 'Tooltip', label: ['Buildings/Upgrades Tooltip Information OFF', 'Buildings/Upgrades Tooltip Information ON'], desc: 'Extra information in tooltip for buildings/upgrades', toggle: true}; CM.ConfigData.TooltipAmor = {type: 'bool', group: 'Tooltip', label: ['Buildings Tooltip Amortization Information OFF', 'Buildings Tooltip Amortization Information ON'], desc: 'Add amortization information to buildings tooltip', toggle: true}; -CM.ConfigData.ToolWarnLucky = {type: 'bool', group: 'Tooltip', label: ['Tooltip Lucky Warning OFF', 'Tooltip Lucky Warning ON'], desc: 'A warning when buying if it will put the bank under the amount needed for max "Lucky!"/"Lucky!" (Frenzy) rewards', toggle: true}; +CM.ConfigData.ToolWarnLucky = {type: 'bool', group: 'Tooltip', label: ['Tooltip Lucky Warning OFF', 'Tooltip Lucky Warning ON'], desc: 'A warning when buying if it will put the bank under the amount needed for max "Lucky!" rewards', toggle: true}; +CM.ConfigData.ToolWarnLuckyFrenzy = {type: 'bool', group: 'Tooltip', label: ['Tooltip Lucky Frenzy Warning OFF', 'Tooltip Lucky Frenzy Warning ON'], desc: 'A warning when buying if it will put the bank under the amount needed for max "Lucky!" (Frenzy) rewards', toggle: true}; CM.ConfigData.ToolWarnConjure = {type: 'bool', group: 'Tooltip', label: ['Tooltip Conjure Warning OFF', 'Tooltip Conjure Warning ON'], desc: 'A warning when buying if it will put the bank under the amount needed for max "Conjure Baked Goods" rewards', toggle: true}; CM.ConfigData.ToolWarnPos = {type: 'bool', group: 'Tooltip', label: ['Tooltip Warning Position (Left)', 'Tooltip Warning Position (Bottom)'], desc: 'Placement of the warning boxes', toggle: false, func: function() {CM.Disp.ToggleToolWarnPos();}}; CM.ConfigData.TooltipGrim = {type: 'bool', group: 'Tooltip', label: ['Grimoire Tooltip Information OFF', 'Grimoire Tooltip Information ON'], desc: 'Extra information in tooltip for grimoire', toggle: true}; @@ -988,6 +989,7 @@ CM.Data.ConfigDefault = { TooltipBuildUp: 1, TooltipAmor: 0, ToolWarnLucky: 1, + ToolWarnLuckyFrenzy: 1, ToolWarnConjure: 1, ToolWarnPos: 1, TooltipGrim:1, @@ -2606,47 +2608,34 @@ CM.Disp.UpdateTooltipWarnings = function() { else CM.Disp.TooltipWarn.style.top = (l('tooltip').offsetHeight) + 'px'; CM.Disp.TooltipWarn.style.width = (l('tooltip').offsetWidth - 6) + 'px'; - + + var amount = (Game.cookies + CM.Disp.GetWrinkConfigBank()) - CM.Disp.TooltipPrice; + var limitLucky = CM.Cache.Lucky; + if (CM.Options.ToolWarnBon == 1) { + var bonusNoFren = CM.Disp.TooltipBonusIncome; + bonusNoFren /= CM.Sim.getCPSBuffMult(); + limitLucky += ((bonusNoFren * 60 * 15) / 0.15); + } + if (CM.Options.ToolWarnLucky == 1) { - var limitLucky = CM.Cache.Lucky; - if (CM.Options.ToolWarnBon == 1) { - var bonusNoFren = CM.Disp.TooltipBonusIncome; - bonusNoFren /= CM.Sim.getCPSBuffMult(); - limitLucky += ((bonusNoFren * 60 * 15) / 0.15); - } - var limitLuckyFrenzy = limitLucky * 7; - var amount = (Game.cookies + CM.Disp.GetWrinkConfigBank()) - CM.Disp.TooltipPrice; - if ((amount < limitLucky || amount < limitLuckyFrenzy) && (CM.Disp.tooltipType != 'b' || Game.buyMode == 1)) { - if (amount < limitLucky) { - l('CMDispTooltipWarnLucky').style.display = ''; - l('CMDispTooltipWarnLuckyText').textContent = Beautify(limitLucky - amount) + ' (' + CM.Disp.FormatTime((limitLucky - amount) / CM.Disp.GetCPS()) + ')'; - l('CMDispTooltipWarnLuckyFrenzy').style.display = ''; - l('CMDispTooltipWarnLuckyFrenzyText').textContent = Beautify(limitLuckyFrenzy - amount) + ' (' + CM.Disp.FormatTime((limitLuckyFrenzy - amount) / CM.Disp.GetCPS()) + ')'; - } - else if (amount < limitLuckyFrenzy) { - l('CMDispTooltipWarnLuckyFrenzy').style.display = ''; - l('CMDispTooltipWarnLuckyFrenzyText').textContent = Beautify(limitLuckyFrenzy - amount) + ' (' + CM.Disp.FormatTime((limitLuckyFrenzy - amount) / CM.Disp.GetCPS()) + ')'; - l('CMDispTooltipWarnLucky').style.display = 'none'; - } - } else { - l('CMDispTooltipWarnLucky').style.display = 'none'; - l('CMDispTooltipWarnLuckyFrenzy').style.display = 'none'; - } - } - else { - l('CMDispTooltipWarnLucky').style.display = 'none'; - l('CMDispTooltipWarnLuckyFrenzy').style.display = 'none'; + if (amount < limitLucky && (CM.Disp.tooltipType != 'b' || Game.buyMode == 1)) { + l('CMDispTooltipWarnLucky').style.display = ''; + l('CMDispTooltipWarnLuckyText').textContent = Beautify(limitLucky - amount) + ' (' + CM.Disp.FormatTime((limitLucky - amount) / CM.Disp.GetCPS()) + ')'; + } else l('CMDispTooltipWarnLucky').style.display = 'none'; } + else l('CMDispTooltipWarnLucky').style.display = 'none'; + if (CM.Options.ToolWarnLuckyFrenzy == 1) { + limitLuckyFrenzy = limitLucky * 7; + if (amount < limitLuckyFrenzy && (CM.Disp.tooltipType != 'b' || Game.buyMode == 1)) { + l('CMDispTooltipWarnLuckyFrenzy').style.display = ''; + l('CMDispTooltipWarnLuckyFrenzyText').textContent = Beautify(limitLuckyFrenzy - amount) + ' (' + CM.Disp.FormatTime((limitLuckyFrenzy - amount) / CM.Disp.GetCPS()) + ')'; + } else l('CMDispTooltipWarnLuckyFrenzy').style.display = 'none'; + } + else l('CMDispTooltipWarnLuckyFrenzy').style.display = 'none'; + if (CM.Options.ToolWarnConjure == 1) { - var limitLucky = CM.Cache.Lucky; - if (CM.Options.ToolWarnBon == 1) { - var bonusNoFren = CM.Disp.TooltipBonusIncome; - bonusNoFren /= CM.Sim.getCPSBuffMult(); - limitLucky += ((bonusNoFren * 60 * 15) / 0.15); - } var limitConjure = limitLucky * 2; - var amount = (Game.cookies + CM.Disp.GetWrinkConfigBank()) - CM.Disp.TooltipPrice; if ((amount < limitConjure) && (CM.Disp.tooltipType != 'b' || Game.buyMode == 1)) { l('CMDispTooltipWarnConjure').style.display = ''; l('CMDispTooltipWarnConjureText').textContent = Beautify(limitConjure - amount) + ' (' + CM.Disp.FormatTime((limitConjure - amount) / CM.Disp.GetCPS()) + ')'; diff --git a/src/Data.js b/src/Data.js index 74e2067..288881d 100644 --- a/src/Data.js +++ b/src/Data.js @@ -158,7 +158,8 @@ CM.ConfigData.Title = {type: 'bool', group: 'Notification', label: ['Title OFF', // Tooltip CM.ConfigData.TooltipBuildUp = {type: 'bool', group: 'Tooltip', label: ['Buildings/Upgrades Tooltip Information OFF', 'Buildings/Upgrades Tooltip Information ON'], desc: 'Extra information in tooltip for buildings/upgrades', toggle: true}; CM.ConfigData.TooltipAmor = {type: 'bool', group: 'Tooltip', label: ['Buildings Tooltip Amortization Information OFF', 'Buildings Tooltip Amortization Information ON'], desc: 'Add amortization information to buildings tooltip', toggle: true}; -CM.ConfigData.ToolWarnLucky = {type: 'bool', group: 'Tooltip', label: ['Tooltip Lucky Warning OFF', 'Tooltip Lucky Warning ON'], desc: 'A warning when buying if it will put the bank under the amount needed for max "Lucky!"/"Lucky!" (Frenzy) rewards', toggle: true}; +CM.ConfigData.ToolWarnLucky = {type: 'bool', group: 'Tooltip', label: ['Tooltip Lucky Warning OFF', 'Tooltip Lucky Warning ON'], desc: 'A warning when buying if it will put the bank under the amount needed for max "Lucky!" rewards', toggle: true}; +CM.ConfigData.ToolWarnLuckyFrenzy = {type: 'bool', group: 'Tooltip', label: ['Tooltip Lucky Frenzy Warning OFF', 'Tooltip Lucky Frenzy Warning ON'], desc: 'A warning when buying if it will put the bank under the amount needed for max "Lucky!" (Frenzy) rewards', toggle: true}; CM.ConfigData.ToolWarnConjure = {type: 'bool', group: 'Tooltip', label: ['Tooltip Conjure Warning OFF', 'Tooltip Conjure Warning ON'], desc: 'A warning when buying if it will put the bank under the amount needed for max "Conjure Baked Goods" rewards', toggle: true}; CM.ConfigData.ToolWarnPos = {type: 'bool', group: 'Tooltip', label: ['Tooltip Warning Position (Left)', 'Tooltip Warning Position (Bottom)'], desc: 'Placement of the warning boxes', toggle: false, func: function() {CM.Disp.ToggleToolWarnPos();}}; CM.ConfigData.TooltipGrim = {type: 'bool', group: 'Tooltip', label: ['Grimoire Tooltip Information OFF', 'Grimoire Tooltip Information ON'], desc: 'Extra information in tooltip for grimoire', toggle: true}; @@ -237,6 +238,7 @@ CM.Data.ConfigDefault = { TooltipBuildUp: 1, TooltipAmor: 0, ToolWarnLucky: 1, + ToolWarnLuckyFrenzy: 1, ToolWarnConjure: 1, ToolWarnPos: 1, TooltipGrim:1, diff --git a/src/Disp.js b/src/Disp.js index d4bbffc..e5a6e81 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -1597,47 +1597,34 @@ CM.Disp.UpdateTooltipWarnings = function() { else CM.Disp.TooltipWarn.style.top = (l('tooltip').offsetHeight) + 'px'; CM.Disp.TooltipWarn.style.width = (l('tooltip').offsetWidth - 6) + 'px'; - + + var amount = (Game.cookies + CM.Disp.GetWrinkConfigBank()) - CM.Disp.TooltipPrice; + var limitLucky = CM.Cache.Lucky; + if (CM.Options.ToolWarnBon == 1) { + var bonusNoFren = CM.Disp.TooltipBonusIncome; + bonusNoFren /= CM.Sim.getCPSBuffMult(); + limitLucky += ((bonusNoFren * 60 * 15) / 0.15); + } + if (CM.Options.ToolWarnLucky == 1) { - var limitLucky = CM.Cache.Lucky; - if (CM.Options.ToolWarnBon == 1) { - var bonusNoFren = CM.Disp.TooltipBonusIncome; - bonusNoFren /= CM.Sim.getCPSBuffMult(); - limitLucky += ((bonusNoFren * 60 * 15) / 0.15); - } - var limitLuckyFrenzy = limitLucky * 7; - var amount = (Game.cookies + CM.Disp.GetWrinkConfigBank()) - CM.Disp.TooltipPrice; - if ((amount < limitLucky || amount < limitLuckyFrenzy) && (CM.Disp.tooltipType != 'b' || Game.buyMode == 1)) { - if (amount < limitLucky) { - l('CMDispTooltipWarnLucky').style.display = ''; - l('CMDispTooltipWarnLuckyText').textContent = Beautify(limitLucky - amount) + ' (' + CM.Disp.FormatTime((limitLucky - amount) / CM.Disp.GetCPS()) + ')'; - l('CMDispTooltipWarnLuckyFrenzy').style.display = ''; - l('CMDispTooltipWarnLuckyFrenzyText').textContent = Beautify(limitLuckyFrenzy - amount) + ' (' + CM.Disp.FormatTime((limitLuckyFrenzy - amount) / CM.Disp.GetCPS()) + ')'; - } - else if (amount < limitLuckyFrenzy) { - l('CMDispTooltipWarnLuckyFrenzy').style.display = ''; - l('CMDispTooltipWarnLuckyFrenzyText').textContent = Beautify(limitLuckyFrenzy - amount) + ' (' + CM.Disp.FormatTime((limitLuckyFrenzy - amount) / CM.Disp.GetCPS()) + ')'; - l('CMDispTooltipWarnLucky').style.display = 'none'; - } - } else { - l('CMDispTooltipWarnLucky').style.display = 'none'; - l('CMDispTooltipWarnLuckyFrenzy').style.display = 'none'; - } - } - else { - l('CMDispTooltipWarnLucky').style.display = 'none'; - l('CMDispTooltipWarnLuckyFrenzy').style.display = 'none'; + if (amount < limitLucky && (CM.Disp.tooltipType != 'b' || Game.buyMode == 1)) { + l('CMDispTooltipWarnLucky').style.display = ''; + l('CMDispTooltipWarnLuckyText').textContent = Beautify(limitLucky - amount) + ' (' + CM.Disp.FormatTime((limitLucky - amount) / CM.Disp.GetCPS()) + ')'; + } else l('CMDispTooltipWarnLucky').style.display = 'none'; } + else l('CMDispTooltipWarnLucky').style.display = 'none'; + if (CM.Options.ToolWarnLuckyFrenzy == 1) { + limitLuckyFrenzy = limitLucky * 7; + if (amount < limitLuckyFrenzy && (CM.Disp.tooltipType != 'b' || Game.buyMode == 1)) { + l('CMDispTooltipWarnLuckyFrenzy').style.display = ''; + l('CMDispTooltipWarnLuckyFrenzyText').textContent = Beautify(limitLuckyFrenzy - amount) + ' (' + CM.Disp.FormatTime((limitLuckyFrenzy - amount) / CM.Disp.GetCPS()) + ')'; + } else l('CMDispTooltipWarnLuckyFrenzy').style.display = 'none'; + } + else l('CMDispTooltipWarnLuckyFrenzy').style.display = 'none'; + if (CM.Options.ToolWarnConjure == 1) { - var limitLucky = CM.Cache.Lucky; - if (CM.Options.ToolWarnBon == 1) { - var bonusNoFren = CM.Disp.TooltipBonusIncome; - bonusNoFren /= CM.Sim.getCPSBuffMult(); - limitLucky += ((bonusNoFren * 60 * 15) / 0.15); - } var limitConjure = limitLucky * 2; - var amount = (Game.cookies + CM.Disp.GetWrinkConfigBank()) - CM.Disp.TooltipPrice; if ((amount < limitConjure) && (CM.Disp.tooltipType != 'b' || Game.buyMode == 1)) { l('CMDispTooltipWarnConjure').style.display = ''; l('CMDispTooltipWarnConjureText').textContent = Beautify(limitConjure - amount) + ' (' + CM.Disp.FormatTime((limitConjure - amount) / CM.Disp.GetCPS()) + ')'; From 28fbb1e0946c59a3e5937cd2fe4d21d4c5c04fd5 Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Fri, 18 Dec 2020 20:31:25 +0100 Subject: [PATCH 067/106] Added missing plant drops to stats page --- CookieMonster.js | 25 +++++++++++++++++-------- src/Data.js | 5 ++++- src/Disp.js | 20 +++++++++++++------- 3 files changed, 34 insertions(+), 16 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index 2a4107d..13df948 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -753,6 +753,9 @@ CM.Config.CheckNotificationPermissions = function(ToggleOnOff) { * Data * ********/ +/******** + * Section: Data used in the stats page to show not yet purchased updates. See CM.Disp.CreateStatsMissDisp() */ + CM.Data.Fortunes = [ 'Fortune #001', 'Fortune #002', @@ -781,7 +784,7 @@ CM.Data.Fortunes = [ CM.Data.HalloCookies = ['Skull cookies', 'Ghost cookies', 'Bat cookies', 'Slime cookies', 'Pumpkin cookies', 'Eyeball cookies', 'Spider cookies']; CM.Data.ChristCookies = ['Christmas tree biscuits', 'Snowflake biscuits', 'Snowman biscuits', 'Holly biscuits', 'Candy cane biscuits', 'Bell biscuits', 'Present biscuits']; CM.Data.ValCookies = ['Pure heart biscuits', 'Ardent heart biscuits', 'Sour heart biscuits', 'Weeping heart biscuits', 'Golden heart biscuits', 'Eternal heart biscuits', 'Prism heart biscuits']; - +CM.Data.PlantDrops = ['Elderwort biscuits', 'Bakeberry cookies', 'Duketater cookies', 'Green yeast digestives', 'Wheat slims', 'Fern tea', 'Ichor syrup'] /******** * Section: Data for the various scales used by CookieMonster */ @@ -3126,19 +3129,25 @@ CM.Disp.AddMenuStats = function(title) { specDisp = true; } } + var missingPlantDrops = []; + for (var i in CM.Data.PlantDrops) { + if (!Game.HasUnlocked(CM.Data.PlantDrops[i])) { + missingPlantDrops.push(CM.Data.PlantDrops[i]); + specDisp = true; + } + } var choEgg = (Game.HasUnlocked('Chocolate egg') && !Game.Has('Chocolate egg')); var centEgg = Game.Has('Century egg'); if (Game.season == 'christmas' || specDisp || choEgg || centEgg) { stats.appendChild(CM.Disp.CreateStatsHeader('Season Specials', 'Sea')); if (CM.Options.Header.Sea) { - if (specDisp) { - if (missingHalloweenCookies.length != 0) stats.appendChild(CM.Disp.CreateStatsListing("basic", 'Halloween Cookies Left to Buy', CM.Disp.CreateStatsMissDisp(missingHalloweenCookies))); - if (missingChristmasCookies.length != 0) stats.appendChild(CM.Disp.CreateStatsListing("basic", 'Christmas Cookies Left to Buy', CM.Disp.CreateStatsMissDisp(missingChristmasCookies))); - if (missingValentineCookies.length != 0) stats.appendChild(CM.Disp.CreateStatsListing("basic", 'Valentine Cookies Left to Buy', CM.Disp.CreateStatsMissDisp(missingValentineCookies))); - if (missingNormalEggs.length != 0) stats.appendChild(CM.Disp.CreateStatsListing("basic", 'Normal Easter Eggs Left to Unlock', CM.Disp.CreateStatsMissDisp(missingNormalEggs))); - if (missingRareEggs.length != 0) stats.appendChild(CM.Disp.CreateStatsListing("basic", 'Rare Easter Eggs Left to Unlock', CM.Disp.CreateStatsMissDisp(missingRareEggs))); - } + if (missingHalloweenCookies.length != 0) stats.appendChild(CM.Disp.CreateStatsListing("basic", 'Halloween Cookies Left to Buy', CM.Disp.CreateStatsMissDisp(missingHalloweenCookies))); + if (missingChristmasCookies.length != 0) stats.appendChild(CM.Disp.CreateStatsListing("basic", 'Christmas Cookies Left to Buy', CM.Disp.CreateStatsMissDisp(missingChristmasCookies))); + if (missingValentineCookies.length != 0) stats.appendChild(CM.Disp.CreateStatsListing("basic", 'Valentine Cookies Left to Buy', CM.Disp.CreateStatsMissDisp(missingValentineCookies))); + if (missingNormalEggs.length != 0) stats.appendChild(CM.Disp.CreateStatsListing("basic", 'Normal Easter Eggs Left to Unlock', CM.Disp.CreateStatsMissDisp(missingNormalEggs))); + if (missingRareEggs.length != 0) stats.appendChild(CM.Disp.CreateStatsListing("basic", 'Rare Easter Eggs Left to Unlock', CM.Disp.CreateStatsMissDisp(missingRareEggs))); + if (missingPlantDrops.length != 0) stats.appendChild(CM.Disp.CreateStatsListing("basic", 'Rare Plant Drops Left to Unlock', CM.Disp.CreateStatsMissDisp(missingPlantDrops))); if (Game.season == 'christmas') stats.appendChild(CM.Disp.CreateStatsListing("basic", 'Reindeer Reward', document.createTextNode(Beautify(CM.Cache.SeaSpec)))); if (choEgg) { diff --git a/src/Data.js b/src/Data.js index 74e2067..c763a25 100644 --- a/src/Data.js +++ b/src/Data.js @@ -2,6 +2,9 @@ * Data * ********/ +/******** + * Section: Data used in the stats page to show not yet purchased updates. See CM.Disp.CreateStatsMissDisp() */ + CM.Data.Fortunes = [ 'Fortune #001', 'Fortune #002', @@ -30,7 +33,7 @@ CM.Data.Fortunes = [ CM.Data.HalloCookies = ['Skull cookies', 'Ghost cookies', 'Bat cookies', 'Slime cookies', 'Pumpkin cookies', 'Eyeball cookies', 'Spider cookies']; CM.Data.ChristCookies = ['Christmas tree biscuits', 'Snowflake biscuits', 'Snowman biscuits', 'Holly biscuits', 'Candy cane biscuits', 'Bell biscuits', 'Present biscuits']; CM.Data.ValCookies = ['Pure heart biscuits', 'Ardent heart biscuits', 'Sour heart biscuits', 'Weeping heart biscuits', 'Golden heart biscuits', 'Eternal heart biscuits', 'Prism heart biscuits']; - +CM.Data.PlantDrops = ['Elderwort biscuits', 'Bakeberry cookies', 'Duketater cookies', 'Green yeast digestives', 'Wheat slims', 'Fern tea', 'Ichor syrup'] /******** * Section: Data for the various scales used by CookieMonster */ diff --git a/src/Disp.js b/src/Disp.js index d4bbffc..e789eaf 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -2117,19 +2117,25 @@ CM.Disp.AddMenuStats = function(title) { specDisp = true; } } + var missingPlantDrops = []; + for (var i in CM.Data.PlantDrops) { + if (!Game.HasUnlocked(CM.Data.PlantDrops[i])) { + missingPlantDrops.push(CM.Data.PlantDrops[i]); + specDisp = true; + } + } var choEgg = (Game.HasUnlocked('Chocolate egg') && !Game.Has('Chocolate egg')); var centEgg = Game.Has('Century egg'); if (Game.season == 'christmas' || specDisp || choEgg || centEgg) { stats.appendChild(CM.Disp.CreateStatsHeader('Season Specials', 'Sea')); if (CM.Options.Header.Sea) { - if (specDisp) { - if (missingHalloweenCookies.length != 0) stats.appendChild(CM.Disp.CreateStatsListing("basic", 'Halloween Cookies Left to Buy', CM.Disp.CreateStatsMissDisp(missingHalloweenCookies))); - if (missingChristmasCookies.length != 0) stats.appendChild(CM.Disp.CreateStatsListing("basic", 'Christmas Cookies Left to Buy', CM.Disp.CreateStatsMissDisp(missingChristmasCookies))); - if (missingValentineCookies.length != 0) stats.appendChild(CM.Disp.CreateStatsListing("basic", 'Valentine Cookies Left to Buy', CM.Disp.CreateStatsMissDisp(missingValentineCookies))); - if (missingNormalEggs.length != 0) stats.appendChild(CM.Disp.CreateStatsListing("basic", 'Normal Easter Eggs Left to Unlock', CM.Disp.CreateStatsMissDisp(missingNormalEggs))); - if (missingRareEggs.length != 0) stats.appendChild(CM.Disp.CreateStatsListing("basic", 'Rare Easter Eggs Left to Unlock', CM.Disp.CreateStatsMissDisp(missingRareEggs))); - } + if (missingHalloweenCookies.length != 0) stats.appendChild(CM.Disp.CreateStatsListing("basic", 'Halloween Cookies Left to Buy', CM.Disp.CreateStatsMissDisp(missingHalloweenCookies))); + if (missingChristmasCookies.length != 0) stats.appendChild(CM.Disp.CreateStatsListing("basic", 'Christmas Cookies Left to Buy', CM.Disp.CreateStatsMissDisp(missingChristmasCookies))); + if (missingValentineCookies.length != 0) stats.appendChild(CM.Disp.CreateStatsListing("basic", 'Valentine Cookies Left to Buy', CM.Disp.CreateStatsMissDisp(missingValentineCookies))); + if (missingNormalEggs.length != 0) stats.appendChild(CM.Disp.CreateStatsListing("basic", 'Normal Easter Eggs Left to Unlock', CM.Disp.CreateStatsMissDisp(missingNormalEggs))); + if (missingRareEggs.length != 0) stats.appendChild(CM.Disp.CreateStatsListing("basic", 'Rare Easter Eggs Left to Unlock', CM.Disp.CreateStatsMissDisp(missingRareEggs))); + if (missingPlantDrops.length != 0) stats.appendChild(CM.Disp.CreateStatsListing("basic", 'Rare Plant Drops Left to Unlock', CM.Disp.CreateStatsMissDisp(missingPlantDrops))); if (Game.season == 'christmas') stats.appendChild(CM.Disp.CreateStatsListing("basic", 'Reindeer Reward', document.createTextNode(Beautify(CM.Cache.SeaSpec)))); if (choEgg) { From c530bd1a4af5839ea344bf8fd959b5347b274f69 Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Fri, 18 Dec 2020 20:47:03 +0100 Subject: [PATCH 068/106] Added Abbreviated short scale (#268) --- CookieMonster.js | 28 +++++++++++++++++++++++----- src/Data.js | 13 ++++++++++++- src/Disp.js | 15 +++++++++++---- 3 files changed, 46 insertions(+), 10 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index 48d9325..2c8eadb 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -791,6 +791,17 @@ CM.Data.PlantDrops = ['Elderwort biscuits', 'Bakeberry cookies', 'Duketater cook CM.Data.metric = ['', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y']; CM.Data.shortScale = ['', 'M', 'B', 'Tr', 'Quadr', 'Quint', 'Sext', 'Sept', 'Oct', 'Non', 'Dec', 'Undec', 'Duodec', 'Tredec', 'Quattuordec', 'Quindec', 'Sexdec', 'Septendec', 'Octodec', 'Novemdec', 'Vigint', 'Unvigint', 'Duovigint', 'Trevigint', 'Quattuorvigint']; +CM.Data.shortScaleAbbreviated = ['K', 'M', 'B', 'T', 'Qa', 'Qi', 'Sx', 'Sp', 'Oc', 'No', 'De', +'UDe', 'DDe', 'TDe', 'QaDe', 'QiDe', 'SxDe', 'SpDe', 'ODe', 'NDe', 'Vi', +'UVi', 'DVi', 'TVi', 'QaVi', 'QiVi', 'SxVi', 'SpVi', 'OVi', 'NVi', 'Tr', +'UTr', 'DTr', 'TTr', 'QaTr', 'QiTr', 'SxTr', 'SpTr', 'OTr', 'NTr', 'Qaa', +'UQa', 'DQa', 'TQa', 'QaQa', 'QiQa', 'SxQa', 'SpQa', 'OQa', 'NQa', 'Qia', +'UQi', 'DQi', 'TQi', 'QaQi', 'QiQi', 'SxQi', 'SpQi', 'OQi', 'NQi', 'Sxa', +'USx', 'DSx', 'TSx', 'QaSx', 'QiSx', 'SxSx', 'SpSx', 'OSx', 'NSx', 'Spa', +'USp', 'DSp', 'TSp', 'QaSp', 'QiSp', 'SxSp', 'SpSp', 'OSp', 'NSp', 'Oco', +'UOc', 'DOc', 'TOc', 'QaOc', 'QiOc', 'SxOc', 'SpOc', 'OOc', 'NOc', 'Noa', +'UNo', 'DNo', 'TNo', 'QaNo', 'QiNo', 'SxNo', 'SpNo', 'ONo', 'NNo', 'Ct', +'UCt'] /******** * Section: An array containing all Config groups and their to-be displayed title */ @@ -930,7 +941,7 @@ CM.ConfigData.DetailedTime = {type: 'bool', group: 'Statistics', label: ['Detail CM.ConfigData.GrimoireBar = {type: 'bool', group: 'Statistics', label: ['Grimoire Magic Meter Timer OFF', 'Grimoire Magic Meter Timer ON'], desc: 'A timer on how long before the Grimoire magic meter is full', toggle: true}; // Notation -CM.ConfigData.Scale = {type: 'bool', group: 'Notation', label: ['Game\'s Setting Scale', 'Metric', 'Short Scale', 'Scientific Notation', 'Engineering Notation'], desc: 'Change how long numbers are handled', toggle: false, func: function() {CM.Disp.RefreshScale();}}; +CM.ConfigData.Scale = {type: 'bool', group: 'Notation', label: ['Game\'s Setting Scale', 'Metric', 'Short Scale', 'Short Scale (Abbreviated)', 'Scientific Notation', 'Engineering Notation'], desc: 'Change how long numbers are handled', toggle: false, func: function() {CM.Disp.RefreshScale();}}; CM.ConfigData.ScaleDecimals = {type: 'bool', group: 'Notation', label: ['1 decimals', '2 decimals', '3 decimals'], desc: 'Set the number of decimals used when applicable', toggle: false, func: function() {CM.Disp.RefreshScale();}}; CM.ConfigData.ScaleSeparator = {type: 'bool', group: 'Notation', label: ['. for decimals (Standard)', '. for thousands'], desc: 'Set the separator used for decimals and thousands', toggle: false, func: function() {CM.Disp.RefreshScale();}}; @@ -1196,7 +1207,7 @@ CM.Disp.Beautify = function(num, floats, forced) { // TODO: Add changing separators of thousands and making this cut-off user configurable answer = Math.round(num * 100) / 100; } - else if (CM.Options.Scale == 3 && !forced || forced == 3) { // Scientific notation, 123456789 => 1.235E+8 + else if (CM.Options.Scale == 4 && !forced || forced == 4) { // Scientific notation, 123456789 => 1.235E+8 answer = num.toExponential(decimals).toString().replace("e", "E"); } else { @@ -1209,16 +1220,23 @@ CM.Disp.Beautify = function(num, floats, forced) { answer += ' ' + CM.Data.metric[AmountOfTenPowerThree - 1] } // If number is too large or little, revert to scientific notation - else answer = CM.Disp.Beautify(num, 0, 3); + else answer = CM.Disp.Beautify(num, 0, 4); } else if (CM.Options.Scale == 2 && !forced || forced == 2) { // Short scale, 123456789 => 123.457 M if (num >= 0.01 && num < Number("1e" + CM.Data.shortScale.length * 3)) { answer += ' ' + CM.Data.shortScale[AmountOfTenPowerThree - 1]; } // If number is too large or little, revert to scientific notation - else answer = CM.Disp.Beautify(num, 0, 3); + else answer = CM.Disp.Beautify(num, 0, 4); } - else if (CM.Options.Scale == 4 && !forced || forced == 4) { // Engineering notation, 123456789 => 123.457E+6 + else if (CM.Options.Scale == 3 && !forced || forced == 3) { // Short scale, 123456789 => 123.457 M + if (num >= 0.01 && num < Number("1e" + CM.Data.shortScaleAbbreviated.length * 3)) { + answer += ' ' + CM.Data.shortScaleAbbreviated[AmountOfTenPowerThree - 1]; + } + // If number is too large or little, revert to scientific notation + else answer = CM.Disp.Beautify(num, 0, 4); + } + else if (CM.Options.Scale == 5 && !forced || forced == 5) { // Engineering notation, 123456789 => 123.457E+6 answer += 'E' + AmountOfTenPowerThree * 3; } } diff --git a/src/Data.js b/src/Data.js index a895caa..9a9ffef 100644 --- a/src/Data.js +++ b/src/Data.js @@ -40,6 +40,17 @@ CM.Data.PlantDrops = ['Elderwort biscuits', 'Bakeberry cookies', 'Duketater cook CM.Data.metric = ['', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y']; CM.Data.shortScale = ['', 'M', 'B', 'Tr', 'Quadr', 'Quint', 'Sext', 'Sept', 'Oct', 'Non', 'Dec', 'Undec', 'Duodec', 'Tredec', 'Quattuordec', 'Quindec', 'Sexdec', 'Septendec', 'Octodec', 'Novemdec', 'Vigint', 'Unvigint', 'Duovigint', 'Trevigint', 'Quattuorvigint']; +CM.Data.shortScaleAbbreviated = ['K', 'M', 'B', 'T', 'Qa', 'Qi', 'Sx', 'Sp', 'Oc', 'No', 'De', +'UDe', 'DDe', 'TDe', 'QaDe', 'QiDe', 'SxDe', 'SpDe', 'ODe', 'NDe', 'Vi', +'UVi', 'DVi', 'TVi', 'QaVi', 'QiVi', 'SxVi', 'SpVi', 'OVi', 'NVi', 'Tr', +'UTr', 'DTr', 'TTr', 'QaTr', 'QiTr', 'SxTr', 'SpTr', 'OTr', 'NTr', 'Qaa', +'UQa', 'DQa', 'TQa', 'QaQa', 'QiQa', 'SxQa', 'SpQa', 'OQa', 'NQa', 'Qia', +'UQi', 'DQi', 'TQi', 'QaQi', 'QiQi', 'SxQi', 'SpQi', 'OQi', 'NQi', 'Sxa', +'USx', 'DSx', 'TSx', 'QaSx', 'QiSx', 'SxSx', 'SpSx', 'OSx', 'NSx', 'Spa', +'USp', 'DSp', 'TSp', 'QaSp', 'QiSp', 'SxSp', 'SpSp', 'OSp', 'NSp', 'Oco', +'UOc', 'DOc', 'TOc', 'QaOc', 'QiOc', 'SxOc', 'SpOc', 'OOc', 'NOc', 'Noa', +'UNo', 'DNo', 'TNo', 'QaNo', 'QiNo', 'SxNo', 'SpNo', 'ONo', 'NNo', 'Ct', +'UCt'] /******** * Section: An array containing all Config groups and their to-be displayed title */ @@ -179,7 +190,7 @@ CM.ConfigData.DetailedTime = {type: 'bool', group: 'Statistics', label: ['Detail CM.ConfigData.GrimoireBar = {type: 'bool', group: 'Statistics', label: ['Grimoire Magic Meter Timer OFF', 'Grimoire Magic Meter Timer ON'], desc: 'A timer on how long before the Grimoire magic meter is full', toggle: true}; // Notation -CM.ConfigData.Scale = {type: 'bool', group: 'Notation', label: ['Game\'s Setting Scale', 'Metric', 'Short Scale', 'Scientific Notation', 'Engineering Notation'], desc: 'Change how long numbers are handled', toggle: false, func: function() {CM.Disp.RefreshScale();}}; +CM.ConfigData.Scale = {type: 'bool', group: 'Notation', label: ['Game\'s Setting Scale', 'Metric', 'Short Scale', 'Short Scale (Abbreviated)', 'Scientific Notation', 'Engineering Notation'], desc: 'Change how long numbers are handled', toggle: false, func: function() {CM.Disp.RefreshScale();}}; CM.ConfigData.ScaleDecimals = {type: 'bool', group: 'Notation', label: ['1 decimals', '2 decimals', '3 decimals'], desc: 'Set the number of decimals used when applicable', toggle: false, func: function() {CM.Disp.RefreshScale();}}; CM.ConfigData.ScaleSeparator = {type: 'bool', group: 'Notation', label: ['. for decimals (Standard)', '. for thousands'], desc: 'Set the separator used for decimals and thousands', toggle: false, func: function() {CM.Disp.RefreshScale();}}; diff --git a/src/Disp.js b/src/Disp.js index dd1dddc..f4b3e03 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -182,7 +182,7 @@ CM.Disp.Beautify = function(num, floats, forced) { // TODO: Add changing separators of thousands and making this cut-off user configurable answer = Math.round(num * 100) / 100; } - else if (CM.Options.Scale == 3 && !forced || forced == 3) { // Scientific notation, 123456789 => 1.235E+8 + else if (CM.Options.Scale == 4 && !forced || forced == 4) { // Scientific notation, 123456789 => 1.235E+8 answer = num.toExponential(decimals).toString().replace("e", "E"); } else { @@ -195,16 +195,23 @@ CM.Disp.Beautify = function(num, floats, forced) { answer += ' ' + CM.Data.metric[AmountOfTenPowerThree - 1] } // If number is too large or little, revert to scientific notation - else answer = CM.Disp.Beautify(num, 0, 3); + else answer = CM.Disp.Beautify(num, 0, 4); } else if (CM.Options.Scale == 2 && !forced || forced == 2) { // Short scale, 123456789 => 123.457 M if (num >= 0.01 && num < Number("1e" + CM.Data.shortScale.length * 3)) { answer += ' ' + CM.Data.shortScale[AmountOfTenPowerThree - 1]; } // If number is too large or little, revert to scientific notation - else answer = CM.Disp.Beautify(num, 0, 3); + else answer = CM.Disp.Beautify(num, 0, 4); } - else if (CM.Options.Scale == 4 && !forced || forced == 4) { // Engineering notation, 123456789 => 123.457E+6 + else if (CM.Options.Scale == 3 && !forced || forced == 3) { // Short scale, 123456789 => 123.457 M + if (num >= 0.01 && num < Number("1e" + CM.Data.shortScaleAbbreviated.length * 3)) { + answer += ' ' + CM.Data.shortScaleAbbreviated[AmountOfTenPowerThree - 1]; + } + // If number is too large or little, revert to scientific notation + else answer = CM.Disp.Beautify(num, 0, 4); + } + else if (CM.Options.Scale == 5 && !forced || forced == 5) { // Engineering notation, 123456789 => 123.457E+6 answer += 'E' + AmountOfTenPowerThree * 3; } } From 90a79dbc0c54173e5c994c3d3c743505aa6aaf36 Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Fri, 18 Dec 2020 23:17:10 +0100 Subject: [PATCH 069/106] Added cookie per click bonus to tooltip --- CookieMonster.js | 111 ++++++++++++++++++++++++++++++++++++++++++++++- src/Disp.js | 27 +++++++++++- src/Sim.js | 84 +++++++++++++++++++++++++++++++++++ 3 files changed, 218 insertions(+), 4 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index 2c8eadb..2ccde6e 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -2344,6 +2344,15 @@ CM.Disp.TooltipCreateCalculationSection = function(tooltip) { income.id = 'CMTooltipIncome'; tooltip.appendChild(income); + tooltip.appendChild(CM.Disp.TooltipCreateHeader('Bonus Cookies per Click')); + tooltip.lastChild.style.display = "none"; + var click = document.createElement('div'); + click.style.marginBottom = '4px'; + click.style.color = 'white'; + click.style.display = "none"; + click.id = 'CMTooltipCookiePerClick'; + tooltip.appendChild(click); + tooltip.appendChild(CM.Disp.TooltipCreateHeader('Payback Period')); var pp = document.createElement('div'); pp.style.marginBottom = '4px'; @@ -2512,6 +2521,7 @@ CM.Disp.UpdateTooltipUpgrade = function() { CM.Disp.TooltipBonusIncome = CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].bonus; CM.Disp.TooltipPrice = Game.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].getPrice(); + CM.Disp.TooltipBonusMouse = CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].bonusMouse if (CM.Options.TooltipBuildUp == 1) { l('CMTooltipIncome').textContent = Beautify(CM.Disp.TooltipBonusIncome, 2); @@ -2520,8 +2530,21 @@ CM.Disp.UpdateTooltipUpgrade = function() { l('CMTooltipIncome').textContent += ' (' + (increase / 100) + '% of income)'; } l('CMTooltipBorder').className = CM.Disp.colorTextPre + CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].color; - l('CMTooltipPP').textContent = Beautify(CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].pp, 2); - l('CMTooltipPP').className = CM.Disp.colorTextPre + CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].color; + // If clicking power upgrade + if (CM.Disp.TooltipBonusMouse) { + l('CMTooltipCookiePerClick').textContent = Beautify(CM.Disp.TooltipBonusMouse) + l('CMTooltipCookiePerClick').style.display = "block"; + l('CMTooltipCookiePerClick').previousSibling.style.display = "block"; + } + // If only a clicking power upgrade change PP to click-based period + if (CM.Disp.TooltipBonusIncome == 0 && CM.Disp.TooltipBonusMouse) { + l('CMTooltipPP').textContent = Beautify(CM.Disp.TooltipPrice / CM.Disp.TooltipBonusMouse) + ' clicks' + l('CMTooltipPP').style.color = "white"; + } + else { + l('CMTooltipPP').textContent = Beautify(CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].pp, 2); + l('CMTooltipPP').className = CM.Disp.colorTextPre + CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].color; + } var timeColor = CM.Disp.GetTimeColor((CM.Disp.TooltipPrice - (Game.cookies + CM.Disp.GetWrinkConfigBank())) / CM.Disp.GetCPS()); l('CMTooltipTime').textContent = timeColor.text; l('CMTooltipTime').className = CM.Disp.colorTextPre + timeColor.color; @@ -4828,6 +4851,9 @@ CM.Sim.BuyUpgrades = function() { CM.Cache.Upgrades[i] = {}; CM.Cache.Upgrades[i].bonus = CM.Sim.cookiesPs - Game.cookiesPs; + + var diffMouseCPS = CM.Sim.mouseCps() - Game.computedMouseCps; + if (diffMouseCPS) CM.Cache.Upgrades[i].bonusMouse = diffMouseCPS; } } } @@ -5021,6 +5047,87 @@ CM.Sim.SellBuildingsForChoEgg = function() { return sellTotal; } + +/******** + * Section: Functions used to calculate clicking power */ + +/** + * This function calculates the cookies per click + * It is called by CM.Sim.BuyUpgrades() when an upgrades has no bonus-income (and is thus a clicking-upgrade) + */ +CM.Sim.mouseCps = function() { + var add=0; + if (CM.Sim.Has('Thousand fingers')) add += 0.1; + if (CM.Sim.Has('Million fingers')) add *= 5; + if (CM.Sim.Has('Billion fingers')) add *= 10; + if (CM.Sim.Has('Trillion fingers')) add *= 20; + if (CM.Sim.Has('Quadrillion fingers')) add *= 20; + if (CM.Sim.Has('Quintillion fingers')) add *= 20; + if (CM.Sim.Has('Sextillion fingers')) add *= 20; + if (CM.Sim.Has('Septillion fingers')) add *= 20; + if (CM.Sim.Has('Octillion fingers')) add *= 20; + if (CM.Sim.Has('Nonillion fingers')) add *= 20; + var num=0; + for (var i in CM.Sim.Objects) {num+=CM.Sim.Objects[i].amount;} + num -= CM.Sim.Objects['Cursor'].amount; + add = add * num; + + // Use CM.Sim.cookiesPs as function is always called after CM.Sim.CalculateGains() + if (CM.Sim.Has('Plastic mouse')) add += CM.Sim.cookiesPs * 0.01; + if (CM.Sim.Has('Iron mouse')) add += CM.Sim.cookiesPs * 0.01; + if (CM.Sim.Has('Titanium mouse')) add += CM.Sim.cookiesPs * 0.01; + if (CM.Sim.Has('Adamantium mouse')) add += CM.Sim.cookiesPs * 0.01; + if (CM.Sim.Has('Unobtainium mouse')) add += CM.Sim.cookiesPs * 0.01; + if (CM.Sim.Has('Eludium mouse')) add += CM.Sim.cookiesPs * 0.01; + if (CM.Sim.Has('Wishalloy mouse')) add += CM.Sim.cookiesPs * 0.01; + if (CM.Sim.Has('Fantasteel mouse')) add += CM.Sim.cookiesPs * 0.01; + if (CM.Sim.Has('Nevercrack mouse')) add += CM.Sim.cookiesPs * 0.01; + if (CM.Sim.Has('Armythril mouse')) add += CM.Sim.cookiesPs * 0.01; + if (CM.Sim.Has('Technobsidian mouse')) add += CM.Sim.cookiesPs * 0.01; + if (CM.Sim.Has('Plasmarble mouse')) add += CM.Sim.cookiesPs * 0.01; + if (CM.Sim.Has('Miraculite mouse')) add += CM.Sim.cookiesPs * 0.01; + + if (CM.Sim.Has('Fortune #104')) add += CM.Sim.cookiesPs * 0.01; + + + var mult=1; + if (CM.Sim.Has('Santa\'s helpers')) mult *= 1.1; + if (CM.Sim.Has('Cookie egg')) mult *= 1.1; + if (CM.Sim.Has('Halo gloves')) mult *= 1.1; + if (CM.Sim.Has('Dragon claw')) mult *= 1.03; + + if (CM.Sim.Has('Aura gloves')) + { + mult *= 1 + 0.05 * Math.min(Game.Objects['Cursor'].level, CM.Sim.Has('Luminous gloves') ? 20 : 10); + } + + mult *= CM.Sim.eff('click'); + + if (CM.Sim.hasGod) + { + var godLvl = CM.Sim.hasGod('labor'); + if (godLvl == 1) mult *= 1.15; + else if (godLvl == 2) mult *= 1.1; + else if (godLvl == 3) mult *= 1.05; + } + + for (var i in Game.buffs) + { + if (typeof Game.buffs[i].multClick != 'undefined') mult*=Game.buffs[i].multClick; + } + + //if (CM.Sim.auraMult('Dragon Cursor')) mult*=1.05; + mult *= 1 + CM.Sim.auraMult('Dragon Cursor') * 0.05; + + // No need to make this function a CM function + var out = mult * Game.ComputeCps(1, CM.Sim.Has('Reinforced index finger') + CM.Sim.Has('Carpal tunnel prevention cream') + CM.Sim.Has('Ambidextrous'), add); + + out = Game.runModHookOnValue('cookiesPerClick', out); + + if (Game.hasBuff('Cursed finger')) out = Game.buffs['Cursed finger'].power; + + return out; +} /********** * Footer * **********/ diff --git a/src/Disp.js b/src/Disp.js index f4b3e03..6aeba49 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -1319,6 +1319,15 @@ CM.Disp.TooltipCreateCalculationSection = function(tooltip) { income.id = 'CMTooltipIncome'; tooltip.appendChild(income); + tooltip.appendChild(CM.Disp.TooltipCreateHeader('Bonus Cookies per Click')); + tooltip.lastChild.style.display = "none"; + var click = document.createElement('div'); + click.style.marginBottom = '4px'; + click.style.color = 'white'; + click.style.display = "none"; + click.id = 'CMTooltipCookiePerClick'; + tooltip.appendChild(click); + tooltip.appendChild(CM.Disp.TooltipCreateHeader('Payback Period')); var pp = document.createElement('div'); pp.style.marginBottom = '4px'; @@ -1487,6 +1496,7 @@ CM.Disp.UpdateTooltipUpgrade = function() { CM.Disp.TooltipBonusIncome = CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].bonus; CM.Disp.TooltipPrice = Game.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].getPrice(); + CM.Disp.TooltipBonusMouse = CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].bonusMouse if (CM.Options.TooltipBuildUp == 1) { l('CMTooltipIncome').textContent = Beautify(CM.Disp.TooltipBonusIncome, 2); @@ -1495,8 +1505,21 @@ CM.Disp.UpdateTooltipUpgrade = function() { l('CMTooltipIncome').textContent += ' (' + (increase / 100) + '% of income)'; } l('CMTooltipBorder').className = CM.Disp.colorTextPre + CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].color; - l('CMTooltipPP').textContent = Beautify(CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].pp, 2); - l('CMTooltipPP').className = CM.Disp.colorTextPre + CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].color; + // If clicking power upgrade + if (CM.Disp.TooltipBonusMouse) { + l('CMTooltipCookiePerClick').textContent = Beautify(CM.Disp.TooltipBonusMouse) + l('CMTooltipCookiePerClick').style.display = "block"; + l('CMTooltipCookiePerClick').previousSibling.style.display = "block"; + } + // If only a clicking power upgrade change PP to click-based period + if (CM.Disp.TooltipBonusIncome == 0 && CM.Disp.TooltipBonusMouse) { + l('CMTooltipPP').textContent = Beautify(CM.Disp.TooltipPrice / CM.Disp.TooltipBonusMouse) + ' clicks' + l('CMTooltipPP').style.color = "white"; + } + else { + l('CMTooltipPP').textContent = Beautify(CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].pp, 2); + l('CMTooltipPP').className = CM.Disp.colorTextPre + CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].color; + } var timeColor = CM.Disp.GetTimeColor((CM.Disp.TooltipPrice - (Game.cookies + CM.Disp.GetWrinkConfigBank())) / CM.Disp.GetCPS()); l('CMTooltipTime').textContent = timeColor.text; l('CMTooltipTime').className = CM.Disp.colorTextPre + timeColor.color; diff --git a/src/Sim.js b/src/Sim.js index fe9bc60..7b3dd29 100644 --- a/src/Sim.js +++ b/src/Sim.js @@ -624,6 +624,9 @@ CM.Sim.BuyUpgrades = function() { CM.Cache.Upgrades[i] = {}; CM.Cache.Upgrades[i].bonus = CM.Sim.cookiesPs - Game.cookiesPs; + + var diffMouseCPS = CM.Sim.mouseCps() - Game.computedMouseCps; + if (diffMouseCPS) CM.Cache.Upgrades[i].bonusMouse = diffMouseCPS; } } } @@ -817,3 +820,84 @@ CM.Sim.SellBuildingsForChoEgg = function() { return sellTotal; } + +/******** + * Section: Functions used to calculate clicking power */ + +/** + * This function calculates the cookies per click + * It is called by CM.Sim.BuyUpgrades() when an upgrades has no bonus-income (and is thus a clicking-upgrade) + */ +CM.Sim.mouseCps = function() { + var add=0; + if (CM.Sim.Has('Thousand fingers')) add += 0.1; + if (CM.Sim.Has('Million fingers')) add *= 5; + if (CM.Sim.Has('Billion fingers')) add *= 10; + if (CM.Sim.Has('Trillion fingers')) add *= 20; + if (CM.Sim.Has('Quadrillion fingers')) add *= 20; + if (CM.Sim.Has('Quintillion fingers')) add *= 20; + if (CM.Sim.Has('Sextillion fingers')) add *= 20; + if (CM.Sim.Has('Septillion fingers')) add *= 20; + if (CM.Sim.Has('Octillion fingers')) add *= 20; + if (CM.Sim.Has('Nonillion fingers')) add *= 20; + var num=0; + for (var i in CM.Sim.Objects) {num+=CM.Sim.Objects[i].amount;} + num -= CM.Sim.Objects['Cursor'].amount; + add = add * num; + + // Use CM.Sim.cookiesPs as function is always called after CM.Sim.CalculateGains() + if (CM.Sim.Has('Plastic mouse')) add += CM.Sim.cookiesPs * 0.01; + if (CM.Sim.Has('Iron mouse')) add += CM.Sim.cookiesPs * 0.01; + if (CM.Sim.Has('Titanium mouse')) add += CM.Sim.cookiesPs * 0.01; + if (CM.Sim.Has('Adamantium mouse')) add += CM.Sim.cookiesPs * 0.01; + if (CM.Sim.Has('Unobtainium mouse')) add += CM.Sim.cookiesPs * 0.01; + if (CM.Sim.Has('Eludium mouse')) add += CM.Sim.cookiesPs * 0.01; + if (CM.Sim.Has('Wishalloy mouse')) add += CM.Sim.cookiesPs * 0.01; + if (CM.Sim.Has('Fantasteel mouse')) add += CM.Sim.cookiesPs * 0.01; + if (CM.Sim.Has('Nevercrack mouse')) add += CM.Sim.cookiesPs * 0.01; + if (CM.Sim.Has('Armythril mouse')) add += CM.Sim.cookiesPs * 0.01; + if (CM.Sim.Has('Technobsidian mouse')) add += CM.Sim.cookiesPs * 0.01; + if (CM.Sim.Has('Plasmarble mouse')) add += CM.Sim.cookiesPs * 0.01; + if (CM.Sim.Has('Miraculite mouse')) add += CM.Sim.cookiesPs * 0.01; + + if (CM.Sim.Has('Fortune #104')) add += CM.Sim.cookiesPs * 0.01; + + + var mult=1; + if (CM.Sim.Has('Santa\'s helpers')) mult *= 1.1; + if (CM.Sim.Has('Cookie egg')) mult *= 1.1; + if (CM.Sim.Has('Halo gloves')) mult *= 1.1; + if (CM.Sim.Has('Dragon claw')) mult *= 1.03; + + if (CM.Sim.Has('Aura gloves')) + { + mult *= 1 + 0.05 * Math.min(Game.Objects['Cursor'].level, CM.Sim.Has('Luminous gloves') ? 20 : 10); + } + + mult *= CM.Sim.eff('click'); + + if (CM.Sim.hasGod) + { + var godLvl = CM.Sim.hasGod('labor'); + if (godLvl == 1) mult *= 1.15; + else if (godLvl == 2) mult *= 1.1; + else if (godLvl == 3) mult *= 1.05; + } + + for (var i in Game.buffs) + { + if (typeof Game.buffs[i].multClick != 'undefined') mult*=Game.buffs[i].multClick; + } + + //if (CM.Sim.auraMult('Dragon Cursor')) mult*=1.05; + mult *= 1 + CM.Sim.auraMult('Dragon Cursor') * 0.05; + + // No need to make this function a CM function + var out = mult * Game.ComputeCps(1, CM.Sim.Has('Reinforced index finger') + CM.Sim.Has('Carpal tunnel prevention cream') + CM.Sim.Has('Ambidextrous'), add); + + out = Game.runModHookOnValue('cookiesPerClick', out); + + if (Game.hasBuff('Cursed finger')) out = Game.buffs['Cursed finger'].power; + + return out; +} From 37b378ad08760e1fc5277c940bd88078940c8aef Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Fri, 18 Dec 2020 23:23:07 +0100 Subject: [PATCH 070/106] Fixed spelling --- CookieMonster.js | 2 +- src/Disp.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index 2ccde6e..c4859bd 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -2538,7 +2538,7 @@ CM.Disp.UpdateTooltipUpgrade = function() { } // If only a clicking power upgrade change PP to click-based period if (CM.Disp.TooltipBonusIncome == 0 && CM.Disp.TooltipBonusMouse) { - l('CMTooltipPP').textContent = Beautify(CM.Disp.TooltipPrice / CM.Disp.TooltipBonusMouse) + ' clicks' + l('CMTooltipPP').textContent = Beautify(CM.Disp.TooltipPrice / CM.Disp.TooltipBonusMouse) + ' Clicks' l('CMTooltipPP').style.color = "white"; } else { diff --git a/src/Disp.js b/src/Disp.js index 6aeba49..6c01da1 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -1513,7 +1513,7 @@ CM.Disp.UpdateTooltipUpgrade = function() { } // If only a clicking power upgrade change PP to click-based period if (CM.Disp.TooltipBonusIncome == 0 && CM.Disp.TooltipBonusMouse) { - l('CMTooltipPP').textContent = Beautify(CM.Disp.TooltipPrice / CM.Disp.TooltipBonusMouse) + ' clicks' + l('CMTooltipPP').textContent = Beautify(CM.Disp.TooltipPrice / CM.Disp.TooltipBonusMouse) + ' Clicks' l('CMTooltipPP').style.color = "white"; } else { From c4295a1ed0cb42bb9c77de78f051d5e8572b9586 Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Sat, 19 Dec 2020 09:35:27 +0100 Subject: [PATCH 071/106] Updated Readme --- README.md | 40 +++++++++++----------------------------- 1 file changed, 11 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 0a9ee61..90c0d68 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Cookie Monster +## Cookie Monster **Cookie Monster** is an addon you can load into Cookie Clicker, that offers a wide range of tools and statistics to enhance the game. **It is not a cheat interface** – although it does offer helpers for golden cookies and such, everything can be toggled off at will to only leave how much information you want. @@ -7,7 +7,7 @@ This is a helper, and it is here to help you at *whichever* degree you want, if ### Current version You can see the current version, and a full history of all versions and what they changed by consulting the [releases page](https://github.com/Aktanusa/CookieMonster/releases). -## What it does +### What it does At its core, Cookie Monster computes an index for both buildings and upgrades: the **Payback Period (PP)**. This indicates how much a building is worth by using the following formula: ``` @@ -28,27 +28,15 @@ This index is computed for buildings and upgrades. If the relevant option is ena Note: For this index, **lower is better**, meaning a building with a PP of 1 is more interesting than one with a PP of 3. -## What it doesn't do +### What it doesn't do -Most likely you'll find items in gray like Golden Cookie upgrades, clicking upgrades, season upgrades – everything that doesn't earn you a direct bonus to your income will display as gray. This means the following upgrades are **not** taken into account by Cookie Monster: - -* Plastic mouse -* Iron mouse -* Titanium mouse -* Adamantium mouse -* Unobtainium mouse -* Lucky day -* Serendipity -* Get lucky -* Elder Pledge -* Sacrificial rolling pins -* **etc.** +Some upgrades do not give a direct bonus to your income and will display as gray. These are mainly Golden Cookie upgrades and season upgrades. Do note though that, although these upgrades have no direct value, if buying them earns you an achievement of some sort which in return gives you milk and income, Cookie Monster **will** display that value. -# Using +## Using -## Bookmarklet +### Bookmarklet Copy this code and save it as a bookmark. Paste it in the URL section. To activate, click the bookmark when the game's open. @@ -60,7 +48,7 @@ javascript: (function () { If (for some reason) the above doesn't work, trying pasting everything after the javascript: bit into your browser's console. -## Userscript +### Userscript If you'd rather use the addon as a script via per example *Greasemonkey* or *Tampermonkey*, you can use the following script, which will automatically load *Cookie Monster* every time the original game loads. You may need to specify http://orteil.dashnet.org/cookieclicker/ when asked for a *namespace* or *includes*. For how to add an userscript to your browser, refer to your browser/plugin's documentation as the method changes for each one. @@ -84,23 +72,17 @@ If you'd rather use the addon as a script via per example *Greasemonkey* or *Tam })(); ``` -# Bugs and suggestions +## Bugs and suggestions Any bug or suggestion should be **opened as an issue** [in the repository](https://github.com/Aktanusa/CookieMonster/issues) for easier tracking. This allows us to close issues once they're fixed. -Before submitting a bug, make sure to give a shot at the latest version of the addon on the dev branch. For this, use the following bookmarklet: +Before submitting a bug, make sure to give a shot at the latest version of the addon on the dev branch. This version can be tested by copying the `CookieMonster.js` file of the dev branch into your console. -```javascript -javascript: (function () { - Game.LoadMod('https://cdn.rawgit.com/Aktanusa/CookieMonster/dev/CookieMonster.js'); -}()); -``` - -If the bug is still here, you can submit an issue for it. +If the bug is still here, you can submit an issue for it. Please do so by using the bug report template. All suggestions are welcome, even the smallest ones. -# Contributors +## Contributors * **[Raving_Kumquat](https://cookieclicker.wikia.com/wiki/User:Raving_Kumquat)**: Original author * **[Maxime Fabre](https://github.com/Anahkiasen)**: Previous maintainer From d3a4eb936a24c4329674bb4766ad8904037c48a8 Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Sat, 19 Dec 2020 10:49:17 +0100 Subject: [PATCH 072/106] Made notation cutoff configurable --- CookieMonster.js | 52 +++++++++++++++++++++++++++++++++++++----------- src/Config.js | 2 +- src/Data.js | 8 +++++--- src/Disp.js | 42 ++++++++++++++++++++++++++++++-------- 4 files changed, 80 insertions(+), 24 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index c4859bd..64b22d0 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -589,7 +589,7 @@ CM.Cache.dragonAura2 = 0; /** * This function saves the config of CookieMonster to localStorage * It is called by CM.Config.LoadConfig(), CM.Config.RestoreDefault(), CM.Config.ToggleConfig(), - * CM.ToggleConfigVolume() and changes in options with type "url" or "color" + * CM.ToggleConfigVolume() and changes in options with type "url", "color" or "numscale" * @param {object} config The Config to be saved (normally CM.Options) */ CM.Config.SaveConfig = function(config) { @@ -789,9 +789,9 @@ CM.Data.PlantDrops = ['Elderwort biscuits', 'Bakeberry cookies', 'Duketater cook /******** * Section: Data for the various scales used by CookieMonster */ -CM.Data.metric = ['', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y']; -CM.Data.shortScale = ['', 'M', 'B', 'Tr', 'Quadr', 'Quint', 'Sext', 'Sept', 'Oct', 'Non', 'Dec', 'Undec', 'Duodec', 'Tredec', 'Quattuordec', 'Quindec', 'Sexdec', 'Septendec', 'Octodec', 'Novemdec', 'Vigint', 'Unvigint', 'Duovigint', 'Trevigint', 'Quattuorvigint']; -CM.Data.shortScaleAbbreviated = ['K', 'M', 'B', 'T', 'Qa', 'Qi', 'Sx', 'Sp', 'Oc', 'No', 'De', +CM.Data.metric = ['', '', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y']; +CM.Data.shortScale = ['', '', 'M', 'B', 'Tr', 'Quadr', 'Quint', 'Sext', 'Sept', 'Oct', 'Non', 'Dec', 'Undec', 'Duodec', 'Tredec', 'Quattuordec', 'Quindec', 'Sexdec', 'Septendec', 'Octodec', 'Novemdec', 'Vigint', 'Unvigint', 'Duovigint', 'Trevigint', 'Quattuorvigint']; +CM.Data.shortScaleAbbreviated = ['', 'K', 'M', 'B', 'T', 'Qa', 'Qi', 'Sx', 'Sp', 'Oc', 'No', 'De', 'UDe', 'DDe', 'TDe', 'QaDe', 'QiDe', 'SxDe', 'SpDe', 'ODe', 'NDe', 'Vi', 'UVi', 'DVi', 'TVi', 'QaVi', 'QiVi', 'SxVi', 'SpVi', 'OVi', 'NVi', 'Tr', 'UTr', 'DTr', 'TTr', 'QaTr', 'QiTr', 'SxTr', 'SpTr', 'OTr', 'NTr', 'Qaa', @@ -944,6 +944,7 @@ CM.ConfigData.GrimoireBar = {type: 'bool', group: 'Statistics', label: ['Grimoir CM.ConfigData.Scale = {type: 'bool', group: 'Notation', label: ['Game\'s Setting Scale', 'Metric', 'Short Scale', 'Short Scale (Abbreviated)', 'Scientific Notation', 'Engineering Notation'], desc: 'Change how long numbers are handled', toggle: false, func: function() {CM.Disp.RefreshScale();}}; CM.ConfigData.ScaleDecimals = {type: 'bool', group: 'Notation', label: ['1 decimals', '2 decimals', '3 decimals'], desc: 'Set the number of decimals used when applicable', toggle: false, func: function() {CM.Disp.RefreshScale();}}; CM.ConfigData.ScaleSeparator = {type: 'bool', group: 'Notation', label: ['. for decimals (Standard)', '. for thousands'], desc: 'Set the separator used for decimals and thousands', toggle: false, func: function() {CM.Disp.RefreshScale();}}; +CM.ConfigData.ScaleCutoff = {type: 'numscale', group: 'Notation', label: 'Notation Cut-off Point', desc: 'The number from which CookieMonster will start formatting numbers based on chosen scale. Standard is 999,999. Setting this above 999,999,999 might break certain notations.', min: 1, max: 999999999}; /** * This array describes all default settings @@ -1019,6 +1020,7 @@ CM.Data.ConfigDefault = { Scale: 2, ScaleDecimals: 2, ScaleSeparator: 0, + ScaleCutoff: 999999, Colors: {Blue: '#4bb8f0', Green: '#00ff00', Yellow: '#ffff00', Orange: '#ff7f00', Red: '#ff0000', Purple: '#ff00ff', Gray: '#b3b3b3', Pink: '#ff1493', Brown: '#8b4513'}, SortBuildings: 0, SortUpgrades: 0, @@ -1199,13 +1201,13 @@ CM.Disp.Beautify = function(num, floats, forced) { } else if (isFinite(num)) { var answer = ''; - var timesTenToPowerThree = Math.trunc(Math.log10(num) / 3) if (num == 0) { return num.toString() } - else if (-1 < timesTenToPowerThree && timesTenToPowerThree < 2) { - // TODO: Add changing separators of thousands and making this cut-off user configurable - answer = Math.round(num * 100) / 100; + else if (0.001 < num && num < CM.Options.ScaleCutoff) { + answer = num.toFixed(0); + if (CM.Options.ScaleSeparator) answer = answer.toLocaleString('nl'); + return answer; } else if (CM.Options.Scale == 4 && !forced || forced == 4) { // Scientific notation, 123456789 => 1.235E+8 answer = num.toExponential(decimals).toString().replace("e", "E"); @@ -1217,21 +1219,21 @@ CM.Disp.Beautify = function(num, floats, forced) { // answer is now "xxx.xx" (e.g., 123456789 would be 123.46) if (CM.Options.Scale == 1 && !forced || forced == 1) { // Metric scale, 123456789 => 123.457 M if (num >= 0.01 && num < Number("1e" + CM.Data.metric.length * 3)) { - answer += ' ' + CM.Data.metric[AmountOfTenPowerThree - 1] + answer += ' ' + CM.Data.metric[AmountOfTenPowerThree] } // If number is too large or little, revert to scientific notation else answer = CM.Disp.Beautify(num, 0, 4); } else if (CM.Options.Scale == 2 && !forced || forced == 2) { // Short scale, 123456789 => 123.457 M if (num >= 0.01 && num < Number("1e" + CM.Data.shortScale.length * 3)) { - answer += ' ' + CM.Data.shortScale[AmountOfTenPowerThree - 1]; + answer += ' ' + CM.Data.shortScale[AmountOfTenPowerThree]; } // If number is too large or little, revert to scientific notation else answer = CM.Disp.Beautify(num, 0, 4); } else if (CM.Options.Scale == 3 && !forced || forced == 3) { // Short scale, 123456789 => 123.457 M if (num >= 0.01 && num < Number("1e" + CM.Data.shortScaleAbbreviated.length * 3)) { - answer += ' ' + CM.Data.shortScaleAbbreviated[AmountOfTenPowerThree - 1]; + answer += ' ' + CM.Data.shortScaleAbbreviated[AmountOfTenPowerThree]; } // If number is too large or little, revert to scientific notation else answer = CM.Disp.Beautify(num, 0, 4); @@ -3030,6 +3032,32 @@ CM.Disp.CreatePrefOption = function(config) { return div; } } + else if (CM.ConfigData[config].type == "numscale") { + var div = document.createElement('div'); + div.className = 'listing'; + var span = document.createElement('span'); + span.className = 'option'; + span.textContent = CM.ConfigData[config].label + ' '; + div.appendChild(span); + var input = document.createElement('input'); + input.id = CM.ConfigPrefix + config; + input.className = 'option'; + input.type = 'number'; + input.value = (CM.Options[config]); + input.min = CM.ConfigData[config].min; + input.max = CM.ConfigData[config].max; + input.oninput = function() {if (this.value > this.max) console.log("TEST"); + CM.Options[config] = this.value; + CM.Config.SaveConfig(CM.Options); + CM.Disp.RefreshScale() + } + div.appendChild(input); + div.appendChild(document.createTextNode(' ')); + var label = document.createElement('label'); + label.textContent = CM.ConfigData[config].desc; + div.appendChild(label); + return div; + } } /** @@ -3043,7 +3071,7 @@ CM.Disp.ToggleDetailedTime = function() { /** * This function refreshes all numbers after a change in scale-setting - * It is therefore called by a change in CM.Options.Scale and CM.Options.ScaleDecimals + * It is therefore called by a changes in CM.Options.Scale, CM.Options.ScaleDecimals, CM.Options.ScaleSeparator and CM.Options.ScaleCutoff */ CM.Disp.RefreshScale = function() { BeautifyAll(); diff --git a/src/Config.js b/src/Config.js index c748b68..6b750ed 100644 --- a/src/Config.js +++ b/src/Config.js @@ -8,7 +8,7 @@ /** * This function saves the config of CookieMonster to localStorage * It is called by CM.Config.LoadConfig(), CM.Config.RestoreDefault(), CM.Config.ToggleConfig(), - * CM.ToggleConfigVolume() and changes in options with type "url" or "color" + * CM.ToggleConfigVolume() and changes in options with type "url", "color" or "numscale" * @param {object} config The Config to be saved (normally CM.Options) */ CM.Config.SaveConfig = function(config) { diff --git a/src/Data.js b/src/Data.js index 9a9ffef..ee4c109 100644 --- a/src/Data.js +++ b/src/Data.js @@ -38,9 +38,9 @@ CM.Data.PlantDrops = ['Elderwort biscuits', 'Bakeberry cookies', 'Duketater cook /******** * Section: Data for the various scales used by CookieMonster */ -CM.Data.metric = ['', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y']; -CM.Data.shortScale = ['', 'M', 'B', 'Tr', 'Quadr', 'Quint', 'Sext', 'Sept', 'Oct', 'Non', 'Dec', 'Undec', 'Duodec', 'Tredec', 'Quattuordec', 'Quindec', 'Sexdec', 'Septendec', 'Octodec', 'Novemdec', 'Vigint', 'Unvigint', 'Duovigint', 'Trevigint', 'Quattuorvigint']; -CM.Data.shortScaleAbbreviated = ['K', 'M', 'B', 'T', 'Qa', 'Qi', 'Sx', 'Sp', 'Oc', 'No', 'De', +CM.Data.metric = ['', '', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y']; +CM.Data.shortScale = ['', '', 'M', 'B', 'Tr', 'Quadr', 'Quint', 'Sext', 'Sept', 'Oct', 'Non', 'Dec', 'Undec', 'Duodec', 'Tredec', 'Quattuordec', 'Quindec', 'Sexdec', 'Septendec', 'Octodec', 'Novemdec', 'Vigint', 'Unvigint', 'Duovigint', 'Trevigint', 'Quattuorvigint']; +CM.Data.shortScaleAbbreviated = ['', 'K', 'M', 'B', 'T', 'Qa', 'Qi', 'Sx', 'Sp', 'Oc', 'No', 'De', 'UDe', 'DDe', 'TDe', 'QaDe', 'QiDe', 'SxDe', 'SpDe', 'ODe', 'NDe', 'Vi', 'UVi', 'DVi', 'TVi', 'QaVi', 'QiVi', 'SxVi', 'SpVi', 'OVi', 'NVi', 'Tr', 'UTr', 'DTr', 'TTr', 'QaTr', 'QiTr', 'SxTr', 'SpTr', 'OTr', 'NTr', 'Qaa', @@ -193,6 +193,7 @@ CM.ConfigData.GrimoireBar = {type: 'bool', group: 'Statistics', label: ['Grimoir CM.ConfigData.Scale = {type: 'bool', group: 'Notation', label: ['Game\'s Setting Scale', 'Metric', 'Short Scale', 'Short Scale (Abbreviated)', 'Scientific Notation', 'Engineering Notation'], desc: 'Change how long numbers are handled', toggle: false, func: function() {CM.Disp.RefreshScale();}}; CM.ConfigData.ScaleDecimals = {type: 'bool', group: 'Notation', label: ['1 decimals', '2 decimals', '3 decimals'], desc: 'Set the number of decimals used when applicable', toggle: false, func: function() {CM.Disp.RefreshScale();}}; CM.ConfigData.ScaleSeparator = {type: 'bool', group: 'Notation', label: ['. for decimals (Standard)', '. for thousands'], desc: 'Set the separator used for decimals and thousands', toggle: false, func: function() {CM.Disp.RefreshScale();}}; +CM.ConfigData.ScaleCutoff = {type: 'numscale', group: 'Notation', label: 'Notation Cut-off Point', desc: 'The number from which CookieMonster will start formatting numbers based on chosen scale. Standard is 999,999. Setting this above 999,999,999 might break certain notations.', min: 1, max: 999999999}; /** * This array describes all default settings @@ -268,6 +269,7 @@ CM.Data.ConfigDefault = { Scale: 2, ScaleDecimals: 2, ScaleSeparator: 0, + ScaleCutoff: 999999, Colors: {Blue: '#4bb8f0', Green: '#00ff00', Yellow: '#ffff00', Orange: '#ff7f00', Red: '#ff0000', Purple: '#ff00ff', Gray: '#b3b3b3', Pink: '#ff1493', Brown: '#8b4513'}, SortBuildings: 0, SortUpgrades: 0, diff --git a/src/Disp.js b/src/Disp.js index 6c01da1..c05d937 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -174,13 +174,13 @@ CM.Disp.Beautify = function(num, floats, forced) { } else if (isFinite(num)) { var answer = ''; - var timesTenToPowerThree = Math.trunc(Math.log10(num) / 3) if (num == 0) { return num.toString() } - else if (-1 < timesTenToPowerThree && timesTenToPowerThree < 2) { - // TODO: Add changing separators of thousands and making this cut-off user configurable - answer = Math.round(num * 100) / 100; + else if (0.001 < num && num < CM.Options.ScaleCutoff) { + answer = num.toFixed(0); + if (CM.Options.ScaleSeparator) answer = answer.toLocaleString('nl'); + return answer; } else if (CM.Options.Scale == 4 && !forced || forced == 4) { // Scientific notation, 123456789 => 1.235E+8 answer = num.toExponential(decimals).toString().replace("e", "E"); @@ -192,21 +192,21 @@ CM.Disp.Beautify = function(num, floats, forced) { // answer is now "xxx.xx" (e.g., 123456789 would be 123.46) if (CM.Options.Scale == 1 && !forced || forced == 1) { // Metric scale, 123456789 => 123.457 M if (num >= 0.01 && num < Number("1e" + CM.Data.metric.length * 3)) { - answer += ' ' + CM.Data.metric[AmountOfTenPowerThree - 1] + answer += ' ' + CM.Data.metric[AmountOfTenPowerThree] } // If number is too large or little, revert to scientific notation else answer = CM.Disp.Beautify(num, 0, 4); } else if (CM.Options.Scale == 2 && !forced || forced == 2) { // Short scale, 123456789 => 123.457 M if (num >= 0.01 && num < Number("1e" + CM.Data.shortScale.length * 3)) { - answer += ' ' + CM.Data.shortScale[AmountOfTenPowerThree - 1]; + answer += ' ' + CM.Data.shortScale[AmountOfTenPowerThree]; } // If number is too large or little, revert to scientific notation else answer = CM.Disp.Beautify(num, 0, 4); } else if (CM.Options.Scale == 3 && !forced || forced == 3) { // Short scale, 123456789 => 123.457 M if (num >= 0.01 && num < Number("1e" + CM.Data.shortScaleAbbreviated.length * 3)) { - answer += ' ' + CM.Data.shortScaleAbbreviated[AmountOfTenPowerThree - 1]; + answer += ' ' + CM.Data.shortScaleAbbreviated[AmountOfTenPowerThree]; } // If number is too large or little, revert to scientific notation else answer = CM.Disp.Beautify(num, 0, 4); @@ -2005,6 +2005,32 @@ CM.Disp.CreatePrefOption = function(config) { return div; } } + else if (CM.ConfigData[config].type == "numscale") { + var div = document.createElement('div'); + div.className = 'listing'; + var span = document.createElement('span'); + span.className = 'option'; + span.textContent = CM.ConfigData[config].label + ' '; + div.appendChild(span); + var input = document.createElement('input'); + input.id = CM.ConfigPrefix + config; + input.className = 'option'; + input.type = 'number'; + input.value = (CM.Options[config]); + input.min = CM.ConfigData[config].min; + input.max = CM.ConfigData[config].max; + input.oninput = function() {if (this.value > this.max) console.log("TEST"); + CM.Options[config] = this.value; + CM.Config.SaveConfig(CM.Options); + CM.Disp.RefreshScale() + } + div.appendChild(input); + div.appendChild(document.createTextNode(' ')); + var label = document.createElement('label'); + label.textContent = CM.ConfigData[config].desc; + div.appendChild(label); + return div; + } } /** @@ -2018,7 +2044,7 @@ CM.Disp.ToggleDetailedTime = function() { /** * This function refreshes all numbers after a change in scale-setting - * It is therefore called by a change in CM.Options.Scale and CM.Options.ScaleDecimals + * It is therefore called by a changes in CM.Options.Scale, CM.Options.ScaleDecimals, CM.Options.ScaleSeparator and CM.Options.ScaleCutoff */ CM.Disp.RefreshScale = function() { BeautifyAll(); From 7cfdcc7662f13e4e40bd1aeb412ff7f57b6cf9c5 Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Sat, 19 Dec 2020 14:38:14 +0100 Subject: [PATCH 073/106] Fixed building colors not reverting (#430) --- CookieMonster.js | 20 +++++++++++++------- src/Disp.js | 20 +++++++++++++------- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index 64b22d0..b4ed40e 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -1696,13 +1696,19 @@ CM.Disp.UpdateBotTimerBarPosition = function() { * And by changes in CM.Options.BuildColor, CM.Options.SortBuild & CM.ConfigData.BulkBuildColor */ CM.Disp.UpdateBuildings = function() { - if (CM.Options.BuildColor == 1 && Game.buyMode == 1) { - var target = ''; - if (Game.buyBulk == 10 && CM.Options.BulkBuildColor == 1) target = 'Objects10'; - else if (Game.buyBulk == 100 && CM.Options.BulkBuildColor == 1) target = 'Objects100'; - else target = 'Objects'; - for (var i in CM.Cache[target]) { - l('productPrice' + Game.Objects[i].id).style.color = CM.Options.Colors[CM.Cache[target][i].color]; + if (Game.buyMode == 1) { + if (CM.Options.BuildColor == 1) { + var target = ''; + if (Game.buyBulk == 10 && CM.Options.BulkBuildColor == 1) target = 'Objects10'; + else if (Game.buyBulk == 100 && CM.Options.BulkBuildColor == 1) target = 'Objects100'; + else target = 'Objects'; + for (var i in CM.Cache[target]) { + l('productPrice' + Game.Objects[i].id).style.color = CM.Options.Colors[CM.Cache[target][i].color]; + } + } else { + for (var i in Game.Objects) { + l('productPrice' + Game.Objects[i].id).style.removeProperty("color"); + } } } else if (Game.buyMode == -1) { diff --git a/src/Disp.js b/src/Disp.js index c05d937..7516ed8 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -669,13 +669,19 @@ CM.Disp.UpdateBotTimerBarPosition = function() { * And by changes in CM.Options.BuildColor, CM.Options.SortBuild & CM.ConfigData.BulkBuildColor */ CM.Disp.UpdateBuildings = function() { - if (CM.Options.BuildColor == 1 && Game.buyMode == 1) { - var target = ''; - if (Game.buyBulk == 10 && CM.Options.BulkBuildColor == 1) target = 'Objects10'; - else if (Game.buyBulk == 100 && CM.Options.BulkBuildColor == 1) target = 'Objects100'; - else target = 'Objects'; - for (var i in CM.Cache[target]) { - l('productPrice' + Game.Objects[i].id).style.color = CM.Options.Colors[CM.Cache[target][i].color]; + if (Game.buyMode == 1) { + if (CM.Options.BuildColor == 1) { + var target = ''; + if (Game.buyBulk == 10 && CM.Options.BulkBuildColor == 1) target = 'Objects10'; + else if (Game.buyBulk == 100 && CM.Options.BulkBuildColor == 1) target = 'Objects100'; + else target = 'Objects'; + for (var i in CM.Cache[target]) { + l('productPrice' + Game.Objects[i].id).style.color = CM.Options.Colors[CM.Cache[target][i].color]; + } + } else { + for (var i in Game.Objects) { + l('productPrice' + Game.Objects[i].id).style.removeProperty("color"); + } } } else if (Game.buyMode == -1) { From c6c54054eed665871191fd9d1c0c1142253e1cd3 Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Sat, 19 Dec 2020 17:37:01 +0100 Subject: [PATCH 074/106] Added section to Cache.js --- CookieMonster.js | 71 ++++++++++++++++++++++++------------------------ src/Cache.js | 71 ++++++++++++++++++++++++------------------------ 2 files changed, 72 insertions(+), 70 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index b4ed40e..8dc4b66 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -31,6 +31,9 @@ if (typeof CM == "undefined") { * Cache * *********/ +/******** + * Section: Functions related to Dragon Auras */ + /** * This functions caches the currently selected Dragon Auras * It is called by CM.Sim.CopyData() and CM.Sim.InitData() @@ -41,6 +44,39 @@ CM.Cache.CacheDragonAuras = function() { CM.Cache.dragonAura2 = Game.dragonAura2; } +/******** + * Section: Functions related to Wrinklers */ + +CM.Cache.RemakeWrinkBank = function() { + CM.Cache.WrinkBankTotal = 0; + CM.Cache.WrinkBankNormal = 0; + var totalSucked = 0; + for (var i in Game.wrinklers) { + var sucked = Game.wrinklers[i].sucked; + var toSuck = 1.1; + if (Game.Has('Sacrilegious corruption')) toSuck *= 1.05; + if (Game.wrinklers[i].type==1) toSuck *= 3; // Shiny wrinklers + sucked *= toSuck; + if (Game.Has('Wrinklerspawn')) sucked *= 1.05; + if (CM.Sim.Objects.Temple.minigameLoaded) { + var godLvl = CM.Sim.hasGod('scorn'); + if (godLvl == 1) sucked *= 1.15; + else if (godLvl == 2) sucked *= 1.1; + else if (godLvl == 3) sucked *= 1.05; + } + CM.Cache.WrinkBankTotal += sucked; + if (Game.wrinklers[i].type == 0) CM.Cache.WrinkBankNormal += sucked; + } + CM.Cache.WrinkGodBank = CM.Cache.WrinkBankTotal; + if (CM.Sim.Objects.Temple.minigameLoaded) { + var godLvl = CM.Sim.hasGod('scorn'); + if (godLvl == 2) CM.Cache.WrinkGodBank = CM.Cache.WrinkGodBank * 1.15 / 1.1; + else if (godLvl == 3) CM.Cache.WrinkGodBank = CM.Cache.WrinkGodBank * 1.15 / 1.05; + else if (godLvl != 1) CM.Cache.WrinkGodBank *= 1.15; + } +} + + /******** * Section: UNSORTED */ @@ -81,35 +117,6 @@ CM.Cache.RemakeIncome = function() { CM.Sim.BuyBuildings(100, 'Objects100'); } -CM.Cache.RemakeWrinkBank = function() { - CM.Cache.WrinkBankTotal = 0; - CM.Cache.WrinkBankNormal = 0; - var totalSucked = 0; - for (var i in Game.wrinklers) { - var sucked = Game.wrinklers[i].sucked; - var toSuck = 1.1; - if (Game.Has('Sacrilegious corruption')) toSuck *= 1.05; - if (Game.wrinklers[i].type==1) toSuck *= 3; // Shiny wrinklers - sucked *= toSuck; - if (Game.Has('Wrinklerspawn')) sucked *= 1.05; - if (CM.Sim.Objects.Temple.minigameLoaded) { - var godLvl = CM.Sim.hasGod('scorn'); - if (godLvl == 1) sucked *= 1.15; - else if (godLvl == 2) sucked *= 1.1; - else if (godLvl == 3) sucked *= 1.05; - } - CM.Cache.WrinkBankTotal += sucked; - if (Game.wrinklers[i].type == 0) CM.Cache.WrinkBankNormal += sucked; - } - CM.Cache.WrinkGodBank = CM.Cache.WrinkBankTotal; - if (CM.Sim.Objects.Temple.minigameLoaded) { - var godLvl = CM.Sim.hasGod('scorn'); - if (godLvl == 2) CM.Cache.WrinkGodBank = CM.Cache.WrinkGodBank * 1.15 / 1.1; - else if (godLvl == 3) CM.Cache.WrinkGodBank = CM.Cache.WrinkGodBank * 1.15 / 1.05; - else if (godLvl != 1) CM.Cache.WrinkGodBank *= 1.15; - } -} - CM.Cache.RemakeBuildingsPP = function() { CM.Cache.min = -1; CM.Cache.max = -1; @@ -573,12 +580,6 @@ CM.Cache.seasonPopShimmer; CM.Cache.goldenShimmersByID = {}; CM.Cache.spawnedGoldenShimmer = 0; -/** - * This variables are used by CM.Cache.CacheDragonAuras(), naming follows naming in Game - */ -CM.Cache.dragonAura = 0; -CM.Cache.dragonAura2 = 0; - /********** * Config * **********/ diff --git a/src/Cache.js b/src/Cache.js index 83416ad..ff95705 100644 --- a/src/Cache.js +++ b/src/Cache.js @@ -2,6 +2,9 @@ * Cache * *********/ +/******** + * Section: Functions related to Dragon Auras */ + /** * This functions caches the currently selected Dragon Auras * It is called by CM.Sim.CopyData() and CM.Sim.InitData() @@ -12,6 +15,39 @@ CM.Cache.CacheDragonAuras = function() { CM.Cache.dragonAura2 = Game.dragonAura2; } +/******** + * Section: Functions related to Wrinklers */ + +CM.Cache.RemakeWrinkBank = function() { + CM.Cache.WrinkBankTotal = 0; + CM.Cache.WrinkBankNormal = 0; + var totalSucked = 0; + for (var i in Game.wrinklers) { + var sucked = Game.wrinklers[i].sucked; + var toSuck = 1.1; + if (Game.Has('Sacrilegious corruption')) toSuck *= 1.05; + if (Game.wrinklers[i].type==1) toSuck *= 3; // Shiny wrinklers + sucked *= toSuck; + if (Game.Has('Wrinklerspawn')) sucked *= 1.05; + if (CM.Sim.Objects.Temple.minigameLoaded) { + var godLvl = CM.Sim.hasGod('scorn'); + if (godLvl == 1) sucked *= 1.15; + else if (godLvl == 2) sucked *= 1.1; + else if (godLvl == 3) sucked *= 1.05; + } + CM.Cache.WrinkBankTotal += sucked; + if (Game.wrinklers[i].type == 0) CM.Cache.WrinkBankNormal += sucked; + } + CM.Cache.WrinkGodBank = CM.Cache.WrinkBankTotal; + if (CM.Sim.Objects.Temple.minigameLoaded) { + var godLvl = CM.Sim.hasGod('scorn'); + if (godLvl == 2) CM.Cache.WrinkGodBank = CM.Cache.WrinkGodBank * 1.15 / 1.1; + else if (godLvl == 3) CM.Cache.WrinkGodBank = CM.Cache.WrinkGodBank * 1.15 / 1.05; + else if (godLvl != 1) CM.Cache.WrinkGodBank *= 1.15; + } +} + + /******** * Section: UNSORTED */ @@ -52,35 +88,6 @@ CM.Cache.RemakeIncome = function() { CM.Sim.BuyBuildings(100, 'Objects100'); } -CM.Cache.RemakeWrinkBank = function() { - CM.Cache.WrinkBankTotal = 0; - CM.Cache.WrinkBankNormal = 0; - var totalSucked = 0; - for (var i in Game.wrinklers) { - var sucked = Game.wrinklers[i].sucked; - var toSuck = 1.1; - if (Game.Has('Sacrilegious corruption')) toSuck *= 1.05; - if (Game.wrinklers[i].type==1) toSuck *= 3; // Shiny wrinklers - sucked *= toSuck; - if (Game.Has('Wrinklerspawn')) sucked *= 1.05; - if (CM.Sim.Objects.Temple.minigameLoaded) { - var godLvl = CM.Sim.hasGod('scorn'); - if (godLvl == 1) sucked *= 1.15; - else if (godLvl == 2) sucked *= 1.1; - else if (godLvl == 3) sucked *= 1.05; - } - CM.Cache.WrinkBankTotal += sucked; - if (Game.wrinklers[i].type == 0) CM.Cache.WrinkBankNormal += sucked; - } - CM.Cache.WrinkGodBank = CM.Cache.WrinkBankTotal; - if (CM.Sim.Objects.Temple.minigameLoaded) { - var godLvl = CM.Sim.hasGod('scorn'); - if (godLvl == 2) CM.Cache.WrinkGodBank = CM.Cache.WrinkGodBank * 1.15 / 1.1; - else if (godLvl == 3) CM.Cache.WrinkGodBank = CM.Cache.WrinkGodBank * 1.15 / 1.05; - else if (godLvl != 1) CM.Cache.WrinkGodBank *= 1.15; - } -} - CM.Cache.RemakeBuildingsPP = function() { CM.Cache.min = -1; CM.Cache.max = -1; @@ -544,9 +551,3 @@ CM.Cache.seasonPopShimmer; CM.Cache.goldenShimmersByID = {}; CM.Cache.spawnedGoldenShimmer = 0; -/** - * This variables are used by CM.Cache.CacheDragonAuras(), naming follows naming in Game - */ -CM.Cache.dragonAura = 0; -CM.Cache.dragonAura2 = 0; - From 389dae4daa3035a5c38762f29b8f51314042d0bc Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Sat, 19 Dec 2020 17:45:33 +0100 Subject: [PATCH 075/106] Created function CM.Cache.InitCache --- CookieMonster.js | 21 ++++++++++++++++++--- src/Cache.js | 17 +++++++++++++++++ src/Main.js | 1 + src/Sim.js | 3 --- 4 files changed, 36 insertions(+), 6 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index 8dc4b66..c711f28 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -31,6 +31,19 @@ if (typeof CM == "undefined") { * Cache * *********/ +/******** + * Section: General Cache related functions */ + +/** + * This functions runs all cache-functions to generate all "full" cache + * The declaration follows the structure of the CM.Cache.js file + * It is called by CM.DelayInit + * TODO: Add all functions that should be here and remove them from CM.Loop() + */ +CM.Cache.InitCache = function() { + CM.Cache.CacheDragonAuras(); +} + /******** * Section: Functions related to Dragon Auras */ @@ -47,6 +60,10 @@ CM.Cache.CacheDragonAuras = function() { /******** * Section: Functions related to Wrinklers */ +/** + * This functions caches data related to Wrinklers + * It is called by CM.Loop() + */ CM.Cache.RemakeWrinkBank = function() { CM.Cache.WrinkBankTotal = 0; CM.Cache.WrinkBankNormal = 0; @@ -4000,6 +4017,7 @@ CM.Init = function() { CM.DelayInit = function() { CM.Sim.InitData(); + CM.Cache.InitCache(); CM.Disp.CreateCssArea(); CM.Disp.CreateBotBar(); CM.Disp.CreateTimerBar(); @@ -4469,9 +4487,6 @@ CM.Sim.InitData = function() { for (var i in Game.Achievements) { CM.Sim.Achievements[i] = CM.Sim.InitAchievement(i); } - - // Auras - CM.Cache.CacheDragonAuras(); } CM.Sim.CopyData = function() { diff --git a/src/Cache.js b/src/Cache.js index ff95705..c575948 100644 --- a/src/Cache.js +++ b/src/Cache.js @@ -2,6 +2,19 @@ * Cache * *********/ +/******** + * Section: General Cache related functions */ + +/** + * This functions runs all cache-functions to generate all "full" cache + * The declaration follows the structure of the CM.Cache.js file + * It is called by CM.DelayInit + * TODO: Add all functions that should be here and remove them from CM.Loop() + */ +CM.Cache.InitCache = function() { + CM.Cache.CacheDragonAuras(); +} + /******** * Section: Functions related to Dragon Auras */ @@ -18,6 +31,10 @@ CM.Cache.CacheDragonAuras = function() { /******** * Section: Functions related to Wrinklers */ +/** + * This functions caches data related to Wrinklers + * It is called by CM.Loop() + */ CM.Cache.RemakeWrinkBank = function() { CM.Cache.WrinkBankTotal = 0; CM.Cache.WrinkBankNormal = 0; diff --git a/src/Main.js b/src/Main.js index 12c0de1..80d16ea 100644 --- a/src/Main.js +++ b/src/Main.js @@ -229,6 +229,7 @@ CM.Init = function() { CM.DelayInit = function() { CM.Sim.InitData(); + CM.Cache.InitCache(); CM.Disp.CreateCssArea(); CM.Disp.CreateBotBar(); CM.Disp.CreateTimerBar(); diff --git a/src/Sim.js b/src/Sim.js index 7b3dd29..d4fc227 100644 --- a/src/Sim.js +++ b/src/Sim.js @@ -207,9 +207,6 @@ CM.Sim.InitData = function() { for (var i in Game.Achievements) { CM.Sim.Achievements[i] = CM.Sim.InitAchievement(i); } - - // Auras - CM.Cache.CacheDragonAuras(); } CM.Sim.CopyData = function() { From 0f865f38974ea5e6c51dbb338f87018460e2349f Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Sat, 19 Dec 2020 18:26:38 +0100 Subject: [PATCH 076/106] Button and stat for single fattest wrinkler (#177) --- CookieMonster.js | 61 ++++++++++++++++++++++++++---------------------- src/Cache.js | 41 +++++++++++++++----------------- src/Disp.js | 18 ++++++++++---- src/Main.js | 2 +- 4 files changed, 66 insertions(+), 56 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index c711f28..15a3da1 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -42,6 +42,7 @@ if (typeof CM == "undefined") { */ CM.Cache.InitCache = function() { CM.Cache.CacheDragonAuras(); + CM.Cache.CacheWrinklers(); } /******** @@ -49,10 +50,13 @@ CM.Cache.InitCache = function() { /** * This functions caches the currently selected Dragon Auras - * It is called by CM.Sim.CopyData() and CM.Sim.InitData() + * It is called by CM.Sim.CopyData() and CM.Cache.InitCache() * Uncapitalized dragon follows Game-naming + * @global {number} CM.Cache.dragonAura The number of the first (right) Aura + * @global {number} CM.Cache.dragonAura2 The number of the second (left) Aura */ CM.Cache.CacheDragonAuras = function() { + /** @global */ CM.Cache.dragonAura = Game.dragonAura; CM.Cache.dragonAura2 = Game.dragonAura2; } @@ -62,12 +66,15 @@ CM.Cache.CacheDragonAuras = function() { /** * This functions caches data related to Wrinklers - * It is called by CM.Loop() + * It is called by CM.Loop() and CM.Cache.InitCache() + * @global {number} CM.Cache.WrinklersTotal The cookies of all wrinklers + * @global {number} CM.Cache.WrinklersNormal The cookies of all normal wrinklers + * @global {[{number}, {number}]} CM.Cache.WrinklersFattest A list containing the cookies and the id of the fattest wrinkler */ -CM.Cache.RemakeWrinkBank = function() { - CM.Cache.WrinkBankTotal = 0; - CM.Cache.WrinkBankNormal = 0; - var totalSucked = 0; +CM.Cache.CacheWrinklers = function() { + CM.Cache.WrinklersTotal = 0; + CM.Cache.WrinklersNormal = 0; + CM.Cache.WrinklersFattest = [0, null]; for (var i in Game.wrinklers) { var sucked = Game.wrinklers[i].sucked; var toSuck = 1.1; @@ -81,19 +88,12 @@ CM.Cache.RemakeWrinkBank = function() { else if (godLvl == 2) sucked *= 1.1; else if (godLvl == 3) sucked *= 1.05; } - CM.Cache.WrinkBankTotal += sucked; - if (Game.wrinklers[i].type == 0) CM.Cache.WrinkBankNormal += sucked; - } - CM.Cache.WrinkGodBank = CM.Cache.WrinkBankTotal; - if (CM.Sim.Objects.Temple.minigameLoaded) { - var godLvl = CM.Sim.hasGod('scorn'); - if (godLvl == 2) CM.Cache.WrinkGodBank = CM.Cache.WrinkGodBank * 1.15 / 1.1; - else if (godLvl == 3) CM.Cache.WrinkGodBank = CM.Cache.WrinkGodBank * 1.15 / 1.05; - else if (godLvl != 1) CM.Cache.WrinkGodBank *= 1.15; + CM.Cache.WrinklersTotal += sucked; + if (Game.wrinklers[i].type == 0) CM.Cache.WrinklersNormal += sucked; + if (sucked > CM.Cache.WrinklersFattest[0]) CM.Cache.WrinklersFattest = [sucked, i]; } } - /******** * Section: UNSORTED */ @@ -434,7 +434,7 @@ CM.Cache.UpdateAvgCPS = function() { if (CM.Cache.lastDate != currDate) { var choEggTotal = Game.cookies + CM.Cache.SellForChoEgg; if (Game.cpsSucked > 0) { - choEggTotal += CM.Cache.WrinkGodBank; + choEggTotal += CM.Cache.WrinklersTotal; } CM.Cache.RealCookiesEarned = Math.max(Game.cookiesEarned, choEggTotal); choEggTotal *= 0.05; @@ -442,7 +442,7 @@ CM.Cache.UpdateAvgCPS = function() { if (CM.Cache.lastDate != -1) { var timeDiff = currDate - CM.Cache.lastDate var bankDiffAvg = Math.max(0, (Game.cookies - CM.Cache.lastCookies)) / timeDiff; - var wrinkDiffAvg = Math.max(0, (CM.Cache.WrinkBankTotal - CM.Cache.lastWrinkCookies)) / timeDiff; + var wrinkDiffAvg = Math.max(0, (CM.Cache.WrinklersTotal - CM.Cache.lastWrinkCookies)) / timeDiff; var choEggDiffAvg = Math.max(0,(choEggTotal - CM.Cache.lastChoEgg)) / timeDiff; var clicksDiffAvg = (Game.cookieClicks - CM.Cache.lastClicks) / timeDiff; for (var i = 0; i < timeDiff; i++) { @@ -464,7 +464,7 @@ CM.Cache.UpdateAvgCPS = function() { } CM.Cache.lastDate = currDate; CM.Cache.lastCookies = Game.cookies; - CM.Cache.lastWrinkCookies = CM.Cache.WrinkBankTotal; + CM.Cache.lastWrinkCookies = CM.Cache.WrinklersTotal; CM.Cache.lastChoEgg = choEggTotal; CM.Cache.lastClicks = Game.cookieClicks; @@ -547,9 +547,6 @@ CM.Cache.CalcMissingUpgrades = function() { CM.Cache.min = -1; CM.Cache.max = -1; CM.Cache.mid = -1; -CM.Cache.WrinkBankTotal = -1; -CM.Cache.WrinkBankNormal = -1; -CM.Cache.WrinkGodBank = -1; CM.Cache.GoldenCookiesMult = 1; CM.Cache.WrathCookiesMult = 1; CM.Cache.DragonsFortuneMultAdjustment = 1; @@ -1058,11 +1055,11 @@ CM.Data.ConfigDefault = { /** * This function returns the total amount stored in the Wrinkler Bank * as calculated by CM.Cache.RemakeWrinkBank() if CM.Options.CalcWrink is set - * @returns {number} 0 or the amount of cookies stored (CM.Cache.WrinkBankTotal) + * @returns {number} 0 or the amount of cookies stored (CM.Cache.WrinklersTotal) */ CM.Disp.GetWrinkConfigBank = function() { if (CM.Options.CalcWrink) - return CM.Cache.WrinkBankTotal; + return CM.Cache.WrinklersTotal; else return 0; } @@ -3164,13 +3161,21 @@ CM.Disp.AddMenuStats = function(title) { stats.appendChild(CM.Disp.CreateStatsHeader('Wrinklers', 'Wrink')); if (CM.Options.Header.Wrink) { var popAllFrag = document.createDocumentFragment(); - popAllFrag.appendChild(document.createTextNode(Beautify(CM.Cache.WrinkBankTotal) + ' / ' + Beautify(CM.Cache.WrinkBankNormal) + ' ')); + popAllFrag.appendChild(document.createTextNode(Beautify(CM.Cache.WrinklersTotal) + ' / ' + Beautify(CM.Cache.WrinklersNormal) + ' ')); var popAllA = document.createElement('a'); popAllA.textContent = 'Pop All Normal'; popAllA.className = 'option'; popAllA.onclick = function() { CM.Disp.PopAllNormalWrinklers(); }; popAllFrag.appendChild(popAllA); stats.appendChild(CM.Disp.CreateStatsListing("basic", 'Rewards of Popping (All/Normal)', popAllFrag)); + var popFattestFrag = document.createDocumentFragment(); + popFattestFrag.appendChild(document.createTextNode(Beautify(CM.Cache.WrinklersFattest[0]) + ' ')); + var popFattestA = document.createElement('a'); + popFattestA.textContent = 'Pop single fattest'; + popFattestA.className = 'option'; + popFattestA.onclick = function() { Game.wrinklers[CM.Cache.WrinklersFattest[1]].hp = 0; }; + popFattestFrag.appendChild(popFattestA); + stats.appendChild(CM.Disp.CreateStatsListing("basic", 'Rewards of Popping Single Fattest Wrinkler (id: ' + CM.Cache.WrinklersFattest[1] + ")", popFattestFrag)); } } @@ -3575,11 +3580,11 @@ CM.Disp.CreateStatsPrestigeSection = function() { section.className = 'CMStatsPrestigeSection'; var possiblePresMax = Math.floor(Game.HowMuchPrestige(CM.Cache.RealCookiesEarned + - Game.cookiesReset + CM.Cache.WrinkGodBank + + Game.cookiesReset + CM.Cache.WrinklersTotal + (Game.HasUnlocked('Chocolate egg') && !Game.Has('Chocolate egg') ? CM.Cache.lastChoEgg : 0))); section.appendChild(CM.Disp.CreateStatsListing("withTooltip", 'Prestige Level (CUR / MAX)', document.createTextNode(Beautify(Game.prestige) + ' / ' + Beautify(possiblePresMax)), 'PrestMaxTooltipPlaceholder')); - var neededCook = Game.HowManyCookiesReset(possiblePresMax + 1) - (CM.Cache.RealCookiesEarned + Game.cookiesReset + CM.Cache.WrinkGodBank + ((Game.HasUnlocked('Chocolate egg') && !Game.Has('Chocolate egg') ? CM.Cache.lastChoEgg : 0) ? CM.Cache.lastChoEgg : 0)); + var neededCook = Game.HowManyCookiesReset(possiblePresMax + 1) - (CM.Cache.RealCookiesEarned + Game.cookiesReset + CM.Cache.WrinklersTotal + ((Game.HasUnlocked('Chocolate egg') && !Game.Has('Chocolate egg') ? CM.Cache.lastChoEgg : 0) ? CM.Cache.lastChoEgg : 0)); var cookiesNextFrag = document.createDocumentFragment(); cookiesNextFrag.appendChild(document.createTextNode(Beautify(neededCook))); var cookiesNextSmall = document.createElement('small'); @@ -3959,7 +3964,7 @@ CM.Loop = function() { } // Update Wrinkler Bank - CM.Cache.RemakeWrinkBank(); + CM.Cache.CacheWrinklers(); // Calculate PP CM.Cache.RemakePP(); diff --git a/src/Cache.js b/src/Cache.js index c575948..2307ffc 100644 --- a/src/Cache.js +++ b/src/Cache.js @@ -13,6 +13,7 @@ */ CM.Cache.InitCache = function() { CM.Cache.CacheDragonAuras(); + CM.Cache.CacheWrinklers(); } /******** @@ -20,10 +21,13 @@ CM.Cache.InitCache = function() { /** * This functions caches the currently selected Dragon Auras - * It is called by CM.Sim.CopyData() and CM.Sim.InitData() + * It is called by CM.Sim.CopyData() and CM.Cache.InitCache() * Uncapitalized dragon follows Game-naming + * @global {number} CM.Cache.dragonAura The number of the first (right) Aura + * @global {number} CM.Cache.dragonAura2 The number of the second (left) Aura */ CM.Cache.CacheDragonAuras = function() { + /** @global */ CM.Cache.dragonAura = Game.dragonAura; CM.Cache.dragonAura2 = Game.dragonAura2; } @@ -33,12 +37,15 @@ CM.Cache.CacheDragonAuras = function() { /** * This functions caches data related to Wrinklers - * It is called by CM.Loop() + * It is called by CM.Loop() and CM.Cache.InitCache() + * @global {number} CM.Cache.WrinklersTotal The cookies of all wrinklers + * @global {number} CM.Cache.WrinklersNormal The cookies of all normal wrinklers + * @global {[{number}, {number}]} CM.Cache.WrinklersFattest A list containing the cookies and the id of the fattest wrinkler */ -CM.Cache.RemakeWrinkBank = function() { - CM.Cache.WrinkBankTotal = 0; - CM.Cache.WrinkBankNormal = 0; - var totalSucked = 0; +CM.Cache.CacheWrinklers = function() { + CM.Cache.WrinklersTotal = 0; + CM.Cache.WrinklersNormal = 0; + CM.Cache.WrinklersFattest = [0, null]; for (var i in Game.wrinklers) { var sucked = Game.wrinklers[i].sucked; var toSuck = 1.1; @@ -52,19 +59,12 @@ CM.Cache.RemakeWrinkBank = function() { else if (godLvl == 2) sucked *= 1.1; else if (godLvl == 3) sucked *= 1.05; } - CM.Cache.WrinkBankTotal += sucked; - if (Game.wrinklers[i].type == 0) CM.Cache.WrinkBankNormal += sucked; - } - CM.Cache.WrinkGodBank = CM.Cache.WrinkBankTotal; - if (CM.Sim.Objects.Temple.minigameLoaded) { - var godLvl = CM.Sim.hasGod('scorn'); - if (godLvl == 2) CM.Cache.WrinkGodBank = CM.Cache.WrinkGodBank * 1.15 / 1.1; - else if (godLvl == 3) CM.Cache.WrinkGodBank = CM.Cache.WrinkGodBank * 1.15 / 1.05; - else if (godLvl != 1) CM.Cache.WrinkGodBank *= 1.15; + CM.Cache.WrinklersTotal += sucked; + if (Game.wrinklers[i].type == 0) CM.Cache.WrinklersNormal += sucked; + if (sucked > CM.Cache.WrinklersFattest[0]) CM.Cache.WrinklersFattest = [sucked, i]; } } - /******** * Section: UNSORTED */ @@ -405,7 +405,7 @@ CM.Cache.UpdateAvgCPS = function() { if (CM.Cache.lastDate != currDate) { var choEggTotal = Game.cookies + CM.Cache.SellForChoEgg; if (Game.cpsSucked > 0) { - choEggTotal += CM.Cache.WrinkGodBank; + choEggTotal += CM.Cache.WrinklersTotal; } CM.Cache.RealCookiesEarned = Math.max(Game.cookiesEarned, choEggTotal); choEggTotal *= 0.05; @@ -413,7 +413,7 @@ CM.Cache.UpdateAvgCPS = function() { if (CM.Cache.lastDate != -1) { var timeDiff = currDate - CM.Cache.lastDate var bankDiffAvg = Math.max(0, (Game.cookies - CM.Cache.lastCookies)) / timeDiff; - var wrinkDiffAvg = Math.max(0, (CM.Cache.WrinkBankTotal - CM.Cache.lastWrinkCookies)) / timeDiff; + var wrinkDiffAvg = Math.max(0, (CM.Cache.WrinklersTotal - CM.Cache.lastWrinkCookies)) / timeDiff; var choEggDiffAvg = Math.max(0,(choEggTotal - CM.Cache.lastChoEgg)) / timeDiff; var clicksDiffAvg = (Game.cookieClicks - CM.Cache.lastClicks) / timeDiff; for (var i = 0; i < timeDiff; i++) { @@ -435,7 +435,7 @@ CM.Cache.UpdateAvgCPS = function() { } CM.Cache.lastDate = currDate; CM.Cache.lastCookies = Game.cookies; - CM.Cache.lastWrinkCookies = CM.Cache.WrinkBankTotal; + CM.Cache.lastWrinkCookies = CM.Cache.WrinklersTotal; CM.Cache.lastChoEgg = choEggTotal; CM.Cache.lastClicks = Game.cookieClicks; @@ -518,9 +518,6 @@ CM.Cache.CalcMissingUpgrades = function() { CM.Cache.min = -1; CM.Cache.max = -1; CM.Cache.mid = -1; -CM.Cache.WrinkBankTotal = -1; -CM.Cache.WrinkBankNormal = -1; -CM.Cache.WrinkGodBank = -1; CM.Cache.GoldenCookiesMult = 1; CM.Cache.WrathCookiesMult = 1; CM.Cache.DragonsFortuneMultAdjustment = 1; diff --git a/src/Disp.js b/src/Disp.js index 7516ed8..8513c30 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -13,11 +13,11 @@ /** * This function returns the total amount stored in the Wrinkler Bank * as calculated by CM.Cache.RemakeWrinkBank() if CM.Options.CalcWrink is set - * @returns {number} 0 or the amount of cookies stored (CM.Cache.WrinkBankTotal) + * @returns {number} 0 or the amount of cookies stored (CM.Cache.WrinklersTotal) */ CM.Disp.GetWrinkConfigBank = function() { if (CM.Options.CalcWrink) - return CM.Cache.WrinkBankTotal; + return CM.Cache.WrinklersTotal; else return 0; } @@ -2119,13 +2119,21 @@ CM.Disp.AddMenuStats = function(title) { stats.appendChild(CM.Disp.CreateStatsHeader('Wrinklers', 'Wrink')); if (CM.Options.Header.Wrink) { var popAllFrag = document.createDocumentFragment(); - popAllFrag.appendChild(document.createTextNode(Beautify(CM.Cache.WrinkBankTotal) + ' / ' + Beautify(CM.Cache.WrinkBankNormal) + ' ')); + popAllFrag.appendChild(document.createTextNode(Beautify(CM.Cache.WrinklersTotal) + ' / ' + Beautify(CM.Cache.WrinklersNormal) + ' ')); var popAllA = document.createElement('a'); popAllA.textContent = 'Pop All Normal'; popAllA.className = 'option'; popAllA.onclick = function() { CM.Disp.PopAllNormalWrinklers(); }; popAllFrag.appendChild(popAllA); stats.appendChild(CM.Disp.CreateStatsListing("basic", 'Rewards of Popping (All/Normal)', popAllFrag)); + var popFattestFrag = document.createDocumentFragment(); + popFattestFrag.appendChild(document.createTextNode(Beautify(CM.Cache.WrinklersFattest[0]) + ' ')); + var popFattestA = document.createElement('a'); + popFattestA.textContent = 'Pop single fattest'; + popFattestA.className = 'option'; + popFattestA.onclick = function() { Game.wrinklers[CM.Cache.WrinklersFattest[1]].hp = 0; }; + popFattestFrag.appendChild(popFattestA); + stats.appendChild(CM.Disp.CreateStatsListing("basic", 'Rewards of Popping Single Fattest Wrinkler (id: ' + CM.Cache.WrinklersFattest[1] + ")", popFattestFrag)); } } @@ -2530,11 +2538,11 @@ CM.Disp.CreateStatsPrestigeSection = function() { section.className = 'CMStatsPrestigeSection'; var possiblePresMax = Math.floor(Game.HowMuchPrestige(CM.Cache.RealCookiesEarned + - Game.cookiesReset + CM.Cache.WrinkGodBank + + Game.cookiesReset + CM.Cache.WrinklersTotal + (Game.HasUnlocked('Chocolate egg') && !Game.Has('Chocolate egg') ? CM.Cache.lastChoEgg : 0))); section.appendChild(CM.Disp.CreateStatsListing("withTooltip", 'Prestige Level (CUR / MAX)', document.createTextNode(Beautify(Game.prestige) + ' / ' + Beautify(possiblePresMax)), 'PrestMaxTooltipPlaceholder')); - var neededCook = Game.HowManyCookiesReset(possiblePresMax + 1) - (CM.Cache.RealCookiesEarned + Game.cookiesReset + CM.Cache.WrinkGodBank + ((Game.HasUnlocked('Chocolate egg') && !Game.Has('Chocolate egg') ? CM.Cache.lastChoEgg : 0) ? CM.Cache.lastChoEgg : 0)); + var neededCook = Game.HowManyCookiesReset(possiblePresMax + 1) - (CM.Cache.RealCookiesEarned + Game.cookiesReset + CM.Cache.WrinklersTotal + ((Game.HasUnlocked('Chocolate egg') && !Game.Has('Chocolate egg') ? CM.Cache.lastChoEgg : 0) ? CM.Cache.lastChoEgg : 0)); var cookiesNextFrag = document.createDocumentFragment(); cookiesNextFrag.appendChild(document.createTextNode(Beautify(neededCook))); var cookiesNextSmall = document.createElement('small'); diff --git a/src/Main.js b/src/Main.js index 80d16ea..ff447e1 100644 --- a/src/Main.js +++ b/src/Main.js @@ -171,7 +171,7 @@ CM.Loop = function() { } // Update Wrinkler Bank - CM.Cache.RemakeWrinkBank(); + CM.Cache.CacheWrinklers(); // Calculate PP CM.Cache.RemakePP(); From 07d73b10e36b87f47241da934e1c88df9628904f Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Sat, 19 Dec 2020 18:32:53 +0100 Subject: [PATCH 077/106] Option to calc with single fattest wrinkler (#245) --- CookieMonster.js | 17 ++++++++++------- src/Cache.js | 3 ++- src/Data.js | 2 +- src/Disp.js | 12 +++++++----- 4 files changed, 20 insertions(+), 14 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index 15a3da1..42d30ea 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -506,7 +506,8 @@ CM.Cache.UpdateAvgCPS = function() { totalGainWrink += sortedGainWrink[i]; totalGainChoEgg += sortedGainChoEgg[i]; } - CM.Cache.AvgCPS = (totalGainBank + (CM.Options.CalcWrink ? totalGainWrink : 0)) / sortedGainBank.length; + // TODO: Incorporate situation if CM.Options.CalcWrink == 2 + CM.Cache.AvgCPS = (totalGainBank + (CM.Options.CalcWrink == 1 ? totalGainWrink : 0)) / sortedGainBank.length; var choEgg = (Game.HasUnlocked('Chocolate egg') && !Game.Has('Chocolate egg')); @@ -869,7 +870,7 @@ CM.ConfigData.Colors = { type: 'color', group: 'BarsColors', CM.ConfigData.UpgradeBarFixedPos = {type: 'bool', group: 'BarsColors', label: ['Upgrade Bar Fixed Position OFF', 'Upgrade Bar Fixed Position ON'], desc: 'Lock the upgrade bar at top of the screen to prevent it from moving ofscreen when scrolling', toggle: true, func: function() {CM.Disp.ToggleUpgradeBarFixedPos();}}; // Calculation -CM.ConfigData.CalcWrink = {type: 'bool', group: 'Calculation', label: ['Calculate with Wrinklers OFF', 'Calculate with Wrinklers ON'], desc: 'Calculate times and average Cookies Per Second with Wrinklers', toggle: true}; +CM.ConfigData.CalcWrink = {type: 'bool', group: 'Calculation', label: ['Calculate with Wrinklers OFF', 'Calculate with Wrinklers ON', 'Calculate with Single Fattest Wrinkler ON'], desc: 'Calculate times and average Cookies Per Second with (only the single fattest) Wrinklers', toggle: true}; CM.ConfigData.CPSMode = {type: 'bool', group: 'Calculation', label: ['Current Cookies Per Second', 'Average Cookies Per Second'], desc: 'Calculate times using current Cookies Per Second or average Cookies Per Second', toggle: false}; CM.ConfigData.AvgCPSHist = {type: 'bool', group: 'Calculation', label: ['Average CPS for past 10s', 'Average CPS for past 15s', 'Average CPS for past 30s', 'Average CPS for past 1m', 'Average CPS for past 5m', 'Average CPS for past 10m', 'Average CPS for past 15m', 'Average CPS for past 30m'], desc: 'How much time average Cookies Per Second should consider', toggle: false}; CM.ConfigData.AvgClicksHist = {type: 'bool', group: 'Calculation', label: ['Average Cookie Clicks for past 1s', 'Average Cookie Clicks for past 5s', 'Average Cookie Clicks for past 10s', 'Average Cookie Clicks for past 15s', 'Average Cookie Clicks for past 30s'], desc: 'How much time average Cookie Clicks should consider', toggle: false}; @@ -1054,14 +1055,16 @@ CM.Data.ConfigDefault = { /** * This function returns the total amount stored in the Wrinkler Bank - * as calculated by CM.Cache.RemakeWrinkBank() if CM.Options.CalcWrink is set + * as calculated by CM.Cache.CacheWrinklers() if CM.Options.CalcWrink is set * @returns {number} 0 or the amount of cookies stored (CM.Cache.WrinklersTotal) */ CM.Disp.GetWrinkConfigBank = function() { - if (CM.Options.CalcWrink) - return CM.Cache.WrinklersTotal; - else - return 0; + if (CM.Options.CalcWrink == 1) { + return CM.Cache.WrinklersTotal;} + else if (CM.Options.CalcWrink == 2) { + return CM.Cache.WrinklersFattest[0];} + else { + return 0;} } /** diff --git a/src/Cache.js b/src/Cache.js index 2307ffc..c8377c9 100644 --- a/src/Cache.js +++ b/src/Cache.js @@ -477,7 +477,8 @@ CM.Cache.UpdateAvgCPS = function() { totalGainWrink += sortedGainWrink[i]; totalGainChoEgg += sortedGainChoEgg[i]; } - CM.Cache.AvgCPS = (totalGainBank + (CM.Options.CalcWrink ? totalGainWrink : 0)) / sortedGainBank.length; + // TODO: Incorporate situation if CM.Options.CalcWrink == 2 + CM.Cache.AvgCPS = (totalGainBank + (CM.Options.CalcWrink == 1 ? totalGainWrink : 0)) / sortedGainBank.length; var choEgg = (Game.HasUnlocked('Chocolate egg') && !Game.Has('Chocolate egg')); diff --git a/src/Data.js b/src/Data.js index ee4c109..e96b951 100644 --- a/src/Data.js +++ b/src/Data.js @@ -103,7 +103,7 @@ CM.ConfigData.Colors = { type: 'color', group: 'BarsColors', CM.ConfigData.UpgradeBarFixedPos = {type: 'bool', group: 'BarsColors', label: ['Upgrade Bar Fixed Position OFF', 'Upgrade Bar Fixed Position ON'], desc: 'Lock the upgrade bar at top of the screen to prevent it from moving ofscreen when scrolling', toggle: true, func: function() {CM.Disp.ToggleUpgradeBarFixedPos();}}; // Calculation -CM.ConfigData.CalcWrink = {type: 'bool', group: 'Calculation', label: ['Calculate with Wrinklers OFF', 'Calculate with Wrinklers ON'], desc: 'Calculate times and average Cookies Per Second with Wrinklers', toggle: true}; +CM.ConfigData.CalcWrink = {type: 'bool', group: 'Calculation', label: ['Calculate with Wrinklers OFF', 'Calculate with Wrinklers ON', 'Calculate with Single Fattest Wrinkler ON'], desc: 'Calculate times and average Cookies Per Second with (only the single fattest) Wrinklers', toggle: true}; CM.ConfigData.CPSMode = {type: 'bool', group: 'Calculation', label: ['Current Cookies Per Second', 'Average Cookies Per Second'], desc: 'Calculate times using current Cookies Per Second or average Cookies Per Second', toggle: false}; CM.ConfigData.AvgCPSHist = {type: 'bool', group: 'Calculation', label: ['Average CPS for past 10s', 'Average CPS for past 15s', 'Average CPS for past 30s', 'Average CPS for past 1m', 'Average CPS for past 5m', 'Average CPS for past 10m', 'Average CPS for past 15m', 'Average CPS for past 30m'], desc: 'How much time average Cookies Per Second should consider', toggle: false}; CM.ConfigData.AvgClicksHist = {type: 'bool', group: 'Calculation', label: ['Average Cookie Clicks for past 1s', 'Average Cookie Clicks for past 5s', 'Average Cookie Clicks for past 10s', 'Average Cookie Clicks for past 15s', 'Average Cookie Clicks for past 30s'], desc: 'How much time average Cookie Clicks should consider', toggle: false}; diff --git a/src/Disp.js b/src/Disp.js index 8513c30..261b707 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -12,14 +12,16 @@ /** * This function returns the total amount stored in the Wrinkler Bank - * as calculated by CM.Cache.RemakeWrinkBank() if CM.Options.CalcWrink is set + * as calculated by CM.Cache.CacheWrinklers() if CM.Options.CalcWrink is set * @returns {number} 0 or the amount of cookies stored (CM.Cache.WrinklersTotal) */ CM.Disp.GetWrinkConfigBank = function() { - if (CM.Options.CalcWrink) - return CM.Cache.WrinklersTotal; - else - return 0; + if (CM.Options.CalcWrink == 1) { + return CM.Cache.WrinklersTotal;} + else if (CM.Options.CalcWrink == 2) { + return CM.Cache.WrinklersFattest[0];} + else { + return 0;} } /** From 51617c97772b861993cff74170e4a377a4555a4e Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Sun, 20 Dec 2020 11:50:48 +0100 Subject: [PATCH 078/106] Added ToolWarnEdifice option --- CookieMonster.js | 2 ++ src/Data.js | 2 ++ 2 files changed, 4 insertions(+) diff --git a/CookieMonster.js b/CookieMonster.js index 42d30ea..f3e281c 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -942,6 +942,7 @@ CM.ConfigData.TooltipAmor = {type: 'bool', group: 'Tooltip', label: ['Buildings CM.ConfigData.ToolWarnLucky = {type: 'bool', group: 'Tooltip', label: ['Tooltip Lucky Warning OFF', 'Tooltip Lucky Warning ON'], desc: 'A warning when buying if it will put the bank under the amount needed for max "Lucky!" rewards', toggle: true}; CM.ConfigData.ToolWarnLuckyFrenzy = {type: 'bool', group: 'Tooltip', label: ['Tooltip Lucky Frenzy Warning OFF', 'Tooltip Lucky Frenzy Warning ON'], desc: 'A warning when buying if it will put the bank under the amount needed for max "Lucky!" (Frenzy) rewards', toggle: true}; CM.ConfigData.ToolWarnConjure = {type: 'bool', group: 'Tooltip', label: ['Tooltip Conjure Warning OFF', 'Tooltip Conjure Warning ON'], desc: 'A warning when buying if it will put the bank under the amount needed for max "Conjure Baked Goods" rewards', toggle: true}; +CM.ConfigData.ToolWarnEdifice = {type: 'bool', group: 'Tooltip', label: ['Tooltip Edifice Warning OFF', 'Tooltip Edifice Warning ON'], desc: 'A warning when buying if it will put the bank under the amount needed for "Spontaneous Edifice" to give you your most expensive building', toggle: true}; CM.ConfigData.ToolWarnPos = {type: 'bool', group: 'Tooltip', label: ['Tooltip Warning Position (Left)', 'Tooltip Warning Position (Bottom)'], desc: 'Placement of the warning boxes', toggle: false, func: function() {CM.Disp.ToggleToolWarnPos();}}; CM.ConfigData.TooltipGrim = {type: 'bool', group: 'Tooltip', label: ['Grimoire Tooltip Information OFF', 'Grimoire Tooltip Information ON'], desc: 'Extra information in tooltip for grimoire', toggle: true}; CM.ConfigData.ToolWrink = {type: 'bool', group: 'Tooltip', label: ['Wrinkler Tooltip OFF', 'Wrinkler Tooltip ON'], desc: 'Shows the amount of cookies a wrinkler will give when popping it', toggle: true}; @@ -1022,6 +1023,7 @@ CM.Data.ConfigDefault = { ToolWarnLucky: 1, ToolWarnLuckyFrenzy: 1, ToolWarnConjure: 1, + ToolWarnEdifice: 1, ToolWarnPos: 1, TooltipGrim:1, ToolWrink: 1, diff --git a/src/Data.js b/src/Data.js index e96b951..8d3290d 100644 --- a/src/Data.js +++ b/src/Data.js @@ -175,6 +175,7 @@ CM.ConfigData.TooltipAmor = {type: 'bool', group: 'Tooltip', label: ['Buildings CM.ConfigData.ToolWarnLucky = {type: 'bool', group: 'Tooltip', label: ['Tooltip Lucky Warning OFF', 'Tooltip Lucky Warning ON'], desc: 'A warning when buying if it will put the bank under the amount needed for max "Lucky!" rewards', toggle: true}; CM.ConfigData.ToolWarnLuckyFrenzy = {type: 'bool', group: 'Tooltip', label: ['Tooltip Lucky Frenzy Warning OFF', 'Tooltip Lucky Frenzy Warning ON'], desc: 'A warning when buying if it will put the bank under the amount needed for max "Lucky!" (Frenzy) rewards', toggle: true}; CM.ConfigData.ToolWarnConjure = {type: 'bool', group: 'Tooltip', label: ['Tooltip Conjure Warning OFF', 'Tooltip Conjure Warning ON'], desc: 'A warning when buying if it will put the bank under the amount needed for max "Conjure Baked Goods" rewards', toggle: true}; +CM.ConfigData.ToolWarnEdifice = {type: 'bool', group: 'Tooltip', label: ['Tooltip Edifice Warning OFF', 'Tooltip Edifice Warning ON'], desc: 'A warning when buying if it will put the bank under the amount needed for "Spontaneous Edifice" to give you your most expensive building', toggle: true}; CM.ConfigData.ToolWarnPos = {type: 'bool', group: 'Tooltip', label: ['Tooltip Warning Position (Left)', 'Tooltip Warning Position (Bottom)'], desc: 'Placement of the warning boxes', toggle: false, func: function() {CM.Disp.ToggleToolWarnPos();}}; CM.ConfigData.TooltipGrim = {type: 'bool', group: 'Tooltip', label: ['Grimoire Tooltip Information OFF', 'Grimoire Tooltip Information ON'], desc: 'Extra information in tooltip for grimoire', toggle: true}; CM.ConfigData.ToolWrink = {type: 'bool', group: 'Tooltip', label: ['Wrinkler Tooltip OFF', 'Wrinkler Tooltip ON'], desc: 'Shows the amount of cookies a wrinkler will give when popping it', toggle: true}; @@ -255,6 +256,7 @@ CM.Data.ConfigDefault = { ToolWarnLucky: 1, ToolWarnLuckyFrenzy: 1, ToolWarnConjure: 1, + ToolWarnEdifice: 1, ToolWarnPos: 1, TooltipGrim:1, ToolWrink: 1, From a05c9290de6e2192f156e51c4d50c91f0b3b5ff4 Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Sun, 20 Dec 2020 12:15:50 +0100 Subject: [PATCH 079/106] Created warning for ToolWarnEdifice --- CookieMonster.js | 38 ++++++++++++++++++++++++++++++-------- src/Data.js | 5 +++-- src/Disp.js | 32 ++++++++++++++++++++++++++------ 3 files changed, 59 insertions(+), 16 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index f3e281c..fe706cc 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -942,7 +942,7 @@ CM.ConfigData.TooltipAmor = {type: 'bool', group: 'Tooltip', label: ['Buildings CM.ConfigData.ToolWarnLucky = {type: 'bool', group: 'Tooltip', label: ['Tooltip Lucky Warning OFF', 'Tooltip Lucky Warning ON'], desc: 'A warning when buying if it will put the bank under the amount needed for max "Lucky!" rewards', toggle: true}; CM.ConfigData.ToolWarnLuckyFrenzy = {type: 'bool', group: 'Tooltip', label: ['Tooltip Lucky Frenzy Warning OFF', 'Tooltip Lucky Frenzy Warning ON'], desc: 'A warning when buying if it will put the bank under the amount needed for max "Lucky!" (Frenzy) rewards', toggle: true}; CM.ConfigData.ToolWarnConjure = {type: 'bool', group: 'Tooltip', label: ['Tooltip Conjure Warning OFF', 'Tooltip Conjure Warning ON'], desc: 'A warning when buying if it will put the bank under the amount needed for max "Conjure Baked Goods" rewards', toggle: true}; -CM.ConfigData.ToolWarnEdifice = {type: 'bool', group: 'Tooltip', label: ['Tooltip Edifice Warning OFF', 'Tooltip Edifice Warning ON'], desc: 'A warning when buying if it will put the bank under the amount needed for "Spontaneous Edifice" to give you your most expensive building', toggle: true}; +CM.ConfigData.ToolWarnEdifice = {type: 'bool', group: 'Tooltip', label: ['Tooltip Edifice Warning OFF', 'Tooltip Edifice Warning ON'], desc: 'A warning when buying if it will put the bank under the amount needed for "Spontaneous Edifice" to possibly give you your most expensive building', toggle: true}; CM.ConfigData.ToolWarnPos = {type: 'bool', group: 'Tooltip', label: ['Tooltip Warning Position (Left)', 'Tooltip Warning Position (Bottom)'], desc: 'Placement of the warning boxes', toggle: false, func: function() {CM.Disp.ToggleToolWarnPos();}}; CM.ConfigData.TooltipGrim = {type: 'bool', group: 'Tooltip', label: ['Grimoire Tooltip Information OFF', 'Grimoire Tooltip Information ON'], desc: 'Extra information in tooltip for grimoire', toggle: true}; CM.ConfigData.ToolWrink = {type: 'bool', group: 'Tooltip', label: ['Wrinkler Tooltip OFF', 'Wrinkler Tooltip ON'], desc: 'Shows the amount of cookies a wrinkler will give when popping it', toggle: true}; @@ -1043,7 +1043,9 @@ CM.Data.ConfigDefault = { SortBuildings: 0, SortUpgrades: 0, Header: {BarsColors: 1, Calculation: 1, Notification: 1, Tooltip: 1, Statistics: 1, Notation: 1, Lucky: 1, Conjure: 1, Chain: 1, Prestige: 1, Wrink: 1, Sea: 1, Misc: 1}, -};/******** +}; + +/******** * Disp * ********/ @@ -2449,7 +2451,9 @@ CM.Disp.TooltipCreateWarningSection = function() { CM.Disp.TooltipWarn.appendChild(create('CMDispTooltipWarnLuckyFrenzy', CM.Disp.colorYellow, 'Warning: ', 'Purchase of this item will put you under the number of Cookies required for "Lucky!" (Frenzy)', 'CMDispTooltipWarnLuckyFrenzyText')); CM.Disp.TooltipWarn.lastChild.style.marginBottom = '4px'; CM.Disp.TooltipWarn.appendChild(create('CMDispTooltipWarnConjure', CM.Disp.colorPurple, 'Warning: ', 'Purchase of this item will put you under the number of Cookies required for "Conjure Baked Goods"', 'CMDispTooltipWarnConjureText')); - + CM.Disp.TooltipWarn.lastChild.style.marginBottom = '4px'; + CM.Disp.TooltipWarn.appendChild(create('CMDispTooltipWarnEdifice', CM.Disp.colorPurple, 'Warning: ', 'Purchase of this item will put you under the number of Cookies needed for "Spontaneous Edifice" to possibly give you your most expensive building"', 'CMDispTooltipWarnEdificeText')); + return CM.Disp.TooltipWarn; } @@ -2711,13 +2715,31 @@ CM.Disp.UpdateTooltipWarnings = function() { if ((amount < limitConjure) && (CM.Disp.tooltipType != 'b' || Game.buyMode == 1)) { l('CMDispTooltipWarnConjure').style.display = ''; l('CMDispTooltipWarnConjureText').textContent = Beautify(limitConjure - amount) + ' (' + CM.Disp.FormatTime((limitConjure - amount) / CM.Disp.GetCPS()) + ')'; - } else { - l('CMDispTooltipWarnConjure').style.display = 'none'; + } else l('CMDispTooltipWarnConjure').style.display = 'none'; + } + else l('CMDispTooltipWarnConjure').style.display = 'none'; + + if (CM.Options.ToolWarnEdifice == 1) { + var limitEdifice = 0; + var max = 0; + var n = 0; + for (var i in Game.Objects) { + if (Game.Objects[i].amount > max) max = Game.Objects[i].amount; + if (Game.Objects[i].amount > 0) n++; } + for (var i in Game.Objects) { + if ((Game.Objects[i].amount < max || n == 1) && + Game.Objects[i].amount < 400 && + Game.Objects[i].price * 2 > limitEdifice) { + limitEdifice = Game.Objects[i].price * 2; + } + } + if (limitEdifice && amount < limitEdifice && (CM.Disp.tooltipType != 'b' || Game.buyMode == 1)) { + l('CMDispTooltipWarnEdifice').style.display = ''; + l('CMDispTooltipWarnEdificeText').textContent = Beautify(limitEdifice - amount) + ' (' + CM.Disp.FormatTime((limitEdifice - amount) / CM.Disp.GetCPS()) + ')'; + } else l('CMDispTooltipWarnEdifice').style.display = 'none'; } - else { - l('CMDispTooltipWarnConjure').style.display = 'none'; - } + else l('CMDispTooltipWarnEdifice').style.display = 'none'; } else { if (l('CMDispTooltipWarningParent') != null) { diff --git a/src/Data.js b/src/Data.js index 8d3290d..5bb518e 100644 --- a/src/Data.js +++ b/src/Data.js @@ -175,7 +175,7 @@ CM.ConfigData.TooltipAmor = {type: 'bool', group: 'Tooltip', label: ['Buildings CM.ConfigData.ToolWarnLucky = {type: 'bool', group: 'Tooltip', label: ['Tooltip Lucky Warning OFF', 'Tooltip Lucky Warning ON'], desc: 'A warning when buying if it will put the bank under the amount needed for max "Lucky!" rewards', toggle: true}; CM.ConfigData.ToolWarnLuckyFrenzy = {type: 'bool', group: 'Tooltip', label: ['Tooltip Lucky Frenzy Warning OFF', 'Tooltip Lucky Frenzy Warning ON'], desc: 'A warning when buying if it will put the bank under the amount needed for max "Lucky!" (Frenzy) rewards', toggle: true}; CM.ConfigData.ToolWarnConjure = {type: 'bool', group: 'Tooltip', label: ['Tooltip Conjure Warning OFF', 'Tooltip Conjure Warning ON'], desc: 'A warning when buying if it will put the bank under the amount needed for max "Conjure Baked Goods" rewards', toggle: true}; -CM.ConfigData.ToolWarnEdifice = {type: 'bool', group: 'Tooltip', label: ['Tooltip Edifice Warning OFF', 'Tooltip Edifice Warning ON'], desc: 'A warning when buying if it will put the bank under the amount needed for "Spontaneous Edifice" to give you your most expensive building', toggle: true}; +CM.ConfigData.ToolWarnEdifice = {type: 'bool', group: 'Tooltip', label: ['Tooltip Edifice Warning OFF', 'Tooltip Edifice Warning ON'], desc: 'A warning when buying if it will put the bank under the amount needed for "Spontaneous Edifice" to possibly give you your most expensive building', toggle: true}; CM.ConfigData.ToolWarnPos = {type: 'bool', group: 'Tooltip', label: ['Tooltip Warning Position (Left)', 'Tooltip Warning Position (Bottom)'], desc: 'Placement of the warning boxes', toggle: false, func: function() {CM.Disp.ToggleToolWarnPos();}}; CM.ConfigData.TooltipGrim = {type: 'bool', group: 'Tooltip', label: ['Grimoire Tooltip Information OFF', 'Grimoire Tooltip Information ON'], desc: 'Extra information in tooltip for grimoire', toggle: true}; CM.ConfigData.ToolWrink = {type: 'bool', group: 'Tooltip', label: ['Wrinkler Tooltip OFF', 'Wrinkler Tooltip ON'], desc: 'Shows the amount of cookies a wrinkler will give when popping it', toggle: true}; @@ -276,4 +276,5 @@ CM.Data.ConfigDefault = { SortBuildings: 0, SortUpgrades: 0, Header: {BarsColors: 1, Calculation: 1, Notification: 1, Tooltip: 1, Statistics: 1, Notation: 1, Lucky: 1, Conjure: 1, Chain: 1, Prestige: 1, Wrink: 1, Sea: 1, Misc: 1}, -}; \ No newline at end of file +}; + diff --git a/src/Disp.js b/src/Disp.js index 261b707..8141621 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -1404,7 +1404,9 @@ CM.Disp.TooltipCreateWarningSection = function() { CM.Disp.TooltipWarn.appendChild(create('CMDispTooltipWarnLuckyFrenzy', CM.Disp.colorYellow, 'Warning: ', 'Purchase of this item will put you under the number of Cookies required for "Lucky!" (Frenzy)', 'CMDispTooltipWarnLuckyFrenzyText')); CM.Disp.TooltipWarn.lastChild.style.marginBottom = '4px'; CM.Disp.TooltipWarn.appendChild(create('CMDispTooltipWarnConjure', CM.Disp.colorPurple, 'Warning: ', 'Purchase of this item will put you under the number of Cookies required for "Conjure Baked Goods"', 'CMDispTooltipWarnConjureText')); - + CM.Disp.TooltipWarn.lastChild.style.marginBottom = '4px'; + CM.Disp.TooltipWarn.appendChild(create('CMDispTooltipWarnEdifice', CM.Disp.colorPurple, 'Warning: ', 'Purchase of this item will put you under the number of Cookies needed for "Spontaneous Edifice" to possibly give you your most expensive building"', 'CMDispTooltipWarnEdificeText')); + return CM.Disp.TooltipWarn; } @@ -1666,13 +1668,31 @@ CM.Disp.UpdateTooltipWarnings = function() { if ((amount < limitConjure) && (CM.Disp.tooltipType != 'b' || Game.buyMode == 1)) { l('CMDispTooltipWarnConjure').style.display = ''; l('CMDispTooltipWarnConjureText').textContent = Beautify(limitConjure - amount) + ' (' + CM.Disp.FormatTime((limitConjure - amount) / CM.Disp.GetCPS()) + ')'; - } else { - l('CMDispTooltipWarnConjure').style.display = 'none'; + } else l('CMDispTooltipWarnConjure').style.display = 'none'; + } + else l('CMDispTooltipWarnConjure').style.display = 'none'; + + if (CM.Options.ToolWarnEdifice == 1) { + var limitEdifice = 0; + var max = 0; + var n = 0; + for (var i in Game.Objects) { + if (Game.Objects[i].amount > max) max = Game.Objects[i].amount; + if (Game.Objects[i].amount > 0) n++; } + for (var i in Game.Objects) { + if ((Game.Objects[i].amount < max || n == 1) && + Game.Objects[i].amount < 400 && + Game.Objects[i].price * 2 > limitEdifice) { + limitEdifice = Game.Objects[i].price * 2; + } + } + if (limitEdifice && amount < limitEdifice && (CM.Disp.tooltipType != 'b' || Game.buyMode == 1)) { + l('CMDispTooltipWarnEdifice').style.display = ''; + l('CMDispTooltipWarnEdificeText').textContent = Beautify(limitEdifice - amount) + ' (' + CM.Disp.FormatTime((limitEdifice - amount) / CM.Disp.GetCPS()) + ')'; + } else l('CMDispTooltipWarnEdifice').style.display = 'none'; } - else { - l('CMDispTooltipWarnConjure').style.display = 'none'; - } + else l('CMDispTooltipWarnEdifice').style.display = 'none'; } else { if (l('CMDispTooltipWarningParent') != null) { From 1715306374e34152ab0530146da570dbe8f8b90b Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Sun, 20 Dec 2020 12:27:43 +0100 Subject: [PATCH 080/106] Removed tooltip box from Sell tooltip --- CookieMonster.js | 8 +++++--- src/Disp.js | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index fe706cc..b9f99be 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -2317,9 +2317,11 @@ CM.Disp.Tooltip = function(type, name) { else if (type === 'g') l('tooltip').innerHTML = Game.Objects['Wizard tower'].minigame.spellTooltip(name)(); // Grimoire // Adds area for extra tooltip-sections - var area = document.createElement('div'); - area.id = 'CMTooltipArea'; - l('tooltip').appendChild(area); + if ((type == 'b' && Game.buyMode == 1) || type == 'u' || type == 's' || type == 'g') { + var area = document.createElement('div'); + area.id = 'CMTooltipArea'; + l('tooltip').appendChild(area); + } // Sets global variables used by CM.Disp.UpdateTooltip() CM.Disp.tooltipType = type; diff --git a/src/Disp.js b/src/Disp.js index 8141621..4993eec 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -1270,9 +1270,11 @@ CM.Disp.Tooltip = function(type, name) { else if (type === 'g') l('tooltip').innerHTML = Game.Objects['Wizard tower'].minigame.spellTooltip(name)(); // Grimoire // Adds area for extra tooltip-sections - var area = document.createElement('div'); - area.id = 'CMTooltipArea'; - l('tooltip').appendChild(area); + if ((type == 'b' && Game.buyMode == 1) || type == 'u' || type == 's' || type == 'g') { + var area = document.createElement('div'); + area.id = 'CMTooltipArea'; + l('tooltip').appendChild(area); + } // Sets global variables used by CM.Disp.UpdateTooltip() CM.Disp.tooltipType = type; From 5d5256bfc9ebce69047f4e92d06dbb0865751119 Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Sun, 20 Dec 2020 13:09:16 +0100 Subject: [PATCH 081/106] Added Edifice to Spells stats section --- CookieMonster.js | 124 ++++++++++++++++++++++++++--------------------- src/Cache.js | 84 +++++++++++++++++++++----------- src/Data.js | 2 +- src/Disp.js | 35 +++++-------- src/Main.js | 3 +- 5 files changed, 140 insertions(+), 108 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index b9f99be..3b037d0 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -43,6 +43,7 @@ if (typeof CM == "undefined") { CM.Cache.InitCache = function() { CM.Cache.CacheDragonAuras(); CM.Cache.CacheWrinklers(); + CM.Cache.CacheStats(); } /******** @@ -94,6 +95,60 @@ CM.Cache.CacheWrinklers = function() { } } +/******** + * Section: Functions related to Cachining stats */ + +/** + * This functions caches variables related to the stats apge + * It is called by CM.Loop() upon changes to cps and CM.Cache.InitCache() + * @global {number} CM.Cache.Lucky Cookies required for max Lucky + * @global {number} CM.Cache.LuckyReward Reward for max normal Lucky + * @global {number} CM.Cache.LuckyWrathReward Reward for max normal Lucky from Wrath cookie + * @global {number} CM.Cache.LuckyFrenzy Cookies required for max Lucky Frenzy + * @global {number} CM.Cache.LuckyRewardFrenzy Reward for max Lucky Frenzy + * @global {number} CM.Cache.LuckyWrathRewardFrenzy Reward for max Lucky Frenzy from Wrath cookie + * @global {number} CM.Cache.Conjure Cookies required for max Conjure Baked Goods + * @global {number} CM.Cache.ConjureReward Reward for max Conjure Baked Goods + * @global {number} CM.Cache.Edifice Cookies required for most expensive building through Spontaneous Edifice + * @global {string} CM.Cache.EdificeBuilding Name of most expensive building possible with Spontaneous Edifice + */ +CM.Cache.CacheStats = function() { + var goldenMult = CM.Cache.GoldenCookiesMult; + var wrathMult = CM.Cache.WrathCookiesMult; + + CM.Cache.Lucky = (CM.Cache.NoGoldSwitchCookiesPS * 900) / 0.15; + CM.Cache.Lucky *= CM.Cache.DragonsFortuneMultAdjustment; + var cpsBuffMult = CM.Sim.getCPSBuffMult(); + if (cpsBuffMult > 0) { + CM.Cache.Lucky /= cpsBuffMult; + } else { + CM.Cache.Lucky = 0; + } + CM.Cache.LuckyReward = goldenMult * (CM.Cache.Lucky * 0.15) + 13; + CM.Cache.LuckyWrathReward = wrathMult * (CM.Cache.Lucky * 0.15) + 13; + CM.Cache.LuckyFrenzy = CM.Cache.Lucky * 7; + CM.Cache.LuckyRewardFrenzy = goldenMult * (CM.Cache.LuckyFrenzy * 0.15) + 13; + CM.Cache.LuckyWrathRewardFrenzy = wrathMult * (CM.Cache.LuckyFrenzy * 0.15) + 13; + CM.Cache.Conjure = CM.Cache.Lucky * 2; + CM.Cache.ConjureReward = CM.Cache.Conjure * 0.15; + + CM.Cache.Edifice = 0; + var max = 0; + var n = 0; + for (var i in Game.Objects) { + if (Game.Objects[i].amount > max) max = Game.Objects[i].amount; + if (Game.Objects[i].amount > 0) n++; + } + for (var i in Game.Objects) { + if ((Game.Objects[i].amount < max || n == 1) && + Game.Objects[i].amount < 400 && + Game.Objects[i].price * 2 > CM.Cache.Edifice) { + CM.Cache.Edifice = Game.Objects[i].price * 2; + CM.Cache.EdificeBuilding = i; + } + } +} + /******** * Section: UNSORTED */ @@ -314,27 +369,6 @@ CM.Cache.RemakeGoldenAndWrathCookiesMults = function() { } } -CM.Cache.RemakeLucky = function() { - var goldenMult = CM.Cache.GoldenCookiesMult; - var wrathMult = CM.Cache.WrathCookiesMult; - - CM.Cache.Lucky = (CM.Cache.NoGoldSwitchCookiesPS * 900) / 0.15; - CM.Cache.Lucky *= CM.Cache.DragonsFortuneMultAdjustment; - var cpsBuffMult = CM.Sim.getCPSBuffMult(); - if (cpsBuffMult > 0) { - CM.Cache.Lucky /= cpsBuffMult; - } else { - CM.Cache.Lucky = 0; - } - CM.Cache.LuckyReward = goldenMult * (CM.Cache.Lucky * 0.15) + 13; - CM.Cache.LuckyWrathReward = wrathMult * (CM.Cache.Lucky * 0.15) + 13; - CM.Cache.LuckyFrenzy = CM.Cache.Lucky * 7; - CM.Cache.LuckyRewardFrenzy = goldenMult * (CM.Cache.LuckyFrenzy * 0.15) + 13; - CM.Cache.LuckyWrathRewardFrenzy = wrathMult * (CM.Cache.LuckyFrenzy * 0.15) + 13; - CM.Cache.Conjure = CM.Cache.Lucky * 2; - CM.Cache.ConjureReward = CM.Cache.Conjure * 0.15; -} - CM.Cache.MaxChainMoni = function(digit, maxPayout, mult) { var chain = 1 + Math.max(0, Math.ceil(Math.log(Game.cookies) / Math.LN10) - 10); var moni = Math.max(digit, Math.min(Math.floor(1 / 9 * Math.pow(10, chain) * digit * mult), maxPayout)); @@ -552,14 +586,6 @@ CM.Cache.GoldenCookiesMult = 1; CM.Cache.WrathCookiesMult = 1; CM.Cache.DragonsFortuneMultAdjustment = 1; CM.Cache.NoGoldSwitchCookiesPS = 0; -CM.Cache.Lucky = 0; -CM.Cache.LuckyReward = 0; -CM.Cache.LuckyWrathReward = 0; -CM.Cache.LuckyFrenzy = 0; -CM.Cache.LuckyRewardFrenzy = 0; -CM.Cache.LuckyWrathRewardFrenzy = 0; -CM.Cache.Conjure = 0; -CM.Cache.ConjureReward = 0; CM.Cache.SeaSpec = 0; CM.Cache.Chain = 0; CM.Cache.ChainWrath = 0; @@ -1042,7 +1068,7 @@ CM.Data.ConfigDefault = { Colors: {Blue: '#4bb8f0', Green: '#00ff00', Yellow: '#ffff00', Orange: '#ff7f00', Red: '#ff0000', Purple: '#ff00ff', Gray: '#b3b3b3', Pink: '#ff1493', Brown: '#8b4513'}, SortBuildings: 0, SortUpgrades: 0, - Header: {BarsColors: 1, Calculation: 1, Notification: 1, Tooltip: 1, Statistics: 1, Notation: 1, Lucky: 1, Conjure: 1, Chain: 1, Prestige: 1, Wrink: 1, Sea: 1, Misc: 1}, + Header: {BarsColors: 1, Calculation: 1, Notification: 1, Tooltip: 1, Statistics: 1, Notation: 1, Lucky: 1, Spells: 1, Chain: 1, Prestige: 1, Wrink: 1, Sea: 1, Misc: 1}, }; /******** @@ -2722,23 +2748,9 @@ CM.Disp.UpdateTooltipWarnings = function() { else l('CMDispTooltipWarnConjure').style.display = 'none'; if (CM.Options.ToolWarnEdifice == 1) { - var limitEdifice = 0; - var max = 0; - var n = 0; - for (var i in Game.Objects) { - if (Game.Objects[i].amount > max) max = Game.Objects[i].amount; - if (Game.Objects[i].amount > 0) n++; - } - for (var i in Game.Objects) { - if ((Game.Objects[i].amount < max || n == 1) && - Game.Objects[i].amount < 400 && - Game.Objects[i].price * 2 > limitEdifice) { - limitEdifice = Game.Objects[i].price * 2; - } - } - if (limitEdifice && amount < limitEdifice && (CM.Disp.tooltipType != 'b' || Game.buyMode == 1)) { + if (CM.Cache.Edifice && amount < CM.Cache.Edifice && (CM.Disp.tooltipType != 'b' || Game.buyMode == 1)) { l('CMDispTooltipWarnEdifice').style.display = ''; - l('CMDispTooltipWarnEdificeText').textContent = Beautify(limitEdifice - amount) + ' (' + CM.Disp.FormatTime((limitEdifice - amount) / CM.Disp.GetCPS()) + ')'; + l('CMDispTooltipWarnEdificeText').textContent = Beautify(CM.Cache.Edifice - amount) + ' (' + CM.Disp.FormatTime((CM.Cache.Edifice - amount) / CM.Disp.GetCPS()) + ')'; } else l('CMDispTooltipWarnEdifice').style.display = 'none'; } else l('CMDispTooltipWarnEdifice').style.display = 'none'; @@ -3176,9 +3188,9 @@ CM.Disp.AddMenuStats = function(title) { stats.appendChild(CM.Disp.CreateStatsChainSection()); } - stats.appendChild(CM.Disp.CreateStatsHeader('Conjure Baked Goods', 'Conjure')); - if (CM.Options.Header.Conjure) { - stats.appendChild(CM.Disp.CreateStatsConjureSection()); + stats.appendChild(CM.Disp.CreateStatsHeader('Spells', 'Spells')); + if (CM.Options.Header.Spells) { + stats.appendChild(CM.Disp.CreateStatsSpellsSection()); } stats.appendChild(CM.Disp.CreateStatsHeader('Prestige', 'Prestige')); @@ -3572,12 +3584,12 @@ CM.Disp.CreateStatsChainSection = function() { } /** - * This function creates the "Conjure" section of the stats page - * @returns {object} section The object contating the Conjure section + * This function creates the "Spells" section of the stats page + * @returns {object} section The object contating the Spells section */ -CM.Disp.CreateStatsConjureSection = function() { +CM.Disp.CreateStatsSpellsSection = function() { var section = document.createElement('div'); - section.className = 'CMStatsConjureSection'; + section.className = 'CMStatsSpellsSection'; var conjureColor = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.Conjure) ? CM.Disp.colorRed : CM.Disp.colorGreen; var conjureCur = Math.min((Game.cookies + CM.Disp.GetWrinkConfigBank()) * 0.15, CM.Cache.NoGoldSwitchCookiesPS * 60 * 30); @@ -3597,6 +3609,9 @@ CM.Disp.CreateStatsConjureSection = function() { section.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Conjure Baked Goods\" Cookies Required', conjureReqFrag, 'GoldCookTooltipPlaceholder')); section.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Conjure Baked Goods\" Reward (MAX)', document.createTextNode(CM.Disp.Beautify(CM.Cache.ConjureReward)), 'GoldCookTooltipPlaceholder')); section.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Conjure Baked Goods\" Reward (CUR)', document.createTextNode(CM.Disp.Beautify(conjureCur)), 'GoldCookTooltipPlaceholder')); + if (CM.Cache.Edifice) { + section.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Spontaneous Edifice\" Cookies Required (most expensive building)', document.createTextNode(CM.Disp.Beautify(CM.Cache.Edifice) + ' (' + CM.Cache.EdificeBuilding + ")"), 'GoldCookTooltipPlaceholder')); + } return section; } @@ -3962,12 +3977,13 @@ CM.Loop = function() { CM.Disp.UpdateAscendState(); } if (!Game.OnAscend && Game.AscendTimer == 0) { + // CM.Sim.DoSims is set whenever CPS has changed if (CM.Sim.DoSims) { CM.Cache.RemakeIncome(); CM.Sim.NoGoldSwitchCookiesPS(); // Needed first CM.Cache.RemakeGoldenAndWrathCookiesMults(); - CM.Cache.RemakeLucky(); + CM.Cache.CacheStats(); CM.Cache.RemakeChain(); CM.Cache.RemakeSeaSpec(); diff --git a/src/Cache.js b/src/Cache.js index c8377c9..e06a3cf 100644 --- a/src/Cache.js +++ b/src/Cache.js @@ -14,6 +14,7 @@ CM.Cache.InitCache = function() { CM.Cache.CacheDragonAuras(); CM.Cache.CacheWrinklers(); + CM.Cache.CacheStats(); } /******** @@ -65,6 +66,60 @@ CM.Cache.CacheWrinklers = function() { } } +/******** + * Section: Functions related to Cachining stats */ + +/** + * This functions caches variables related to the stats apge + * It is called by CM.Loop() upon changes to cps and CM.Cache.InitCache() + * @global {number} CM.Cache.Lucky Cookies required for max Lucky + * @global {number} CM.Cache.LuckyReward Reward for max normal Lucky + * @global {number} CM.Cache.LuckyWrathReward Reward for max normal Lucky from Wrath cookie + * @global {number} CM.Cache.LuckyFrenzy Cookies required for max Lucky Frenzy + * @global {number} CM.Cache.LuckyRewardFrenzy Reward for max Lucky Frenzy + * @global {number} CM.Cache.LuckyWrathRewardFrenzy Reward for max Lucky Frenzy from Wrath cookie + * @global {number} CM.Cache.Conjure Cookies required for max Conjure Baked Goods + * @global {number} CM.Cache.ConjureReward Reward for max Conjure Baked Goods + * @global {number} CM.Cache.Edifice Cookies required for most expensive building through Spontaneous Edifice + * @global {string} CM.Cache.EdificeBuilding Name of most expensive building possible with Spontaneous Edifice + */ +CM.Cache.CacheStats = function() { + var goldenMult = CM.Cache.GoldenCookiesMult; + var wrathMult = CM.Cache.WrathCookiesMult; + + CM.Cache.Lucky = (CM.Cache.NoGoldSwitchCookiesPS * 900) / 0.15; + CM.Cache.Lucky *= CM.Cache.DragonsFortuneMultAdjustment; + var cpsBuffMult = CM.Sim.getCPSBuffMult(); + if (cpsBuffMult > 0) { + CM.Cache.Lucky /= cpsBuffMult; + } else { + CM.Cache.Lucky = 0; + } + CM.Cache.LuckyReward = goldenMult * (CM.Cache.Lucky * 0.15) + 13; + CM.Cache.LuckyWrathReward = wrathMult * (CM.Cache.Lucky * 0.15) + 13; + CM.Cache.LuckyFrenzy = CM.Cache.Lucky * 7; + CM.Cache.LuckyRewardFrenzy = goldenMult * (CM.Cache.LuckyFrenzy * 0.15) + 13; + CM.Cache.LuckyWrathRewardFrenzy = wrathMult * (CM.Cache.LuckyFrenzy * 0.15) + 13; + CM.Cache.Conjure = CM.Cache.Lucky * 2; + CM.Cache.ConjureReward = CM.Cache.Conjure * 0.15; + + CM.Cache.Edifice = 0; + var max = 0; + var n = 0; + for (var i in Game.Objects) { + if (Game.Objects[i].amount > max) max = Game.Objects[i].amount; + if (Game.Objects[i].amount > 0) n++; + } + for (var i in Game.Objects) { + if ((Game.Objects[i].amount < max || n == 1) && + Game.Objects[i].amount < 400 && + Game.Objects[i].price * 2 > CM.Cache.Edifice) { + CM.Cache.Edifice = Game.Objects[i].price * 2; + CM.Cache.EdificeBuilding = i; + } + } +} + /******** * Section: UNSORTED */ @@ -285,27 +340,6 @@ CM.Cache.RemakeGoldenAndWrathCookiesMults = function() { } } -CM.Cache.RemakeLucky = function() { - var goldenMult = CM.Cache.GoldenCookiesMult; - var wrathMult = CM.Cache.WrathCookiesMult; - - CM.Cache.Lucky = (CM.Cache.NoGoldSwitchCookiesPS * 900) / 0.15; - CM.Cache.Lucky *= CM.Cache.DragonsFortuneMultAdjustment; - var cpsBuffMult = CM.Sim.getCPSBuffMult(); - if (cpsBuffMult > 0) { - CM.Cache.Lucky /= cpsBuffMult; - } else { - CM.Cache.Lucky = 0; - } - CM.Cache.LuckyReward = goldenMult * (CM.Cache.Lucky * 0.15) + 13; - CM.Cache.LuckyWrathReward = wrathMult * (CM.Cache.Lucky * 0.15) + 13; - CM.Cache.LuckyFrenzy = CM.Cache.Lucky * 7; - CM.Cache.LuckyRewardFrenzy = goldenMult * (CM.Cache.LuckyFrenzy * 0.15) + 13; - CM.Cache.LuckyWrathRewardFrenzy = wrathMult * (CM.Cache.LuckyFrenzy * 0.15) + 13; - CM.Cache.Conjure = CM.Cache.Lucky * 2; - CM.Cache.ConjureReward = CM.Cache.Conjure * 0.15; -} - CM.Cache.MaxChainMoni = function(digit, maxPayout, mult) { var chain = 1 + Math.max(0, Math.ceil(Math.log(Game.cookies) / Math.LN10) - 10); var moni = Math.max(digit, Math.min(Math.floor(1 / 9 * Math.pow(10, chain) * digit * mult), maxPayout)); @@ -523,14 +557,6 @@ CM.Cache.GoldenCookiesMult = 1; CM.Cache.WrathCookiesMult = 1; CM.Cache.DragonsFortuneMultAdjustment = 1; CM.Cache.NoGoldSwitchCookiesPS = 0; -CM.Cache.Lucky = 0; -CM.Cache.LuckyReward = 0; -CM.Cache.LuckyWrathReward = 0; -CM.Cache.LuckyFrenzy = 0; -CM.Cache.LuckyRewardFrenzy = 0; -CM.Cache.LuckyWrathRewardFrenzy = 0; -CM.Cache.Conjure = 0; -CM.Cache.ConjureReward = 0; CM.Cache.SeaSpec = 0; CM.Cache.Chain = 0; CM.Cache.ChainWrath = 0; diff --git a/src/Data.js b/src/Data.js index 5bb518e..4f24aaf 100644 --- a/src/Data.js +++ b/src/Data.js @@ -275,6 +275,6 @@ CM.Data.ConfigDefault = { Colors: {Blue: '#4bb8f0', Green: '#00ff00', Yellow: '#ffff00', Orange: '#ff7f00', Red: '#ff0000', Purple: '#ff00ff', Gray: '#b3b3b3', Pink: '#ff1493', Brown: '#8b4513'}, SortBuildings: 0, SortUpgrades: 0, - Header: {BarsColors: 1, Calculation: 1, Notification: 1, Tooltip: 1, Statistics: 1, Notation: 1, Lucky: 1, Conjure: 1, Chain: 1, Prestige: 1, Wrink: 1, Sea: 1, Misc: 1}, + Header: {BarsColors: 1, Calculation: 1, Notification: 1, Tooltip: 1, Statistics: 1, Notation: 1, Lucky: 1, Spells: 1, Chain: 1, Prestige: 1, Wrink: 1, Sea: 1, Misc: 1}, }; diff --git a/src/Disp.js b/src/Disp.js index 4993eec..4dd1c0f 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -1675,23 +1675,9 @@ CM.Disp.UpdateTooltipWarnings = function() { else l('CMDispTooltipWarnConjure').style.display = 'none'; if (CM.Options.ToolWarnEdifice == 1) { - var limitEdifice = 0; - var max = 0; - var n = 0; - for (var i in Game.Objects) { - if (Game.Objects[i].amount > max) max = Game.Objects[i].amount; - if (Game.Objects[i].amount > 0) n++; - } - for (var i in Game.Objects) { - if ((Game.Objects[i].amount < max || n == 1) && - Game.Objects[i].amount < 400 && - Game.Objects[i].price * 2 > limitEdifice) { - limitEdifice = Game.Objects[i].price * 2; - } - } - if (limitEdifice && amount < limitEdifice && (CM.Disp.tooltipType != 'b' || Game.buyMode == 1)) { + if (CM.Cache.Edifice && amount < CM.Cache.Edifice && (CM.Disp.tooltipType != 'b' || Game.buyMode == 1)) { l('CMDispTooltipWarnEdifice').style.display = ''; - l('CMDispTooltipWarnEdificeText').textContent = Beautify(limitEdifice - amount) + ' (' + CM.Disp.FormatTime((limitEdifice - amount) / CM.Disp.GetCPS()) + ')'; + l('CMDispTooltipWarnEdificeText').textContent = Beautify(CM.Cache.Edifice - amount) + ' (' + CM.Disp.FormatTime((CM.Cache.Edifice - amount) / CM.Disp.GetCPS()) + ')'; } else l('CMDispTooltipWarnEdifice').style.display = 'none'; } else l('CMDispTooltipWarnEdifice').style.display = 'none'; @@ -2129,9 +2115,9 @@ CM.Disp.AddMenuStats = function(title) { stats.appendChild(CM.Disp.CreateStatsChainSection()); } - stats.appendChild(CM.Disp.CreateStatsHeader('Conjure Baked Goods', 'Conjure')); - if (CM.Options.Header.Conjure) { - stats.appendChild(CM.Disp.CreateStatsConjureSection()); + stats.appendChild(CM.Disp.CreateStatsHeader('Spells', 'Spells')); + if (CM.Options.Header.Spells) { + stats.appendChild(CM.Disp.CreateStatsSpellsSection()); } stats.appendChild(CM.Disp.CreateStatsHeader('Prestige', 'Prestige')); @@ -2525,12 +2511,12 @@ CM.Disp.CreateStatsChainSection = function() { } /** - * This function creates the "Conjure" section of the stats page - * @returns {object} section The object contating the Conjure section + * This function creates the "Spells" section of the stats page + * @returns {object} section The object contating the Spells section */ -CM.Disp.CreateStatsConjureSection = function() { +CM.Disp.CreateStatsSpellsSection = function() { var section = document.createElement('div'); - section.className = 'CMStatsConjureSection'; + section.className = 'CMStatsSpellsSection'; var conjureColor = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.Conjure) ? CM.Disp.colorRed : CM.Disp.colorGreen; var conjureCur = Math.min((Game.cookies + CM.Disp.GetWrinkConfigBank()) * 0.15, CM.Cache.NoGoldSwitchCookiesPS * 60 * 30); @@ -2550,6 +2536,9 @@ CM.Disp.CreateStatsConjureSection = function() { section.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Conjure Baked Goods\" Cookies Required', conjureReqFrag, 'GoldCookTooltipPlaceholder')); section.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Conjure Baked Goods\" Reward (MAX)', document.createTextNode(CM.Disp.Beautify(CM.Cache.ConjureReward)), 'GoldCookTooltipPlaceholder')); section.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Conjure Baked Goods\" Reward (CUR)', document.createTextNode(CM.Disp.Beautify(conjureCur)), 'GoldCookTooltipPlaceholder')); + if (CM.Cache.Edifice) { + section.appendChild(CM.Disp.CreateStatsListing("withTooltip", '\"Spontaneous Edifice\" Cookies Required (most expensive building)', document.createTextNode(CM.Disp.Beautify(CM.Cache.Edifice) + ' (' + CM.Cache.EdificeBuilding + ")"), 'GoldCookTooltipPlaceholder')); + } return section; } diff --git a/src/Main.js b/src/Main.js index ff447e1..9af3d1b 100644 --- a/src/Main.js +++ b/src/Main.js @@ -140,12 +140,13 @@ CM.Loop = function() { CM.Disp.UpdateAscendState(); } if (!Game.OnAscend && Game.AscendTimer == 0) { + // CM.Sim.DoSims is set whenever CPS has changed if (CM.Sim.DoSims) { CM.Cache.RemakeIncome(); CM.Sim.NoGoldSwitchCookiesPS(); // Needed first CM.Cache.RemakeGoldenAndWrathCookiesMults(); - CM.Cache.RemakeLucky(); + CM.Cache.CacheStats(); CM.Cache.RemakeChain(); CM.Cache.RemakeSeaSpec(); From ca0889790d58f1285a2312f2275f0f2fcb8a30e0 Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Sun, 20 Dec 2020 13:13:02 +0100 Subject: [PATCH 082/106] Fixed lay-out of code --- CookieMonster.js | 7 ++----- src/Cache.js | 7 ++----- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index 3b037d0..1853acb 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -119,11 +119,8 @@ CM.Cache.CacheStats = function() { CM.Cache.Lucky = (CM.Cache.NoGoldSwitchCookiesPS * 900) / 0.15; CM.Cache.Lucky *= CM.Cache.DragonsFortuneMultAdjustment; var cpsBuffMult = CM.Sim.getCPSBuffMult(); - if (cpsBuffMult > 0) { - CM.Cache.Lucky /= cpsBuffMult; - } else { - CM.Cache.Lucky = 0; - } + if (cpsBuffMult > 0) CM.Cache.Lucky /= cpsBuffMult; + else CM.Cache.Lucky = 0; CM.Cache.LuckyReward = goldenMult * (CM.Cache.Lucky * 0.15) + 13; CM.Cache.LuckyWrathReward = wrathMult * (CM.Cache.Lucky * 0.15) + 13; CM.Cache.LuckyFrenzy = CM.Cache.Lucky * 7; diff --git a/src/Cache.js b/src/Cache.js index e06a3cf..72fd350 100644 --- a/src/Cache.js +++ b/src/Cache.js @@ -90,11 +90,8 @@ CM.Cache.CacheStats = function() { CM.Cache.Lucky = (CM.Cache.NoGoldSwitchCookiesPS * 900) / 0.15; CM.Cache.Lucky *= CM.Cache.DragonsFortuneMultAdjustment; var cpsBuffMult = CM.Sim.getCPSBuffMult(); - if (cpsBuffMult > 0) { - CM.Cache.Lucky /= cpsBuffMult; - } else { - CM.Cache.Lucky = 0; - } + if (cpsBuffMult > 0) CM.Cache.Lucky /= cpsBuffMult; + else CM.Cache.Lucky = 0; CM.Cache.LuckyReward = goldenMult * (CM.Cache.Lucky * 0.15) + 13; CM.Cache.LuckyWrathReward = wrathMult * (CM.Cache.Lucky * 0.15) + 13; CM.Cache.LuckyFrenzy = CM.Cache.Lucky * 7; From 1cffb822fb5b03161d6ec36ef87394e81b2cc904 Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Mon, 21 Dec 2020 11:24:23 +0100 Subject: [PATCH 083/106] Rewrote Missing Upgrades code --- CookieMonster.js | 224 ++++++++++++++++++++++++++++------------------- src/Cache.js | 78 ++++++++++++++--- src/Data.js | 4 +- src/Disp.js | 141 ++++++++++++++--------------- src/Main.js | 1 + 5 files changed, 270 insertions(+), 178 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index 1853acb..b805f7a 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -44,6 +44,7 @@ CM.Cache.InitCache = function() { CM.Cache.CacheDragonAuras(); CM.Cache.CacheWrinklers(); CM.Cache.CacheStats(); + CM.Cache.CacheMissingUpgrades(); } /******** @@ -146,6 +147,43 @@ CM.Cache.CacheStats = function() { } } +/** + * This functions caches variables related to missing upgrades + * It is called by CM.Loop() and CM.Cache.InitCache() + * @global {string} CM.Cache.MissingUpgrades String containig the HTML to create the "crates" for missing normal upgrades + * @global {string} CM.Cache.MissingUpgradesCookies String containig the HTML to create the "crates" for missing cookie upgrades + * @global {string} CM.Cache.MissingUpgradesPrestige String containig the HTML to create the "crates" for missing prestige upgrades + */ +CM.Cache.CacheMissingUpgrades = function() { + CM.Cache.MissingUpgrades = ""; + CM.Cache.MissingUpgradesCookies = ""; + CM.Cache.MissingUpgradesPrestige = ""; + var list = []; + //sort the upgrades + for (var i in Game.Upgrades) { + list.push(Game.Upgrades[i]); + } + var sortMap = function(a, b) { + if (a.order>b.order) return 1; + else if (a.orderb.order) return 1; + else if (a.order b.order) return 1; - else if (a.order < b.order) return -1; - else return 0; + if (CM.Cache.MissingUpgrades) { + var normalUpgradesOwned = Game.UpgradesByPool[""].length + Game.UpgradesByPool["tech"].length - l('menu').children[6].childNodes[2].children.length; + var title = document.createElement('div'); + title.id = "CMMissingUpgradesTitle"; + title.className = "listing"; + titlefrag = document.createElement('div'); + titlefrag.innerHTML = 'Missing normal upgrades: '+ normalUpgradesOwned + '/' + (Game.UpgradesByPool[""].length + Game.UpgradesByPool["tech"].length) + ' (' + Math.floor((normalUpgradesOwned / ( Game.UpgradesByPool[""].length + Game.UpgradesByPool["tech"].length)) * 100) + '%)'; + title.appendChild(titlefrag) + l('menu').children[6].insertBefore(title, l('menu').children[6].childNodes[3]) + upgrades = document.createElement('div'); + upgrades.className = "listing crateBox"; + upgrades.innerHTML = CM.Cache.MissingUpgrades; + l('menu').children[6].insertBefore(upgrades, document.getElementById("CMMissingUpgradesTitle").nextSibling) } - CM.Cache.MissingUpgrades.sort(sortMap); - CM.Cache.MissingCookies.sort(sortMap);; - - // Find Upgrades-section of stats menu - var upgradesMenu = null; - for (var i = 0; i < l("menu").getElementsByClassName("subsection").length && upgradesMenu == null; i++) - { - if (l("menu").getElementsByClassName("subsection")[i].getElementsByClassName("title")[0].textContent === "Upgrades") - { - upgradesMenu = l("menu").getElementsByClassName("subsection")[i]; - } - } - - // This function creates div element from given object. It also adds tooltip for it. - var createUpgradeElement = function (me) { - return '
' + - '
' + - '
' + Beautify(Math.round(me.getPrice())) + '
' + - '
' + me.name + '
' + - '
' + me.desc + '
', - 'top', - true) + - ' style="background-position:' + (-me.icon[0] * 48) + 'px ' + (-me.icon[1] * 48) + 'px;">'; - }; - - // This function creates section of given elements and adds this elements to it. - var createElementBox = function (elements) { - var div = document.createElement('div'); - div.className = 'listing crateBox'; - elements.forEach(function (element) { - div.innerHTML += createUpgradeElement(element); - }); - return div; - }; - - // This function creates header element with given text. - var createHeader = function (text) { - var div = document.createElement('div'); - div.className = 'listing'; - var b = document.createElement('b'); - b.textContent = text; - div.appendChild(b); - return div; - }; - - if (CM.Cache.MissingUpgrades.length > 0) { - upgradesMenu.appendChild(createHeader("Missing Upgrades")); - if (CM.Cache.MissingUpgradesString == null) { - CM.Cache.MissingUpgradesString = createElementBox(CM.Cache.MissingUpgrades); - } - upgradesMenu.appendChild(CM.Cache.MissingUpgradesString); + if (CM.Cache.MissingUpgradesCookies) { + var cookieUpgradesOwned = Game.UpgradesByPool["cookie"].length - l('menu').children[6].lastChild.children.length; + var title = document.createElement('div'); + title.id = "CMMissingUpgradesCookiesTitle"; + title.className = "listing"; + titlefrag = document.createElement('div'); + titlefrag.innerHTML = 'Missing Cookie upgrades: '+ cookieUpgradesOwned + '/' + Game.UpgradesByPool["cookie"].length + ' (' + Math.floor((cookieUpgradesOwned / Game.UpgradesByPool["cookie"].length) * 100) + '%)'; + title.appendChild(titlefrag) + l('menu').children[6].appendChild(title) + upgrades = document.createElement('div'); + upgrades.className = "listing crateBox"; + upgrades.innerHTML = CM.Cache.MissingUpgradesCookies; + l('menu').children[6].appendChild(upgrades) + } +} + +/** + * This function returns the "crates" (icons) for missing upgrades in the stats sections + * It returns a html string that gets appended to the respective CM.Cache.MissingUpgrades-variable by CM.Cache.CacheMissingUpgrades() + * It is also called by CM.Cache.CacheMissingUpgrades() for every non bought upgrade + * @param {object} me The upgrade object + * @returns {string} ? The HTML string that creates the icon. + */ +CM.Disp.crateMissing = function(me) { + var classes = 'crate upgrade missing'; + if (me.pool == 'prestige') classes+=' heavenly'; + + var noFrame = 0; + if (!Game.prefs.crates) noFrame = 1; + if (noFrame) classes += ' noFrame'; + + var icon = me.icon; + if (me.iconFunction) icon = me.iconFunction(); + tooltip = `function() {return Game.crateTooltip(Game.UpgradesById[${me.id}], 'stats');}`; + return `
+
`; +} - if (CM.Cache.MissingCookies.length > 0) { - upgradesMenu.appendChild(createHeader("Missing Cookies")); - if (CM.Cache.MissingCookiesString == null) { - CM.Cache.MissingCookiesString = createElementBox(CM.Cache.MissingCookies); - } - upgradesMenu.appendChild(CM.Cache.MissingCookiesString); - } -} */ /******** * Section: Variables used in Disp functions @@ -3981,6 +4026,7 @@ CM.Loop = function() { CM.Sim.NoGoldSwitchCookiesPS(); // Needed first CM.Cache.RemakeGoldenAndWrathCookiesMults(); CM.Cache.CacheStats(); + CM.Cache.CacheMissingUpgrades(); CM.Cache.RemakeChain(); CM.Cache.RemakeSeaSpec(); diff --git a/src/Cache.js b/src/Cache.js index 72fd350..f60ecce 100644 --- a/src/Cache.js +++ b/src/Cache.js @@ -15,6 +15,7 @@ CM.Cache.InitCache = function() { CM.Cache.CacheDragonAuras(); CM.Cache.CacheWrinklers(); CM.Cache.CacheStats(); + CM.Cache.CacheMissingUpgrades(); } /******** @@ -117,6 +118,43 @@ CM.Cache.CacheStats = function() { } } +/** + * This functions caches variables related to missing upgrades + * It is called by CM.Loop() and CM.Cache.InitCache() + * @global {string} CM.Cache.MissingUpgrades String containig the HTML to create the "crates" for missing normal upgrades + * @global {string} CM.Cache.MissingUpgradesCookies String containig the HTML to create the "crates" for missing cookie upgrades + * @global {string} CM.Cache.MissingUpgradesPrestige String containig the HTML to create the "crates" for missing prestige upgrades + */ +CM.Cache.CacheMissingUpgrades = function() { + CM.Cache.MissingUpgrades = ""; + CM.Cache.MissingUpgradesCookies = ""; + CM.Cache.MissingUpgradesPrestige = ""; + var list = []; + //sort the upgrades + for (var i in Game.Upgrades) { + list.push(Game.Upgrades[i]); + } + var sortMap = function(a, b) { + if (a.order>b.order) return 1; + else if (a.orderb.order) return 1; + else if (a.order b.order) return 1; - else if (a.order < b.order) return -1; - else return 0; + if (CM.Cache.MissingUpgrades) { + var normalUpgradesOwned = Game.UpgradesByPool[""].length + Game.UpgradesByPool["tech"].length - l('menu').children[6].childNodes[2].children.length; + var title = document.createElement('div'); + title.id = "CMMissingUpgradesTitle"; + title.className = "listing"; + titlefrag = document.createElement('div'); + titlefrag.innerHTML = 'Missing normal upgrades: '+ normalUpgradesOwned + '/' + (Game.UpgradesByPool[""].length + Game.UpgradesByPool["tech"].length) + ' (' + Math.floor((normalUpgradesOwned / ( Game.UpgradesByPool[""].length + Game.UpgradesByPool["tech"].length)) * 100) + '%)'; + title.appendChild(titlefrag) + l('menu').children[6].insertBefore(title, l('menu').children[6].childNodes[3]) + upgrades = document.createElement('div'); + upgrades.className = "listing crateBox"; + upgrades.innerHTML = CM.Cache.MissingUpgrades; + l('menu').children[6].insertBefore(upgrades, document.getElementById("CMMissingUpgradesTitle").nextSibling) } - CM.Cache.MissingUpgrades.sort(sortMap); - CM.Cache.MissingCookies.sort(sortMap);; - - // Find Upgrades-section of stats menu - var upgradesMenu = null; - for (var i = 0; i < l("menu").getElementsByClassName("subsection").length && upgradesMenu == null; i++) - { - if (l("menu").getElementsByClassName("subsection")[i].getElementsByClassName("title")[0].textContent === "Upgrades") - { - upgradesMenu = l("menu").getElementsByClassName("subsection")[i]; - } - } - - // This function creates div element from given object. It also adds tooltip for it. - var createUpgradeElement = function (me) { - return '
' + - '
' + - '
' + Beautify(Math.round(me.getPrice())) + '
' + - '
' + me.name + '
' + - '
' + me.desc + '
', - 'top', - true) + - ' style="background-position:' + (-me.icon[0] * 48) + 'px ' + (-me.icon[1] * 48) + 'px;">'; - }; - - // This function creates section of given elements and adds this elements to it. - var createElementBox = function (elements) { - var div = document.createElement('div'); - div.className = 'listing crateBox'; - elements.forEach(function (element) { - div.innerHTML += createUpgradeElement(element); - }); - return div; - }; - - // This function creates header element with given text. - var createHeader = function (text) { - var div = document.createElement('div'); - div.className = 'listing'; - var b = document.createElement('b'); - b.textContent = text; - div.appendChild(b); - return div; - }; - - if (CM.Cache.MissingUpgrades.length > 0) { - upgradesMenu.appendChild(createHeader("Missing Upgrades")); - if (CM.Cache.MissingUpgradesString == null) { - CM.Cache.MissingUpgradesString = createElementBox(CM.Cache.MissingUpgrades); - } - upgradesMenu.appendChild(CM.Cache.MissingUpgradesString); + if (CM.Cache.MissingUpgradesCookies) { + var cookieUpgradesOwned = Game.UpgradesByPool["cookie"].length - l('menu').children[6].lastChild.children.length; + var title = document.createElement('div'); + title.id = "CMMissingUpgradesCookiesTitle"; + title.className = "listing"; + titlefrag = document.createElement('div'); + titlefrag.innerHTML = 'Missing Cookie upgrades: '+ cookieUpgradesOwned + '/' + Game.UpgradesByPool["cookie"].length + ' (' + Math.floor((cookieUpgradesOwned / Game.UpgradesByPool["cookie"].length) * 100) + '%)'; + title.appendChild(titlefrag) + l('menu').children[6].appendChild(title) + upgrades = document.createElement('div'); + upgrades.className = "listing crateBox"; + upgrades.innerHTML = CM.Cache.MissingUpgradesCookies; + l('menu').children[6].appendChild(upgrades) + } +} + +/** + * This function returns the "crates" (icons) for missing upgrades in the stats sections + * It returns a html string that gets appended to the respective CM.Cache.MissingUpgrades-variable by CM.Cache.CacheMissingUpgrades() + * It is also called by CM.Cache.CacheMissingUpgrades() for every non bought upgrade + * @param {object} me The upgrade object + * @returns {string} ? The HTML string that creates the icon. + */ +CM.Disp.crateMissing = function(me) { + var classes = 'crate upgrade missing'; + if (me.pool == 'prestige') classes+=' heavenly'; + + var noFrame = 0; + if (!Game.prefs.crates) noFrame = 1; + if (noFrame) classes += ' noFrame'; + + var icon = me.icon; + if (me.iconFunction) icon = me.iconFunction(); + tooltip = `function() {return Game.crateTooltip(Game.UpgradesById[${me.id}], 'stats');}`; + return `
+
`; +} - if (CM.Cache.MissingCookies.length > 0) { - upgradesMenu.appendChild(createHeader("Missing Cookies")); - if (CM.Cache.MissingCookiesString == null) { - CM.Cache.MissingCookiesString = createElementBox(CM.Cache.MissingCookies); - } - upgradesMenu.appendChild(CM.Cache.MissingCookiesString); - } -} */ /******** * Section: Variables used in Disp functions diff --git a/src/Main.js b/src/Main.js index 9af3d1b..72a9f15 100644 --- a/src/Main.js +++ b/src/Main.js @@ -147,6 +147,7 @@ CM.Loop = function() { CM.Sim.NoGoldSwitchCookiesPS(); // Needed first CM.Cache.RemakeGoldenAndWrathCookiesMults(); CM.Cache.CacheStats(); + CM.Cache.CacheMissingUpgrades(); CM.Cache.RemakeChain(); CM.Cache.RemakeSeaSpec(); From 203dc8137e78fc887cda5fc3d576e17c4233001c Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Mon, 21 Dec 2020 22:53:23 +0100 Subject: [PATCH 084/106] Incorporated Modding API --- CookieMonster.js | 92 +++++++++++++++++++++++++++++------------------- src/Cache.js | 7 ---- src/Config.js | 19 +++++----- src/Disp.js | 11 ------ src/Footer.js | 80 ++++++++++++++++++++++++++++++++++++++++- src/Header.js | 2 ++ src/Main.js | 27 -------------- src/Sim.js | 1 + 8 files changed, 147 insertions(+), 92 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index b805f7a..b139ddc 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -190,7 +190,7 @@ CM.Cache.CacheMissingUpgrades = function() { CM.Cache.AddQueue = function() { CM.Cache.Queue = document.createElement('script'); CM.Cache.Queue.type = 'text/javascript'; - CM.Cache.Queue.setAttribute('src', 'https://aktanusa.github.io/CookieMonster/queue/queue.js'); + CM.Cache.Queue.src = 'https://aktanusa.github.io/CookieMonster/queue/queue.js'; document.head.appendChild(CM.Cache.Queue); } @@ -682,16 +682,16 @@ CM.Cache.spawnedGoldenShimmer = 0; * @param {object} config The Config to be saved (normally CM.Options) */ CM.Config.SaveConfig = function(config) { - localStorage.setItem(CM.ConfigPrefix, JSON.stringify(config)); + CM.save(); } /** * This function loads the config of CookieMonster saved in localStorage and loads it into CM.Options * It is called by CM.DelayInit() and CM.Config.RestoreDefault() */ -CM.Config.LoadConfig = function() { - if (localStorage.getItem(CM.ConfigPrefix) != null) { - CM.Options = JSON.parse(localStorage.getItem(CM.ConfigPrefix)); +CM.Config.LoadConfig = function(settings) { + if (settings != null) { + CM.Options = settings; // Check values var mod = false; @@ -749,9 +749,8 @@ CM.Config.LoadConfig = function() { * It is called by resDefBut.onclick loaded in the options page or by CM.Config.LoadConfig if no localStorage is found */ CM.Config.RestoreDefault = function() { - CM.Options = {}; - CM.Config.SaveConfig(CM.Data.ConfigDefault); - CM.Config.LoadConfig(); + CM.Config.LoadConfig(CM.Data.ConfigDefault); + CM.Config.SaveConfig(); Game.UpdateMenu(); } @@ -1386,7 +1385,7 @@ CM.Disp.CreateCssArea = function() { /** * TODO: What does this do? @Aktanusa - * It is called by CM.Init() + * It is called by CM.init, which is called by Game.registerMod */ CM.Disp.AddJscolor = function() { CM.Disp.Jscolor = document.createElement('script'); @@ -4090,24 +4089,6 @@ CM.Loop = function() { CM.Cache.UpdateAvgCPS() } -CM.Init = function() { - var proceed = true; - if (Game.version != CM.VersionMajor) { - proceed = confirm('Cookie Monster version ' + CM.VersionMajor + '.' + CM.VersionMinor + ' is meant for Game version ' + CM.VersionMajor + '. Loading a different version may cause errors. Do you still want to load Cookie Monster?'); - } - if (proceed) { - CM.Cache.AddQueue(); - CM.Disp.AddJscolor(); - - var delay = setInterval(function() { - if (typeof Queue !== 'undefined' && typeof jscolor !== 'undefined') { - CM.DelayInit(); - clearInterval(delay); - } - }, 500); - } -} - CM.DelayInit = function() { CM.Sim.InitData(); CM.Cache.InitCache(); @@ -4144,18 +4125,9 @@ CM.DelayInit = function() { l("upgrades").style.display = "flex"; l("upgrades").style["flex-wrap"] = "wrap"; - CM.Main.RegisterHooks(); - Game.Win('Third-party'); } -/** - * Hook custom methods into the game - */ -CM.Main.RegisterHooks = function() { - Game.registerHook('draw', CM.Disp.Draw); -} - /******** * Section: Functions related to checking for changes in Minigames/GC's/Ticker * TODO: Possibly move this section */ @@ -4580,6 +4552,7 @@ CM.Sim.InitData = function() { for (var i in Game.Achievements) { CM.Sim.Achievements[i] = CM.Sim.InitAchievement(i); } + CM.Sim.CopyData } CM.Sim.CopyData = function() { @@ -5275,8 +5248,53 @@ CM.Sim.mouseCps = function() { * Footer * **********/ +/******** + * Section: Functions related to base game modding API */ + +/** + * TODO: This should at one point be used to register hooks + */ +CM.init = function() { + var proceed = true; + if (Game.version != CM.VersionMajor) { + proceed = confirm('Cookie Monster version ' + CM.VersionMajor + '.' + CM.VersionMinor + ' is meant for Game version ' + CM.VersionMajor + '. Loading a different version may cause errors. Do you still want to load Cookie Monster?'); + } + if (proceed) { + CM.DelayInit(); + Game.registerHook('draw', CM.Disp.Draw); + } +} + +/** + * This registers a save function. Per Game code/comments: + * "use this to store persistent data associated with your mod + * return 'a string to be saved';" + */ +CM.save = function() { + return JSON.stringify({ + settings: CM.Options, + version: CM.VersionMajor + '.' + CM.VersionMinor, + }); +} + +/** + * This registers a load function. Per Game code/comments: + * "do stuff with the string data you saved previously" + */ +CM.load = function(str) { + let save = JSON.parse(str); + CM.Config.LoadConfig(save.settings); +} + if (!CM.isRunning) { - CM.Init(); + CM.Cache.AddQueue(); + CM.Disp.AddJscolor(); + var delay = setInterval(function() { + if (typeof Queue !== 'undefined' && typeof jscolor !== 'undefined') { + Game.registerMod('CookieMonster', CM); + clearInterval(delay); + } + }, 500); CM.isRunning = 1 } diff --git a/src/Cache.js b/src/Cache.js index f60ecce..97600f3 100644 --- a/src/Cache.js +++ b/src/Cache.js @@ -158,13 +158,6 @@ CM.Cache.CacheMissingUpgrades = function() { /******** * Section: UNSORTED */ -CM.Cache.AddQueue = function() { - CM.Cache.Queue = document.createElement('script'); - CM.Cache.Queue.type = 'text/javascript'; - CM.Cache.Queue.setAttribute('src', 'https://aktanusa.github.io/CookieMonster/queue/queue.js'); - document.head.appendChild(CM.Cache.Queue); -} - CM.Cache.NextNumber = function(base) { var count = base > Math.pow(2, 53) ? Math.pow(2, Math.floor(Math.log(base) / Math.log(2)) - 53) : 1; while (base == base + count) { diff --git a/src/Config.js b/src/Config.js index 6b750ed..066b88d 100644 --- a/src/Config.js +++ b/src/Config.js @@ -6,22 +6,24 @@ * Section: Functions related to saving, loading and restoring configs */ /** - * This function saves the config of CookieMonster to localStorage + * @deprecated + * This function (used to) save the config of CookieMonster * It is called by CM.Config.LoadConfig(), CM.Config.RestoreDefault(), CM.Config.ToggleConfig(), * CM.ToggleConfigVolume() and changes in options with type "url", "color" or "numscale" - * @param {object} config The Config to be saved (normally CM.Options) + * TODO: See if there is a way to force Cookie CLICKER to save only the mod-data and not also Save-data. + * Otherwise this can be removed */ CM.Config.SaveConfig = function(config) { - localStorage.setItem(CM.ConfigPrefix, JSON.stringify(config)); + CM.save(); } /** * This function loads the config of CookieMonster saved in localStorage and loads it into CM.Options * It is called by CM.DelayInit() and CM.Config.RestoreDefault() */ -CM.Config.LoadConfig = function() { - if (localStorage.getItem(CM.ConfigPrefix) != null) { - CM.Options = JSON.parse(localStorage.getItem(CM.ConfigPrefix)); +CM.Config.LoadConfig = function(settings) { + if (settings != null) { + CM.Options = settings; // Check values var mod = false; @@ -79,9 +81,8 @@ CM.Config.LoadConfig = function() { * It is called by resDefBut.onclick loaded in the options page or by CM.Config.LoadConfig if no localStorage is found */ CM.Config.RestoreDefault = function() { - CM.Options = {}; - CM.Config.SaveConfig(CM.Data.ConfigDefault); - CM.Config.LoadConfig(); + CM.Config.LoadConfig(CM.Data.ConfigDefault); + CM.Config.SaveConfig(CM.Options); Game.UpdateMenu(); } diff --git a/src/Disp.js b/src/Disp.js index acbf0bb..705700f 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -264,17 +264,6 @@ CM.Disp.CreateCssArea = function() { document.head.appendChild(CM.Disp.Css); } -/** - * TODO: What does this do? @Aktanusa - * It is called by CM.Init() - */ -CM.Disp.AddJscolor = function() { - CM.Disp.Jscolor = document.createElement('script'); - CM.Disp.Jscolor.type = 'text/javascript'; - CM.Disp.Jscolor.setAttribute('src', 'https://aktanusa.github.io/CookieMonster/jscolor/jscolor.js'); - document.head.appendChild(CM.Disp.Jscolor); -} - /** * This function sets the size of the background of the full game and the left column * depending on whether certain abrs are activated diff --git a/src/Footer.js b/src/Footer.js index c40dd31..45eb3a8 100644 --- a/src/Footer.js +++ b/src/Footer.js @@ -2,8 +2,86 @@ * Footer * **********/ +/******** + * Section: Functions related to base game modding API */ + +/** + * This register a init function to the CM object. Per Game code/comments: + * "this function is called as soon as the mod is registered + * declare hooks here" + * It starts the further initialization of CookieMonster and registers hooks + */ +CM.init = function() { + var proceed = true; + if (Game.version != CM.VersionMajor) { + proceed = confirm('Cookie Monster version ' + CM.VersionMajor + '.' + CM.VersionMinor + ' is meant for Game version ' + CM.VersionMajor + '. Loading a different version may cause errors. Do you still want to load Cookie Monster?'); + } + if (proceed) { + CM.DelayInit(); + Game.registerHook('draw', CM.Disp.Draw); + } +} + +/** + * This registers a save function to the CM object. Per Game code/comments: + * "use this to store persistent data associated with your mod + * return 'a string to be saved';" + */ +CM.save = function() { + return JSON.stringify({ + settings: CM.Options, + version: CM.VersionMajor + '.' + CM.VersionMinor, + }); +} + +/** + * This registers a load function to the CM object. Per Game code/comments: + * "do stuff with the string data you saved previously" + */ +CM.load = function(str) { + let save = JSON.parse(str); + CM.Config.LoadConfig(save.settings); +} + +/******** + * Section: Functions related to the initialization of CookieMonster */ + +/** + * This functions loads an external script (on the same repository) that creates a Queue() function + * It is called by the last function in the footer + */ +CM.Footer.AddQueue = function() { + CM.Footer.Queue = document.createElement('script'); + CM.Footer.Queue.type = 'text/javascript'; + CM.Footer.Queue.src = 'https://aktanusa.github.io/CookieMonster/queue/queue.js'; + document.head.appendChild(CM.Footer.Queue); +} + +/** + * This functions loads an external script (on the same repository) that creates the + * functionality needed to dynamiccaly change colours + * It is called by the last function in the footer + */ +CM.Footer.AddJscolor = function() { + CM.Footer.Jscolor = document.createElement('script'); + CM.Footer.Jscolor.type = 'text/javascript'; + CM.Footer.Jscolor.setAttribute('src', 'https://aktanusa.github.io/CookieMonster/jscolor/jscolor.js'); + document.head.appendChild(CM.Footer.Jscolor); +} + +/** + * This functions starts the initizialization and register CookieMonster + * It is called as the last function in this script's execution + */ if (!CM.isRunning) { - CM.Init(); + CM.Footer.AddQueue(); + CM.Footer.AddJscolor(); + var delay = setInterval(function() { + if (typeof Queue !== 'undefined' && typeof jscolor !== 'undefined') { + Game.registerMod('CookieMonster', CM); + clearInterval(delay); + } + }, 500); CM.isRunning = 1 } diff --git a/src/Header.js b/src/Header.js index 11f5e28..aa8446f 100644 --- a/src/Header.js +++ b/src/Header.js @@ -16,6 +16,8 @@ RunCookieMonsterHeader = function() { CM.Disp = {}; + CM.Footer = {}; + CM.Main = {}; CM.Options = {}; diff --git a/src/Main.js b/src/Main.js index 72a9f15..3306791 100644 --- a/src/Main.js +++ b/src/Main.js @@ -211,24 +211,6 @@ CM.Loop = function() { CM.Cache.UpdateAvgCPS() } -CM.Init = function() { - var proceed = true; - if (Game.version != CM.VersionMajor) { - proceed = confirm('Cookie Monster version ' + CM.VersionMajor + '.' + CM.VersionMinor + ' is meant for Game version ' + CM.VersionMajor + '. Loading a different version may cause errors. Do you still want to load Cookie Monster?'); - } - if (proceed) { - CM.Cache.AddQueue(); - CM.Disp.AddJscolor(); - - var delay = setInterval(function() { - if (typeof Queue !== 'undefined' && typeof jscolor !== 'undefined') { - CM.DelayInit(); - clearInterval(delay); - } - }, 500); - } -} - CM.DelayInit = function() { CM.Sim.InitData(); CM.Cache.InitCache(); @@ -265,18 +247,9 @@ CM.DelayInit = function() { l("upgrades").style.display = "flex"; l("upgrades").style["flex-wrap"] = "wrap"; - CM.Main.RegisterHooks(); - Game.Win('Third-party'); } -/** - * Hook custom methods into the game - */ -CM.Main.RegisterHooks = function() { - Game.registerHook('draw', CM.Disp.Draw); -} - /******** * Section: Functions related to checking for changes in Minigames/GC's/Ticker * TODO: Possibly move this section */ diff --git a/src/Sim.js b/src/Sim.js index d4fc227..52ead0c 100644 --- a/src/Sim.js +++ b/src/Sim.js @@ -207,6 +207,7 @@ CM.Sim.InitData = function() { for (var i in Game.Achievements) { CM.Sim.Achievements[i] = CM.Sim.InitAchievement(i); } + CM.Sim.CopyData } CM.Sim.CopyData = function() { From 72aef84fcc5a0474976673f1bc142c59c6014aa9 Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Mon, 21 Dec 2020 22:54:14 +0100 Subject: [PATCH 085/106] Combined CookieMonster (#364) --- CookieMonster.js | 71 ++++++++++++++++++++++++++++++------------------ 1 file changed, 45 insertions(+), 26 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index b139ddc..289ee6a 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -16,6 +16,8 @@ RunCookieMonsterHeader = function() { CM.Disp = {}; + CM.Footer = {}; + CM.Main = {}; CM.Options = {}; @@ -187,13 +189,6 @@ CM.Cache.CacheMissingUpgrades = function() { /******** * Section: UNSORTED */ -CM.Cache.AddQueue = function() { - CM.Cache.Queue = document.createElement('script'); - CM.Cache.Queue.type = 'text/javascript'; - CM.Cache.Queue.src = 'https://aktanusa.github.io/CookieMonster/queue/queue.js'; - document.head.appendChild(CM.Cache.Queue); -} - CM.Cache.NextNumber = function(base) { var count = base > Math.pow(2, 53) ? Math.pow(2, Math.floor(Math.log(base) / Math.log(2)) - 53) : 1; while (base == base + count) { @@ -676,10 +671,12 @@ CM.Cache.spawnedGoldenShimmer = 0; * Section: Functions related to saving, loading and restoring configs */ /** - * This function saves the config of CookieMonster to localStorage + * @deprecated + * This function (used to) save the config of CookieMonster * It is called by CM.Config.LoadConfig(), CM.Config.RestoreDefault(), CM.Config.ToggleConfig(), * CM.ToggleConfigVolume() and changes in options with type "url", "color" or "numscale" - * @param {object} config The Config to be saved (normally CM.Options) + * TODO: See if there is a way to force Cookie CLICKER to save only the mod-data and not also Save-data. + * Otherwise this can be removed */ CM.Config.SaveConfig = function(config) { CM.save(); @@ -750,7 +747,7 @@ CM.Config.LoadConfig = function(settings) { */ CM.Config.RestoreDefault = function() { CM.Config.LoadConfig(CM.Data.ConfigDefault); - CM.Config.SaveConfig(); + CM.Config.SaveConfig(CM.Options); Game.UpdateMenu(); } @@ -1383,17 +1380,6 @@ CM.Disp.CreateCssArea = function() { document.head.appendChild(CM.Disp.Css); } -/** - * TODO: What does this do? @Aktanusa - * It is called by CM.init, which is called by Game.registerMod - */ -CM.Disp.AddJscolor = function() { - CM.Disp.Jscolor = document.createElement('script'); - CM.Disp.Jscolor.type = 'text/javascript'; - CM.Disp.Jscolor.setAttribute('src', 'https://aktanusa.github.io/CookieMonster/jscolor/jscolor.js'); - document.head.appendChild(CM.Disp.Jscolor); -} - /** * This function sets the size of the background of the full game and the left column * depending on whether certain abrs are activated @@ -5252,7 +5238,10 @@ CM.Sim.mouseCps = function() { * Section: Functions related to base game modding API */ /** - * TODO: This should at one point be used to register hooks + * This register a init function to the CM object. Per Game code/comments: + * "this function is called as soon as the mod is registered + * declare hooks here" + * It starts the further initialization of CookieMonster and registers hooks */ CM.init = function() { var proceed = true; @@ -5266,7 +5255,7 @@ CM.init = function() { } /** - * This registers a save function. Per Game code/comments: + * This registers a save function to the CM object. Per Game code/comments: * "use this to store persistent data associated with your mod * return 'a string to be saved';" */ @@ -5278,7 +5267,7 @@ CM.save = function() { } /** - * This registers a load function. Per Game code/comments: + * This registers a load function to the CM object. Per Game code/comments: * "do stuff with the string data you saved previously" */ CM.load = function(str) { @@ -5286,9 +5275,39 @@ CM.load = function(str) { CM.Config.LoadConfig(save.settings); } +/******** + * Section: Functions related to the initialization of CookieMonster */ + +/** + * This functions loads an external script (on the same repository) that creates a Queue() function + * It is called by the last function in the footer + */ +CM.Footer.AddQueue = function() { + CM.Footer.Queue = document.createElement('script'); + CM.Footer.Queue.type = 'text/javascript'; + CM.Footer.Queue.src = 'https://aktanusa.github.io/CookieMonster/queue/queue.js'; + document.head.appendChild(CM.Footer.Queue); +} + +/** + * This functions loads an external script (on the same repository) that creates the + * functionality needed to dynamiccaly change colours + * It is called by the last function in the footer + */ +CM.Footer.AddJscolor = function() { + CM.Footer.Jscolor = document.createElement('script'); + CM.Footer.Jscolor.type = 'text/javascript'; + CM.Footer.Jscolor.setAttribute('src', 'https://aktanusa.github.io/CookieMonster/jscolor/jscolor.js'); + document.head.appendChild(CM.Footer.Jscolor); +} + +/** + * This functions starts the initizialization and register CookieMonster + * It is called as the last function in this script's execution + */ if (!CM.isRunning) { - CM.Cache.AddQueue(); - CM.Disp.AddJscolor(); + CM.Footer.AddQueue(); + CM.Footer.AddJscolor(); var delay = setInterval(function() { if (typeof Queue !== 'undefined' && typeof jscolor !== 'undefined') { Game.registerMod('CookieMonster', CM); From 63ddf7fa384aa715376d67a079041503fda24cae Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Mon, 21 Dec 2020 23:28:00 +0100 Subject: [PATCH 086/106] Added code to remove cookies from old save system --- CookieMonster.js | 4 ++++ src/Config.js | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/CookieMonster.js b/CookieMonster.js index 289ee6a..80554b2 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -687,6 +687,10 @@ CM.Config.SaveConfig = function(config) { * It is called by CM.DelayInit() and CM.Config.RestoreDefault() */ CM.Config.LoadConfig = function(settings) { + // This removes cookies left from earlier versions of CookieMonster + if (typeof localStorage.CMConfig != "undefined") { + delete localStorage.CMConfig; + } if (settings != null) { CM.Options = settings; diff --git a/src/Config.js b/src/Config.js index 066b88d..dd86c78 100644 --- a/src/Config.js +++ b/src/Config.js @@ -22,6 +22,10 @@ CM.Config.SaveConfig = function(config) { * It is called by CM.DelayInit() and CM.Config.RestoreDefault() */ CM.Config.LoadConfig = function(settings) { + // This removes cookies left from earlier versions of CookieMonster + if (typeof localStorage.CMConfig != "undefined") { + delete localStorage.CMConfig; + } if (settings != null) { CM.Options = settings; From c1501b47d6ec5f8a2c04f88348fe90080f0a39b8 Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Mon, 21 Dec 2020 23:56:50 +0100 Subject: [PATCH 087/106] Add subsections for notifications settings (#445) --- CookieMonster.js | 109 +++++++++++++++++++++++++++++------------------ src/Data.js | 90 +++++++++++++++++++++----------------- src/Disp.js | 19 ++++++++- 3 files changed, 136 insertions(+), 82 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index 80554b2..7ba0c74 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -893,7 +893,7 @@ CM.Data.shortScaleAbbreviated = ['', 'K', 'M', 'B', 'T', 'Qa', 'Qi', 'Sx', 'Sp', 'UCt'] /******** - * Section: An array containing all Config groups and their to-be displayed title */ + * Section: Two array's containing all Config groups and their to-be displayed title */ CM.ConfigGroups = { BarsColors: "Bars/Colors", @@ -901,7 +901,18 @@ CM.ConfigGroups = { Notification: "Notification", Tooltip: "Tooltips", Statistics: "Statistics", - Notation: "Notation"}, + Notation: "Notation" +} + +CM.ConfigGroupsNotification = { + NotificationGC: "Golden Cookie", + NotificationFC: "Fortune Cookie", + NotificationSea: "Season Special", + NotificationGard: "Garden Tick", + NotificationMagi: "Full Magic Bar", + NotificationWrink: "Wrinkler", + NotificationWrinkMax: "Maximum Wrinklers", +} /******** * Section: An array (CM.ConfigData) containing all Config options and an array of default settings */ @@ -948,65 +959,66 @@ CM.ConfigData.CPSMode = {type: 'bool', group: 'Calculation', label: ['Current Co CM.ConfigData.AvgCPSHist = {type: 'bool', group: 'Calculation', label: ['Average CPS for past 10s', 'Average CPS for past 15s', 'Average CPS for past 30s', 'Average CPS for past 1m', 'Average CPS for past 5m', 'Average CPS for past 10m', 'Average CPS for past 15m', 'Average CPS for past 30m'], desc: 'How much time average Cookies Per Second should consider', toggle: false}; CM.ConfigData.AvgClicksHist = {type: 'bool', group: 'Calculation', label: ['Average Cookie Clicks for past 1s', 'Average Cookie Clicks for past 5s', 'Average Cookie Clicks for past 10s', 'Average Cookie Clicks for past 15s', 'Average Cookie Clicks for past 30s'], desc: 'How much time average Cookie Clicks should consider', toggle: false}; CM.ConfigData.ToolWarnBon = {type: 'bool', group: 'Calculation', label: ['Calculate Tooltip Warning With Bonus CPS OFF', 'Calculate Tooltip Warning With Bonus CPS ON'], desc: 'Calculate the warning with or without the bonus CPS you get from buying', toggle: true}; +CM.ConfigData.GCTimer = {type: 'bool', group: 'Calculation', label: ['Timer OFF', 'Timer ON'], desc: 'A timer on the Golden Cookie when it has been spawned', toggle: true, func: function() {CM.Disp.ToggleGCTimer();}}; +CM.ConfigData.Favicon = {type: 'bool', group: 'Calculation', label: ['Favicon OFF', 'Favicon ON'], desc: 'Update favicon with Golden/Wrath Cookie', toggle: true, func: function() {CM.Disp.UpdateFavicon();}}; + // Notification -CM.ConfigData.GCNotification = {type: 'bool', group: 'Notification', label: ['Golden Cookie Notification OFF', 'Golden Cookie Notification ON'], desc: 'Create a notification when Golden Cookie spawns', toggle: true, func: function () {CM.Config.CheckNotificationPermissions(CM.Options.GCNotification);}}; -CM.ConfigData.GCFlash = {type: 'bool', group: 'Notification', label: ['Golden Cookie Flash OFF', 'Golden Cookie Flash ON'], desc: 'Flash screen on Golden Cookie', toggle: true}; -CM.ConfigData.GCSound = {type: 'bool', group: 'Notification', label: ['Golden Cookie Sound OFF', 'Golden Cookie Sound ON'], desc: 'Play a sound on Golden Cookie', toggle: true}; -CM.ConfigData.GCVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of Golden Cookie'}; +CM.ConfigData.GCNotification = {type: 'bool', group: 'NotificationGC', label: ['Notification OFF', 'Notification ON'], desc: 'Create a notification when Golden Cookie spawns', toggle: true, func: function () {CM.Config.CheckNotificationPermissions(CM.Options.GCNotification);}}; +CM.ConfigData.GCFlash = {type: 'bool', group: 'NotificationGC', label: ['Flash OFF', 'Flash ON'], desc: 'Flash screen on Golden Cookie', toggle: true}; +CM.ConfigData.GCSound = {type: 'bool', group: 'NotificationGC', label: ['Sound OFF', 'Sound ON'], desc: 'Play a sound on Golden Cookie', toggle: true}; +CM.ConfigData.GCVolume = {type: 'vol', group: 'NotificationGC', label: [], desc: 'Volume'}; for (var i = 0; i < 101; i++) { CM.ConfigData.GCVolume.label[i] = i + '%'; } -CM.ConfigData.GCSoundURL = {type: 'url', group: 'Notification', label: 'Golden Cookie Sound URL:', desc: 'URL of the sound to be played when a Golden Cookie spawns'}; -CM.ConfigData.GCTimer = {type: 'bool', group: 'Notification', label: ['Golden Cookie Timer OFF', 'Golden Cookie Timer ON'], desc: 'A timer on the Golden Cookie when it has been spawned', toggle: true, func: function() {CM.Disp.ToggleGCTimer();}}; -CM.ConfigData.Favicon = {type: 'bool', group: 'Notification', label: ['Favicon OFF', 'Favicon ON'], desc: 'Update favicon with Golden/Wrath Cookie', toggle: true, func: function() {CM.Disp.UpdateFavicon();}}; -CM.ConfigData.FortuneNotification = {type: 'bool', group: 'Notification', label: ['Fortune Cookie Notification OFF', 'Fortune Cookie Notification ON'], desc: 'Create a notification when Fortune Cookie is on the Ticker', toggle: true, func: function () {CM.Config.CheckNotificationPermissions(CM.Options.FortuneNotification);}}; -CM.ConfigData.FortuneFlash = {type: 'bool', group: 'Notification', label: ['Fortune Cookie Flash OFF', 'Fortune Cookie Flash ON'], desc: 'Flash screen on Fortune Cookie', toggle: true}; -CM.ConfigData.FortuneSound = {type: 'bool', group: 'Notification', label: ['Fortune Cookie Sound OFF', 'Fortune Cookie Sound ON'], desc: 'Play a sound on Fortune Cookie', toggle: true}; -CM.ConfigData.FortuneVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of Fortune Cookie'}; +CM.ConfigData.GCSoundURL = {type: 'url', group: 'NotificationGC', label: 'Sound URL:', desc: 'URL of the sound to be played when a Golden Cookie spawns'}; +CM.ConfigData.FortuneNotification = {type: 'bool', group: 'NotificationFC', label: ['Notification OFF', 'Notification ON'], desc: 'Create a notification when Fortune Cookie is on the Ticker', toggle: true, func: function () {CM.Config.CheckNotificationPermissions(CM.Options.FortuneNotification);}}; +CM.ConfigData.FortuneFlash = {type: 'bool', group: 'NotificationFC', label: ['Flash OFF', 'Flash ON'], desc: 'Flash screen on Fortune Cookie', toggle: true}; +CM.ConfigData.FortuneSound = {type: 'bool', group: 'NotificationFC', label: ['Sound OFF', 'Sound ON'], desc: 'Play a sound on Fortune Cookie', toggle: true}; +CM.ConfigData.FortuneVolume = {type: 'vol', group: 'NotificationFC', label: [], desc: 'Volume'}; for (var i = 0; i < 101; i++) { CM.ConfigData.FortuneVolume.label[i] = i + '%'; } -CM.ConfigData.FortuneSoundURL = {type: 'url', group: 'Notification', label: 'Fortune Cookie Sound URL:', desc: 'URL of the sound to be played when the Ticker has a Fortune Cookie'}; -CM.ConfigData.SeaNotification = {type: 'bool', group: 'Notification', label: ['Season Special Notification OFF', 'Season Special Notification ON'], desc: 'Create a notification on Season Popup', toggle: true, func: function () {CM.Config.CheckNotificationPermissions(CM.Options.SeaNotification);}}; -CM.ConfigData.SeaFlash = {type: 'bool', group: 'Notification', label: ['Season Special Flash OFF', 'Season Special Flash ON'], desc: 'Flash screen on Season Popup', toggle: true}; -CM.ConfigData.SeaSound = {type: 'bool', group: 'Notification', label: ['Season Special Sound OFF', 'Season Special Sound ON'], desc: 'Play a sound on Season Popup', toggle: true}; -CM.ConfigData.SeaVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of Season Special'}; +CM.ConfigData.FortuneSoundURL = {type: 'url', group: 'NotificationFC', label: 'Sound URL:', desc: 'URL of the sound to be played when the Ticker has a Fortune Cookie'}; +CM.ConfigData.SeaNotification = {type: 'bool', group: 'NotificationSea', label: ['Notification OFF', 'Notification ON'], desc: 'Create a notification on Season Popup', toggle: true, func: function () {CM.Config.CheckNotificationPermissions(CM.Options.SeaNotification);}}; +CM.ConfigData.SeaFlash = {type: 'bool', group: 'NotificationSea', label: ['Flash OFF', 'Flash ON'], desc: 'Flash screen on Season Popup', toggle: true}; +CM.ConfigData.SeaSound = {type: 'bool', group: 'NotificationSea', label: ['Sound OFF', 'Sound ON'], desc: 'Play a sound on Season Popup', toggle: true}; +CM.ConfigData.SeaVolume = {type: 'vol', group: 'NotificationSea', label: [], desc: 'Volume'}; for (var i = 0; i < 101; i++) { CM.ConfigData.SeaVolume.label[i] = i + '%'; } -CM.ConfigData.SeaSoundURL = {type: 'url', group: 'Notification', label: 'Season Special Sound URL:', desc: 'URL of the sound to be played when a Season Special spawns'}; -CM.ConfigData.GardFlash = {type: 'bool', group: 'Notification', label: ['Garden Tick Flash OFF', 'Garden Tick Flash ON'], desc: 'Flash screen on Garden Tick', toggle: true}; -CM.ConfigData.GardSound = {type: 'bool', group: 'Notification', label: ['Garden Tick Sound OFF', 'Garden Tick Sound ON'], desc: 'Play a sound on Garden Tick', toggle: true}; -CM.ConfigData.GardVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of Garden Tick'}; +CM.ConfigData.SeaSoundURL = {type: 'url', group: 'NotificationSea', label: 'Sound URL:', desc: 'URL of the sound to be played when a Season Special spawns'}; +CM.ConfigData.GardFlash = {type: 'bool', group: 'NotificationGard', label: ['Garden Tick Flash OFF', 'Flash ON'], desc: 'Flash screen on Garden Tick', toggle: true}; +CM.ConfigData.GardSound = {type: 'bool', group: 'NotificationGard', label: ['Sound OFF', 'Sound ON'], desc: 'Play a sound on Garden Tick', toggle: true}; +CM.ConfigData.GardVolume = {type: 'vol', group: 'NotificationGard', label: [], desc: 'Volume'}; for (var i = 0; i < 101; i++) { CM.ConfigData.GardVolume.label[i] = i + '%'; } -CM.ConfigData.GardSoundURL = {type: 'url', group: 'Notification', label: 'Garden Tick Sound URL:', desc: 'URL of the sound to be played when the garden ticks'}; -CM.ConfigData.MagicNotification = {type: 'bool', group: 'Notification', label: ['Magic Max Notification OFF', 'Magic Max Notification ON'], desc: 'Create a notification when magic reaches maximum', toggle: true, func: function () {CM.Config.CheckNotificationPermissions(CM.Options.MagicNotification);}}; -CM.ConfigData.MagicFlash = {type: 'bool', group: 'Notification', label: ['Magic Max Flash OFF', 'Magic Max Flash ON'], desc: 'Flash screen when magic reaches maximum', toggle: true}; -CM.ConfigData.MagicSound = {type: 'bool', group: 'Notification', label: ['Magic Max Sound OFF', 'Magic Max Sound ON'], desc: 'Play a sound when magic reaches maximum', toggle: true}; -CM.ConfigData.MagicVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of Max Magic'}; +CM.ConfigData.GardSoundURL = {type: 'url', group: 'NotificationGard', label: 'Garden Tick Sound URL:', desc: 'URL of the sound to be played when the garden ticks'}; +CM.ConfigData.MagicNotification = {type: 'bool', group: 'NotificationMagi', label: ['Notification OFF', 'Notification ON'], desc: 'Create a notification when magic reaches maximum', toggle: true, func: function () {CM.Config.CheckNotificationPermissions(CM.Options.MagicNotification);}}; +CM.ConfigData.MagicFlash = {type: 'bool', group: 'NotificationMagi', label: ['Flash OFF', 'Flash ON'], desc: 'Flash screen when magic reaches maximum', toggle: true}; +CM.ConfigData.MagicSound = {type: 'bool', group: 'NotificationMagi', label: ['Sound OFF', 'Sound ON'], desc: 'Play a sound when magic reaches maximum', toggle: true}; +CM.ConfigData.MagicVolume = {type: 'vol', group: 'NotificationMagi', label: [], desc: 'Volume'}; for (var i = 0; i < 101; i++) { CM.ConfigData.MagicVolume.label[i] = i + '%'; } -CM.ConfigData.MagicSoundURL = {type: 'url', group: 'Notification', label: 'Magic Max Sound URL:', desc: 'URL of the sound to be played when magic reaches maxium'}; -CM.ConfigData.WrinklerNotification = {type: 'bool', group: 'Notification', label: ['Wrinkler Notification OFF', 'Wrinkler Notification ON'], desc: 'Create a notification when a Wrinkler appears', toggle: true, func: function () {CM.Config.CheckNotificationPermissions(CM.Options.WrinklerNotification);}}; -CM.ConfigData.WrinklerFlash = {type: 'bool', group: 'Notification', label: ['Wrinkler Flash OFF', 'Wrinkler Flash ON'], desc: 'Flash screen when a Wrinkler appears', toggle: true}; -CM.ConfigData.WrinklerSound = {type: 'bool', group: 'Notification', label: ['Wrinkler Sound OFF', 'Wrinkler Sound ON'], desc: 'Play a sound when a Wrinkler appears', toggle: true}; -CM.ConfigData.WrinklerVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of Wrinkler'}; +CM.ConfigData.MagicSoundURL = {type: 'url', group: 'NotificationMagi', label: 'Sound URL:', desc: 'URL of the sound to be played when magic reaches maxium'}; +CM.ConfigData.WrinklerNotification = {type: 'bool', group: 'NotificationWrink', label: ['Notification OFF', 'Notification ON'], desc: 'Create a notification when a Wrinkler appears', toggle: true, func: function () {CM.Config.CheckNotificationPermissions(CM.Options.WrinklerNotification);}}; +CM.ConfigData.WrinklerFlash = {type: 'bool', group: 'NotificationWrink', label: ['Flash OFF', 'Flash ON'], desc: 'Flash screen when a Wrinkler appears', toggle: true}; +CM.ConfigData.WrinklerSound = {type: 'bool', group: 'NotificationWrink', label: ['Sound OFF', 'Sound ON'], desc: 'Play a sound when a Wrinkler appears', toggle: true}; +CM.ConfigData.WrinklerVolume = {type: 'vol', group: 'NotificationWrink', label: [], desc: 'Volume'}; for (var i = 0; i < 101; i++) { CM.ConfigData.WrinklerVolume.label[i] = i + '%'; } -CM.ConfigData.WrinklerSoundURL = {type: 'url', group: 'Notification', label: 'Wrinkler Sound URL:', desc: 'URL of the sound to be played when a Wrinkler appears'}; -CM.ConfigData.WrinklerMaxNotification = {type: 'bool', group: 'Notification', label: ['Wrinkler Max Notification OFF', 'Wrinkler Max Notification ON'], desc: 'Create a notification when the maximum amount of Wrinklers has appeared', toggle: true, func: function () {CM.Config.CheckNotificationPermissions(CM.Options.WrinklerMaxNotification);}}; -CM.ConfigData.WrinklerMaxFlash = {type: 'bool', group: 'Notification', label: ['Wrinkler Max Flash OFF', 'Wrinkler Max Flash ON'], desc: 'Flash screen when the maximum amount of Wrinklers has appeared', toggle: true}; -CM.ConfigData.WrinklerMaxSound = {type: 'bool', group: 'Notification', label: ['Wrinkler Max Sound OFF', 'Wrinkler Max Sound ON'], desc: 'Play a sound when the maximum amount of Wrinklers has appeared', toggle: true}; -CM.ConfigData.WrinklerMaxVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of Wrinkler Max'}; +CM.ConfigData.WrinklerSoundURL = {type: 'url', group: 'NotificationWrink', label: 'Sound URL:', desc: 'URL of the sound to be played when a Wrinkler appears'}; +CM.ConfigData.WrinklerMaxNotification = {type: 'bool', group: 'NotificationWrinkMax', label: ['Notification OFF', 'Notification ON'], desc: 'Create a notification when the maximum amount of Wrinklers has appeared', toggle: true, func: function () {CM.Config.CheckNotificationPermissions(CM.Options.WrinklerMaxNotification);}}; +CM.ConfigData.WrinklerMaxFlash = {type: 'bool', group: 'NotificationWrinkMax', label: ['Flash OFF', 'Flash ON'], desc: 'Flash screen when the maximum amount of Wrinklers has appeared', toggle: true}; +CM.ConfigData.WrinklerMaxSound = {type: 'bool', group: 'NotificationWrinkMax', label: ['Sound OFF', 'Sound ON'], desc: 'Play a sound when the maximum amount of Wrinklers has appeared', toggle: true}; +CM.ConfigData.WrinklerMaxVolume = {type: 'vol', group: 'NotificationWrinkMax', label: [], desc: 'Volume'}; for (var i = 0; i < 101; i++) { CM.ConfigData.WrinklerMaxVolume.label[i] = i + '%'; } -CM.ConfigData.WrinklerMaxSoundURL = {type: 'url', group: 'Notification', label: 'Wrinkler Max Sound URL:', desc: 'URL of the sound to be played when the maximum amount of Wrinklers has appeared'}; +CM.ConfigData.WrinklerMaxSoundURL = {type: 'url', group: 'NotificationWrinkMax', label: 'Sound URL:', desc: 'URL of the sound to be played when the maximum amount of Wrinklers has appeared'}; CM.ConfigData.Title = {type: 'bool', group: 'Notification', label: ['Title OFF', 'Title ON', 'Title Pinned Tab Highlight'], desc: 'Update title with Golden Cookie/Season Popup timers; pinned tab highlight only changes the title when a Golden Cookie/Season Popup spawns', toggle: true}; // Tooltip @@ -1115,7 +1127,7 @@ CM.Data.ConfigDefault = { Colors: {Blue: '#4bb8f0', Green: '#00ff00', Yellow: '#ffff00', Orange: '#ff7f00', Red: '#ff0000', Purple: '#ff00ff', Gray: '#b3b3b3', Pink: '#ff1493', Brown: '#8b4513'}, SortBuildings: 0, SortUpgrades: 0, - Header: {BarsColors: 1, Calculation: 1, Notification: 1, Tooltip: 1, Statistics: 1, Notation: 1, Lucky: 1, Spells: 1, Chain: 1, Prestige: 1, Wrink: 1, Sea: 1, Misc: 1}, + Header: {BarsColors: 1, Calculation: 1, Notification: 1, NotificationGC: 1, NotificationFC: 1, NotificationSea: 1, NotificationGard: 1, NotificationMagi: 1, NotificationWrink: 1, NotificationWrinkMax: 1, Tooltip: 1, Statistics: 1, Notation: 1, Lucky: 1, Spells: 1, Chain: 1, Prestige: 1, Wrink: 1, Sea: 1, Misc: 1}, }; /******** @@ -2977,8 +2989,23 @@ CM.Disp.AddMenuPref = function(title) { groupObject = CM.Disp.CreatePrefHeader(group, CM.ConfigGroups[group]) // (group, display-name of group) frag.appendChild(groupObject) if (CM.Options.Header[group]) { // 0 is show, 1 is collapsed - for (var option in CM.ConfigData) { - if (CM.ConfigData[option].group == group) frag.appendChild(CM.Disp.CreatePrefOption(option)) + // Make sub-sections of Notification section + if (group == "Notification") { + for (var subGroup in CM.ConfigGroupsNotification) { + subGroupObject = CM.Disp.CreatePrefHeader(subGroup, CM.ConfigGroupsNotification[subGroup]) // (group, display-name of group) + subGroupObject.style.fontSize = "15px"; + subGroupObject.style.opacity = "0.5"; + frag.appendChild(subGroupObject) + if (CM.Options.Header[subGroup]) { + for (var option in CM.ConfigData) { + if (CM.ConfigData[option].group == subGroup) frag.appendChild(CM.Disp.CreatePrefOption(option)) + } + } + } + } else { + for (var option in CM.ConfigData) { + if (CM.ConfigData[option].group == group) frag.appendChild(CM.Disp.CreatePrefOption(option)) + } } } } diff --git a/src/Data.js b/src/Data.js index dd06377..dd94794 100644 --- a/src/Data.js +++ b/src/Data.js @@ -53,7 +53,7 @@ CM.Data.shortScaleAbbreviated = ['', 'K', 'M', 'B', 'T', 'Qa', 'Qi', 'Sx', 'Sp', 'UCt'] /******** - * Section: An array containing all Config groups and their to-be displayed title */ + * Section: Two array's containing all Config groups and their to-be displayed title */ CM.ConfigGroups = { BarsColors: "Bars/Colors", @@ -61,7 +61,18 @@ CM.ConfigGroups = { Notification: "Notification", Tooltip: "Tooltips", Statistics: "Statistics", - Notation: "Notation"}, + Notation: "Notation" +} + +CM.ConfigGroupsNotification = { + NotificationGC: "Golden Cookie", + NotificationFC: "Fortune Cookie", + NotificationSea: "Season Special", + NotificationGard: "Garden Tick", + NotificationMagi: "Full Magic Bar", + NotificationWrink: "Wrinkler", + NotificationWrinkMax: "Maximum Wrinklers", +} /******** * Section: An array (CM.ConfigData) containing all Config options and an array of default settings */ @@ -108,65 +119,66 @@ CM.ConfigData.CPSMode = {type: 'bool', group: 'Calculation', label: ['Current Co CM.ConfigData.AvgCPSHist = {type: 'bool', group: 'Calculation', label: ['Average CPS for past 10s', 'Average CPS for past 15s', 'Average CPS for past 30s', 'Average CPS for past 1m', 'Average CPS for past 5m', 'Average CPS for past 10m', 'Average CPS for past 15m', 'Average CPS for past 30m'], desc: 'How much time average Cookies Per Second should consider', toggle: false}; CM.ConfigData.AvgClicksHist = {type: 'bool', group: 'Calculation', label: ['Average Cookie Clicks for past 1s', 'Average Cookie Clicks for past 5s', 'Average Cookie Clicks for past 10s', 'Average Cookie Clicks for past 15s', 'Average Cookie Clicks for past 30s'], desc: 'How much time average Cookie Clicks should consider', toggle: false}; CM.ConfigData.ToolWarnBon = {type: 'bool', group: 'Calculation', label: ['Calculate Tooltip Warning With Bonus CPS OFF', 'Calculate Tooltip Warning With Bonus CPS ON'], desc: 'Calculate the warning with or without the bonus CPS you get from buying', toggle: true}; +CM.ConfigData.GCTimer = {type: 'bool', group: 'Calculation', label: ['Timer OFF', 'Timer ON'], desc: 'A timer on the Golden Cookie when it has been spawned', toggle: true, func: function() {CM.Disp.ToggleGCTimer();}}; +CM.ConfigData.Favicon = {type: 'bool', group: 'Calculation', label: ['Favicon OFF', 'Favicon ON'], desc: 'Update favicon with Golden/Wrath Cookie', toggle: true, func: function() {CM.Disp.UpdateFavicon();}}; + // Notification -CM.ConfigData.GCNotification = {type: 'bool', group: 'Notification', label: ['Golden Cookie Notification OFF', 'Golden Cookie Notification ON'], desc: 'Create a notification when Golden Cookie spawns', toggle: true, func: function () {CM.Config.CheckNotificationPermissions(CM.Options.GCNotification);}}; -CM.ConfigData.GCFlash = {type: 'bool', group: 'Notification', label: ['Golden Cookie Flash OFF', 'Golden Cookie Flash ON'], desc: 'Flash screen on Golden Cookie', toggle: true}; -CM.ConfigData.GCSound = {type: 'bool', group: 'Notification', label: ['Golden Cookie Sound OFF', 'Golden Cookie Sound ON'], desc: 'Play a sound on Golden Cookie', toggle: true}; -CM.ConfigData.GCVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of Golden Cookie'}; +CM.ConfigData.GCNotification = {type: 'bool', group: 'NotificationGC', label: ['Notification OFF', 'Notification ON'], desc: 'Create a notification when Golden Cookie spawns', toggle: true, func: function () {CM.Config.CheckNotificationPermissions(CM.Options.GCNotification);}}; +CM.ConfigData.GCFlash = {type: 'bool', group: 'NotificationGC', label: ['Flash OFF', 'Flash ON'], desc: 'Flash screen on Golden Cookie', toggle: true}; +CM.ConfigData.GCSound = {type: 'bool', group: 'NotificationGC', label: ['Sound OFF', 'Sound ON'], desc: 'Play a sound on Golden Cookie', toggle: true}; +CM.ConfigData.GCVolume = {type: 'vol', group: 'NotificationGC', label: [], desc: 'Volume'}; for (var i = 0; i < 101; i++) { CM.ConfigData.GCVolume.label[i] = i + '%'; } -CM.ConfigData.GCSoundURL = {type: 'url', group: 'Notification', label: 'Golden Cookie Sound URL:', desc: 'URL of the sound to be played when a Golden Cookie spawns'}; -CM.ConfigData.GCTimer = {type: 'bool', group: 'Notification', label: ['Golden Cookie Timer OFF', 'Golden Cookie Timer ON'], desc: 'A timer on the Golden Cookie when it has been spawned', toggle: true, func: function() {CM.Disp.ToggleGCTimer();}}; -CM.ConfigData.Favicon = {type: 'bool', group: 'Notification', label: ['Favicon OFF', 'Favicon ON'], desc: 'Update favicon with Golden/Wrath Cookie', toggle: true, func: function() {CM.Disp.UpdateFavicon();}}; -CM.ConfigData.FortuneNotification = {type: 'bool', group: 'Notification', label: ['Fortune Cookie Notification OFF', 'Fortune Cookie Notification ON'], desc: 'Create a notification when Fortune Cookie is on the Ticker', toggle: true, func: function () {CM.Config.CheckNotificationPermissions(CM.Options.FortuneNotification);}}; -CM.ConfigData.FortuneFlash = {type: 'bool', group: 'Notification', label: ['Fortune Cookie Flash OFF', 'Fortune Cookie Flash ON'], desc: 'Flash screen on Fortune Cookie', toggle: true}; -CM.ConfigData.FortuneSound = {type: 'bool', group: 'Notification', label: ['Fortune Cookie Sound OFF', 'Fortune Cookie Sound ON'], desc: 'Play a sound on Fortune Cookie', toggle: true}; -CM.ConfigData.FortuneVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of Fortune Cookie'}; +CM.ConfigData.GCSoundURL = {type: 'url', group: 'NotificationGC', label: 'Sound URL:', desc: 'URL of the sound to be played when a Golden Cookie spawns'}; +CM.ConfigData.FortuneNotification = {type: 'bool', group: 'NotificationFC', label: ['Notification OFF', 'Notification ON'], desc: 'Create a notification when Fortune Cookie is on the Ticker', toggle: true, func: function () {CM.Config.CheckNotificationPermissions(CM.Options.FortuneNotification);}}; +CM.ConfigData.FortuneFlash = {type: 'bool', group: 'NotificationFC', label: ['Flash OFF', 'Flash ON'], desc: 'Flash screen on Fortune Cookie', toggle: true}; +CM.ConfigData.FortuneSound = {type: 'bool', group: 'NotificationFC', label: ['Sound OFF', 'Sound ON'], desc: 'Play a sound on Fortune Cookie', toggle: true}; +CM.ConfigData.FortuneVolume = {type: 'vol', group: 'NotificationFC', label: [], desc: 'Volume'}; for (var i = 0; i < 101; i++) { CM.ConfigData.FortuneVolume.label[i] = i + '%'; } -CM.ConfigData.FortuneSoundURL = {type: 'url', group: 'Notification', label: 'Fortune Cookie Sound URL:', desc: 'URL of the sound to be played when the Ticker has a Fortune Cookie'}; -CM.ConfigData.SeaNotification = {type: 'bool', group: 'Notification', label: ['Season Special Notification OFF', 'Season Special Notification ON'], desc: 'Create a notification on Season Popup', toggle: true, func: function () {CM.Config.CheckNotificationPermissions(CM.Options.SeaNotification);}}; -CM.ConfigData.SeaFlash = {type: 'bool', group: 'Notification', label: ['Season Special Flash OFF', 'Season Special Flash ON'], desc: 'Flash screen on Season Popup', toggle: true}; -CM.ConfigData.SeaSound = {type: 'bool', group: 'Notification', label: ['Season Special Sound OFF', 'Season Special Sound ON'], desc: 'Play a sound on Season Popup', toggle: true}; -CM.ConfigData.SeaVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of Season Special'}; +CM.ConfigData.FortuneSoundURL = {type: 'url', group: 'NotificationFC', label: 'Sound URL:', desc: 'URL of the sound to be played when the Ticker has a Fortune Cookie'}; +CM.ConfigData.SeaNotification = {type: 'bool', group: 'NotificationSea', label: ['Notification OFF', 'Notification ON'], desc: 'Create a notification on Season Popup', toggle: true, func: function () {CM.Config.CheckNotificationPermissions(CM.Options.SeaNotification);}}; +CM.ConfigData.SeaFlash = {type: 'bool', group: 'NotificationSea', label: ['Flash OFF', 'Flash ON'], desc: 'Flash screen on Season Popup', toggle: true}; +CM.ConfigData.SeaSound = {type: 'bool', group: 'NotificationSea', label: ['Sound OFF', 'Sound ON'], desc: 'Play a sound on Season Popup', toggle: true}; +CM.ConfigData.SeaVolume = {type: 'vol', group: 'NotificationSea', label: [], desc: 'Volume'}; for (var i = 0; i < 101; i++) { CM.ConfigData.SeaVolume.label[i] = i + '%'; } -CM.ConfigData.SeaSoundURL = {type: 'url', group: 'Notification', label: 'Season Special Sound URL:', desc: 'URL of the sound to be played when a Season Special spawns'}; -CM.ConfigData.GardFlash = {type: 'bool', group: 'Notification', label: ['Garden Tick Flash OFF', 'Garden Tick Flash ON'], desc: 'Flash screen on Garden Tick', toggle: true}; -CM.ConfigData.GardSound = {type: 'bool', group: 'Notification', label: ['Garden Tick Sound OFF', 'Garden Tick Sound ON'], desc: 'Play a sound on Garden Tick', toggle: true}; -CM.ConfigData.GardVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of Garden Tick'}; +CM.ConfigData.SeaSoundURL = {type: 'url', group: 'NotificationSea', label: 'Sound URL:', desc: 'URL of the sound to be played when a Season Special spawns'}; +CM.ConfigData.GardFlash = {type: 'bool', group: 'NotificationGard', label: ['Garden Tick Flash OFF', 'Flash ON'], desc: 'Flash screen on Garden Tick', toggle: true}; +CM.ConfigData.GardSound = {type: 'bool', group: 'NotificationGard', label: ['Sound OFF', 'Sound ON'], desc: 'Play a sound on Garden Tick', toggle: true}; +CM.ConfigData.GardVolume = {type: 'vol', group: 'NotificationGard', label: [], desc: 'Volume'}; for (var i = 0; i < 101; i++) { CM.ConfigData.GardVolume.label[i] = i + '%'; } -CM.ConfigData.GardSoundURL = {type: 'url', group: 'Notification', label: 'Garden Tick Sound URL:', desc: 'URL of the sound to be played when the garden ticks'}; -CM.ConfigData.MagicNotification = {type: 'bool', group: 'Notification', label: ['Magic Max Notification OFF', 'Magic Max Notification ON'], desc: 'Create a notification when magic reaches maximum', toggle: true, func: function () {CM.Config.CheckNotificationPermissions(CM.Options.MagicNotification);}}; -CM.ConfigData.MagicFlash = {type: 'bool', group: 'Notification', label: ['Magic Max Flash OFF', 'Magic Max Flash ON'], desc: 'Flash screen when magic reaches maximum', toggle: true}; -CM.ConfigData.MagicSound = {type: 'bool', group: 'Notification', label: ['Magic Max Sound OFF', 'Magic Max Sound ON'], desc: 'Play a sound when magic reaches maximum', toggle: true}; -CM.ConfigData.MagicVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of Max Magic'}; +CM.ConfigData.GardSoundURL = {type: 'url', group: 'NotificationGard', label: 'Garden Tick Sound URL:', desc: 'URL of the sound to be played when the garden ticks'}; +CM.ConfigData.MagicNotification = {type: 'bool', group: 'NotificationMagi', label: ['Notification OFF', 'Notification ON'], desc: 'Create a notification when magic reaches maximum', toggle: true, func: function () {CM.Config.CheckNotificationPermissions(CM.Options.MagicNotification);}}; +CM.ConfigData.MagicFlash = {type: 'bool', group: 'NotificationMagi', label: ['Flash OFF', 'Flash ON'], desc: 'Flash screen when magic reaches maximum', toggle: true}; +CM.ConfigData.MagicSound = {type: 'bool', group: 'NotificationMagi', label: ['Sound OFF', 'Sound ON'], desc: 'Play a sound when magic reaches maximum', toggle: true}; +CM.ConfigData.MagicVolume = {type: 'vol', group: 'NotificationMagi', label: [], desc: 'Volume'}; for (var i = 0; i < 101; i++) { CM.ConfigData.MagicVolume.label[i] = i + '%'; } -CM.ConfigData.MagicSoundURL = {type: 'url', group: 'Notification', label: 'Magic Max Sound URL:', desc: 'URL of the sound to be played when magic reaches maxium'}; -CM.ConfigData.WrinklerNotification = {type: 'bool', group: 'Notification', label: ['Wrinkler Notification OFF', 'Wrinkler Notification ON'], desc: 'Create a notification when a Wrinkler appears', toggle: true, func: function () {CM.Config.CheckNotificationPermissions(CM.Options.WrinklerNotification);}}; -CM.ConfigData.WrinklerFlash = {type: 'bool', group: 'Notification', label: ['Wrinkler Flash OFF', 'Wrinkler Flash ON'], desc: 'Flash screen when a Wrinkler appears', toggle: true}; -CM.ConfigData.WrinklerSound = {type: 'bool', group: 'Notification', label: ['Wrinkler Sound OFF', 'Wrinkler Sound ON'], desc: 'Play a sound when a Wrinkler appears', toggle: true}; -CM.ConfigData.WrinklerVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of Wrinkler'}; +CM.ConfigData.MagicSoundURL = {type: 'url', group: 'NotificationMagi', label: 'Sound URL:', desc: 'URL of the sound to be played when magic reaches maxium'}; +CM.ConfigData.WrinklerNotification = {type: 'bool', group: 'NotificationWrink', label: ['Notification OFF', 'Notification ON'], desc: 'Create a notification when a Wrinkler appears', toggle: true, func: function () {CM.Config.CheckNotificationPermissions(CM.Options.WrinklerNotification);}}; +CM.ConfigData.WrinklerFlash = {type: 'bool', group: 'NotificationWrink', label: ['Flash OFF', 'Flash ON'], desc: 'Flash screen when a Wrinkler appears', toggle: true}; +CM.ConfigData.WrinklerSound = {type: 'bool', group: 'NotificationWrink', label: ['Sound OFF', 'Sound ON'], desc: 'Play a sound when a Wrinkler appears', toggle: true}; +CM.ConfigData.WrinklerVolume = {type: 'vol', group: 'NotificationWrink', label: [], desc: 'Volume'}; for (var i = 0; i < 101; i++) { CM.ConfigData.WrinklerVolume.label[i] = i + '%'; } -CM.ConfigData.WrinklerSoundURL = {type: 'url', group: 'Notification', label: 'Wrinkler Sound URL:', desc: 'URL of the sound to be played when a Wrinkler appears'}; -CM.ConfigData.WrinklerMaxNotification = {type: 'bool', group: 'Notification', label: ['Wrinkler Max Notification OFF', 'Wrinkler Max Notification ON'], desc: 'Create a notification when the maximum amount of Wrinklers has appeared', toggle: true, func: function () {CM.Config.CheckNotificationPermissions(CM.Options.WrinklerMaxNotification);}}; -CM.ConfigData.WrinklerMaxFlash = {type: 'bool', group: 'Notification', label: ['Wrinkler Max Flash OFF', 'Wrinkler Max Flash ON'], desc: 'Flash screen when the maximum amount of Wrinklers has appeared', toggle: true}; -CM.ConfigData.WrinklerMaxSound = {type: 'bool', group: 'Notification', label: ['Wrinkler Max Sound OFF', 'Wrinkler Max Sound ON'], desc: 'Play a sound when the maximum amount of Wrinklers has appeared', toggle: true}; -CM.ConfigData.WrinklerMaxVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of Wrinkler Max'}; +CM.ConfigData.WrinklerSoundURL = {type: 'url', group: 'NotificationWrink', label: 'Sound URL:', desc: 'URL of the sound to be played when a Wrinkler appears'}; +CM.ConfigData.WrinklerMaxNotification = {type: 'bool', group: 'NotificationWrinkMax', label: ['Notification OFF', 'Notification ON'], desc: 'Create a notification when the maximum amount of Wrinklers has appeared', toggle: true, func: function () {CM.Config.CheckNotificationPermissions(CM.Options.WrinklerMaxNotification);}}; +CM.ConfigData.WrinklerMaxFlash = {type: 'bool', group: 'NotificationWrinkMax', label: ['Flash OFF', 'Flash ON'], desc: 'Flash screen when the maximum amount of Wrinklers has appeared', toggle: true}; +CM.ConfigData.WrinklerMaxSound = {type: 'bool', group: 'NotificationWrinkMax', label: ['Sound OFF', 'Sound ON'], desc: 'Play a sound when the maximum amount of Wrinklers has appeared', toggle: true}; +CM.ConfigData.WrinklerMaxVolume = {type: 'vol', group: 'NotificationWrinkMax', label: [], desc: 'Volume'}; for (var i = 0; i < 101; i++) { CM.ConfigData.WrinklerMaxVolume.label[i] = i + '%'; } -CM.ConfigData.WrinklerMaxSoundURL = {type: 'url', group: 'Notification', label: 'Wrinkler Max Sound URL:', desc: 'URL of the sound to be played when the maximum amount of Wrinklers has appeared'}; +CM.ConfigData.WrinklerMaxSoundURL = {type: 'url', group: 'NotificationWrinkMax', label: 'Sound URL:', desc: 'URL of the sound to be played when the maximum amount of Wrinklers has appeared'}; CM.ConfigData.Title = {type: 'bool', group: 'Notification', label: ['Title OFF', 'Title ON', 'Title Pinned Tab Highlight'], desc: 'Update title with Golden Cookie/Season Popup timers; pinned tab highlight only changes the title when a Golden Cookie/Season Popup spawns', toggle: true}; // Tooltip @@ -275,6 +287,6 @@ CM.Data.ConfigDefault = { Colors: {Blue: '#4bb8f0', Green: '#00ff00', Yellow: '#ffff00', Orange: '#ff7f00', Red: '#ff0000', Purple: '#ff00ff', Gray: '#b3b3b3', Pink: '#ff1493', Brown: '#8b4513'}, SortBuildings: 0, SortUpgrades: 0, - Header: {BarsColors: 1, Calculation: 1, Notification: 1, Tooltip: 1, Statistics: 1, Notation: 1, Lucky: 1, Spells: 1, Chain: 1, Prestige: 1, Wrink: 1, Sea: 1, Misc: 1}, + Header: {BarsColors: 1, Calculation: 1, Notification: 1, NotificationGC: 1, NotificationFC: 1, NotificationSea: 1, NotificationGard: 1, NotificationMagi: 1, NotificationWrink: 1, NotificationWrinkMax: 1, Tooltip: 1, Statistics: 1, Notation: 1, Lucky: 1, Spells: 1, Chain: 1, Prestige: 1, Wrink: 1, Sea: 1, Misc: 1}, }; diff --git a/src/Disp.js b/src/Disp.js index 705700f..45f627c 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -1857,8 +1857,23 @@ CM.Disp.AddMenuPref = function(title) { groupObject = CM.Disp.CreatePrefHeader(group, CM.ConfigGroups[group]) // (group, display-name of group) frag.appendChild(groupObject) if (CM.Options.Header[group]) { // 0 is show, 1 is collapsed - for (var option in CM.ConfigData) { - if (CM.ConfigData[option].group == group) frag.appendChild(CM.Disp.CreatePrefOption(option)) + // Make sub-sections of Notification section + if (group == "Notification") { + for (var subGroup in CM.ConfigGroupsNotification) { + subGroupObject = CM.Disp.CreatePrefHeader(subGroup, CM.ConfigGroupsNotification[subGroup]) // (group, display-name of group) + subGroupObject.style.fontSize = "15px"; + subGroupObject.style.opacity = "0.5"; + frag.appendChild(subGroupObject) + if (CM.Options.Header[subGroup]) { + for (var option in CM.ConfigData) { + if (CM.ConfigData[option].group == subGroup) frag.appendChild(CM.Disp.CreatePrefOption(option)) + } + } + } + } else { + for (var option in CM.ConfigData) { + if (CM.ConfigData[option].group == group) frag.appendChild(CM.Disp.CreatePrefOption(option)) + } } } } From 2f430e82e14425d1f20228504f8409ca6ecda776 Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Tue, 22 Dec 2020 23:13:12 +0100 Subject: [PATCH 088/106] Added CM to version number in BotBar (#471) --- CookieMonster.js | 2 +- src/Disp.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index 7ba0c74..cf9185c 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -1479,7 +1479,7 @@ CM.Disp.CreateBotBar = function() { } var type = tbody.appendChild(document.createElement('tr')); type.style.fontWeight = 'bold'; - type.appendChild(firstCol(CM.VersionMajor + '.' + CM.VersionMinor, CM.Disp.colorYellow)); + type.appendChild(firstCol('CM ' + CM.VersionMajor + '.' + CM.VersionMinor, CM.Disp.colorYellow)); var bonus = tbody.appendChild(document.createElement('tr')); bonus.appendChild(firstCol('Bonus Income', CM.Disp.colorBlue)); var pp = tbody.appendChild(document.createElement('tr')); diff --git a/src/Disp.js b/src/Disp.js index 45f627c..6a56fcb 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -347,7 +347,7 @@ CM.Disp.CreateBotBar = function() { } var type = tbody.appendChild(document.createElement('tr')); type.style.fontWeight = 'bold'; - type.appendChild(firstCol(CM.VersionMajor + '.' + CM.VersionMinor, CM.Disp.colorYellow)); + type.appendChild(firstCol('CM ' + CM.VersionMajor + '.' + CM.VersionMinor, CM.Disp.colorYellow)); var bonus = tbody.appendChild(document.createElement('tr')); bonus.appendChild(firstCol('Bonus Income', CM.Disp.colorBlue)); var pp = tbody.appendChild(document.createElement('tr')); From 0c095e4d81a90a2a30ba91f1d328f1d628ebd7eb Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Tue, 22 Dec 2020 23:16:50 +0100 Subject: [PATCH 089/106] Add new options section (#470) --- CookieMonster.js | 13 ++++++++----- src/Data.js | 13 ++++++++----- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index cf9185c..9a5a6b6 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -901,7 +901,8 @@ CM.ConfigGroups = { Notification: "Notification", Tooltip: "Tooltips", Statistics: "Statistics", - Notation: "Notation" + Notation: "Notation", + Miscellaneous: "Miscellaneous" } CM.ConfigGroupsNotification = { @@ -959,9 +960,6 @@ CM.ConfigData.CPSMode = {type: 'bool', group: 'Calculation', label: ['Current Co CM.ConfigData.AvgCPSHist = {type: 'bool', group: 'Calculation', label: ['Average CPS for past 10s', 'Average CPS for past 15s', 'Average CPS for past 30s', 'Average CPS for past 1m', 'Average CPS for past 5m', 'Average CPS for past 10m', 'Average CPS for past 15m', 'Average CPS for past 30m'], desc: 'How much time average Cookies Per Second should consider', toggle: false}; CM.ConfigData.AvgClicksHist = {type: 'bool', group: 'Calculation', label: ['Average Cookie Clicks for past 1s', 'Average Cookie Clicks for past 5s', 'Average Cookie Clicks for past 10s', 'Average Cookie Clicks for past 15s', 'Average Cookie Clicks for past 30s'], desc: 'How much time average Cookie Clicks should consider', toggle: false}; CM.ConfigData.ToolWarnBon = {type: 'bool', group: 'Calculation', label: ['Calculate Tooltip Warning With Bonus CPS OFF', 'Calculate Tooltip Warning With Bonus CPS ON'], desc: 'Calculate the warning with or without the bonus CPS you get from buying', toggle: true}; -CM.ConfigData.GCTimer = {type: 'bool', group: 'Calculation', label: ['Timer OFF', 'Timer ON'], desc: 'A timer on the Golden Cookie when it has been spawned', toggle: true, func: function() {CM.Disp.ToggleGCTimer();}}; -CM.ConfigData.Favicon = {type: 'bool', group: 'Calculation', label: ['Favicon OFF', 'Favicon ON'], desc: 'Update favicon with Golden/Wrath Cookie', toggle: true, func: function() {CM.Disp.UpdateFavicon();}}; - // Notification CM.ConfigData.GCNotification = {type: 'bool', group: 'NotificationGC', label: ['Notification OFF', 'Notification ON'], desc: 'Create a notification when Golden Cookie spawns', toggle: true, func: function () {CM.Config.CheckNotificationPermissions(CM.Options.GCNotification);}}; @@ -1048,6 +1046,11 @@ CM.ConfigData.ScaleDecimals = {type: 'bool', group: 'Notation', label: ['1 decim CM.ConfigData.ScaleSeparator = {type: 'bool', group: 'Notation', label: ['. for decimals (Standard)', '. for thousands'], desc: 'Set the separator used for decimals and thousands', toggle: false, func: function() {CM.Disp.RefreshScale();}}; CM.ConfigData.ScaleCutoff = {type: 'numscale', group: 'Notation', label: 'Notation Cut-off Point', desc: 'The number from which CookieMonster will start formatting numbers based on chosen scale. Standard is 999,999. Setting this above 999,999,999 might break certain notations.', min: 1, max: 999999999}; +// Miscellaneous +CM.ConfigData.GCTimer = {type: 'bool', group: 'Miscellaneous', label: ['Golden Cookie Timer OFF', 'Golden Cookie Timer ON'], desc: 'A timer on the Golden Cookie when it has been spawned', toggle: true, func: function() {CM.Disp.ToggleGCTimer();}}; +CM.ConfigData.Favicon = {type: 'bool', group: 'Miscellaneous', label: ['Favicon OFF', 'Favicon ON'], desc: 'Update favicon with Golden/Wrath Cookie', toggle: true, func: function() {CM.Disp.UpdateFavicon();}}; + + /** * This array describes all default settings * It is used by CM.LoadConfig() and CM.Config.RestoreDefault() @@ -1127,7 +1130,7 @@ CM.Data.ConfigDefault = { Colors: {Blue: '#4bb8f0', Green: '#00ff00', Yellow: '#ffff00', Orange: '#ff7f00', Red: '#ff0000', Purple: '#ff00ff', Gray: '#b3b3b3', Pink: '#ff1493', Brown: '#8b4513'}, SortBuildings: 0, SortUpgrades: 0, - Header: {BarsColors: 1, Calculation: 1, Notification: 1, NotificationGC: 1, NotificationFC: 1, NotificationSea: 1, NotificationGard: 1, NotificationMagi: 1, NotificationWrink: 1, NotificationWrinkMax: 1, Tooltip: 1, Statistics: 1, Notation: 1, Lucky: 1, Spells: 1, Chain: 1, Prestige: 1, Wrink: 1, Sea: 1, Misc: 1}, + Header: {BarsColors: 1, Calculation: 1, Notification: 1, NotificationGC: 1, NotificationFC: 1, NotificationSea: 1, NotificationGard: 1, NotificationMagi: 1, NotificationWrink: 1, NotificationWrinkMax: 1, Tooltip: 1, Statistics: 1, Notation: 1, Miscellaneous: 1, Lucky: 1, Spells: 1, Chain: 1, Prestige: 1, Wrink: 1, Sea: 1, Misc: 1}, }; /******** diff --git a/src/Data.js b/src/Data.js index dd94794..cd71820 100644 --- a/src/Data.js +++ b/src/Data.js @@ -61,7 +61,8 @@ CM.ConfigGroups = { Notification: "Notification", Tooltip: "Tooltips", Statistics: "Statistics", - Notation: "Notation" + Notation: "Notation", + Miscellaneous: "Miscellaneous" } CM.ConfigGroupsNotification = { @@ -119,9 +120,6 @@ CM.ConfigData.CPSMode = {type: 'bool', group: 'Calculation', label: ['Current Co CM.ConfigData.AvgCPSHist = {type: 'bool', group: 'Calculation', label: ['Average CPS for past 10s', 'Average CPS for past 15s', 'Average CPS for past 30s', 'Average CPS for past 1m', 'Average CPS for past 5m', 'Average CPS for past 10m', 'Average CPS for past 15m', 'Average CPS for past 30m'], desc: 'How much time average Cookies Per Second should consider', toggle: false}; CM.ConfigData.AvgClicksHist = {type: 'bool', group: 'Calculation', label: ['Average Cookie Clicks for past 1s', 'Average Cookie Clicks for past 5s', 'Average Cookie Clicks for past 10s', 'Average Cookie Clicks for past 15s', 'Average Cookie Clicks for past 30s'], desc: 'How much time average Cookie Clicks should consider', toggle: false}; CM.ConfigData.ToolWarnBon = {type: 'bool', group: 'Calculation', label: ['Calculate Tooltip Warning With Bonus CPS OFF', 'Calculate Tooltip Warning With Bonus CPS ON'], desc: 'Calculate the warning with or without the bonus CPS you get from buying', toggle: true}; -CM.ConfigData.GCTimer = {type: 'bool', group: 'Calculation', label: ['Timer OFF', 'Timer ON'], desc: 'A timer on the Golden Cookie when it has been spawned', toggle: true, func: function() {CM.Disp.ToggleGCTimer();}}; -CM.ConfigData.Favicon = {type: 'bool', group: 'Calculation', label: ['Favicon OFF', 'Favicon ON'], desc: 'Update favicon with Golden/Wrath Cookie', toggle: true, func: function() {CM.Disp.UpdateFavicon();}}; - // Notification CM.ConfigData.GCNotification = {type: 'bool', group: 'NotificationGC', label: ['Notification OFF', 'Notification ON'], desc: 'Create a notification when Golden Cookie spawns', toggle: true, func: function () {CM.Config.CheckNotificationPermissions(CM.Options.GCNotification);}}; @@ -208,6 +206,11 @@ CM.ConfigData.ScaleDecimals = {type: 'bool', group: 'Notation', label: ['1 decim CM.ConfigData.ScaleSeparator = {type: 'bool', group: 'Notation', label: ['. for decimals (Standard)', '. for thousands'], desc: 'Set the separator used for decimals and thousands', toggle: false, func: function() {CM.Disp.RefreshScale();}}; CM.ConfigData.ScaleCutoff = {type: 'numscale', group: 'Notation', label: 'Notation Cut-off Point', desc: 'The number from which CookieMonster will start formatting numbers based on chosen scale. Standard is 999,999. Setting this above 999,999,999 might break certain notations.', min: 1, max: 999999999}; +// Miscellaneous +CM.ConfigData.GCTimer = {type: 'bool', group: 'Miscellaneous', label: ['Golden Cookie Timer OFF', 'Golden Cookie Timer ON'], desc: 'A timer on the Golden Cookie when it has been spawned', toggle: true, func: function() {CM.Disp.ToggleGCTimer();}}; +CM.ConfigData.Favicon = {type: 'bool', group: 'Miscellaneous', label: ['Favicon OFF', 'Favicon ON'], desc: 'Update favicon with Golden/Wrath Cookie', toggle: true, func: function() {CM.Disp.UpdateFavicon();}}; + + /** * This array describes all default settings * It is used by CM.LoadConfig() and CM.Config.RestoreDefault() @@ -287,6 +290,6 @@ CM.Data.ConfigDefault = { Colors: {Blue: '#4bb8f0', Green: '#00ff00', Yellow: '#ffff00', Orange: '#ff7f00', Red: '#ff0000', Purple: '#ff00ff', Gray: '#b3b3b3', Pink: '#ff1493', Brown: '#8b4513'}, SortBuildings: 0, SortUpgrades: 0, - Header: {BarsColors: 1, Calculation: 1, Notification: 1, NotificationGC: 1, NotificationFC: 1, NotificationSea: 1, NotificationGard: 1, NotificationMagi: 1, NotificationWrink: 1, NotificationWrinkMax: 1, Tooltip: 1, Statistics: 1, Notation: 1, Lucky: 1, Spells: 1, Chain: 1, Prestige: 1, Wrink: 1, Sea: 1, Misc: 1}, + Header: {BarsColors: 1, Calculation: 1, Notification: 1, NotificationGC: 1, NotificationFC: 1, NotificationSea: 1, NotificationGard: 1, NotificationMagi: 1, NotificationWrink: 1, NotificationWrinkMax: 1, Tooltip: 1, Statistics: 1, Notation: 1, Miscellaneous: 1, Lucky: 1, Spells: 1, Chain: 1, Prestige: 1, Wrink: 1, Sea: 1, Misc: 1}, }; From 3ca1018a51907d9c25c50287245563e1e75da39c Mon Sep 17 00:00:00 2001 From: DanielNoord Date: Thu, 24 Dec 2020 10:42:15 +0100 Subject: [PATCH 090/106] Create main.yml --- .github/workflows/main.yml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..3acbe6f --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,30 @@ +# This is a basic workflow to help you get started with Actions + +name: CI + +# Controls when the action will run. +on: + # Triggers the workflow on push or pull request events but only for the dev branch + push: + branches: [ dev ] + pull_request: + branches: [ dev ] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + # This workflow contains a single job called "build" + build: + # The type of runner that the job will run on + runs-on: ubuntu-latest + + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - uses: actions/checkout@v2 + + - name: es-check-action + uses: ali-kamalizade/es-check-action@1.0.2 + From 68c30e7bdda7de3395336e0a983793685cf8ceb8 Mon Sep 17 00:00:00 2001 From: DanielNoord Date: Thu, 24 Dec 2020 10:51:56 +0100 Subject: [PATCH 091/106] Update main.yml --- .github/workflows/main.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 3acbe6f..6ee36e3 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -25,6 +25,10 @@ jobs: # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - uses: actions/checkout@v2 - - name: es-check-action - uses: ali-kamalizade/es-check-action@1.0.2 + - name: es-check-action + uses: actions/es-check-action@1.0.2 + with: + directory: '' + ecmaVersion: 'es5' + files: '*.js' From 6bb99ace113e2505470f5b41bb403ed8f1c434aa Mon Sep 17 00:00:00 2001 From: DanielNoord Date: Thu, 24 Dec 2020 10:54:32 +0100 Subject: [PATCH 092/106] Update main.yml --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6ee36e3..a6d3f38 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -26,7 +26,7 @@ jobs: - uses: actions/checkout@v2 - name: es-check-action - uses: actions/es-check-action@1.0.2 + uses: ali-kamalizade/es-check-action@1.0.2 with: directory: '' ecmaVersion: 'es5' From d89c8e3a0f51c0e619ce426526e178e7acc46cb7 Mon Sep 17 00:00:00 2001 From: DanielNoord Date: Thu, 24 Dec 2020 10:58:01 +0100 Subject: [PATCH 093/106] Create Lint.yml --- .github/workflows/Lint.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 .github/workflows/Lint.yml diff --git a/.github/workflows/Lint.yml b/.github/workflows/Lint.yml new file mode 100644 index 0000000..93ca5ad --- /dev/null +++ b/.github/workflows/Lint.yml @@ -0,0 +1,12 @@ +name: Lint + +on: [push] + +jobs: + eslint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - uses: stefanoeb/eslint-action@1.0.2 + with: + files: src/ From 9a649f93d294595d725cbd0dac9087fd355b91d6 Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Thu, 24 Dec 2020 11:02:22 +0100 Subject: [PATCH 094/106] Removed action .yml files --- .github/workflows/Lint.yml | 12 ------------ .github/workflows/main.yml | 34 ---------------------------------- 2 files changed, 46 deletions(-) delete mode 100644 .github/workflows/Lint.yml delete mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/Lint.yml b/.github/workflows/Lint.yml deleted file mode 100644 index 93ca5ad..0000000 --- a/.github/workflows/Lint.yml +++ /dev/null @@ -1,12 +0,0 @@ -name: Lint - -on: [push] - -jobs: - eslint: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v1 - - uses: stefanoeb/eslint-action@1.0.2 - with: - files: src/ diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml deleted file mode 100644 index a6d3f38..0000000 --- a/.github/workflows/main.yml +++ /dev/null @@ -1,34 +0,0 @@ -# This is a basic workflow to help you get started with Actions - -name: CI - -# Controls when the action will run. -on: - # Triggers the workflow on push or pull request events but only for the dev branch - push: - branches: [ dev ] - pull_request: - branches: [ dev ] - - # Allows you to run this workflow manually from the Actions tab - workflow_dispatch: - -# A workflow run is made up of one or more jobs that can run sequentially or in parallel -jobs: - # This workflow contains a single job called "build" - build: - # The type of runner that the job will run on - runs-on: ubuntu-latest - - # Steps represent a sequence of tasks that will be executed as part of the job - steps: - # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - - uses: actions/checkout@v2 - - - name: es-check-action - uses: ali-kamalizade/es-check-action@1.0.2 - with: - directory: '' - ecmaVersion: 'es5' - files: '*.js' - From b9a1a5444fd22aa7bd690524709cdb9dede608e7 Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Sat, 26 Dec 2020 17:53:12 +0100 Subject: [PATCH 095/106] Fixed calculation of average and current CPS --- CookieMonster.js | 329 ++++++++++++++++++++++------------------------- queue/queue.js | 82 ------------ src/Cache.js | 287 +++++++++++++++++++---------------------- src/Disp.js | 25 +++- src/Footer.js | 14 +- src/Main.js | 3 +- 6 files changed, 314 insertions(+), 426 deletions(-) delete mode 100644 queue/queue.js diff --git a/CookieMonster.js b/CookieMonster.js index 9a5a6b6..08fe36e 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -99,7 +99,7 @@ CM.Cache.CacheWrinklers = function() { } /******** - * Section: Functions related to Cachining stats */ + * Section: Functions related to Caching stats */ /** * This functions caches variables related to the stats apge @@ -186,6 +186,139 @@ CM.Cache.CacheMissingUpgrades = function() { } } +/******** + * Section: Functions related to Caching CPS */ + +/** + * @class + * @classdesc This is a class used to store values used to calculate average over time (mostly cps) + * @var {number} maxLength The maximum length of the value-storage + * @var {[]} queue The values stored + * @method addLatest(newValue) Appends newValue to the value storage + * @method calcAverage(timePeriod) Returns the average over the specified timeperiod + */ +class CMAvgQueue { + constructor(maxLength) { + this.maxLength = maxLength; + this.queue = [] + } + + addLatest (newValue) { + if (this.queue.push(newValue) > this.maxLength) { + this.queue.shift(); + } + } + + // TODO: Might want to do this according to "https://stackoverflow.com/questions/10359907/how-to-compute-the-sum-and-average-of-elements-in-an-array" + calcAverage (timePeriod) { + if (timePeriod > this.maxLength) timePeriod = this.maxLength, console.log("Called for average of Queue for time-period longer than MaxLength"); + if (timePeriod > this.queue.length) timePeriod = this.queue.length; + var ret = 0 + for (var i = this.queue.length - 1; i >= 0 && i > this.queue.length - 1 - timePeriod; i--) { + ret += this.queue[i]; + } + return ret / timePeriod; + } +} + +/** + * This functions caches creates the CMAvgQueue used by CM.Cache.UpdateAvgCPS() to calculate CPS + * Called by CM.DelayInit() + */ +CM.Cache.InitCookiesDiff = function() { + CM.Cache.CookiesDiff = new CMAvgQueue(CM.Disp.cookieTimes[CM.Disp.cookieTimes.length - 1]); + CM.Cache.WrinkDiff = new CMAvgQueue(CM.Disp.cookieTimes[CM.Disp.cookieTimes.length - 1]); + CM.Cache.WrinkFattestDiff = new CMAvgQueue(CM.Disp.cookieTimes[CM.Disp.cookieTimes.length - 1]); + CM.Cache.ChoEggDiff = new CMAvgQueue(CM.Disp.cookieTimes[CM.Disp.cookieTimes.length - 1]); + CM.Cache.ClicksDiff = new CMAvgQueue(CM.Disp.clickTimes[CM.Disp.clickTimes.length - 1]); +} + +/** + * This functions caches two variables related average CPS and Clicks + * * It is called by CM.Loop() + * TODO: Check if this can be made more concise + * @global {number} CM.Cache.AvgCPS Average cookies over time-period as defined by AvgCPSHist + * @global {number} CM.Cache.AverageClicks Average cookies from clicking over time-period as defined by AvgClicksHist + */ +CM.Cache.UpdateAvgCPS = function() { + var currDate = Math.floor(Date.now() / 1000); + // Only calculate every new second + if ((Game.T / Game.fps) % 1 == 0) { + var choEggTotal = Game.cookies + CM.Cache.SellForChoEgg; + if (Game.cpsSucked > 0) { + choEggTotal += CM.Cache.WrinklersTotal; + } + CM.Cache.RealCookiesEarned = Math.max(Game.cookiesEarned, choEggTotal); + choEggTotal *= 0.05; + + if (CM.Cache.lastDate != -1) { + var timeDiff = currDate - CM.Cache.lastDate + var bankDiffAvg = Math.max(0, (Game.cookies - CM.Cache.lastCookies)) / timeDiff; + var wrinkDiffAvg = Math.max(0, (CM.Cache.WrinklersTotal - CM.Cache.lastWrinkCookies)) / timeDiff; + var wrinkFattestDiffAvg = Math.max(0, (CM.Cache.WrinklersFattest[0] - CM.Cache.lastWrinkFattestCookies)) / timeDiff; + var choEggDiffAvg = Math.max(0,(choEggTotal - CM.Cache.lastChoEgg)) / timeDiff; + var clicksDiffAvg = (Game.cookieClicks - CM.Cache.lastClicks) / timeDiff; + for (var i = 0; i < timeDiff; i++) { + CM.Cache.CookiesDiff.addLatest(bankDiffAvg); + CM.Cache.WrinkDiff.addLatest(wrinkDiffAvg); + CM.Cache.WrinkFattestDiff.addLatest(wrinkFattestDiffAvg); + CM.Cache.ChoEggDiff.addLatest(choEggDiffAvg); + CM.Cache.ClicksDiff.addLatest(clicksDiffAvg); + } + } + CM.Cache.lastDate = currDate; + CM.Cache.lastCookies = Game.cookies; + CM.Cache.lastWrinkCookies = CM.Cache.WrinklersTotal; + CM.Cache.lastWrinkFattestCookies = CM.Cache.WrinklersFattest[0]; + CM.Cache.lastChoEgg = choEggTotal; + CM.Cache.lastClicks = Game.cookieClicks; + + var cpsLength = CM.Disp.cookieTimes[CM.Options.AvgCPSHist]; + + CM.Cache.AverageGainBank = CM.Cache.CookiesDiff.calcAverage(cpsLength); + CM.Cache.AverageGainWrink = CM.Cache.WrinkDiff.calcAverage(cpsLength); + CM.Cache.AverageGainWrinkFattest = CM.Cache.WrinkFattestDiff.calcAverage(cpsLength); + CM.Cache.AverageGainChoEgg = CM.Cache.ChoEggDiff.calcAverage(cpsLength); + + CM.Cache.AvgCPS = CM.Cache.AverageGainBank + if (CM.Options.CalcWrink == 1) CM.Cache.AvgCPS += CM.Cache.AverageGainWrink; + if (CM.Options.CalcWrink == 2) CM.Cache.AvgCPS += CM.Cache.AverageGainWrinkFattest; + + var choEgg = (Game.HasUnlocked('Chocolate egg') && !Game.Has('Chocolate egg')); + + // TODO: Why and where is this used? + if (choEgg || CM.Options.CalcWrink == 0) { + CM.Cache.AvgCPSChoEgg = CM.Cache.AverageGainBank + CM.Cache.AverageGainWrink + (choEgg ? CM.Cache.AverageGainChoEgg : 0); + } + else CM.Cache.AvgCPSChoEgg = CM.Cache.AvgCPS; + + CM.Cache.AverageClicks = CM.Cache.ClicksDiff.calcAverage(CM.Disp.clickTimes[CM.Options.AvgClicksHist]); + } +} + +/** + * This functions caches the current Wrinkler CPS multiplier + * It is called by CM.Loop(). Variables are mostly used by CM.Disp.GetCPS(). + * @global {number} CM.Cache.CurrWrinklerCount Current number of wrinklers + * @global {number} CM.Cache.CurrWrinklerCPSMult Current multiplier of CPS because of wrinklers (excluding their negative sucking effect) + */ +CM.Cache.UpdateCurrWrinklerCPS = function() { + CM.Cache.CurrWrinklerCPSMult = 0; + let count = 0; + for (let i in Game.wrinklers) { + if (Game.wrinklers[i].phase == 2) count++ + } + let godMult = 1; + if (CM.Sim.Objects.Temple.minigameLoaded) { + var godLvl = CM.Sim.hasGod('scorn'); + if (godLvl == 1) godMult *= 1.15; + else if (godLvl == 2) godMult *= 1.1; + else if (godLvl == 3) godMult *= 1.05; + } + CM.Cache.CurrWrinklerCount = count; + CM.Cache.CurrWrinklerCPSMult = count * (count * 0.05 * 1.1) * (Game.Has('Sacrilegious corruption') * 0.05 + 1) * (Game.Has('Wrinklerspawn') * 0.05 + 1) * godMult; +} + /******** * Section: UNSORTED */ @@ -486,141 +619,6 @@ CM.Cache.RemakeSellForChoEgg = function() { CM.Cache.SellForChoEgg = sellTotal; } -CM.Cache.InitCookiesDiff = function() { - CM.Cache.CookiesDiff = new Queue(); - CM.Cache.WrinkDiff = new Queue(); - CM.Cache.ChoEggDiff = new Queue(); - CM.Cache.ClicksDiff = new Queue(); -} - -CM.Cache.UpdateAvgCPS = function() { - var currDate = Math.floor(Date.now() / 1000); - if (CM.Cache.lastDate != currDate) { - var choEggTotal = Game.cookies + CM.Cache.SellForChoEgg; - if (Game.cpsSucked > 0) { - choEggTotal += CM.Cache.WrinklersTotal; - } - CM.Cache.RealCookiesEarned = Math.max(Game.cookiesEarned, choEggTotal); - choEggTotal *= 0.05; - - if (CM.Cache.lastDate != -1) { - var timeDiff = currDate - CM.Cache.lastDate - var bankDiffAvg = Math.max(0, (Game.cookies - CM.Cache.lastCookies)) / timeDiff; - var wrinkDiffAvg = Math.max(0, (CM.Cache.WrinklersTotal - CM.Cache.lastWrinkCookies)) / timeDiff; - var choEggDiffAvg = Math.max(0,(choEggTotal - CM.Cache.lastChoEgg)) / timeDiff; - var clicksDiffAvg = (Game.cookieClicks - CM.Cache.lastClicks) / timeDiff; - for (var i = 0; i < timeDiff; i++) { - CM.Cache.CookiesDiff.enqueue(bankDiffAvg); - CM.Cache.WrinkDiff.enqueue(wrinkDiffAvg); - CM.Cache.ChoEggDiff.enqueue(choEggDiffAvg); - CM.Cache.ClicksDiff.enqueue(clicksDiffAvg); - } - // Assumes the queues are the same length - while (CM.Cache.CookiesDiff.getLength() > 1800) { - CM.Cache.CookiesDiff.dequeue(); - CM.Cache.WrinkDiff.dequeue(); - CM.Cache.ClicksDiff.dequeue(); - } - - while (CM.Cache.ClicksDiff.getLength() > 30) { - CM.Cache.ClicksDiff.dequeue(); - } - } - CM.Cache.lastDate = currDate; - CM.Cache.lastCookies = Game.cookies; - CM.Cache.lastWrinkCookies = CM.Cache.WrinklersTotal; - CM.Cache.lastChoEgg = choEggTotal; - CM.Cache.lastClicks = Game.cookieClicks; - - var sortedGainBank = new Array(); - var sortedGainWrink = new Array(); - var sortedGainChoEgg = new Array(); - - var cpsLength = Math.min(CM.Cache.CookiesDiff.getLength(), CM.Disp.cookieTimes[CM.Options.AvgCPSHist]); - - // Assumes the queues are the same length - for (var i = CM.Cache.CookiesDiff.getLength() - cpsLength; i < CM.Cache.CookiesDiff.getLength(); i++) { - sortedGainBank.push(CM.Cache.CookiesDiff.get(i)); - sortedGainWrink.push(CM.Cache.WrinkDiff.get(i)); - sortedGainChoEgg.push(CM.Cache.ChoEggDiff.get(i)); - } - - sortedGainBank.sort(function(a, b) { return a - b; }); - sortedGainWrink.sort(function(a, b) { return a - b; }); - sortedGainChoEgg.sort(function(a, b) { return a - b; }); - - var cut = Math.round(sortedGainBank.length / 10); - - while (cut > 0) { - sortedGainBank.shift(); - sortedGainBank.pop(); - sortedGainWrink.shift(); - sortedGainWrink.pop(); - sortedGainChoEgg.shift(); - sortedGainChoEgg.pop(); - cut--; - } - - var totalGainBank = 0; - var totalGainWrink = 0; - var totalGainChoEgg = 0; - - for (var i = 0; i < sortedGainBank.length; i++) { - totalGainBank += sortedGainBank[i]; - totalGainWrink += sortedGainWrink[i]; - totalGainChoEgg += sortedGainChoEgg[i]; - } - // TODO: Incorporate situation if CM.Options.CalcWrink == 2 - CM.Cache.AvgCPS = (totalGainBank + (CM.Options.CalcWrink == 1 ? totalGainWrink : 0)) / sortedGainBank.length; - - var choEgg = (Game.HasUnlocked('Chocolate egg') && !Game.Has('Chocolate egg')); - - if (choEgg || CM.Options.CalcWrink == 0) { - CM.Cache.AvgCPSChoEgg = (totalGainBank + totalGainWrink + (choEgg ? totalGainChoEgg : 0)) / sortedGainBank.length; - } - else { - CM.Cache.AvgCPSChoEgg = CM.Cache.AvgCPS; - } - - var totalClicks = 0; - var clicksLength = Math.min(CM.Cache.ClicksDiff.getLength(), CM.Disp.clickTimes[CM.Options.AvgClicksHist]); - for (var i = CM.Cache.ClicksDiff.getLength() - clicksLength; i < CM.Cache.ClicksDiff.getLength(); i++) { - totalClicks += CM.Cache.ClicksDiff.get(i); - } - CM.Cache.AvgClicks = totalClicks / clicksLength; - } -} - -CM.Cache.CacheMissingUpgrades = function() { - CM.Cache.MissingUpgrades = ""; - CM.Cache.MissingUpgradesCookies = ""; - CM.Cache.MissingUpgradesPrestige = ""; - var list = []; - //sort the upgrades - for (var i in Game.Upgrades) { - list.push(Game.Upgrades[i]); - } - var sortMap = function(a, b) { - if (a.order>b.order) return 1; - else if (a.order= queue.length){ - queue = queue.slice(offset); - offset = 0; - } - - // return the dequeued item - return item; - - } - - /* Returns the item at the front of the queue (without dequeuing it). If the - * queue is empty then undefined is returned. - */ - this.peek = function(){ - return (queue.length > 0 ? queue[offset] : undefined); - } - - /* Returns the item at the spot specified by place in the queue (without - * dequeuing it). If the queue is emprty or the requested place is outside - * the queue then undefined is returned. - */ - this.get = function(place){ - var item = undefined; - if (queue.length > 0 && place < (queue.length - offset) && place >= 0) { - item = queue[(offset + place)]; - } - return item; - } - -} diff --git a/src/Cache.js b/src/Cache.js index 97600f3..8172a17 100644 --- a/src/Cache.js +++ b/src/Cache.js @@ -68,7 +68,7 @@ CM.Cache.CacheWrinklers = function() { } /******** - * Section: Functions related to Cachining stats */ + * Section: Functions related to Caching stats */ /** * This functions caches variables related to the stats apge @@ -155,6 +155,139 @@ CM.Cache.CacheMissingUpgrades = function() { } } +/******** + * Section: Functions related to Caching CPS */ + +/** + * @class + * @classdesc This is a class used to store values used to calculate average over time (mostly cps) + * @var {number} maxLength The maximum length of the value-storage + * @var {[]} queue The values stored + * @method addLatest(newValue) Appends newValue to the value storage + * @method calcAverage(timePeriod) Returns the average over the specified timeperiod + */ +class CMAvgQueue { + constructor(maxLength) { + this.maxLength = maxLength; + this.queue = [] + } + + addLatest (newValue) { + if (this.queue.push(newValue) > this.maxLength) { + this.queue.shift(); + } + } + + // TODO: Might want to do this according to "https://stackoverflow.com/questions/10359907/how-to-compute-the-sum-and-average-of-elements-in-an-array" + calcAverage (timePeriod) { + if (timePeriod > this.maxLength) timePeriod = this.maxLength, console.log("Called for average of Queue for time-period longer than MaxLength"); + if (timePeriod > this.queue.length) timePeriod = this.queue.length; + var ret = 0 + for (var i = this.queue.length - 1; i >= 0 && i > this.queue.length - 1 - timePeriod; i--) { + ret += this.queue[i]; + } + return ret / timePeriod; + } +} + +/** + * This functions caches creates the CMAvgQueue used by CM.Cache.UpdateAvgCPS() to calculate CPS + * Called by CM.DelayInit() + */ +CM.Cache.InitCookiesDiff = function() { + CM.Cache.CookiesDiff = new CMAvgQueue(CM.Disp.cookieTimes[CM.Disp.cookieTimes.length - 1]); + CM.Cache.WrinkDiff = new CMAvgQueue(CM.Disp.cookieTimes[CM.Disp.cookieTimes.length - 1]); + CM.Cache.WrinkFattestDiff = new CMAvgQueue(CM.Disp.cookieTimes[CM.Disp.cookieTimes.length - 1]); + CM.Cache.ChoEggDiff = new CMAvgQueue(CM.Disp.cookieTimes[CM.Disp.cookieTimes.length - 1]); + CM.Cache.ClicksDiff = new CMAvgQueue(CM.Disp.clickTimes[CM.Disp.clickTimes.length - 1]); +} + +/** + * This functions caches two variables related average CPS and Clicks + * * It is called by CM.Loop() + * TODO: Check if this can be made more concise + * @global {number} CM.Cache.AvgCPS Average cookies over time-period as defined by AvgCPSHist + * @global {number} CM.Cache.AverageClicks Average cookies from clicking over time-period as defined by AvgClicksHist + */ +CM.Cache.UpdateAvgCPS = function() { + var currDate = Math.floor(Date.now() / 1000); + // Only calculate every new second + if ((Game.T / Game.fps) % 1 == 0) { + var choEggTotal = Game.cookies + CM.Cache.SellForChoEgg; + if (Game.cpsSucked > 0) { + choEggTotal += CM.Cache.WrinklersTotal; + } + CM.Cache.RealCookiesEarned = Math.max(Game.cookiesEarned, choEggTotal); + choEggTotal *= 0.05; + + if (CM.Cache.lastDate != -1) { + var timeDiff = currDate - CM.Cache.lastDate + var bankDiffAvg = Math.max(0, (Game.cookies - CM.Cache.lastCookies)) / timeDiff; + var wrinkDiffAvg = Math.max(0, (CM.Cache.WrinklersTotal - CM.Cache.lastWrinkCookies)) / timeDiff; + var wrinkFattestDiffAvg = Math.max(0, (CM.Cache.WrinklersFattest[0] - CM.Cache.lastWrinkFattestCookies)) / timeDiff; + var choEggDiffAvg = Math.max(0,(choEggTotal - CM.Cache.lastChoEgg)) / timeDiff; + var clicksDiffAvg = (Game.cookieClicks - CM.Cache.lastClicks) / timeDiff; + for (var i = 0; i < timeDiff; i++) { + CM.Cache.CookiesDiff.addLatest(bankDiffAvg); + CM.Cache.WrinkDiff.addLatest(wrinkDiffAvg); + CM.Cache.WrinkFattestDiff.addLatest(wrinkFattestDiffAvg); + CM.Cache.ChoEggDiff.addLatest(choEggDiffAvg); + CM.Cache.ClicksDiff.addLatest(clicksDiffAvg); + } + } + CM.Cache.lastDate = currDate; + CM.Cache.lastCookies = Game.cookies; + CM.Cache.lastWrinkCookies = CM.Cache.WrinklersTotal; + CM.Cache.lastWrinkFattestCookies = CM.Cache.WrinklersFattest[0]; + CM.Cache.lastChoEgg = choEggTotal; + CM.Cache.lastClicks = Game.cookieClicks; + + var cpsLength = CM.Disp.cookieTimes[CM.Options.AvgCPSHist]; + + CM.Cache.AverageGainBank = CM.Cache.CookiesDiff.calcAverage(cpsLength); + CM.Cache.AverageGainWrink = CM.Cache.WrinkDiff.calcAverage(cpsLength); + CM.Cache.AverageGainWrinkFattest = CM.Cache.WrinkFattestDiff.calcAverage(cpsLength); + CM.Cache.AverageGainChoEgg = CM.Cache.ChoEggDiff.calcAverage(cpsLength); + + CM.Cache.AvgCPS = CM.Cache.AverageGainBank + if (CM.Options.CalcWrink == 1) CM.Cache.AvgCPS += CM.Cache.AverageGainWrink; + if (CM.Options.CalcWrink == 2) CM.Cache.AvgCPS += CM.Cache.AverageGainWrinkFattest; + + var choEgg = (Game.HasUnlocked('Chocolate egg') && !Game.Has('Chocolate egg')); + + // TODO: Why and where is this used? + if (choEgg || CM.Options.CalcWrink == 0) { + CM.Cache.AvgCPSChoEgg = CM.Cache.AverageGainBank + CM.Cache.AverageGainWrink + (choEgg ? CM.Cache.AverageGainChoEgg : 0); + } + else CM.Cache.AvgCPSChoEgg = CM.Cache.AvgCPS; + + CM.Cache.AverageClicks = CM.Cache.ClicksDiff.calcAverage(CM.Disp.clickTimes[CM.Options.AvgClicksHist]); + } +} + +/** + * This functions caches the current Wrinkler CPS multiplier + * It is called by CM.Loop(). Variables are mostly used by CM.Disp.GetCPS(). + * @global {number} CM.Cache.CurrWrinklerCount Current number of wrinklers + * @global {number} CM.Cache.CurrWrinklerCPSMult Current multiplier of CPS because of wrinklers (excluding their negative sucking effect) + */ +CM.Cache.UpdateCurrWrinklerCPS = function() { + CM.Cache.CurrWrinklerCPSMult = 0; + let count = 0; + for (let i in Game.wrinklers) { + if (Game.wrinklers[i].phase == 2) count++ + } + let godMult = 1; + if (CM.Sim.Objects.Temple.minigameLoaded) { + var godLvl = CM.Sim.hasGod('scorn'); + if (godLvl == 1) godMult *= 1.15; + else if (godLvl == 2) godMult *= 1.1; + else if (godLvl == 3) godMult *= 1.05; + } + CM.Cache.CurrWrinklerCount = count; + CM.Cache.CurrWrinklerCPSMult = count * (count * 0.05 * 1.1) * (Game.Has('Sacrilegious corruption') * 0.05 + 1) * (Game.Has('Wrinklerspawn') * 0.05 + 1) * godMult; +} + /******** * Section: UNSORTED */ @@ -455,141 +588,6 @@ CM.Cache.RemakeSellForChoEgg = function() { CM.Cache.SellForChoEgg = sellTotal; } -CM.Cache.InitCookiesDiff = function() { - CM.Cache.CookiesDiff = new Queue(); - CM.Cache.WrinkDiff = new Queue(); - CM.Cache.ChoEggDiff = new Queue(); - CM.Cache.ClicksDiff = new Queue(); -} - -CM.Cache.UpdateAvgCPS = function() { - var currDate = Math.floor(Date.now() / 1000); - if (CM.Cache.lastDate != currDate) { - var choEggTotal = Game.cookies + CM.Cache.SellForChoEgg; - if (Game.cpsSucked > 0) { - choEggTotal += CM.Cache.WrinklersTotal; - } - CM.Cache.RealCookiesEarned = Math.max(Game.cookiesEarned, choEggTotal); - choEggTotal *= 0.05; - - if (CM.Cache.lastDate != -1) { - var timeDiff = currDate - CM.Cache.lastDate - var bankDiffAvg = Math.max(0, (Game.cookies - CM.Cache.lastCookies)) / timeDiff; - var wrinkDiffAvg = Math.max(0, (CM.Cache.WrinklersTotal - CM.Cache.lastWrinkCookies)) / timeDiff; - var choEggDiffAvg = Math.max(0,(choEggTotal - CM.Cache.lastChoEgg)) / timeDiff; - var clicksDiffAvg = (Game.cookieClicks - CM.Cache.lastClicks) / timeDiff; - for (var i = 0; i < timeDiff; i++) { - CM.Cache.CookiesDiff.enqueue(bankDiffAvg); - CM.Cache.WrinkDiff.enqueue(wrinkDiffAvg); - CM.Cache.ChoEggDiff.enqueue(choEggDiffAvg); - CM.Cache.ClicksDiff.enqueue(clicksDiffAvg); - } - // Assumes the queues are the same length - while (CM.Cache.CookiesDiff.getLength() > 1800) { - CM.Cache.CookiesDiff.dequeue(); - CM.Cache.WrinkDiff.dequeue(); - CM.Cache.ClicksDiff.dequeue(); - } - - while (CM.Cache.ClicksDiff.getLength() > 30) { - CM.Cache.ClicksDiff.dequeue(); - } - } - CM.Cache.lastDate = currDate; - CM.Cache.lastCookies = Game.cookies; - CM.Cache.lastWrinkCookies = CM.Cache.WrinklersTotal; - CM.Cache.lastChoEgg = choEggTotal; - CM.Cache.lastClicks = Game.cookieClicks; - - var sortedGainBank = new Array(); - var sortedGainWrink = new Array(); - var sortedGainChoEgg = new Array(); - - var cpsLength = Math.min(CM.Cache.CookiesDiff.getLength(), CM.Disp.cookieTimes[CM.Options.AvgCPSHist]); - - // Assumes the queues are the same length - for (var i = CM.Cache.CookiesDiff.getLength() - cpsLength; i < CM.Cache.CookiesDiff.getLength(); i++) { - sortedGainBank.push(CM.Cache.CookiesDiff.get(i)); - sortedGainWrink.push(CM.Cache.WrinkDiff.get(i)); - sortedGainChoEgg.push(CM.Cache.ChoEggDiff.get(i)); - } - - sortedGainBank.sort(function(a, b) { return a - b; }); - sortedGainWrink.sort(function(a, b) { return a - b; }); - sortedGainChoEgg.sort(function(a, b) { return a - b; }); - - var cut = Math.round(sortedGainBank.length / 10); - - while (cut > 0) { - sortedGainBank.shift(); - sortedGainBank.pop(); - sortedGainWrink.shift(); - sortedGainWrink.pop(); - sortedGainChoEgg.shift(); - sortedGainChoEgg.pop(); - cut--; - } - - var totalGainBank = 0; - var totalGainWrink = 0; - var totalGainChoEgg = 0; - - for (var i = 0; i < sortedGainBank.length; i++) { - totalGainBank += sortedGainBank[i]; - totalGainWrink += sortedGainWrink[i]; - totalGainChoEgg += sortedGainChoEgg[i]; - } - // TODO: Incorporate situation if CM.Options.CalcWrink == 2 - CM.Cache.AvgCPS = (totalGainBank + (CM.Options.CalcWrink == 1 ? totalGainWrink : 0)) / sortedGainBank.length; - - var choEgg = (Game.HasUnlocked('Chocolate egg') && !Game.Has('Chocolate egg')); - - if (choEgg || CM.Options.CalcWrink == 0) { - CM.Cache.AvgCPSChoEgg = (totalGainBank + totalGainWrink + (choEgg ? totalGainChoEgg : 0)) / sortedGainBank.length; - } - else { - CM.Cache.AvgCPSChoEgg = CM.Cache.AvgCPS; - } - - var totalClicks = 0; - var clicksLength = Math.min(CM.Cache.ClicksDiff.getLength(), CM.Disp.clickTimes[CM.Options.AvgClicksHist]); - for (var i = CM.Cache.ClicksDiff.getLength() - clicksLength; i < CM.Cache.ClicksDiff.getLength(); i++) { - totalClicks += CM.Cache.ClicksDiff.get(i); - } - CM.Cache.AvgClicks = totalClicks / clicksLength; - } -} - -CM.Cache.CacheMissingUpgrades = function() { - CM.Cache.MissingUpgrades = ""; - CM.Cache.MissingUpgradesCookies = ""; - CM.Cache.MissingUpgradesPrestige = ""; - var list = []; - //sort the upgrades - for (var i in Game.Upgrades) { - list.push(Game.Upgrades[i]); - } - var sortMap = function(a, b) { - if (a.order>b.order) return 1; - else if (a.order Date: Sun, 27 Dec 2020 12:39:33 +0100 Subject: [PATCH 096/106] Added timer overlays in TimerBar (#147) --- CookieMonster.js | 12 +++++++++--- src/Disp.js | 12 +++++++++--- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index 08fe36e..191ee81 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -1592,7 +1592,7 @@ CM.Disp.CreateTimerBar = function() { */ CM.Disp.TimerBarCreateBar = function(id, name, bars) { timerBar = document.createElement('div'); - timerBar.id = 'CMTimerBarGC'; + timerBar.id = 'CMTimerBar'; timerBar.style.height = '12px'; timerBar.style.margin = '0px 10px'; timerBar.style.position = 'relative'; @@ -1621,6 +1621,8 @@ CM.Disp.TimerBarCreateBar = function(id, name, bars) { colorBar.id = bars[i].id colorBar.style.display = 'inline-block'; colorBar.style.height = '10px'; + colorBar.style.verticalAlign = "text-top"; + colorBar.style.textAlign="center"; if (bars.length - 1 == i) { colorBar.style.borderTopRightRadius = '10px'; colorBar.style.borderBottomRightRadius = '10px'; @@ -1643,7 +1645,7 @@ CM.Disp.TimerBarCreateBar = function(id, name, bars) { } /** - * This function creates an indivudual timer for the timer bar + * This function updates indivudual timers in the timer bar * It is called by CM.Loop() */ CM.Disp.UpdateTimerBar = function() { @@ -1656,6 +1658,7 @@ CM.Disp.UpdateTimerBar = function() { if (Game.shimmerTypes['golden'].spawned == 0 && !Game.Has('Golden switch [off]')) { CM.Disp.TimerBars['CMTimerBarGC'].style.display = ''; l('CMTimerBarGCMinBar').style.width = Math.round(Math.max(0, Game.shimmerTypes['golden'].minTime - Game.shimmerTypes['golden'].time) * maxWidth / Game.shimmerTypes['golden'].maxTime) + 'px'; + l('CMTimerBarGCMinBar').textContent = Math.ceil((Game.shimmerTypes['golden'].minTime - Game.shimmerTypes['golden'].time)/ Game.fps) if (Game.shimmerTypes['golden'].minTime == Game.shimmerTypes['golden'].maxTime) { l('CMTimerBarGCMinBar').style.borderTopRightRadius = '10px'; l('CMTimerBarGCMinBar').style.borderBottomRightRadius = '10px'; @@ -1665,16 +1668,19 @@ CM.Disp.UpdateTimerBar = function() { l('CMTimerBarGCMinBar').style.borderBottomRightRadius = ''; } l('CMTimerBarGCBar').style.width = Math.round(Math.min(Game.shimmerTypes['golden'].maxTime - Game.shimmerTypes['golden'].minTime, Game.shimmerTypes['golden'].maxTime - Game.shimmerTypes['golden'].time) * maxWidth / Game.shimmerTypes['golden'].maxTime) + 'px'; + l('CMTimerBarGCBar').textContent = Math.ceil(Math.min(Game.shimmerTypes['golden'].maxTime - Game.shimmerTypes['golden'].minTime, Game.shimmerTypes['golden'].maxTime - Game.shimmerTypes['golden'].time) / Game.fps); l('CMTimerBarGCTime').textContent = Math.ceil((Game.shimmerTypes['golden'].maxTime - Game.shimmerTypes['golden'].time) / Game.fps); numberOfTimers++; } else CM.Disp.TimerBars['CMTimerBarGC'].style.display = 'none'; - // Regulates visibility of Reinder timer + // Regulates visibility of Reindeer timer if (Game.season == 'christmas' && Game.shimmerTypes['reindeer'].spawned == 0) { CM.Disp.TimerBars['CMTimerBarRen'].style.display = ''; l('CMTimerBarRenMinBar').style.width = Math.round(Math.max(0, Game.shimmerTypes['reindeer'].minTime - Game.shimmerTypes['reindeer'].time) * maxWidth / Game.shimmerTypes['reindeer'].maxTime) + 'px'; + l('CMTimerBarRenMinBar').textContent = Math.ceil((Game.shimmerTypes['reindeer'].minTime - Game.shimmerTypes['reindeer'].time)/ Game.fps) l('CMTimerBarRenBar').style.width = Math.round(Math.min(Game.shimmerTypes['reindeer'].maxTime - Game.shimmerTypes['reindeer'].minTime, Game.shimmerTypes['reindeer'].maxTime - Game.shimmerTypes['reindeer'].time) * maxWidth / Game.shimmerTypes['reindeer'].maxTime) + 'px'; + l('CMTimerBarRenBar').textContent = Math.ceil(Math.min(Game.shimmerTypes['reindeer'].maxTime - Game.shimmerTypes['reindeer'].minTime, Game.shimmerTypes['reindeer'].maxTime - Game.shimmerTypes['reindeer'].time) / Game.fps); l('CMTimerBarRenTime').textContent = Math.ceil((Game.shimmerTypes['reindeer'].maxTime - Game.shimmerTypes['reindeer'].time) / Game.fps); numberOfTimers++; } diff --git a/src/Disp.js b/src/Disp.js index f538e7d..02dc403 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -476,7 +476,7 @@ CM.Disp.CreateTimerBar = function() { */ CM.Disp.TimerBarCreateBar = function(id, name, bars) { timerBar = document.createElement('div'); - timerBar.id = 'CMTimerBarGC'; + timerBar.id = 'CMTimerBar'; timerBar.style.height = '12px'; timerBar.style.margin = '0px 10px'; timerBar.style.position = 'relative'; @@ -505,6 +505,8 @@ CM.Disp.TimerBarCreateBar = function(id, name, bars) { colorBar.id = bars[i].id colorBar.style.display = 'inline-block'; colorBar.style.height = '10px'; + colorBar.style.verticalAlign = "text-top"; + colorBar.style.textAlign="center"; if (bars.length - 1 == i) { colorBar.style.borderTopRightRadius = '10px'; colorBar.style.borderBottomRightRadius = '10px'; @@ -527,7 +529,7 @@ CM.Disp.TimerBarCreateBar = function(id, name, bars) { } /** - * This function creates an indivudual timer for the timer bar + * This function updates indivudual timers in the timer bar * It is called by CM.Loop() */ CM.Disp.UpdateTimerBar = function() { @@ -540,6 +542,7 @@ CM.Disp.UpdateTimerBar = function() { if (Game.shimmerTypes['golden'].spawned == 0 && !Game.Has('Golden switch [off]')) { CM.Disp.TimerBars['CMTimerBarGC'].style.display = ''; l('CMTimerBarGCMinBar').style.width = Math.round(Math.max(0, Game.shimmerTypes['golden'].minTime - Game.shimmerTypes['golden'].time) * maxWidth / Game.shimmerTypes['golden'].maxTime) + 'px'; + l('CMTimerBarGCMinBar').textContent = Math.ceil((Game.shimmerTypes['golden'].minTime - Game.shimmerTypes['golden'].time)/ Game.fps) if (Game.shimmerTypes['golden'].minTime == Game.shimmerTypes['golden'].maxTime) { l('CMTimerBarGCMinBar').style.borderTopRightRadius = '10px'; l('CMTimerBarGCMinBar').style.borderBottomRightRadius = '10px'; @@ -549,16 +552,19 @@ CM.Disp.UpdateTimerBar = function() { l('CMTimerBarGCMinBar').style.borderBottomRightRadius = ''; } l('CMTimerBarGCBar').style.width = Math.round(Math.min(Game.shimmerTypes['golden'].maxTime - Game.shimmerTypes['golden'].minTime, Game.shimmerTypes['golden'].maxTime - Game.shimmerTypes['golden'].time) * maxWidth / Game.shimmerTypes['golden'].maxTime) + 'px'; + l('CMTimerBarGCBar').textContent = Math.ceil(Math.min(Game.shimmerTypes['golden'].maxTime - Game.shimmerTypes['golden'].minTime, Game.shimmerTypes['golden'].maxTime - Game.shimmerTypes['golden'].time) / Game.fps); l('CMTimerBarGCTime').textContent = Math.ceil((Game.shimmerTypes['golden'].maxTime - Game.shimmerTypes['golden'].time) / Game.fps); numberOfTimers++; } else CM.Disp.TimerBars['CMTimerBarGC'].style.display = 'none'; - // Regulates visibility of Reinder timer + // Regulates visibility of Reindeer timer if (Game.season == 'christmas' && Game.shimmerTypes['reindeer'].spawned == 0) { CM.Disp.TimerBars['CMTimerBarRen'].style.display = ''; l('CMTimerBarRenMinBar').style.width = Math.round(Math.max(0, Game.shimmerTypes['reindeer'].minTime - Game.shimmerTypes['reindeer'].time) * maxWidth / Game.shimmerTypes['reindeer'].maxTime) + 'px'; + l('CMTimerBarRenMinBar').textContent = Math.ceil((Game.shimmerTypes['reindeer'].minTime - Game.shimmerTypes['reindeer'].time)/ Game.fps) l('CMTimerBarRenBar').style.width = Math.round(Math.min(Game.shimmerTypes['reindeer'].maxTime - Game.shimmerTypes['reindeer'].minTime, Game.shimmerTypes['reindeer'].maxTime - Game.shimmerTypes['reindeer'].time) * maxWidth / Game.shimmerTypes['reindeer'].maxTime) + 'px'; + l('CMTimerBarRenBar').textContent = Math.ceil(Math.min(Game.shimmerTypes['reindeer'].maxTime - Game.shimmerTypes['reindeer'].minTime, Game.shimmerTypes['reindeer'].maxTime - Game.shimmerTypes['reindeer'].time) / Game.fps); l('CMTimerBarRenTime').textContent = Math.ceil((Game.shimmerTypes['reindeer'].maxTime - Game.shimmerTypes['reindeer'].time) / Game.fps); numberOfTimers++; } From 6edda5420f7873a12bfc17fbe37b486531aa1022 Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Sun, 27 Dec 2020 13:07:07 +0100 Subject: [PATCH 097/106] Fixed Timers for loans (#304) --- CookieMonster.js | 17 ++++++++++------- src/Disp.js | 17 ++++++++++------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index 191ee81..cab285e 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -1610,6 +1610,7 @@ CM.Disp.TimerBarCreateBar = function(id, name, bars) { var type = document.createElement('span'); type.style.display = 'inline-block'; type.style.textAlign = 'right'; + type.style.fontSize = "10px"; type.style.width = '108px'; type.style.marginRight = '5px'; type.style.verticalAlign = 'text-top'; @@ -1650,14 +1651,16 @@ CM.Disp.TimerBarCreateBar = function(id, name, bars) { */ CM.Disp.UpdateTimerBar = function() { if (CM.Options.TimerBar == 1) { - // label width: 113, timer width: 26, div margin: 20 - var maxWidth = CM.Disp.TimerBar.offsetWidth - 159; + // label width: 113, timer width: 30, div margin: 20 + var maxWidthTwoBar = CM.Disp.TimerBar.offsetWidth - 163; + // label width: 113, div margin: 20, calculate timer width at runtime + var maxWidthOneBar = CM.Disp.TimerBar.offsetWidth - 133; var numberOfTimers = 0; // Regulates visibility of Golden Cookie timer if (Game.shimmerTypes['golden'].spawned == 0 && !Game.Has('Golden switch [off]')) { CM.Disp.TimerBars['CMTimerBarGC'].style.display = ''; - l('CMTimerBarGCMinBar').style.width = Math.round(Math.max(0, Game.shimmerTypes['golden'].minTime - Game.shimmerTypes['golden'].time) * maxWidth / Game.shimmerTypes['golden'].maxTime) + 'px'; + l('CMTimerBarGCMinBar').style.width = Math.round(Math.max(0, Game.shimmerTypes['golden'].minTime - Game.shimmerTypes['golden'].time) * maxWidthTwoBar / Game.shimmerTypes['golden'].maxTime) + 'px'; l('CMTimerBarGCMinBar').textContent = Math.ceil((Game.shimmerTypes['golden'].minTime - Game.shimmerTypes['golden'].time)/ Game.fps) if (Game.shimmerTypes['golden'].minTime == Game.shimmerTypes['golden'].maxTime) { l('CMTimerBarGCMinBar').style.borderTopRightRadius = '10px'; @@ -1667,7 +1670,7 @@ CM.Disp.UpdateTimerBar = function() { l('CMTimerBarGCMinBar').style.borderTopRightRadius = ''; l('CMTimerBarGCMinBar').style.borderBottomRightRadius = ''; } - l('CMTimerBarGCBar').style.width = Math.round(Math.min(Game.shimmerTypes['golden'].maxTime - Game.shimmerTypes['golden'].minTime, Game.shimmerTypes['golden'].maxTime - Game.shimmerTypes['golden'].time) * maxWidth / Game.shimmerTypes['golden'].maxTime) + 'px'; + l('CMTimerBarGCBar').style.width = Math.round(Math.min(Game.shimmerTypes['golden'].maxTime - Game.shimmerTypes['golden'].minTime, Game.shimmerTypes['golden'].maxTime - Game.shimmerTypes['golden'].time) * maxWidthTwoBar / Game.shimmerTypes['golden'].maxTime) + 'px'; l('CMTimerBarGCBar').textContent = Math.ceil(Math.min(Game.shimmerTypes['golden'].maxTime - Game.shimmerTypes['golden'].minTime, Game.shimmerTypes['golden'].maxTime - Game.shimmerTypes['golden'].time) / Game.fps); l('CMTimerBarGCTime').textContent = Math.ceil((Game.shimmerTypes['golden'].maxTime - Game.shimmerTypes['golden'].time) / Game.fps); numberOfTimers++; @@ -1677,9 +1680,9 @@ CM.Disp.UpdateTimerBar = function() { // Regulates visibility of Reindeer timer if (Game.season == 'christmas' && Game.shimmerTypes['reindeer'].spawned == 0) { CM.Disp.TimerBars['CMTimerBarRen'].style.display = ''; - l('CMTimerBarRenMinBar').style.width = Math.round(Math.max(0, Game.shimmerTypes['reindeer'].minTime - Game.shimmerTypes['reindeer'].time) * maxWidth / Game.shimmerTypes['reindeer'].maxTime) + 'px'; + l('CMTimerBarRenMinBar').style.width = Math.round(Math.max(0, Game.shimmerTypes['reindeer'].minTime - Game.shimmerTypes['reindeer'].time) * maxWidthTwoBar / Game.shimmerTypes['reindeer'].maxTime) + 'px'; l('CMTimerBarRenMinBar').textContent = Math.ceil((Game.shimmerTypes['reindeer'].minTime - Game.shimmerTypes['reindeer'].time)/ Game.fps) - l('CMTimerBarRenBar').style.width = Math.round(Math.min(Game.shimmerTypes['reindeer'].maxTime - Game.shimmerTypes['reindeer'].minTime, Game.shimmerTypes['reindeer'].maxTime - Game.shimmerTypes['reindeer'].time) * maxWidth / Game.shimmerTypes['reindeer'].maxTime) + 'px'; + l('CMTimerBarRenBar').style.width = Math.round(Math.min(Game.shimmerTypes['reindeer'].maxTime - Game.shimmerTypes['reindeer'].minTime, Game.shimmerTypes['reindeer'].maxTime - Game.shimmerTypes['reindeer'].time) * maxWidthTwoBar / Game.shimmerTypes['reindeer'].maxTime) + 'px'; l('CMTimerBarRenBar').textContent = Math.ceil(Math.min(Game.shimmerTypes['reindeer'].maxTime - Game.shimmerTypes['reindeer'].minTime, Game.shimmerTypes['reindeer'].maxTime - Game.shimmerTypes['reindeer'].time) / Game.fps); l('CMTimerBarRenTime').textContent = Math.ceil((Game.shimmerTypes['reindeer'].maxTime - Game.shimmerTypes['reindeer'].time) / Game.fps); numberOfTimers++; @@ -1704,7 +1707,7 @@ CM.Disp.UpdateTimerBar = function() { } else classColor = CM.Disp.colorPurple; timer.lastChild.children[1].className = CM.Disp.colorBackPre + classColor; - timer.lastChild.children[1].style.width = Math.round(Game.buffs[i].time * maxWidth / Game.buffs[i].maxTime) + 'px'; + timer.lastChild.children[1].style.width = Math.round(Game.buffs[i].time *(maxWidthOneBar - Math.ceil(Game.buffs[i].time / Game.fps).toString().length * 8) / Game.buffs[i].maxTime) + 'px'; timer.lastChild.children[2].textContent = Math.ceil(Game.buffs[i].time / Game.fps); numberOfTimers++; CM.Disp.BuffTimerBars[Game.buffs[i].name] = timer diff --git a/src/Disp.js b/src/Disp.js index 02dc403..045c4a7 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -494,6 +494,7 @@ CM.Disp.TimerBarCreateBar = function(id, name, bars) { var type = document.createElement('span'); type.style.display = 'inline-block'; type.style.textAlign = 'right'; + type.style.fontSize = "10px"; type.style.width = '108px'; type.style.marginRight = '5px'; type.style.verticalAlign = 'text-top'; @@ -534,14 +535,16 @@ CM.Disp.TimerBarCreateBar = function(id, name, bars) { */ CM.Disp.UpdateTimerBar = function() { if (CM.Options.TimerBar == 1) { - // label width: 113, timer width: 26, div margin: 20 - var maxWidth = CM.Disp.TimerBar.offsetWidth - 159; + // label width: 113, timer width: 30, div margin: 20 + var maxWidthTwoBar = CM.Disp.TimerBar.offsetWidth - 163; + // label width: 113, div margin: 20, calculate timer width at runtime + var maxWidthOneBar = CM.Disp.TimerBar.offsetWidth - 133; var numberOfTimers = 0; // Regulates visibility of Golden Cookie timer if (Game.shimmerTypes['golden'].spawned == 0 && !Game.Has('Golden switch [off]')) { CM.Disp.TimerBars['CMTimerBarGC'].style.display = ''; - l('CMTimerBarGCMinBar').style.width = Math.round(Math.max(0, Game.shimmerTypes['golden'].minTime - Game.shimmerTypes['golden'].time) * maxWidth / Game.shimmerTypes['golden'].maxTime) + 'px'; + l('CMTimerBarGCMinBar').style.width = Math.round(Math.max(0, Game.shimmerTypes['golden'].minTime - Game.shimmerTypes['golden'].time) * maxWidthTwoBar / Game.shimmerTypes['golden'].maxTime) + 'px'; l('CMTimerBarGCMinBar').textContent = Math.ceil((Game.shimmerTypes['golden'].minTime - Game.shimmerTypes['golden'].time)/ Game.fps) if (Game.shimmerTypes['golden'].minTime == Game.shimmerTypes['golden'].maxTime) { l('CMTimerBarGCMinBar').style.borderTopRightRadius = '10px'; @@ -551,7 +554,7 @@ CM.Disp.UpdateTimerBar = function() { l('CMTimerBarGCMinBar').style.borderTopRightRadius = ''; l('CMTimerBarGCMinBar').style.borderBottomRightRadius = ''; } - l('CMTimerBarGCBar').style.width = Math.round(Math.min(Game.shimmerTypes['golden'].maxTime - Game.shimmerTypes['golden'].minTime, Game.shimmerTypes['golden'].maxTime - Game.shimmerTypes['golden'].time) * maxWidth / Game.shimmerTypes['golden'].maxTime) + 'px'; + l('CMTimerBarGCBar').style.width = Math.round(Math.min(Game.shimmerTypes['golden'].maxTime - Game.shimmerTypes['golden'].minTime, Game.shimmerTypes['golden'].maxTime - Game.shimmerTypes['golden'].time) * maxWidthTwoBar / Game.shimmerTypes['golden'].maxTime) + 'px'; l('CMTimerBarGCBar').textContent = Math.ceil(Math.min(Game.shimmerTypes['golden'].maxTime - Game.shimmerTypes['golden'].minTime, Game.shimmerTypes['golden'].maxTime - Game.shimmerTypes['golden'].time) / Game.fps); l('CMTimerBarGCTime').textContent = Math.ceil((Game.shimmerTypes['golden'].maxTime - Game.shimmerTypes['golden'].time) / Game.fps); numberOfTimers++; @@ -561,9 +564,9 @@ CM.Disp.UpdateTimerBar = function() { // Regulates visibility of Reindeer timer if (Game.season == 'christmas' && Game.shimmerTypes['reindeer'].spawned == 0) { CM.Disp.TimerBars['CMTimerBarRen'].style.display = ''; - l('CMTimerBarRenMinBar').style.width = Math.round(Math.max(0, Game.shimmerTypes['reindeer'].minTime - Game.shimmerTypes['reindeer'].time) * maxWidth / Game.shimmerTypes['reindeer'].maxTime) + 'px'; + l('CMTimerBarRenMinBar').style.width = Math.round(Math.max(0, Game.shimmerTypes['reindeer'].minTime - Game.shimmerTypes['reindeer'].time) * maxWidthTwoBar / Game.shimmerTypes['reindeer'].maxTime) + 'px'; l('CMTimerBarRenMinBar').textContent = Math.ceil((Game.shimmerTypes['reindeer'].minTime - Game.shimmerTypes['reindeer'].time)/ Game.fps) - l('CMTimerBarRenBar').style.width = Math.round(Math.min(Game.shimmerTypes['reindeer'].maxTime - Game.shimmerTypes['reindeer'].minTime, Game.shimmerTypes['reindeer'].maxTime - Game.shimmerTypes['reindeer'].time) * maxWidth / Game.shimmerTypes['reindeer'].maxTime) + 'px'; + l('CMTimerBarRenBar').style.width = Math.round(Math.min(Game.shimmerTypes['reindeer'].maxTime - Game.shimmerTypes['reindeer'].minTime, Game.shimmerTypes['reindeer'].maxTime - Game.shimmerTypes['reindeer'].time) * maxWidthTwoBar / Game.shimmerTypes['reindeer'].maxTime) + 'px'; l('CMTimerBarRenBar').textContent = Math.ceil(Math.min(Game.shimmerTypes['reindeer'].maxTime - Game.shimmerTypes['reindeer'].minTime, Game.shimmerTypes['reindeer'].maxTime - Game.shimmerTypes['reindeer'].time) / Game.fps); l('CMTimerBarRenTime').textContent = Math.ceil((Game.shimmerTypes['reindeer'].maxTime - Game.shimmerTypes['reindeer'].time) / Game.fps); numberOfTimers++; @@ -588,7 +591,7 @@ CM.Disp.UpdateTimerBar = function() { } else classColor = CM.Disp.colorPurple; timer.lastChild.children[1].className = CM.Disp.colorBackPre + classColor; - timer.lastChild.children[1].style.width = Math.round(Game.buffs[i].time * maxWidth / Game.buffs[i].maxTime) + 'px'; + timer.lastChild.children[1].style.width = Math.round(Game.buffs[i].time *(maxWidthOneBar - Math.ceil(Game.buffs[i].time / Game.fps).toString().length * 8) / Game.buffs[i].maxTime) + 'px'; timer.lastChild.children[2].textContent = Math.ceil(Game.buffs[i].time / Game.fps); numberOfTimers++; CM.Disp.BuffTimerBars[Game.buffs[i].name] = timer From b6cd262ff2674f0e5187c081fc5051f378492d9f Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Sun, 27 Dec 2020 13:27:44 +0100 Subject: [PATCH 098/106] Fixed (#388) and add percentage overlay to timers --- CookieMonster.js | 21 ++++++++------------- src/Disp.js | 21 ++++++++------------- 2 files changed, 16 insertions(+), 26 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index cab285e..c8215fd 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -1558,7 +1558,7 @@ CM.Disp.CreateTimerBar = function() { CM.Disp.TimerBar.id = 'CMTimerBar'; CM.Disp.TimerBar.style.position = 'absolute'; CM.Disp.TimerBar.style.display = 'none'; - CM.Disp.TimerBar.style.height = '48px'; + CM.Disp.TimerBar.style.height = '30px'; CM.Disp.TimerBar.style.fontSize = '10px'; CM.Disp.TimerBar.style.fontWeight = 'bold'; CM.Disp.TimerBar.style.backgroundColor = 'black'; @@ -1707,7 +1707,8 @@ CM.Disp.UpdateTimerBar = function() { } else classColor = CM.Disp.colorPurple; timer.lastChild.children[1].className = CM.Disp.colorBackPre + classColor; - timer.lastChild.children[1].style.width = Math.round(Game.buffs[i].time *(maxWidthOneBar - Math.ceil(Game.buffs[i].time / Game.fps).toString().length * 8) / Game.buffs[i].maxTime) + 'px'; + timer.lastChild.children[1].textContent = Math.round(100 * (Game.buffs[i].time / Game.buffs[i].maxTime)) + "%"; + timer.lastChild.children[1].style.width = Math.round(Game.buffs[i].time * (maxWidthOneBar - Math.ceil(Game.buffs[i].time / Game.fps).toString().length * 8) / Game.buffs[i].maxTime) + 'px'; timer.lastChild.children[2].textContent = Math.ceil(Game.buffs[i].time / Game.fps); numberOfTimers++; CM.Disp.BuffTimerBars[Game.buffs[i].name] = timer @@ -1718,13 +1719,7 @@ CM.Disp.UpdateTimerBar = function() { } if (numberOfTimers != 0) { - var height = 48 / numberOfTimers; - for (var i in CM.Disp.TimerBars) { - CM.Disp.TimerBars[i].style.height = height + 'px'; - } - for (var i in CM.Disp.BuffTimerBars) { - CM.Disp.BuffTimerBars[i].style.height = height + 'px'; - } + CM.Disp.TimerBar.style.height = numberOfTimers * 12 + 2 + 'px'; } } } @@ -1766,22 +1761,22 @@ CM.Disp.ToggleTimerBarPos = function() { */ CM.Disp.UpdateBotTimerBarPosition = function() { if (CM.Options.BotBar == 1 && CM.Options.TimerBar == 1 && CM.Options.TimerBarPos == 1) { - CM.Disp.BotBar.style.bottom = '48px'; - l('game').style.bottom = '118px'; + CM.Disp.BotBar.style.bottom = CM.Disp.TimerBar.style.height; + l('game').style.bottom = Number(CM.Disp.TimerBar.style.height.replace("px","")) + 70 + "px"; } else if (CM.Options.BotBar == 1) { CM.Disp.BotBar.style.bottom = '0px'; l('game').style.bottom = '70px'; } else if (CM.Options.TimerBar == 1 && CM.Options.TimerBarPos == 1) { - l('game').style.bottom = '48px'; + l('game').style.bottom = CM.Disp.TimerBar.style.height; } else { // No bars l('game').style.bottom = '0px'; } if (CM.Options.TimerBar == 1 && CM.Options.TimerBarPos == 0) { - l('sectionLeft').style.top = '48px'; + l('sectionLeft').style.top = CM.Disp.TimerBar.style.height; } else { l('sectionLeft').style.top = ''; diff --git a/src/Disp.js b/src/Disp.js index 045c4a7..52f5eeb 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -442,7 +442,7 @@ CM.Disp.CreateTimerBar = function() { CM.Disp.TimerBar.id = 'CMTimerBar'; CM.Disp.TimerBar.style.position = 'absolute'; CM.Disp.TimerBar.style.display = 'none'; - CM.Disp.TimerBar.style.height = '48px'; + CM.Disp.TimerBar.style.height = '30px'; CM.Disp.TimerBar.style.fontSize = '10px'; CM.Disp.TimerBar.style.fontWeight = 'bold'; CM.Disp.TimerBar.style.backgroundColor = 'black'; @@ -591,7 +591,8 @@ CM.Disp.UpdateTimerBar = function() { } else classColor = CM.Disp.colorPurple; timer.lastChild.children[1].className = CM.Disp.colorBackPre + classColor; - timer.lastChild.children[1].style.width = Math.round(Game.buffs[i].time *(maxWidthOneBar - Math.ceil(Game.buffs[i].time / Game.fps).toString().length * 8) / Game.buffs[i].maxTime) + 'px'; + timer.lastChild.children[1].textContent = Math.round(100 * (Game.buffs[i].time / Game.buffs[i].maxTime)) + "%"; + timer.lastChild.children[1].style.width = Math.round(Game.buffs[i].time * (maxWidthOneBar - Math.ceil(Game.buffs[i].time / Game.fps).toString().length * 8) / Game.buffs[i].maxTime) + 'px'; timer.lastChild.children[2].textContent = Math.ceil(Game.buffs[i].time / Game.fps); numberOfTimers++; CM.Disp.BuffTimerBars[Game.buffs[i].name] = timer @@ -602,13 +603,7 @@ CM.Disp.UpdateTimerBar = function() { } if (numberOfTimers != 0) { - var height = 48 / numberOfTimers; - for (var i in CM.Disp.TimerBars) { - CM.Disp.TimerBars[i].style.height = height + 'px'; - } - for (var i in CM.Disp.BuffTimerBars) { - CM.Disp.BuffTimerBars[i].style.height = height + 'px'; - } + CM.Disp.TimerBar.style.height = numberOfTimers * 12 + 2 + 'px'; } } } @@ -650,22 +645,22 @@ CM.Disp.ToggleTimerBarPos = function() { */ CM.Disp.UpdateBotTimerBarPosition = function() { if (CM.Options.BotBar == 1 && CM.Options.TimerBar == 1 && CM.Options.TimerBarPos == 1) { - CM.Disp.BotBar.style.bottom = '48px'; - l('game').style.bottom = '118px'; + CM.Disp.BotBar.style.bottom = CM.Disp.TimerBar.style.height; + l('game').style.bottom = Number(CM.Disp.TimerBar.style.height.replace("px","")) + 70 + "px"; } else if (CM.Options.BotBar == 1) { CM.Disp.BotBar.style.bottom = '0px'; l('game').style.bottom = '70px'; } else if (CM.Options.TimerBar == 1 && CM.Options.TimerBarPos == 1) { - l('game').style.bottom = '48px'; + l('game').style.bottom = CM.Disp.TimerBar.style.height; } else { // No bars l('game').style.bottom = '0px'; } if (CM.Options.TimerBar == 1 && CM.Options.TimerBarPos == 0) { - l('sectionLeft').style.top = '48px'; + l('sectionLeft').style.top = CM.Disp.TimerBar.style.height; } else { l('sectionLeft').style.top = ''; From b4e2236fb7d83523a1a61d323bf70985d93aa1a4 Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Sun, 27 Dec 2020 14:11:21 +0100 Subject: [PATCH 099/106] Fixed #88 --- CookieMonster.js | 13 ++++++++++++- src/Disp.js | 13 ++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index c8215fd..6ad740f 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -1511,7 +1511,10 @@ CM.Disp.UpdateBotBar = function() { CM.Disp.BotBar.firstChild.firstChild.childNodes[2].childNodes[count].textContent = Beautify(CM.Cache[target][i].pp, 2); var timeColor = CM.Disp.GetTimeColor((Game.Objects[i].bulkPrice - (Game.cookies + CM.Disp.GetWrinkConfigBank())) / CM.Disp.GetCPS()); CM.Disp.BotBar.firstChild.firstChild.childNodes[3].childNodes[count].className = CM.Disp.colorTextPre + timeColor.color; - CM.Disp.BotBar.firstChild.firstChild.childNodes[3].childNodes[count].textContent = timeColor.text; + if (timeColor.text == "Done!" && Game.cookies < Game.Objects[i].bulkPrice) { + CM.Disp.BotBar.firstChild.firstChild.childNodes[3].childNodes[count].textContent = timeColor.text + " (with Wrink)"; + } + else CM.Disp.BotBar.firstChild.firstChild.childNodes[3].childNodes[count].textContent = timeColor.text; } } } @@ -2599,6 +2602,10 @@ CM.Disp.UpdateTooltipBuilding = function() { l('CMTooltipPP').className = CM.Disp.colorTextPre + CM.Cache[target][CM.Disp.tooltipName].color; var timeColor = CM.Disp.GetTimeColor((CM.Disp.TooltipPrice - (Game.cookies + CM.Disp.GetWrinkConfigBank())) / CM.Disp.GetCPS()); l('CMTooltipTime').textContent = timeColor.text; + if (timeColor.text == "Done!" && Game.cookies < CM.Cache[target][CM.Disp.tooltipName].price) { + l('CMTooltipTime').textContent = timeColor.text + " (with Wrink)"; + } + else l('CMTooltipTime').textContent = timeColor.text; l('CMTooltipTime').className = CM.Disp.colorTextPre + timeColor.color; } @@ -2658,6 +2665,10 @@ CM.Disp.UpdateTooltipUpgrade = function() { } var timeColor = CM.Disp.GetTimeColor((CM.Disp.TooltipPrice - (Game.cookies + CM.Disp.GetWrinkConfigBank())) / CM.Disp.GetCPS()); l('CMTooltipTime').textContent = timeColor.text; + if (timeColor.text == "Done!" && Game.cookies < Game.UpgradesInStore[CM.Disp.tooltipName].getPrice()) { + l('CMTooltipTime').textContent = timeColor.text + " (with Wrink)"; + } + else l('CMTooltipTime').textContent = timeColor.text; l('CMTooltipTime').className = CM.Disp.colorTextPre + timeColor.color; // Add extra info to Chocolate egg tooltip diff --git a/src/Disp.js b/src/Disp.js index 52f5eeb..bb4bac8 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -395,7 +395,10 @@ CM.Disp.UpdateBotBar = function() { CM.Disp.BotBar.firstChild.firstChild.childNodes[2].childNodes[count].textContent = Beautify(CM.Cache[target][i].pp, 2); var timeColor = CM.Disp.GetTimeColor((Game.Objects[i].bulkPrice - (Game.cookies + CM.Disp.GetWrinkConfigBank())) / CM.Disp.GetCPS()); CM.Disp.BotBar.firstChild.firstChild.childNodes[3].childNodes[count].className = CM.Disp.colorTextPre + timeColor.color; - CM.Disp.BotBar.firstChild.firstChild.childNodes[3].childNodes[count].textContent = timeColor.text; + if (timeColor.text == "Done!" && Game.cookies < Game.Objects[i].bulkPrice) { + CM.Disp.BotBar.firstChild.firstChild.childNodes[3].childNodes[count].textContent = timeColor.text + " (with Wrink)"; + } + else CM.Disp.BotBar.firstChild.firstChild.childNodes[3].childNodes[count].textContent = timeColor.text; } } } @@ -1483,6 +1486,10 @@ CM.Disp.UpdateTooltipBuilding = function() { l('CMTooltipPP').className = CM.Disp.colorTextPre + CM.Cache[target][CM.Disp.tooltipName].color; var timeColor = CM.Disp.GetTimeColor((CM.Disp.TooltipPrice - (Game.cookies + CM.Disp.GetWrinkConfigBank())) / CM.Disp.GetCPS()); l('CMTooltipTime').textContent = timeColor.text; + if (timeColor.text == "Done!" && Game.cookies < CM.Cache[target][CM.Disp.tooltipName].price) { + l('CMTooltipTime').textContent = timeColor.text + " (with Wrink)"; + } + else l('CMTooltipTime').textContent = timeColor.text; l('CMTooltipTime').className = CM.Disp.colorTextPre + timeColor.color; } @@ -1542,6 +1549,10 @@ CM.Disp.UpdateTooltipUpgrade = function() { } var timeColor = CM.Disp.GetTimeColor((CM.Disp.TooltipPrice - (Game.cookies + CM.Disp.GetWrinkConfigBank())) / CM.Disp.GetCPS()); l('CMTooltipTime').textContent = timeColor.text; + if (timeColor.text == "Done!" && Game.cookies < Game.UpgradesInStore[CM.Disp.tooltipName].getPrice()) { + l('CMTooltipTime').textContent = timeColor.text + " (with Wrink)"; + } + else l('CMTooltipTime').textContent = timeColor.text; l('CMTooltipTime').className = CM.Disp.colorTextPre + timeColor.color; // Add extra info to Chocolate egg tooltip From b58c3ea292b2b63cc4812d6390641a92214eed1a Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Mon, 28 Dec 2020 10:53:58 +0100 Subject: [PATCH 100/106] Allow saving outside of autosave-interval (#469) --- CookieMonster.js | 31 +++++++++++++++++-------------- src/Config.js | 26 +++++++++++++++----------- src/Disp.js | 6 +++--- 3 files changed, 35 insertions(+), 28 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index 6ad740f..6b2149e 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -652,15 +652,18 @@ CM.Cache.spawnedGoldenShimmer = 0; * Section: Functions related to saving, loading and restoring configs */ /** - * @deprecated - * This function (used to) save the config of CookieMonster + * This function saves the config of CookieMonster without saving any of the other save-data + * This allows saving in between the autosave intervals * It is called by CM.Config.LoadConfig(), CM.Config.RestoreDefault(), CM.Config.ToggleConfig(), * CM.ToggleConfigVolume() and changes in options with type "url", "color" or "numscale" - * TODO: See if there is a way to force Cookie CLICKER to save only the mod-data and not also Save-data. - * Otherwise this can be removed */ -CM.Config.SaveConfig = function(config) { - CM.save(); +CM.Config.SaveConfig = function() { + let saveString = b64_to_utf8(unescape(localStorage.getItem('CookieClickerGame')).split('!END!')[0]); + CookieMonsterSave = saveString.match(/CookieMonster.*(;|$)/); + if (CookieMonsterSave != null) { + newSaveString = saveString.replace(CookieMonsterSave[0], "CookieMonster:" + CM.save()); + localStorage.setItem('CookieClickerGame', escape(utf8_to_b64(newSaveString)+'!END!')) + } } /** @@ -713,7 +716,7 @@ CM.Config.LoadConfig = function(settings) { } } } - if (mod) CM.Config.SaveConfig(CM.Options); + if (mod) CM.Config.SaveConfig(); CM.Loop(); // Do loop once for (var i in CM.Data.ConfigDefault) { if (i != 'Header' && typeof CM.ConfigData[i].func !== 'undefined') { @@ -732,7 +735,7 @@ CM.Config.LoadConfig = function(settings) { */ CM.Config.RestoreDefault = function() { CM.Config.LoadConfig(CM.Data.ConfigDefault); - CM.Config.SaveConfig(CM.Options); + CM.Config.SaveConfig(); Game.UpdateMenu(); } @@ -758,7 +761,7 @@ CM.Config.ToggleConfig = function(config) { } l(CM.ConfigPrefix + config).innerHTML = CM.ConfigData[config].label[CM.Options[config]]; - CM.Config.SaveConfig(CM.Options); + CM.Config.SaveConfig(); } /** @@ -771,7 +774,7 @@ CM.Config.ToggleConfigVolume = function(config) { l("slider" + config + "right").innerHTML = l("slider" + config).value + "%"; CM.Options[config] = Math.round(l("slider" + config).value); } - CM.Config.SaveConfig(CM.Options); + CM.Config.SaveConfig(); } /** @@ -782,7 +785,7 @@ CM.Config.ToggleConfigVolume = function(config) { CM.Config.ToggleHeader = function(config) { CM.Options.Header[config]++; if (CM.Options.Header[config] > 1) CM.Options.Header[config] = 0; - CM.Config.SaveConfig(CM.Options); + CM.Config.SaveConfig(); } /******** @@ -3145,7 +3148,7 @@ CM.Disp.CreatePrefOption = function(config) { inputPrompt.setAttribute('value', CM.Options[config]); var a = document.createElement('a'); a.className = 'option'; - a.onclick = function() {Game.Prompt(inputPrompt.outerHTML, [['Save', 'CM.Options[\'' + config + '\'] = l(CM.ConfigPrefix + \'' + config + '\' + \'Prompt\').value; CM.Config.SaveConfig(CM.Options); Game.ClosePrompt(); Game.UpdateMenu();'], 'Cancel']);}; + a.onclick = function() {Game.Prompt(inputPrompt.outerHTML, [['Save', 'CM.Options[\'' + config + '\'] = l(CM.ConfigPrefix + \'' + config + '\' + \'Prompt\').value; CM.Config.SaveConfig(); Game.ClosePrompt(); Game.UpdateMenu();'], 'Cancel']);}; a.textContent = 'Edit'; div.appendChild(a); var label = document.createElement('label'); @@ -3163,7 +3166,7 @@ CM.Disp.CreatePrefOption = function(config) { input.style.width = '65px'; input.setAttribute('value', CM.Options.Colors[CM.Disp.colors[i]]); div.appendChild(input); - eval('var change = function() {CM.Options.Colors[\'' + CM.Disp.colors[i] + '\'] = l(CM.ConfigPrefix + \'Color\' + \'' + CM.Disp.colors[i] + '\').value; CM.Disp.UpdateColors(); CM.Config.SaveConfig(CM.Options);}'); + eval('var change = function() {CM.Options.Colors[\'' + CM.Disp.colors[i] + '\'] = l(CM.ConfigPrefix + \'Color\' + \'' + CM.Disp.colors[i] + '\').value; CM.Disp.UpdateColors(); CM.Config.SaveConfig();}'); var jscolorpicker = new jscolor.color(input, {hash: true, caps: false, pickerZIndex: 1000000, pickerPosition: 'right', onImmediateChange: change}); var label = document.createElement('label'); label.textContent = CM.ConfigData.Colors.desc[CM.Disp.colors[i]]; @@ -3187,7 +3190,7 @@ CM.Disp.CreatePrefOption = function(config) { input.max = CM.ConfigData[config].max; input.oninput = function() {if (this.value > this.max) console.log("TEST"); CM.Options[config] = this.value; - CM.Config.SaveConfig(CM.Options); + CM.Config.SaveConfig(); CM.Disp.RefreshScale() } div.appendChild(input); diff --git a/src/Config.js b/src/Config.js index dd86c78..e9b8717 100644 --- a/src/Config.js +++ b/src/Config.js @@ -6,15 +6,19 @@ * Section: Functions related to saving, loading and restoring configs */ /** - * @deprecated - * This function (used to) save the config of CookieMonster + * This function saves the config of CookieMonster without saving any of the other save-data + * This allows saving in between the autosave intervals * It is called by CM.Config.LoadConfig(), CM.Config.RestoreDefault(), CM.Config.ToggleConfig(), * CM.ToggleConfigVolume() and changes in options with type "url", "color" or "numscale" - * TODO: See if there is a way to force Cookie CLICKER to save only the mod-data and not also Save-data. - * Otherwise this can be removed */ -CM.Config.SaveConfig = function(config) { - CM.save(); +CM.Config.SaveConfig = function() { + let saveString = b64_to_utf8(unescape(localStorage.getItem('CookieClickerGame')).split('!END!')[0]); + let pattern = /CookieMonster.*[;$]/; + CookieMonsterSave = saveString.match(/CookieMonster.*(;|$)/); + if (CookieMonsterSave != null) { + newSaveString = saveString.replace(CookieMonsterSave[0], "CookieMonster:" + CM.save()); + localStorage.setItem('CookieClickerGame', escape(utf8_to_b64(newSaveString)+'!END!')) + } } /** @@ -67,7 +71,7 @@ CM.Config.LoadConfig = function(settings) { } } } - if (mod) CM.Config.SaveConfig(CM.Options); + if (mod) CM.Config.SaveConfig(); CM.Loop(); // Do loop once for (var i in CM.Data.ConfigDefault) { if (i != 'Header' && typeof CM.ConfigData[i].func !== 'undefined') { @@ -86,7 +90,7 @@ CM.Config.LoadConfig = function(settings) { */ CM.Config.RestoreDefault = function() { CM.Config.LoadConfig(CM.Data.ConfigDefault); - CM.Config.SaveConfig(CM.Options); + CM.Config.SaveConfig(); Game.UpdateMenu(); } @@ -112,7 +116,7 @@ CM.Config.ToggleConfig = function(config) { } l(CM.ConfigPrefix + config).innerHTML = CM.ConfigData[config].label[CM.Options[config]]; - CM.Config.SaveConfig(CM.Options); + CM.Config.SaveConfig(); } /** @@ -125,7 +129,7 @@ CM.Config.ToggleConfigVolume = function(config) { l("slider" + config + "right").innerHTML = l("slider" + config).value + "%"; CM.Options[config] = Math.round(l("slider" + config).value); } - CM.Config.SaveConfig(CM.Options); + CM.Config.SaveConfig(); } /** @@ -136,7 +140,7 @@ CM.Config.ToggleConfigVolume = function(config) { CM.Config.ToggleHeader = function(config) { CM.Options.Header[config]++; if (CM.Options.Header[config] > 1) CM.Options.Header[config] = 0; - CM.Config.SaveConfig(CM.Options); + CM.Config.SaveConfig(); } /******** diff --git a/src/Disp.js b/src/Disp.js index bb4bac8..f61e8a6 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -2029,7 +2029,7 @@ CM.Disp.CreatePrefOption = function(config) { inputPrompt.setAttribute('value', CM.Options[config]); var a = document.createElement('a'); a.className = 'option'; - a.onclick = function() {Game.Prompt(inputPrompt.outerHTML, [['Save', 'CM.Options[\'' + config + '\'] = l(CM.ConfigPrefix + \'' + config + '\' + \'Prompt\').value; CM.Config.SaveConfig(CM.Options); Game.ClosePrompt(); Game.UpdateMenu();'], 'Cancel']);}; + a.onclick = function() {Game.Prompt(inputPrompt.outerHTML, [['Save', 'CM.Options[\'' + config + '\'] = l(CM.ConfigPrefix + \'' + config + '\' + \'Prompt\').value; CM.Config.SaveConfig(); Game.ClosePrompt(); Game.UpdateMenu();'], 'Cancel']);}; a.textContent = 'Edit'; div.appendChild(a); var label = document.createElement('label'); @@ -2047,7 +2047,7 @@ CM.Disp.CreatePrefOption = function(config) { input.style.width = '65px'; input.setAttribute('value', CM.Options.Colors[CM.Disp.colors[i]]); div.appendChild(input); - eval('var change = function() {CM.Options.Colors[\'' + CM.Disp.colors[i] + '\'] = l(CM.ConfigPrefix + \'Color\' + \'' + CM.Disp.colors[i] + '\').value; CM.Disp.UpdateColors(); CM.Config.SaveConfig(CM.Options);}'); + eval('var change = function() {CM.Options.Colors[\'' + CM.Disp.colors[i] + '\'] = l(CM.ConfigPrefix + \'Color\' + \'' + CM.Disp.colors[i] + '\').value; CM.Disp.UpdateColors(); CM.Config.SaveConfig();}'); var jscolorpicker = new jscolor.color(input, {hash: true, caps: false, pickerZIndex: 1000000, pickerPosition: 'right', onImmediateChange: change}); var label = document.createElement('label'); label.textContent = CM.ConfigData.Colors.desc[CM.Disp.colors[i]]; @@ -2071,7 +2071,7 @@ CM.Disp.CreatePrefOption = function(config) { input.max = CM.ConfigData[config].max; input.oninput = function() {if (this.value > this.max) console.log("TEST"); CM.Options[config] = this.value; - CM.Config.SaveConfig(CM.Options); + CM.Config.SaveConfig(); CM.Disp.RefreshScale() } div.appendChild(input); From 91ebbf39b9ebc22d9a93435925b8ef1fc0b42cd1 Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Mon, 28 Dec 2020 12:41:01 +0100 Subject: [PATCH 101/106] Added tooltip with costs for Dragon Levels (#65) --- CookieMonster.js | 95 +++++++++++++++++++++++++++++++++++++++++++++--- src/Cache.js | 57 +++++++++++++++++++++++++++++ src/Config.js | 1 - src/Disp.js | 22 +++++++++-- src/Main.js | 16 +++++++- 5 files changed, 180 insertions(+), 11 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index 6b2149e..894ae36 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -319,6 +319,63 @@ CM.Cache.UpdateCurrWrinklerCPS = function() { CM.Cache.CurrWrinklerCPSMult = count * (count * 0.05 * 1.1) * (Game.Has('Sacrilegious corruption') * 0.05 + 1) * (Game.Has('Wrinklerspawn') * 0.05 + 1) * godMult; } +/******** + * Section: Functions related to "Specials" (Dragon and Santa) */ + +/** + * This functions caches the current cost of upgrading the dragon level so it can be displayed in the tooltip + * It is called by the relevan tooltip-code as a result of CM.Disp.AddDragonLevelUpTooltip() and by CM.Loop() + * @global {number} CM.Cache.lastDragonLevel The last cached dragon level + * @global {string} CM.Cache.CostDragonUpgrade The Beautified cost of the next upgrade + */ +CM.Cache.CacheDragonCost = function() { + if (CM.Cache.lastDragonLevel != Game.dragonLevel || CM.Sim.DoSims) { + if (Game.dragonLevels[Game.dragonLevel].buy.toString().includes("sacrifice")) { + var target = Game.dragonLevels[Game.dragonLevel].buy.toString().match(/Objects\[(.*)\]/)[1]; + var amount = Game.dragonLevels[Game.dragonLevel].buy.toString().match(/sacrifice\((.*?)\)/)[1]; + if (target != "i") { + target = target.replaceAll("\'", ""); + if (Game.Objects[target].amount < amount) { + CM.Cache.CostDragonUpgrade = "Not enough buildings to sell"; + } + else { + var cost = 0; + CM.Sim.CopyData(); + for (var i = 0; i < amount; i++) { + var price = CM.Sim.Objects[target].basePrice * Math.pow(Game.priceIncrease, Math.max(0, CM.Sim.Objects[target].amount - 1 - CM.Sim.Objects[target].free)); + price = Game.modifyBuildingPrice(CM.Sim.Objects[target], price); + price = Math.ceil(price); + cost += price; + CM.Sim.Objects[target].amount--; + } + CM.Cache.CostDragonUpgrade = CM.Disp.Beautify(cost); + } + } + else { + var cost = 0; + CM.Sim.CopyData(); + for (var j in Game.Objects) { + target = j; + if (Game.Objects[target].amount < amount) { + CM.Cache.CostDragonUpgrade = "Not enough buildings to sell"; + } + else { + for (var i = 0; i < amount; i++) { + var price = CM.Sim.Objects[target].basePrice * Math.pow(Game.priceIncrease, Math.max(0, CM.Sim.Objects[target].amount - 1 - CM.Sim.Objects[target].free)); + price = Game.modifyBuildingPrice(CM.Sim.Objects[target], price); + price = Math.ceil(price); + cost += price; + CM.Sim.Objects[target].amount--; + } + } + } + CM.Cache.CostDragonUpgrade = CM.Disp.Beautify(cost); + } + } + CM.Cache.lastDragonLevel = Game.dragonLevel; + } +} + /******** * Section: UNSORTED */ @@ -2927,7 +2984,7 @@ CM.Disp.UpdateWrinklerTooltip = function() { } /******** - * Section: Functions related to the dragon aura interface */ + * Section: Functions related to the Dragon */ /** * This functions adds the two extra lines about CPS and time to recover to the aura picker infoscreen @@ -2957,6 +3014,22 @@ CM.Disp.AddAuraInfo = function(aura) { } } +/** + * This functions adds a tooltip to the level up button displaying the cost of rebuying all + * It is called by Game.ToggleSpecialMenu() after CM.ReplaceNative() + */ +CM.Disp.AddDragonLevelUpTooltip = function() { + // Check if it is the dragon popup that is on screen + if ((l('specialPopup').className.match(/onScreen/) && l('specialPopup').children[0].style.background.match(/dragon/)) != null) { + for (let i = 0; i < l('specialPopup').childNodes.length; i++) { + if (l('specialPopup').childNodes[i].className == "optionBox") { + l('specialPopup').children[i].onmouseover = function() {CM.Cache.CacheDragonCost(); Game.tooltip.dynamic = 1; Game.tooltip.draw(this, CM.Cache.CostDragonUpgrade, 'this'); Game.tooltip.wobble();} + l('specialPopup').children[i].onmouseout = function() {Game.tooltip.shouldHide=1;} + } + } + } +} + /******** * Section: General functions related to the Options/Stats pages @@ -3519,7 +3592,7 @@ CM.Disp.CreateStatsMissDisp = function(theMissDisp) { * @returns {object} section The object contating the Lucky section */ CM.Disp.CreateStatsLuckySection = function() { - // TODO: Remove this and creater better tooltip!! + // This sets which tooltip to display for certain stats var goldCookTooltip = CM.Sim.auraMult('Dragon\'s Fortune') ? 'GoldCookDragonsFortuneTooltipPlaceholder' : 'GoldCookTooltipPlaceholder'; var section = document.createElement('div'); @@ -3584,7 +3657,7 @@ CM.Disp.CreateStatsLuckySection = function() { * @returns {object} section The object contating the Chain section */ CM.Disp.CreateStatsChainSection = function() { - // TODO: Remove this and creater better tooltip!! + // This sets which tooltip to display for certain stats var goldCookTooltip = CM.Sim.auraMult('Dragon\'s Fortune') ? 'GoldCookDragonsFortuneTooltipPlaceholder' : 'GoldCookTooltipPlaceholder'; var section = document.createElement('div'); @@ -3957,7 +4030,7 @@ CM.ReplaceNative = function() { CM.Backup.scriptLoaded = Game.scriptLoaded; Game.scriptLoaded = function(who, script) { CM.Backup.scriptLoaded(who, script); - CM.Disp.AddTooltipGrimoire() + CM.Disp.ReplaceTooltipGrimoire() CM.ReplaceNativeGrimoire(); } @@ -3982,6 +4055,16 @@ CM.ReplaceNative = function() { CM.Disp.AddAuraInfo(aura); } + CM.Backup.ToggleSpecialMenu = Game.ToggleSpecialMenu; + /** + * This functions adds the code to display the tooltips for the levelUp button of the dragon + */ + Game.ToggleSpecialMenu = function(on) { + CM.Backup.ToggleSpecialMenu(on); + CM.Disp.AddDragonLevelUpTooltip(); + } + + CM.Backup.UpdateMenu = Game.UpdateMenu; Game.UpdateMenu = function() { if (typeof jscolor.picker === 'undefined' || typeof jscolor.picker.owner === 'undefined') { @@ -4024,7 +4107,7 @@ CM.ReplaceNativeGrimoireLaunch = function() { eval('CM.Backup.GrimoireLaunchMod = ' + minigame.launch.toString().split('=this').join('= Game.Objects[\'Wizard tower\'].minigame')); Game.Objects['Wizard tower'].minigame.launch = function() { CM.Backup.GrimoireLaunchMod(); - CM.Disp.AddTooltipGrimoire(); + CM.Disp.ReplaceTooltipGrimoire(); CM.HasReplaceNativeGrimoireDraw = false; CM.ReplaceNativeGrimoireDraw(); } @@ -4061,11 +4144,13 @@ CM.Loop = function() { CM.Cache.CacheStats(); CM.Cache.CacheMissingUpgrades(); CM.Cache.RemakeChain(); + CM.Cache.CacheDragonCost(); CM.Cache.RemakeSeaSpec(); CM.Cache.RemakeSellForChoEgg(); CM.Sim.DoSims = 0; + } // Check for aura change to recalculate buildings prices diff --git a/src/Cache.js b/src/Cache.js index 8172a17..49cd373 100644 --- a/src/Cache.js +++ b/src/Cache.js @@ -288,6 +288,63 @@ CM.Cache.UpdateCurrWrinklerCPS = function() { CM.Cache.CurrWrinklerCPSMult = count * (count * 0.05 * 1.1) * (Game.Has('Sacrilegious corruption') * 0.05 + 1) * (Game.Has('Wrinklerspawn') * 0.05 + 1) * godMult; } +/******** + * Section: Functions related to "Specials" (Dragon and Santa) */ + +/** + * This functions caches the current cost of upgrading the dragon level so it can be displayed in the tooltip + * It is called by the relevan tooltip-code as a result of CM.Disp.AddDragonLevelUpTooltip() and by CM.Loop() + * @global {number} CM.Cache.lastDragonLevel The last cached dragon level + * @global {string} CM.Cache.CostDragonUpgrade The Beautified cost of the next upgrade + */ +CM.Cache.CacheDragonCost = function() { + if (CM.Cache.lastDragonLevel != Game.dragonLevel || CM.Sim.DoSims) { + if (Game.dragonLevels[Game.dragonLevel].buy.toString().includes("sacrifice")) { + var target = Game.dragonLevels[Game.dragonLevel].buy.toString().match(/Objects\[(.*)\]/)[1]; + var amount = Game.dragonLevels[Game.dragonLevel].buy.toString().match(/sacrifice\((.*?)\)/)[1]; + if (target != "i") { + target = target.replaceAll("\'", ""); + if (Game.Objects[target].amount < amount) { + CM.Cache.CostDragonUpgrade = "Not enough buildings to sell"; + } + else { + var cost = 0; + CM.Sim.CopyData(); + for (var i = 0; i < amount; i++) { + var price = CM.Sim.Objects[target].basePrice * Math.pow(Game.priceIncrease, Math.max(0, CM.Sim.Objects[target].amount - 1 - CM.Sim.Objects[target].free)); + price = Game.modifyBuildingPrice(CM.Sim.Objects[target], price); + price = Math.ceil(price); + cost += price; + CM.Sim.Objects[target].amount--; + } + CM.Cache.CostDragonUpgrade = CM.Disp.Beautify(cost); + } + } + else { + var cost = 0; + CM.Sim.CopyData(); + for (var j in Game.Objects) { + target = j; + if (Game.Objects[target].amount < amount) { + CM.Cache.CostDragonUpgrade = "Not enough buildings to sell"; + } + else { + for (var i = 0; i < amount; i++) { + var price = CM.Sim.Objects[target].basePrice * Math.pow(Game.priceIncrease, Math.max(0, CM.Sim.Objects[target].amount - 1 - CM.Sim.Objects[target].free)); + price = Game.modifyBuildingPrice(CM.Sim.Objects[target], price); + price = Math.ceil(price); + cost += price; + CM.Sim.Objects[target].amount--; + } + } + } + CM.Cache.CostDragonUpgrade = CM.Disp.Beautify(cost); + } + } + CM.Cache.lastDragonLevel = Game.dragonLevel; + } +} + /******** * Section: UNSORTED */ diff --git a/src/Config.js b/src/Config.js index e9b8717..54e467e 100644 --- a/src/Config.js +++ b/src/Config.js @@ -13,7 +13,6 @@ */ CM.Config.SaveConfig = function() { let saveString = b64_to_utf8(unescape(localStorage.getItem('CookieClickerGame')).split('!END!')[0]); - let pattern = /CookieMonster.*[;$]/; CookieMonsterSave = saveString.match(/CookieMonster.*(;|$)/); if (CookieMonsterSave != null) { newSaveString = saveString.replace(CookieMonsterSave[0], "CookieMonster:" + CM.save()); diff --git a/src/Disp.js b/src/Disp.js index f61e8a6..469c8ed 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -1808,7 +1808,7 @@ CM.Disp.UpdateWrinklerTooltip = function() { } /******** - * Section: Functions related to the dragon aura interface */ + * Section: Functions related to the Dragon */ /** * This functions adds the two extra lines about CPS and time to recover to the aura picker infoscreen @@ -1838,6 +1838,22 @@ CM.Disp.AddAuraInfo = function(aura) { } } +/** + * This functions adds a tooltip to the level up button displaying the cost of rebuying all + * It is called by Game.ToggleSpecialMenu() after CM.ReplaceNative() + */ +CM.Disp.AddDragonLevelUpTooltip = function() { + // Check if it is the dragon popup that is on screen + if ((l('specialPopup').className.match(/onScreen/) && l('specialPopup').children[0].style.background.match(/dragon/)) != null) { + for (let i = 0; i < l('specialPopup').childNodes.length; i++) { + if (l('specialPopup').childNodes[i].className == "optionBox") { + l('specialPopup').children[i].onmouseover = function() {CM.Cache.CacheDragonCost(); Game.tooltip.dynamic = 1; Game.tooltip.draw(this, CM.Cache.CostDragonUpgrade, 'this'); Game.tooltip.wobble();} + l('specialPopup').children[i].onmouseout = function() {Game.tooltip.shouldHide=1;} + } + } + } +} + /******** * Section: General functions related to the Options/Stats pages @@ -2400,7 +2416,7 @@ CM.Disp.CreateStatsMissDisp = function(theMissDisp) { * @returns {object} section The object contating the Lucky section */ CM.Disp.CreateStatsLuckySection = function() { - // TODO: Remove this and creater better tooltip!! + // This sets which tooltip to display for certain stats var goldCookTooltip = CM.Sim.auraMult('Dragon\'s Fortune') ? 'GoldCookDragonsFortuneTooltipPlaceholder' : 'GoldCookTooltipPlaceholder'; var section = document.createElement('div'); @@ -2465,7 +2481,7 @@ CM.Disp.CreateStatsLuckySection = function() { * @returns {object} section The object contating the Chain section */ CM.Disp.CreateStatsChainSection = function() { - // TODO: Remove this and creater better tooltip!! + // This sets which tooltip to display for certain stats var goldCookTooltip = CM.Sim.auraMult('Dragon\'s Fortune') ? 'GoldCookDragonsFortuneTooltipPlaceholder' : 'GoldCookTooltipPlaceholder'; var section = document.createElement('div'); diff --git a/src/Main.js b/src/Main.js index 5d3e2a4..3db9a69 100644 --- a/src/Main.js +++ b/src/Main.js @@ -45,7 +45,7 @@ CM.ReplaceNative = function() { CM.Backup.scriptLoaded = Game.scriptLoaded; Game.scriptLoaded = function(who, script) { CM.Backup.scriptLoaded(who, script); - CM.Disp.AddTooltipGrimoire() + CM.Disp.ReplaceTooltipGrimoire() CM.ReplaceNativeGrimoire(); } @@ -70,6 +70,16 @@ CM.ReplaceNative = function() { CM.Disp.AddAuraInfo(aura); } + CM.Backup.ToggleSpecialMenu = Game.ToggleSpecialMenu; + /** + * This functions adds the code to display the tooltips for the levelUp button of the dragon + */ + Game.ToggleSpecialMenu = function(on) { + CM.Backup.ToggleSpecialMenu(on); + CM.Disp.AddDragonLevelUpTooltip(); + } + + CM.Backup.UpdateMenu = Game.UpdateMenu; Game.UpdateMenu = function() { if (typeof jscolor.picker === 'undefined' || typeof jscolor.picker.owner === 'undefined') { @@ -112,7 +122,7 @@ CM.ReplaceNativeGrimoireLaunch = function() { eval('CM.Backup.GrimoireLaunchMod = ' + minigame.launch.toString().split('=this').join('= Game.Objects[\'Wizard tower\'].minigame')); Game.Objects['Wizard tower'].minigame.launch = function() { CM.Backup.GrimoireLaunchMod(); - CM.Disp.AddTooltipGrimoire(); + CM.Disp.ReplaceTooltipGrimoire(); CM.HasReplaceNativeGrimoireDraw = false; CM.ReplaceNativeGrimoireDraw(); } @@ -149,11 +159,13 @@ CM.Loop = function() { CM.Cache.CacheStats(); CM.Cache.CacheMissingUpgrades(); CM.Cache.RemakeChain(); + CM.Cache.CacheDragonCost(); CM.Cache.RemakeSeaSpec(); CM.Cache.RemakeSellForChoEgg(); CM.Sim.DoSims = 0; + } // Check for aura change to recalculate buildings prices From ad7d35e1eebf555aa009ca93c3e8cbbf3f57988d Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Mon, 28 Dec 2020 12:51:50 +0100 Subject: [PATCH 102/106] Hotfix for dragon levelup Tooltip --- CookieMonster.js | 9 +++++---- src/Cache.js | 5 +++-- src/Disp.js | 4 ++-- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index 894ae36..6677100 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -348,7 +348,7 @@ CM.Cache.CacheDragonCost = function() { cost += price; CM.Sim.Objects[target].amount--; } - CM.Cache.CostDragonUpgrade = CM.Disp.Beautify(cost); + CM.Cache.CostDragonUpgrade = "Cost to rebuy: " + CM.Disp.Beautify(cost); } } else { @@ -358,6 +358,7 @@ CM.Cache.CacheDragonCost = function() { target = j; if (Game.Objects[target].amount < amount) { CM.Cache.CostDragonUpgrade = "Not enough buildings to sell"; + break } else { for (var i = 0; i < amount; i++) { @@ -368,8 +369,8 @@ CM.Cache.CacheDragonCost = function() { CM.Sim.Objects[target].amount--; } } + CM.Cache.CostDragonUpgrade = "Cost to rebuy: " + CM.Disp.Beautify(cost); } - CM.Cache.CostDragonUpgrade = CM.Disp.Beautify(cost); } } CM.Cache.lastDragonLevel = Game.dragonLevel; @@ -3023,8 +3024,8 @@ CM.Disp.AddDragonLevelUpTooltip = function() { if ((l('specialPopup').className.match(/onScreen/) && l('specialPopup').children[0].style.background.match(/dragon/)) != null) { for (let i = 0; i < l('specialPopup').childNodes.length; i++) { if (l('specialPopup').childNodes[i].className == "optionBox") { - l('specialPopup').children[i].onmouseover = function() {CM.Cache.CacheDragonCost(); Game.tooltip.dynamic = 1; Game.tooltip.draw(this, CM.Cache.CostDragonUpgrade, 'this'); Game.tooltip.wobble();} - l('specialPopup').children[i].onmouseout = function() {Game.tooltip.shouldHide=1;} + l('specialPopup').children[i].onmouseover = function() {CM.Cache.CacheDragonCost(); Game.tooltip.dynamic = 1; Game.tooltip.draw(l('specialPopup'), `
${CM.Cache.CostDragonUpgrade}
`, 'this'); Game.tooltip.wobble();} + l('specialPopup').children[i].onmouseout = function() {Game.tooltip.shouldHide = 1;} } } } diff --git a/src/Cache.js b/src/Cache.js index 49cd373..3b8b437 100644 --- a/src/Cache.js +++ b/src/Cache.js @@ -317,7 +317,7 @@ CM.Cache.CacheDragonCost = function() { cost += price; CM.Sim.Objects[target].amount--; } - CM.Cache.CostDragonUpgrade = CM.Disp.Beautify(cost); + CM.Cache.CostDragonUpgrade = "Cost to rebuy: " + CM.Disp.Beautify(cost); } } else { @@ -327,6 +327,7 @@ CM.Cache.CacheDragonCost = function() { target = j; if (Game.Objects[target].amount < amount) { CM.Cache.CostDragonUpgrade = "Not enough buildings to sell"; + break } else { for (var i = 0; i < amount; i++) { @@ -337,8 +338,8 @@ CM.Cache.CacheDragonCost = function() { CM.Sim.Objects[target].amount--; } } + CM.Cache.CostDragonUpgrade = "Cost to rebuy: " + CM.Disp.Beautify(cost); } - CM.Cache.CostDragonUpgrade = CM.Disp.Beautify(cost); } } CM.Cache.lastDragonLevel = Game.dragonLevel; diff --git a/src/Disp.js b/src/Disp.js index 469c8ed..ecbc026 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -1847,8 +1847,8 @@ CM.Disp.AddDragonLevelUpTooltip = function() { if ((l('specialPopup').className.match(/onScreen/) && l('specialPopup').children[0].style.background.match(/dragon/)) != null) { for (let i = 0; i < l('specialPopup').childNodes.length; i++) { if (l('specialPopup').childNodes[i].className == "optionBox") { - l('specialPopup').children[i].onmouseover = function() {CM.Cache.CacheDragonCost(); Game.tooltip.dynamic = 1; Game.tooltip.draw(this, CM.Cache.CostDragonUpgrade, 'this'); Game.tooltip.wobble();} - l('specialPopup').children[i].onmouseout = function() {Game.tooltip.shouldHide=1;} + l('specialPopup').children[i].onmouseover = function() {CM.Cache.CacheDragonCost(); Game.tooltip.dynamic = 1; Game.tooltip.draw(l('specialPopup'), `
${CM.Cache.CostDragonUpgrade}
`, 'this'); Game.tooltip.wobble();} + l('specialPopup').children[i].onmouseout = function() {Game.tooltip.shouldHide = 1;} } } } From 4a3bb46f8bc861aa2c56227dc808b92b05e5899f Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Mon, 28 Dec 2020 12:57:34 +0100 Subject: [PATCH 103/106] Another hotfix for levelup tooltip --- CookieMonster.js | 2 +- src/Cache.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index 6677100..30dbdc6 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -330,7 +330,7 @@ CM.Cache.UpdateCurrWrinklerCPS = function() { */ CM.Cache.CacheDragonCost = function() { if (CM.Cache.lastDragonLevel != Game.dragonLevel || CM.Sim.DoSims) { - if (Game.dragonLevels[Game.dragonLevel].buy.toString().includes("sacrifice")) { + if (Game.dragonLevel < 25 && Game.dragonLevels[Game.dragonLevel].buy.toString().includes("sacrifice")) { var target = Game.dragonLevels[Game.dragonLevel].buy.toString().match(/Objects\[(.*)\]/)[1]; var amount = Game.dragonLevels[Game.dragonLevel].buy.toString().match(/sacrifice\((.*?)\)/)[1]; if (target != "i") { diff --git a/src/Cache.js b/src/Cache.js index 3b8b437..349c517 100644 --- a/src/Cache.js +++ b/src/Cache.js @@ -299,7 +299,7 @@ CM.Cache.UpdateCurrWrinklerCPS = function() { */ CM.Cache.CacheDragonCost = function() { if (CM.Cache.lastDragonLevel != Game.dragonLevel || CM.Sim.DoSims) { - if (Game.dragonLevels[Game.dragonLevel].buy.toString().includes("sacrifice")) { + if (Game.dragonLevel < 25 && Game.dragonLevels[Game.dragonLevel].buy.toString().includes("sacrifice")) { var target = Game.dragonLevels[Game.dragonLevel].buy.toString().match(/Objects\[(.*)\]/)[1]; var amount = Game.dragonLevels[Game.dragonLevel].buy.toString().match(/sacrifice\((.*?)\)/)[1]; if (target != "i") { From c997ace2cf1761c13518e3bcbfffeaf32828a64d Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Mon, 28 Dec 2020 13:25:26 +0100 Subject: [PATCH 104/106] Option for extra wrinkler popping buttons (#126) --- CookieMonster.js | 48 +++++++++++++++++++++++++++++++++++++++++++----- src/Data.js | 6 ++++-- src/Disp.js | 41 ++++++++++++++++++++++++++++++++++++++--- src/Main.js | 1 + 4 files changed, 86 insertions(+), 10 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index 30dbdc6..171414b 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -1091,6 +1091,7 @@ CM.ConfigData.ScaleCutoff = {type: 'numscale', group: 'Notation', label: 'Notati // Miscellaneous CM.ConfigData.GCTimer = {type: 'bool', group: 'Miscellaneous', label: ['Golden Cookie Timer OFF', 'Golden Cookie Timer ON'], desc: 'A timer on the Golden Cookie when it has been spawned', toggle: true, func: function() {CM.Disp.ToggleGCTimer();}}; CM.ConfigData.Favicon = {type: 'bool', group: 'Miscellaneous', label: ['Favicon OFF', 'Favicon ON'], desc: 'Update favicon with Golden/Wrath Cookie', toggle: true, func: function() {CM.Disp.UpdateFavicon();}}; +CM.ConfigData.WrinklerButtons = {type: 'bool', group: 'Miscellaneous', label: ['Extra Buttons OFF', 'Extra Buttons ON'], desc: 'Show buttons for popping wrinklers at bottom of cookie section', toggle: true, func: function() {CM.Disp.UpdateWrinklerButtons();}}; /** @@ -1116,8 +1117,6 @@ CM.Data.ConfigDefault = { GCSound: 1, GCVolume: 100, GCSoundURL: 'https://freesound.org/data/previews/66/66717_931655-lq.mp3', - GCTimer: 1, - Favicon: 1, FortuneNotification: 0, FortuneFlash: 1, FortuneSound: 1, @@ -1172,6 +1171,9 @@ CM.Data.ConfigDefault = { Colors: {Blue: '#4bb8f0', Green: '#00ff00', Yellow: '#ffff00', Orange: '#ff7f00', Red: '#ff0000', Purple: '#ff00ff', Gray: '#b3b3b3', Pink: '#ff1493', Brown: '#8b4513'}, SortBuildings: 0, SortUpgrades: 0, + GCTimer: 1, + Favicon: 1, + WrinklerButtons: 1, Header: {BarsColors: 1, Calculation: 1, Notification: 1, NotificationGC: 1, NotificationFC: 1, NotificationSea: 1, NotificationGard: 1, NotificationMagi: 1, NotificationWrink: 1, NotificationWrinkMax: 1, Tooltip: 1, Statistics: 1, Notation: 1, Miscellaneous: 1, Lucky: 1, Spells: 1, Chain: 1, Prestige: 1, Wrink: 1, Sea: 1, Misc: 1}, }; @@ -3365,7 +3367,7 @@ CM.Disp.AddMenuStats = function(title) { var popFattestFrag = document.createDocumentFragment(); popFattestFrag.appendChild(document.createTextNode(Beautify(CM.Cache.WrinklersFattest[0]) + ' ')); var popFattestA = document.createElement('a'); - popFattestA.textContent = 'Pop single fattest'; + popFattestA.textContent = 'Pop Single Fattest'; popFattestA.className = 'option'; popFattestA.onclick = function() { Game.wrinklers[CM.Cache.WrinklersFattest[1]].hp = 0; }; popFattestFrag.appendChild(popFattestA); @@ -3912,10 +3914,45 @@ CM.Disp.crateMissing = function(me) { `; } +/******** + * Section: Functions related to the left column of the page */ + +/** + * This function creates two objects at the bottom of the left column that allowing popping of wrinklers + * It is called by CM.DelayInit() + */ +CM.Disp.CreateWrinklerButtons = function() { + var popAllA = document.createElement('a'); + popAllA.id = "PopAllNormalWrinklerButton" + popAllA.textContent = 'Pop All Normal'; + popAllA.className = 'option'; + popAllA.onclick = function() { CM.Disp.PopAllNormalWrinklers(); }; + l('sectionLeftExtra').children[0].append(popAllA); + var popFattestA = document.createElement('a'); + popFattestA.id = "PopFattestWrinklerButton" + popFattestA.textContent = 'Pop Single Fattest'; + popFattestA.className = 'option'; + popFattestA.onclick = function() { Game.wrinklers[CM.Cache.WrinklersFattest[1]].hp = 0; }; + l('sectionLeftExtra').children[0].append(popFattestA); +} + +/** + * This function updates the display setting of the two objects created by CM.Disp.CreateWrinklerButtons() + * It is called by changes in CM.Options.WrinklerButtons + */ +CM.Disp.UpdateWrinklerButtons = function() { + if (CM.Options.WrinklerButtons) { + l('PopAllNormalWrinklerButton').style.display = ""; + l('PopFattestWrinklerButton').style.display = ""; + } + else { + l('PopAllNormalWrinklerButton').style.display = "none"; + l('PopFattestWrinklerButton').style.display = "none"; + } +} /******** - * Section: Variables used in Disp functions - */ + * Section: Variables used in Disp functions */ /** * This list is used to make some very basic tooltips. @@ -4222,6 +4259,7 @@ CM.DelayInit = function() { for (var i in CM.Disp.TooltipText) { CM.Disp.CreateSimpleTooltip(CM.Disp.TooltipText[i][0], CM.Disp.TooltipText[i][1], CM.Disp.TooltipText[i][2]); } + CM.Disp.CreateWrinklerButtons(); CM.Disp.ReplaceTooltipBuild(); CM.Disp.ReplaceTooltipGrimoire(); CM.Disp.ReplaceTooltipLump(); diff --git a/src/Data.js b/src/Data.js index cd71820..6b2b142 100644 --- a/src/Data.js +++ b/src/Data.js @@ -209,6 +209,7 @@ CM.ConfigData.ScaleCutoff = {type: 'numscale', group: 'Notation', label: 'Notati // Miscellaneous CM.ConfigData.GCTimer = {type: 'bool', group: 'Miscellaneous', label: ['Golden Cookie Timer OFF', 'Golden Cookie Timer ON'], desc: 'A timer on the Golden Cookie when it has been spawned', toggle: true, func: function() {CM.Disp.ToggleGCTimer();}}; CM.ConfigData.Favicon = {type: 'bool', group: 'Miscellaneous', label: ['Favicon OFF', 'Favicon ON'], desc: 'Update favicon with Golden/Wrath Cookie', toggle: true, func: function() {CM.Disp.UpdateFavicon();}}; +CM.ConfigData.WrinklerButtons = {type: 'bool', group: 'Miscellaneous', label: ['Extra Buttons OFF', 'Extra Buttons ON'], desc: 'Show buttons for popping wrinklers at bottom of cookie section', toggle: true, func: function() {CM.Disp.UpdateWrinklerButtons();}}; /** @@ -234,8 +235,6 @@ CM.Data.ConfigDefault = { GCSound: 1, GCVolume: 100, GCSoundURL: 'https://freesound.org/data/previews/66/66717_931655-lq.mp3', - GCTimer: 1, - Favicon: 1, FortuneNotification: 0, FortuneFlash: 1, FortuneSound: 1, @@ -290,6 +289,9 @@ CM.Data.ConfigDefault = { Colors: {Blue: '#4bb8f0', Green: '#00ff00', Yellow: '#ffff00', Orange: '#ff7f00', Red: '#ff0000', Purple: '#ff00ff', Gray: '#b3b3b3', Pink: '#ff1493', Brown: '#8b4513'}, SortBuildings: 0, SortUpgrades: 0, + GCTimer: 1, + Favicon: 1, + WrinklerButtons: 1, Header: {BarsColors: 1, Calculation: 1, Notification: 1, NotificationGC: 1, NotificationFC: 1, NotificationSea: 1, NotificationGard: 1, NotificationMagi: 1, NotificationWrink: 1, NotificationWrinkMax: 1, Tooltip: 1, Statistics: 1, Notation: 1, Miscellaneous: 1, Lucky: 1, Spells: 1, Chain: 1, Prestige: 1, Wrink: 1, Sea: 1, Misc: 1}, }; diff --git a/src/Disp.js b/src/Disp.js index ecbc026..86e47be 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -2188,7 +2188,7 @@ CM.Disp.AddMenuStats = function(title) { var popFattestFrag = document.createDocumentFragment(); popFattestFrag.appendChild(document.createTextNode(Beautify(CM.Cache.WrinklersFattest[0]) + ' ')); var popFattestA = document.createElement('a'); - popFattestA.textContent = 'Pop single fattest'; + popFattestA.textContent = 'Pop Single Fattest'; popFattestA.className = 'option'; popFattestA.onclick = function() { Game.wrinklers[CM.Cache.WrinklersFattest[1]].hp = 0; }; popFattestFrag.appendChild(popFattestA); @@ -2735,10 +2735,45 @@ CM.Disp.crateMissing = function(me) { `; } +/******** + * Section: Functions related to the left column of the page */ + +/** + * This function creates two objects at the bottom of the left column that allowing popping of wrinklers + * It is called by CM.DelayInit() + */ +CM.Disp.CreateWrinklerButtons = function() { + var popAllA = document.createElement('a'); + popAllA.id = "PopAllNormalWrinklerButton" + popAllA.textContent = 'Pop All Normal'; + popAllA.className = 'option'; + popAllA.onclick = function() { CM.Disp.PopAllNormalWrinklers(); }; + l('sectionLeftExtra').children[0].append(popAllA); + var popFattestA = document.createElement('a'); + popFattestA.id = "PopFattestWrinklerButton" + popFattestA.textContent = 'Pop Single Fattest'; + popFattestA.className = 'option'; + popFattestA.onclick = function() { Game.wrinklers[CM.Cache.WrinklersFattest[1]].hp = 0; }; + l('sectionLeftExtra').children[0].append(popFattestA); +} + +/** + * This function updates the display setting of the two objects created by CM.Disp.CreateWrinklerButtons() + * It is called by changes in CM.Options.WrinklerButtons + */ +CM.Disp.UpdateWrinklerButtons = function() { + if (CM.Options.WrinklerButtons) { + l('PopAllNormalWrinklerButton').style.display = ""; + l('PopFattestWrinklerButton').style.display = ""; + } + else { + l('PopAllNormalWrinklerButton').style.display = "none"; + l('PopFattestWrinklerButton').style.display = "none"; + } +} /******** - * Section: Variables used in Disp functions - */ + * Section: Variables used in Disp functions */ /** * This list is used to make some very basic tooltips. diff --git a/src/Main.js b/src/Main.js index 3db9a69..feb50df 100644 --- a/src/Main.js +++ b/src/Main.js @@ -236,6 +236,7 @@ CM.DelayInit = function() { for (var i in CM.Disp.TooltipText) { CM.Disp.CreateSimpleTooltip(CM.Disp.TooltipText[i][0], CM.Disp.TooltipText[i][1], CM.Disp.TooltipText[i][2]); } + CM.Disp.CreateWrinklerButtons(); CM.Disp.ReplaceTooltipBuild(); CM.Disp.ReplaceTooltipGrimoire(); CM.Disp.ReplaceTooltipLump(); From 5f5a1abac007c7cae08492d654be90d6897996db Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Mon, 28 Dec 2020 14:00:21 +0100 Subject: [PATCH 105/106] Removed a TODO --- CookieMonster.js | 5 ----- src/Disp.js | 5 ----- 2 files changed, 10 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index 171414b..e9aa840 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -2566,11 +2566,6 @@ CM.Disp.TooltipCreateWarningSection = function() { var box = document.createElement('div'); box.id = boxId; box.style.display = 'none'; - // TODO: This is very old code and can probably be removed - //box.style.WebkitTransition = 'opacity 0.1s ease-out'; - //box.style.MozTransition = 'opacity 0.1s ease-out'; - //box.style.MsTransition = 'opacity 0.1s ease-out'; - //box.style.OTransition = 'opacity 0.1s ease-out'; box.style.transition = 'opacity 0.1s ease-out'; box.className = CM.Disp.colorBorderPre + color; box.style.padding = '2px'; diff --git a/src/Disp.js b/src/Disp.js index 86e47be..e15985f 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -1387,11 +1387,6 @@ CM.Disp.TooltipCreateWarningSection = function() { var box = document.createElement('div'); box.id = boxId; box.style.display = 'none'; - // TODO: This is very old code and can probably be removed - //box.style.WebkitTransition = 'opacity 0.1s ease-out'; - //box.style.MozTransition = 'opacity 0.1s ease-out'; - //box.style.MsTransition = 'opacity 0.1s ease-out'; - //box.style.OTransition = 'opacity 0.1s ease-out'; box.style.transition = 'opacity 0.1s ease-out'; box.className = CM.Disp.colorBorderPre + color; box.style.padding = '2px'; From cb284ed22d868d9508b89e443eacfacb796d960e Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Mon, 28 Dec 2020 14:00:35 +0100 Subject: [PATCH 106/106] Bumped version to 2.031.3 --- CookieMonster.js | 2 +- src/Main.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index e9aa840..328e739 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -4495,7 +4495,7 @@ CM.Main.lastWrinklerCount = 0; CM.ConfigPrefix = 'CMConfig'; CM.VersionMajor = '2.031'; -CM.VersionMinor = '2'; +CM.VersionMinor = '3'; /******* * Sim * diff --git a/src/Main.js b/src/Main.js index feb50df..caa11b2 100644 --- a/src/Main.js +++ b/src/Main.js @@ -477,5 +477,5 @@ CM.Main.lastWrinklerCount = 0; CM.ConfigPrefix = 'CMConfig'; CM.VersionMajor = '2.031'; -CM.VersionMinor = '2'; +CM.VersionMinor = '3';