Added prettier to master (#662)
* Bump dev to 2.031.6 * Added prettier (#661) * Added prettier * Added prettier * Added prettier
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
/* eslint-disable no-unused-vars */
|
||||
import * as UpdateTooltip from './UpdateTooltips';
|
||||
import { TooltipCreateTooltipBox } from './CreateTooltip';
|
||||
import { Beautify, GetTimeColor } from '../BeautifyAndFormatting/BeautifyFormatting';
|
||||
import {
|
||||
Beautify,
|
||||
GetTimeColor,
|
||||
} from '../BeautifyAndFormatting/BeautifyFormatting';
|
||||
import CopyData from '../../Sim/SimulationData/CopyData';
|
||||
import { TooltipName, TooltipType } from '../VariablesAndData';
|
||||
import { CMOptions } from '../../Config/VariablesAndData';
|
||||
@@ -17,47 +20,48 @@ import BuildingGetPrice from '../../Sim/SimulationEvents/BuyBuilding';
|
||||
* @param {string} minWidth The minimum width of the tooltip
|
||||
*/
|
||||
export function CreateSimpleTooltip(placeholder, text, minWidth) {
|
||||
const Tooltip = document.createElement('div');
|
||||
Tooltip.id = placeholder;
|
||||
const desc = document.createElement('div');
|
||||
desc.style.minWidth = minWidth;
|
||||
desc.style.marginBottom = '4px';
|
||||
const div = document.createElement('div');
|
||||
div.style.textAlign = 'left';
|
||||
div.textContent = text;
|
||||
desc.appendChild(div);
|
||||
Tooltip.appendChild(desc);
|
||||
const Tooltip = document.createElement('div');
|
||||
Tooltip.id = placeholder;
|
||||
const desc = document.createElement('div');
|
||||
desc.style.minWidth = minWidth;
|
||||
desc.style.marginBottom = '4px';
|
||||
const div = document.createElement('div');
|
||||
div.style.textAlign = 'left';
|
||||
div.textContent = text;
|
||||
desc.appendChild(div);
|
||||
Tooltip.appendChild(desc);
|
||||
}
|
||||
|
||||
/**
|
||||
* This function updates the sections of the tooltips created by CookieMonster
|
||||
*/
|
||||
export function UpdateTooltips() {
|
||||
CopyData();
|
||||
if (l('tooltipAnchor').style.display !== 'none' && l('CMTooltipArea')) {
|
||||
l('CMTooltipArea').innerHTML = '';
|
||||
const tooltipBox = TooltipCreateTooltipBox();
|
||||
l('CMTooltipArea').appendChild(tooltipBox);
|
||||
CopyData();
|
||||
if (l('tooltipAnchor').style.display !== 'none' && l('CMTooltipArea')) {
|
||||
l('CMTooltipArea').innerHTML = '';
|
||||
const tooltipBox = TooltipCreateTooltipBox();
|
||||
l('CMTooltipArea').appendChild(tooltipBox);
|
||||
|
||||
if (TooltipType === 'b') {
|
||||
UpdateTooltip.Building();
|
||||
} else if (TooltipType === 'u') {
|
||||
UpdateTooltip.Upgrade();
|
||||
} else if (TooltipType === 's') {
|
||||
UpdateTooltip.SugarLump();
|
||||
} else if (TooltipType === 'g') {
|
||||
UpdateTooltip.Grimoire();
|
||||
} else if (TooltipType === 'p') {
|
||||
UpdateTooltip.GardenPlots();
|
||||
} else if (TooltipType === 'ha') {
|
||||
UpdateTooltip.HarvestAll();
|
||||
}
|
||||
UpdateTooltip.Warnings();
|
||||
} else if (l('CMTooltipArea') === null) { // Remove warnings if its a basic tooltip
|
||||
if (l('CMDispTooltipWarningParent') !== null) {
|
||||
l('CMDispTooltipWarningParent').remove();
|
||||
}
|
||||
}
|
||||
if (TooltipType === 'b') {
|
||||
UpdateTooltip.Building();
|
||||
} else if (TooltipType === 'u') {
|
||||
UpdateTooltip.Upgrade();
|
||||
} else if (TooltipType === 's') {
|
||||
UpdateTooltip.SugarLump();
|
||||
} else if (TooltipType === 'g') {
|
||||
UpdateTooltip.Grimoire();
|
||||
} else if (TooltipType === 'p') {
|
||||
UpdateTooltip.GardenPlots();
|
||||
} else if (TooltipType === 'ha') {
|
||||
UpdateTooltip.HarvestAll();
|
||||
}
|
||||
UpdateTooltip.Warnings();
|
||||
} else if (l('CMTooltipArea') === null) {
|
||||
// Remove warnings if its a basic tooltip
|
||||
if (l('CMDispTooltipWarningParent') !== null) {
|
||||
l('CMDispTooltipWarningParent').remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -68,49 +72,98 @@ export function UpdateTooltips() {
|
||||
* @returns {string} l('tooltip').innerHTML The HTML of the l('tooltip')-object
|
||||
*/
|
||||
export function CreateTooltip(type, name) {
|
||||
if (type === 'b') { // Buildings
|
||||
l('tooltip').innerHTML = Game.Objects[name].tooltip();
|
||||
// Adds amortization info to the list of info per building
|
||||
if (CMOptions.TooltipAmor === 1) {
|
||||
const buildPrice = BuildingGetPrice(Game.Objects[name], Game.Objects[name].basePrice, 0, Game.Objects[name].free, Game.Objects[name].amount);
|
||||
const amortizeAmount = buildPrice - Game.Objects[name].totalCookies;
|
||||
if (amortizeAmount > 0) {
|
||||
l('tooltip').innerHTML = l('tooltip').innerHTML
|
||||
.split('so far</div>')
|
||||
.join(`so far<br/>• <b>${Beautify(amortizeAmount)}</b> ${Math.floor(amortizeAmount) === 1 ? 'cookie' : 'cookies'} left to amortize (${GetTimeColor((buildPrice - Game.Objects[name].totalCookies) / (Game.Objects[name].storedTotalCps * Game.globalCpsMult)).text})</div>`);
|
||||
}
|
||||
}
|
||||
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((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
|
||||
else if (type === 'p') l('tooltip').innerHTML = Game.ObjectsById[2].minigame.tileTooltip(name[0], name[1])(); // Garden plots
|
||||
else if (type === 'ha') l('tooltip').innerHTML = Game.ObjectsById[2].minigame.toolTooltip(1)(); // Harvest all button in garden
|
||||
if (type === 'b') {
|
||||
// Buildings
|
||||
l('tooltip').innerHTML = Game.Objects[name].tooltip();
|
||||
// Adds amortization info to the list of info per building
|
||||
if (CMOptions.TooltipAmor === 1) {
|
||||
const buildPrice = BuildingGetPrice(
|
||||
Game.Objects[name],
|
||||
Game.Objects[name].basePrice,
|
||||
0,
|
||||
Game.Objects[name].free,
|
||||
Game.Objects[name].amount,
|
||||
);
|
||||
const amortizeAmount = buildPrice - Game.Objects[name].totalCookies;
|
||||
if (amortizeAmount > 0) {
|
||||
l('tooltip').innerHTML = l('tooltip')
|
||||
.innerHTML.split('so far</div>')
|
||||
.join(
|
||||
`so far<br/>• <b>${Beautify(amortizeAmount)}</b> ${
|
||||
Math.floor(amortizeAmount) === 1 ? 'cookie' : 'cookies'
|
||||
} left to amortize (${
|
||||
GetTimeColor(
|
||||
(buildPrice - Game.Objects[name].totalCookies) /
|
||||
(Game.Objects[name].storedTotalCps * Game.globalCpsMult),
|
||||
).text
|
||||
})</div>`,
|
||||
);
|
||||
}
|
||||
}
|
||||
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(
|
||||
(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
|
||||
else if (type === 'p')
|
||||
l('tooltip').innerHTML = Game.ObjectsById[2].minigame.tileTooltip(
|
||||
name[0],
|
||||
name[1],
|
||||
)();
|
||||
// Garden plots
|
||||
else if (type === 'ha')
|
||||
l('tooltip').innerHTML = Game.ObjectsById[2].minigame.toolTooltip(1)(); // Harvest all button in garden
|
||||
|
||||
// Adds area for extra tooltip-sections
|
||||
if ((type === 'b' && Game.buyMode === 1) || type === 'u' || type === 's' || type === 'g' || (type === 'p' && !Game.keys[16]) || type === 'ha') {
|
||||
const area = document.createElement('div');
|
||||
area.id = 'CMTooltipArea';
|
||||
l('tooltip').appendChild(area);
|
||||
}
|
||||
// Adds area for extra tooltip-sections
|
||||
if (
|
||||
(type === 'b' && Game.buyMode === 1) ||
|
||||
type === 'u' ||
|
||||
type === 's' ||
|
||||
type === 'g' ||
|
||||
(type === 'p' && !Game.keys[16]) ||
|
||||
type === 'ha'
|
||||
) {
|
||||
const area = document.createElement('div');
|
||||
area.id = 'CMTooltipArea';
|
||||
l('tooltip').appendChild(area);
|
||||
}
|
||||
|
||||
// Sets global variables used by CM.Disp.UpdateTooltip()
|
||||
TooltipType = type;
|
||||
TooltipName = name;
|
||||
// Sets global variables used by CM.Disp.UpdateTooltip()
|
||||
TooltipType = type;
|
||||
TooltipName = name;
|
||||
|
||||
UpdateTooltips();
|
||||
UpdateTooltips();
|
||||
|
||||
return l('tooltip').innerHTML;
|
||||
return l('tooltip').innerHTML;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user