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();