Changes according to Eslint

This commit is contained in:
Daniël van Noord
2021-03-16 09:32:50 +01:00
parent 26d8e75935
commit a65af049b6
63 changed files with 314 additions and 295 deletions

View File

@@ -1,3 +1,4 @@
/* eslint-disable no-nested-ternary */
/** General functions to format or beautify strings */
import { CMOptions } from '../../Config/VariablesAndData';
@@ -93,23 +94,25 @@ export function Beautify(num, floats, forced) {
* @returns {string} Formatted time
*/
export function FormatTime(time, longFormat) {
let formattedTime = time;
if (time === Infinity) return time;
time = Math.ceil(time);
const y = Math.floor(time / 31557600);
const d = Math.floor((time % 31557600) / 86400);
const h = Math.floor((time % 86400) / 3600);
const m = Math.floor((time % 3600) / 60);
const s = Math.floor(time % 60);
formattedTime = Math.ceil(time);
const y = Math.floor(formattedTime / 31557600);
const d = Math.floor((formattedTime % 31557600) / 86400);
const h = Math.floor((formattedTime % 86400) / 3600);
const m = Math.floor((formattedTime % 3600) / 60);
const s = Math.floor(formattedTime % 60);
let str = '';
if (CMOptions.TimeFormat) {
if (time > 3155760000) return 'XX:XX:XX:XX:XX';
if (formattedTime > 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';
if (formattedTime > 777600000)
return longFormat ? 'Over 9000 days!' : '>9000d';
str +=
y > 0
? `${y + (longFormat ? (y === 1 ? ' year' : ' years') : 'y')}, `

View File

@@ -1,3 +1,4 @@
/* eslint-disable no-nested-ternary */
import {
CacheObjects1,
CacheObjects10,
@@ -30,17 +31,17 @@ export default function UpdateBuildings() {
if (Game.buyMode === 1) {
if (CMOptions.BuildColor === 1) {
for (const i of Object.keys(target)) {
Object.keys(target).forEach((i) => {
l(`productPrice${Game.Objects[i].id}`).style.color =
CMOptions.Colors[target[i].color];
}
});
} else {
for (const i of Object.keys(Game.Objects)) {
Object.keys(Game.Objects).forEach((i) => {
l(`productPrice${Game.Objects[i].id}`).style.removeProperty('color');
}
});
}
} else if (Game.buyMode === -1) {
for (const i of Object.keys(CacheObjects1)) {
Object.keys(CacheObjects1).forEach((i) => {
const o = Game.Objects[i];
l(`productPrice${o.id}`).style.color = '';
/*
@@ -54,7 +55,7 @@ export default function UpdateBuildings() {
l(`productPrice${o.id}`).innerHTML = Beautify(
BuildingSell(o, o.basePrice, o.amount, o.free, Game.buyBulk, 1),
);
}
});
}
// Build array of pointers, sort by pp, use array index (+2) as the grid row number

View File

@@ -1,3 +1,4 @@
/* eslint-disable no-nested-ternary */
import { CacheUpgrades } from '../../Cache/VariablesAndData';
import { CMOptions } from '../../Config/VariablesAndData';
import {
@@ -29,10 +30,10 @@ export default function UpdateUpgrades() {
let purple = 0;
let gray = 0;
for (const i of Object.keys(Game.UpgradesInStore)) {
Object.keys(Game.UpgradesInStore).forEach((i) => {
const me = Game.UpgradesInStore[i];
let addedColor = false;
for (let j = 0; j < l(`upgrade${i}`).childNodes.length; j++) {
for (let j = 0; j < l(`upgrade${i}`).childNodes.length; j += 1) {
if (
l(`upgrade${i}`).childNodes[j].className.indexOf(ColorBackPre) !== -1
) {
@@ -49,14 +50,14 @@ export default function UpdateUpgrades() {
div.className = ColorBackPre + CacheUpgrades[me.name].color;
l(`upgrade${i}`).appendChild(div);
}
if (CacheUpgrades[me.name].color === ColorBlue) blue++;
else if (CacheUpgrades[me.name].color === ColorGreen) green++;
else if (CacheUpgrades[me.name].color === ColorYellow) yellow++;
else if (CacheUpgrades[me.name].color === ColorOrange) orange++;
else if (CacheUpgrades[me.name].color === ColorRed) red++;
else if (CacheUpgrades[me.name].color === ColorPurple) purple++;
else if (CacheUpgrades[me.name].color === ColorGray) gray++;
}
if (CacheUpgrades[me.name].color === ColorBlue) blue += 1;
else if (CacheUpgrades[me.name].color === ColorGreen) green += 1;
else if (CacheUpgrades[me.name].color === ColorYellow) yellow += 1;
else if (CacheUpgrades[me.name].color === ColorOrange) orange += 1;
else if (CacheUpgrades[me.name].color === ColorRed) red += 1;
else if (CacheUpgrades[me.name].color === ColorPurple) purple += 1;
else if (CacheUpgrades[me.name].color === ColorGray) gray += 1;
});
l('CMUpgradeBarBlue').textContent = blue;
l('CMUpgradeBarGreen').textContent = green;
@@ -70,7 +71,7 @@ export default function UpdateUpgrades() {
const arr = [];
// Build array of pointers, sort by pp, set flex positions
// This regulates sorting of upgrades
for (let x = 0; x < Game.UpgradesInStore.length; x++) {
for (let x = 0; x < Game.UpgradesInStore.length; x += 1) {
const o = {};
o.name = Game.UpgradesInStore[x].name;
o.price = Game.UpgradesInStore[x].basePrice;
@@ -95,7 +96,7 @@ export default function UpdateUpgrades() {
const nameChecker = function (arr2, upgrade) {
return arr2.findIndex((e) => e.name === upgrade.name);
};
for (let x = 0; x < Game.UpgradesInStore.length; x++) {
for (let x = 0; x < Game.UpgradesInStore.length; x += 1) {
l(`upgrade${x}`).style.order =
nameChecker(arr, Game.UpgradesInStore[x]) + 1;
}

View File

@@ -1,3 +1,4 @@
/* eslint-disable no-param-reassign */
/** Section: Functions related to the Golden Cookie Timers */
import { CMOptions } from '../../Config/VariablesAndData';

View File

@@ -10,11 +10,11 @@ export default function CalculateGrimoireRefillTime(
maxMagic,
targetMagic,
) {
let magic = currentMagic;
let count = 0;
while (currentMagic < targetMagic) {
currentMagic +=
Math.max(0.002, (currentMagic / Math.max(maxMagic, 100)) ** 0.5) * 0.002;
count++;
while (magic < targetMagic) {
magic += Math.max(0.002, (magic / Math.max(maxMagic, 100)) ** 0.5) * 0.002;
count += 1;
}
return count / Game.fps;
}

View File

@@ -3,9 +3,9 @@
* It is called by a click of the 'pop all' button created by CM.Disp.AddMenuStats()
*/
export default function PopAllNormalWrinklers() {
for (const i of Object.keys(Game.wrinklers)) {
Object.keys(Game.wrinklers).forEach((i) => {
if (Game.wrinklers[i].sucked > 0 && Game.wrinklers[i].type === 0) {
Game.wrinklers[i].hp = 0;
}
}
});
}

View File

@@ -63,9 +63,9 @@ export function CreateBotBar() {
l('wrapper').appendChild(BotBar);
for (const i of Object.keys(Game.Objects)) {
Object.keys(Game.Objects).forEach((i) => {
CreateBotBarBuildingColumn(i);
}
});
}
/**
@@ -74,7 +74,7 @@ export function CreateBotBar() {
export function UpdateBotBar() {
if (CMOptions.BotBar === 1 && CacheObjects1 && Game.buyMode === 1) {
let count = 0;
for (const i of Object.keys(CacheObjects1)) {
Object.keys(CacheObjects1).forEach((i) => {
let target = Game.buyBulk;
if (Game.buyMode === 1) {
LastTargetBotBar = target;
@@ -84,7 +84,7 @@ export function UpdateBotBar() {
if (target === 1) target = CacheObjects1;
if (target === 10) target = CacheObjects10;
if (target === 100) target = CacheObjects100;
count++;
count += 1;
l('CMBotBar').firstChild.firstChild.childNodes[0].childNodes[
count
].childNodes[1].textContent = Game.Objects[i].amount;
@@ -115,6 +115,6 @@ export function UpdateBotBar() {
l('CMBotBar').firstChild.firstChild.childNodes[3].childNodes[
count
].textContent = timeColor.text;
}
});
}
}

View File

@@ -105,7 +105,7 @@ export function UpdateTimerBar() {
(Game.shimmerTypes.golden.maxTime - Game.shimmerTypes.golden.time) /
Game.fps,
);
numberOfTimers++;
numberOfTimers += 1;
} else l('CMTimerBarGC').style.display = 'none';
// Regulates visibility of Reindeer timer
@@ -152,7 +152,7 @@ export function UpdateTimerBar() {
(Game.shimmerTypes.reindeer.maxTime - Game.shimmerTypes.reindeer.time) /
Game.fps,
);
numberOfTimers++;
numberOfTimers += 1;
} else {
l('CMTimerBarRen').style.display = 'none';
}
@@ -160,7 +160,7 @@ export function UpdateTimerBar() {
// On every frame all buff-timers are deleted and re-created
const BuffTimerBars = {};
l('CMTimerBarBuffTimers').innerHTML = '';
for (const i of Object.keys(Game.buffs)) {
Object.keys(Game.buffs).forEach((i) => {
if (Game.buffs[i]) {
const timer = CreateTimer(Game.buffs[i].name, Game.buffs[i].name, [
{ id: `${Game.buffs[i].name}Bar` },
@@ -187,13 +187,13 @@ export function UpdateTimerBar() {
timer.lastChild.children[2].textContent = Math.ceil(
Game.buffs[i].time / Game.fps,
);
numberOfTimers++;
numberOfTimers += 1;
BuffTimerBars[Game.buffs[i].name] = timer;
}
}
for (const i of Object.keys(BuffTimerBars)) {
});
Object.keys(BuffTimerBars).forEach((i) => {
l('CMTimerBarBuffTimers').appendChild(BuffTimerBars[i]);
}
});
if (numberOfTimers !== 0) {
l('CMTimerBar').style.height = `${numberOfTimers * 12 + 2}px`;

View File

@@ -112,47 +112,47 @@ export default function AddMenuStats(title) {
let specDisp = false;
const missingHalloweenCookies = [];
for (const i of Object.keys(GameData.HalloCookies)) {
Object.keys(GameData.HalloCookies).forEach((i) => {
if (!Game.Has(GameData.HalloCookies[i])) {
missingHalloweenCookies.push(GameData.HalloCookies[i]);
specDisp = true;
}
}
});
const missingChristmasCookies = [];
for (const i of Object.keys(GameData.ChristCookies)) {
Object.keys(GameData.ChristCookies).forEach((i) => {
if (!Game.Has(GameData.ChristCookies[i])) {
missingChristmasCookies.push(GameData.ChristCookies[i]);
specDisp = true;
}
}
});
const missingValentineCookies = [];
for (const i of Object.keys(GameData.ValCookies)) {
Object.keys(GameData.ValCookies).forEach((i) => {
if (!Game.Has(GameData.ValCookies[i])) {
missingValentineCookies.push(GameData.ValCookies[i]);
specDisp = true;
}
}
});
const missingNormalEggs = [];
for (const i of Object.keys(Game.eggDrops)) {
Object.keys(Game.eggDrops).forEach((i) => {
if (!Game.HasUnlocked(Game.eggDrops[i])) {
missingNormalEggs.push(Game.eggDrops[i]);
specDisp = true;
}
}
});
const missingRareEggs = [];
for (const i of Object.keys(Game.rareEggDrops)) {
Object.keys(Game.rareEggDrops).forEach((i) => {
if (!Game.HasUnlocked(Game.rareEggDrops[i])) {
missingRareEggs.push(Game.rareEggDrops[i]);
specDisp = true;
}
}
});
const missingPlantDrops = [];
for (const i of Object.keys(GameData.PlantDrops)) {
Object.keys(GameData.PlantDrops).forEach((i) => {
if (!Game.HasUnlocked(GameData.PlantDrops[i])) {
missingPlantDrops.push(GameData.PlantDrops[i]);
specDisp = true;
}
}
});
const choEgg =
Game.HasUnlocked('Chocolate egg') && !Game.Has('Chocolate egg');
const centEgg = Game.Has('Century egg');
@@ -266,11 +266,11 @@ export default function AddMenuStats(title) {
);
if (Game.Has('Fortune cookies')) {
const fortunes = [];
for (const i of Object.keys(GameData.Fortunes)) {
Object.keys(GameData.Fortunes).forEach((i) => {
if (!Game.Has(GameData.Fortunes[i])) {
fortunes.push(GameData.Fortunes[i]);
}
}
});
if (fortunes.length !== 0)
stats.appendChild(
CreateElements.StatsListing(

View File

@@ -106,12 +106,12 @@ export function StatsMissDisp(theMissDisp) {
title.style.textAlign = 'center';
title.textContent = 'Missing';
missing.appendChild(title);
for (const i of Object.keys(theMissDisp)) {
Object.keys(theMissDisp).forEach((i) => {
const 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));

View File

@@ -10,7 +10,7 @@ import {
* This function creates the missing upgrades sections for prestige, normal and cookie upgrades
*/
export function AddMissingUpgrades() {
for (const menuSection of l('menu').children) {
l('menu').childNodes.forEach((menuSection) => {
if (menuSection.children[0]) {
if (
menuSection.children[0].innerHTML === 'Prestige' &&
@@ -82,7 +82,7 @@ export function AddMissingUpgrades() {
}
}
}
}
});
}
/**
@@ -99,7 +99,7 @@ export function crateMissing(me) {
if (!Game.prefs.crates) noFrame = 1;
if (noFrame) classes += ' noFrame';
let icon = me.icon;
let { icon } = me;
if (me.iconFunction) icon = me.iconFunction();
const tooltip = `function() {return Game.crateTooltip(Game.UpgradesById[${me.id}], 'stats');}`;
return `<div class="${classes}"

View File

@@ -170,7 +170,7 @@ function CreatePrefOption(config) {
SaveConfig();
Game.UpdateMenu();
};
new JsColor(input, { hash: true, position: 'right', onInput: change });
JsColor(input, { hash: true, position: 'right', onInput: change });
const label = document.createElement('label');
label.textContent = Config.Colors.desc[Colors[i]];
innerDiv.appendChild(label);
@@ -216,14 +216,14 @@ export default function AddMenuPref(title) {
const frag = document.createDocumentFragment();
frag.appendChild(title);
for (const group of Object.keys(ConfigGroups)) {
Object.keys(ConfigGroups).forEach((group) => {
const groupObject = CreatePrefHeader(group, ConfigGroups[group]); // (group, display-name of group)
frag.appendChild(groupObject);
if (CMOptions.Header[group]) {
// 0 is show, 1 is collapsed
// Make sub-sections of Notification section
if (group === 'Notification') {
for (const subGroup of Object.keys(ConfigGroupsNotification)) {
Object.keys(ConfigGroupsNotification).forEach((subGroup) => {
const subGroupObject = CreatePrefHeader(
subGroup,
ConfigGroupsNotification[subGroup],
@@ -232,20 +232,20 @@ export default function AddMenuPref(title) {
subGroupObject.style.opacity = '0.5';
frag.appendChild(subGroupObject);
if (CMOptions.Header[subGroup]) {
for (const option in Config) {
Object.keys(Config).forEach((option) => {
if (Config[option].group === subGroup)
frag.appendChild(CreatePrefOption(option));
}
});
}
}
});
} else {
for (const option of Object.keys(Config)) {
Object.keys(Config).forEach((option) => {
if (Config[option].group === group)
frag.appendChild(CreatePrefOption(option));
}
});
}
}
}
});
const resDef = document.createElement('div');
resDef.className = 'listing';

View File

@@ -10,7 +10,7 @@ import { isInitializing } from '../../InitSaveLoad/Variables';
* @param {string} title The title of the to-be created notifications
* @param {string} message The text of the to-be created notifications
*/
export default function Notification(notifyConfig, title, message) {
export default function CreateNotification(notifyConfig, title, message) {
// The arguments check makes the sound not play upon initialization of the mod
if (
CMOptions[notifyConfig] === 1 &&
@@ -18,6 +18,7 @@ export default function Notification(notifyConfig, title, message) {
isInitializing === false
) {
const CookieIcon = 'https://orteil.dashnet.org/cookieclicker/favicon.ico';
// eslint-disable-next-line no-new
new Notification(title, { body: message, badge: CookieIcon });
}
}

View File

@@ -1,3 +1,4 @@
/* eslint-disable no-param-reassign */
import { CMOptions } from '../../Config/VariablesAndData';
import {
ColorTextPre,

View File

@@ -1,3 +1,4 @@
/* eslint-disable no-restricted-syntax */
import {
CacheObjects1,
CacheObjects10,

View File

@@ -8,7 +8,7 @@ import * as Create from '../CreateTooltip';
* It adds to the additional information to l('CMTooltipArea')
*/
export default function GardenPlots() {
const minigame = Game.Objects.Farm.minigame;
const { minigame } = Game.Objects.Farm;
if (
CMOptions.TooltipPlots &&
minigame.plot[TooltipName[1]][TooltipName[0]][0] !== 0

View File

@@ -14,7 +14,7 @@ import * as Create from '../CreateTooltip';
* It adds to the additional information to l('CMTooltipArea')
*/
export default function Grimoire() {
const minigame = Game.Objects['Wizard tower'].minigame;
const { minigame } = Game.Objects['Wizard tower'];
const spellCost = minigame.getSpellCost(minigame.spellsById[TooltipName]);
if (CMOptions.TooltipGrim === 1 && spellCost <= minigame.magicM) {

View File

@@ -8,7 +8,7 @@ import * as Create from '../CreateTooltip';
* It adds to the additional information to l('CMTooltipArea')
*/
export default function HarvestAll() {
const minigame = Game.Objects.Farm.minigame;
const { minigame } = Game.Objects.Farm;
if (CMOptions.TooltipLump) {
l('CMTooltipBorder').appendChild(
Create.TooltipCreateHeader('Cookies gained from harvesting:'),

View File

@@ -16,7 +16,7 @@ export function CheckWrinklerTooltip() {
if (CMOptions.TooltipWrink === 1 && TooltipWrinklerArea === 1) {
// Latter is set by CM.Main.AddWrinklerAreaDetect
let showingTooltip = false;
for (const i of Object.keys(Game.wrinklers)) {
Object.keys(Game.wrinklers).forEach((i) => {
const me = Game.wrinklers[i];
if (me.phase > 0 && me.selected) {
showingTooltip = true;
@@ -36,11 +36,11 @@ export function CheckWrinklerTooltip() {
Game.tooltip.draw(this, escape(placeholder.innerHTML));
TooltipWrinkler = i;
TooltipWrinklerBeingShown[i] = 1;
} else break;
}
} else {
TooltipWrinklerBeingShown[i] = 0;
}
}
});
if (!showingTooltip) {
Game.tooltip.hide();
}
@@ -54,7 +54,7 @@ export function CheckWrinklerTooltip() {
*/
export function UpdateWrinklerTooltip() {
if (CMOptions.TooltipWrink === 1 && l('CMTooltipWrinkler') !== null) {
let sucked = Game.wrinklers[TooltipWrinkler].sucked;
let { sucked } = Game.wrinklers[TooltipWrinkler];
let toSuck = 1.1;
if (Game.Has('Sacrilegious corruption')) toSuck *= 1.05;
if (Game.wrinklers[TooltipWrinkler].type === 1) toSuck *= 3; // Shiny wrinklers