Complete overhaul of code structure and relevant files (#639)
This commit is contained in:
15
src/Disp/HelperFunctions/CalculateGrimoireRefillTime.js
Normal file
15
src/Disp/HelperFunctions/CalculateGrimoireRefillTime.js
Normal file
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* This function calculates the time it takes to reach a certain magic level
|
||||
* @param {number} currentMagic The current magic level
|
||||
* @param {number} maxMagic The user's max magic level
|
||||
* @param {number} targetMagic The target magic level
|
||||
* @returns {number} count / Game.fps The time it takes to reach targetMagic
|
||||
*/
|
||||
export default function CalculateGrimoireRefillTime(currentMagic, maxMagic, targetMagic) {
|
||||
let count = 0;
|
||||
while (currentMagic < targetMagic) {
|
||||
currentMagic += Math.max(0.002, (currentMagic / Math.max(maxMagic, 100)) ** 0.5) * 0.002;
|
||||
count++;
|
||||
}
|
||||
return count / Game.fps;
|
||||
}
|
||||
21
src/Disp/HelperFunctions/GetCPS.js
Normal file
21
src/Disp/HelperFunctions/GetCPS.js
Normal file
@@ -0,0 +1,21 @@
|
||||
import {
|
||||
CacheAvgCps, CacheCurrWrinklerCount, CacheCurrWrinklerCPSMult, CacheWrinklersFattest,
|
||||
} from '../../Cache/VariablesAndData';
|
||||
import { CMOptions } from '../../Config/VariablesAndData';
|
||||
|
||||
/**
|
||||
* This function returns the cps as either current or average CPS depending on CM.Options.CPSMode
|
||||
* @returns {number} The average or current cps
|
||||
*/
|
||||
export default function GetCPS() {
|
||||
if (CMOptions.CPSMode) {
|
||||
return CacheAvgCps;
|
||||
} if (CMOptions.CalcWrink === 0) {
|
||||
return (Game.cookiesPs * (1 - Game.cpsSucked));
|
||||
} if (CMOptions.CalcWrink === 1) {
|
||||
return Game.cookiesPs * (CacheCurrWrinklerCPSMult + (1 - (CacheCurrWrinklerCount * 0.05)));
|
||||
} if (CMOptions.CalcWrink === 2 && Game.wrinklers[CacheWrinklersFattest[1]].type === 1) {
|
||||
return Game.cookiesPs * ((CacheCurrWrinklerCPSMult * 3 / CacheCurrWrinklerCount) + (1 - (CacheCurrWrinklerCount * 0.05)));
|
||||
}
|
||||
return Game.cookiesPs * ((CacheCurrWrinklerCPSMult / CacheCurrWrinklerCount) + (1 - (CacheCurrWrinklerCount * 0.05)));
|
||||
}
|
||||
24
src/Disp/HelperFunctions/GetLumpColor.js
Normal file
24
src/Disp/HelperFunctions/GetLumpColor.js
Normal file
@@ -0,0 +1,24 @@
|
||||
import {
|
||||
ColorGray, ColorGreen, ColorOrange, ColorPurple, ColorRed, ColorYellow,
|
||||
} from '../VariablesAndData';
|
||||
|
||||
/**
|
||||
* This function returns Name and Color as object for sugar lump type that is given as input param.
|
||||
* It is called by CM.Disp.UpdateTooltipSugarLump()
|
||||
* @param {string} type Sugar Lump Type.
|
||||
* @returns {{string}, {string}} text, color An array containing the text and display-color of the sugar lump
|
||||
*/
|
||||
export default function GetLumpColor(type) {
|
||||
if (type === 0) {
|
||||
return { text: 'Normal', color: ColorGray };
|
||||
} if (type === 1) {
|
||||
return { text: 'Bifurcated', color: ColorGreen };
|
||||
} if (type === 2) {
|
||||
return { text: 'Golden', color: ColorYellow };
|
||||
} if (type === 3) {
|
||||
return { text: 'Meaty', color: ColorOrange };
|
||||
} if (type === 4) {
|
||||
return { text: 'Caramelized', color: ColorPurple };
|
||||
}
|
||||
return { text: 'Unknown Sugar Lump', color: ColorRed };
|
||||
}
|
||||
16
src/Disp/HelperFunctions/GetWrinkConfigBank.js
Normal file
16
src/Disp/HelperFunctions/GetWrinkConfigBank.js
Normal file
@@ -0,0 +1,16 @@
|
||||
import { CacheWrinklersFattest, CacheWrinklersTotal } from '../../Cache/VariablesAndData';
|
||||
import { CMOptions } from '../../Config/VariablesAndData';
|
||||
|
||||
/**
|
||||
* This function returns the total amount stored in the Wrinkler Bank
|
||||
* as calculated by CM.Cache.CacheWrinklers() if CM.Options.CalcWrink is set
|
||||
* @returns {number} 0 or the amount of cookies stored (CM.Cache.WrinklersTotal)
|
||||
*/
|
||||
export default function GetWrinkConfigBank() {
|
||||
if (CMOptions.CalcWrink === 1) {
|
||||
return CacheWrinklersTotal;
|
||||
} if (CMOptions.CalcWrink === 2) {
|
||||
return CacheWrinklersFattest[0];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
11
src/Disp/HelperFunctions/PopWrinklers.js
Normal file
11
src/Disp/HelperFunctions/PopWrinklers.js
Normal file
@@ -0,0 +1,11 @@
|
||||
/**
|
||||
* This function pops all normal wrinklers
|
||||
* 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)) {
|
||||
if (Game.wrinklers[i].sucked > 0 && Game.wrinklers[i].type === 0) {
|
||||
Game.wrinklers[i].hp = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
17
src/Disp/HelperFunctions/RefreshScale.js
Normal file
17
src/Disp/HelperFunctions/RefreshScale.js
Normal file
@@ -0,0 +1,17 @@
|
||||
import UpdateBuildings from '../BuildingsUpgrades/Buildings';
|
||||
import UpdateUpgrades from '../BuildingsUpgrades/Upgrades';
|
||||
import { UpdateBotBar } from '../InfoBars/BottomBar';
|
||||
|
||||
/**
|
||||
* This function refreshes all numbers after a change in scale-setting
|
||||
* It is therefore called by a changes in CM.Options.Scale, CM.Options.ScaleDecimals, CM.Options.ScaleSeparator and CM.Options.ScaleCutoff
|
||||
*/
|
||||
export default function RefreshScale() {
|
||||
BeautifyAll();
|
||||
Game.RefreshStore();
|
||||
Game.RebuildUpgrades();
|
||||
|
||||
UpdateBotBar();
|
||||
UpdateBuildings();
|
||||
UpdateUpgrades();
|
||||
}
|
||||
20
src/Disp/HelperFunctions/UpdateAscendState.js
Normal file
20
src/Disp/HelperFunctions/UpdateAscendState.js
Normal file
@@ -0,0 +1,20 @@
|
||||
import { ToggleTimerBar } from '../../Config/SpecificToggles';
|
||||
import ToggleBotBar from '../../Config/Toggles/ToggleBotBar';
|
||||
import { CMOptions } from '../../Config/VariablesAndData';
|
||||
import UpdateBackground from './UpdateBackground';
|
||||
|
||||
/**
|
||||
* This function disables and shows the bars created by CookieMonster when the game is "ascending"
|
||||
* It is called by CM.Disp.Draw()
|
||||
*/
|
||||
export default function UpdateAscendState() {
|
||||
if (Game.OnAscend) {
|
||||
l('game').style.bottom = '0px';
|
||||
if (CMOptions.BotBar === 1) l('CMBotBar').style.display = 'none';
|
||||
if (CMOptions.TimerBar === 1) l('CMTimerBar').style.display = 'none';
|
||||
} else {
|
||||
ToggleBotBar();
|
||||
ToggleTimerBar();
|
||||
}
|
||||
UpdateBackground();
|
||||
}
|
||||
11
src/Disp/HelperFunctions/UpdateBackground.js
Normal file
11
src/Disp/HelperFunctions/UpdateBackground.js
Normal file
@@ -0,0 +1,11 @@
|
||||
/**
|
||||
* This function sets the size of the background of the full game and the left column
|
||||
* depending on whether certain abrs are activated
|
||||
* It is called by CM.Disp.UpdateAscendState() and CM.Disp.UpdateBotTimerBarPosition()
|
||||
*/
|
||||
export default function UpdateBackground() {
|
||||
Game.Background.canvas.width = Game.Background.canvas.parentNode.offsetWidth;
|
||||
Game.Background.canvas.height = Game.Background.canvas.parentNode.offsetHeight;
|
||||
Game.LeftBackground.canvas.width = Game.LeftBackground.canvas.parentNode.offsetWidth;
|
||||
Game.LeftBackground.canvas.height = Game.LeftBackground.canvas.parentNode.offsetHeight;
|
||||
}
|
||||
24
src/Disp/HelperFunctions/UpdateColors.js
Normal file
24
src/Disp/HelperFunctions/UpdateColors.js
Normal file
@@ -0,0 +1,24 @@
|
||||
import { CMOptions } from '../../Config/VariablesAndData';
|
||||
import UpdateBuildings from '../BuildingsUpgrades/Buildings';
|
||||
import {
|
||||
ColorBackPre, ColorBorderPre, Colors, ColorTextPre,
|
||||
} from '../VariablesAndData';
|
||||
|
||||
/**
|
||||
* This function changes/refreshes colours if the user has set new standard colours
|
||||
* The function is therefore called by a change in CM.Options.Colors
|
||||
*/
|
||||
export default function UpdateColors() {
|
||||
let str = '';
|
||||
for (let i = 0; i < Colors.length; i++) {
|
||||
str += `.${ColorTextPre}${Colors[i]} { color: ${CMOptions.Colors[Colors[i]]}; }\n`;
|
||||
}
|
||||
for (let i = 0; i < Colors.length; i++) {
|
||||
str += `.${ColorBackPre}${Colors[i]} { background-color: ${CMOptions.Colors[Colors[i]]}; }\n`;
|
||||
}
|
||||
for (let i = 0; i < Colors.length; i++) {
|
||||
str += `.${ColorBorderPre}${Colors[i]} { border: 1px solid ${CMOptions.Colors[Colors[i]]}; }\n`;
|
||||
}
|
||||
l('CMCSS').textContent = str;
|
||||
UpdateBuildings(); // Class has been already set
|
||||
}
|
||||
Reference in New Issue
Block a user