Complete overhaul of code structure and relevant files (#639)

This commit is contained in:
Daniël van Noord
2021-03-14 00:41:14 +01:00
committed by GitHub
parent bb34bce9a5
commit 1bffb58782
163 changed files with 7369 additions and 10882 deletions

View File

@@ -0,0 +1,25 @@
import { CacheSpawnedGoldenShimmer } from '../../Cache/VariablesAndData';
import { CMOptions } from '../../Config/VariablesAndData';
import { LastGoldenCookieState } from '../../Main/VariablesAndData';
/**
* This function creates the Favicon, it is called by CM.Main.DelayInit()
*/
export function CreateFavicon() {
const Favicon = document.createElement('link');
Favicon.id = 'CMFavicon';
Favicon.rel = 'shortcut icon';
Favicon.href = 'https://orteil.dashnet.org/cookieclicker/favicon.ico';
document.getElementsByTagName('head')[0].appendChild(Favicon);
}
/**
* This function updates the Favicon depending on whether a Golden Cookie has spawned
* By relying on CM.Cache.spawnedGoldenShimmer it only changes for non-user spawned cookie
*/
export function UpdateFavicon() {
if (CMOptions.Favicon === 1 && LastGoldenCookieState > 0) {
if (CacheSpawnedGoldenShimmer.wrath) l('CMFavicon').href = 'https://aktanusa.github.io/CookieMonster/favicon/wrathCookie.ico';
else l('CMFavicon').href = 'https://aktanusa.github.io/CookieMonster/favicon/goldenCookie.ico';
} else l('CMFavicon').href = 'https://orteil.dashnet.org/cookieclicker/favicon.ico';
}

View File

@@ -0,0 +1,70 @@
/** Functions related to updating the tab in the browser's tab-bar */
import { CacheSeasonPopShimmer, CacheSpawnedGoldenShimmer } from '../../Cache/VariablesAndData';
import { CMOptions } from '../../Config/VariablesAndData';
import { LastSeasonPopupState, LastTickerFortuneState } from '../../Main/VariablesAndData';
import { Title } from '../VariablesAndData';
/**
* This function updates the tab title
* It is called on every loop by Game.Logic() which also sets CM.Disp.Title to Game.cookies
*/
export default function UpdateTitle() {
if (Game.OnAscend || CMOptions.Title === 0) {
document.title = Title;
} else if (CMOptions.Title === 1) {
let addFC = false;
let addSP = false;
let titleGC;
let titleFC;
let titleSP;
if (CacheSpawnedGoldenShimmer) {
if (CacheSpawnedGoldenShimmer.wrath) titleGC = `[W${Math.ceil(CacheSpawnedGoldenShimmer.life / Game.fps)}]`;
else titleGC = `[G${Math.ceil(CacheSpawnedGoldenShimmer.life / Game.fps)}]`;
} else if (!Game.Has('Golden switch [off]')) {
titleGC = `[${Number(l('CMTimerBarGCMinBar').textContent) < 0 ? '!' : ''}${Math.ceil((Game.shimmerTypes.golden.maxTime - Game.shimmerTypes.golden.time) / Game.fps)}]`;
} else titleGC = '[GS]';
if (LastTickerFortuneState) {
addFC = true;
titleFC = '[F]';
}
if (Game.season === 'christmas') {
addSP = true;
if (LastSeasonPopupState) titleSP = `[R${Math.ceil(CacheSeasonPopShimmer.life / Game.fps)}]`;
else {
titleSP = `[${Number(l('CMTimerBarRenMinBar').textContent) < 0 ? '!' : ''}${Math.ceil((Game.shimmerTypes.reindeer.maxTime - Game.shimmerTypes.reindeer.time) / Game.fps)}]`;
}
}
// Remove previous timers and add current cookies
let str = Title;
if (str.charAt(0) === '[') {
str = str.substring(str.lastIndexOf(']') + 1);
}
document.title = `${titleGC + (addFC ? titleFC : '') + (addSP ? titleSP : '')} ${str}`;
} else if (CMOptions.Title === 2) {
let str = '';
let spawn = false;
if (CacheSpawnedGoldenShimmer) {
spawn = true;
if (CacheSpawnedGoldenShimmer.wrath) str += `[W${Math.ceil(CacheSpawnedGoldenShimmer.life / Game.fps)}]`;
else str += `[G${Math.ceil(CacheSpawnedGoldenShimmer.life / Game.fps)}]`;
}
if (LastTickerFortuneState) {
spawn = true;
str += '[F]';
}
if (Game.season === 'christmas' && LastSeasonPopupState) {
str += `[R${Math.ceil(CacheSeasonPopShimmer.life / Game.fps)}]`;
spawn = true;
}
if (spawn) str += ' - ';
let title = 'Cookie Clicker';
if (Game.season === 'fools') title = 'Cookie Baker';
str += title;
document.title = str;
}
}