From 06c7f59cd6d2c8d1e5d327ba0469f7e1a4f7bf2b Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Thu, 3 Dec 2020 13:05:22 +0100 Subject: [PATCH] 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;