Merge pull request #688 from DanielNoord/ppvalues

Number of functions
This commit is contained in:
Daniël van Noord
2021-03-17 00:01:36 +01:00
committed by GitHub
20 changed files with 161 additions and 177 deletions

View File

File diff suppressed because one or more lines are too long

View File

@@ -18,13 +18,13 @@ Cookie Monster also indicates the time left before being able to buy an upgrade
This index is computed for buildings and upgrades. If the relevant option is enabled, it will color-code each of them based on their value:
* Light Blue: (upgrades) This item has a better PP than any building
* Green: This item has the best PP
* Yellow: This item is not the best, but it is closer to best than it is to worst
* Orange: This item is not the worst, but it is closer to worst than it is to best
* Red: This item has the worst PP
* Purple: (upgrades) This item has a worse PP than any building
* Gray: (upgrades) This item has not been calculated and/or cannot be calculated due to no definitive worth.
* Light Blue: (upgrades) This item has a better PP than the best building to buy
* Green: This building has the best PP
* Yellow: This building is within the top 10 of best PP's
* Orange: This building is within the top 20 of best PP's
* Red: This building is within the top 30 of best PP's
* Purple: This building is worse than the top 10 of best PP's
* Gray: This item does not have a PP, often this means that there is no change to CPS
Note: For this index, **lower is better**, meaning a building with a PP of 1 is more interesting than one with a PP of 3.

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -4,13 +4,11 @@ import { CMOptions } from '../../Config/VariablesAndData';
import GetWrinkConfigBank from '../../Disp/HelperFunctions/GetWrinkConfigBank';
import { ColorGray } from '../../Disp/VariablesAndData';
import {
CacheArrayOfPPs,
CacheMaxPP,
CacheMidPP,
CacheMinPP,
CacheObjects1,
CacheObjects10,
CacheObjects100,
CachePPArray,
} from '../VariablesAndData';
import ColourOfPP from './ColourOfPP';
@@ -19,16 +17,29 @@ import ColourOfPP from './ColourOfPP';
* It saves all date in CM.Cache.Objects...
* It is called by CM.Cache.CacheBuildingsPP()
*/
function CacheBuildingsBulkPP(target) {
function CacheColor(target, amount) {
Object.keys(target).forEach((i) => {
target[i].color = ColourOfPP(
target[i],
Game.Objects[i].getSumPrice(amount),
);
// Colour based on excluding certain top-buildings
for (let j = 0; j < CMOptions.PPExcludeTop; j++) {
if (target[i].pp === CachePPArray[j][0]) target[i].color = ColorGray;
}
});
}
function CachePP(target, amount) {
Object.keys(target).forEach((i) => {
const price = Game.Objects[i].getSumPrice(amount);
if (Game.cookiesPs) {
target[i].pp =
Math.max(target[i].price - (Game.cookies + GetWrinkConfigBank()), 0) /
Math.max(price - (Game.cookies + GetWrinkConfigBank()), 0) /
Game.cookiesPs +
target[i].price / target[i].bonus;
} else target[i].pp = target[i].price / target[i].bonus;
target[i].color = ColourOfPP(target[i], target[i].price);
price / target[i].bonus;
} else target[i].pp = price / target[i].bonus;
CachePPArray.push([target[i].pp, amount]);
});
}
@@ -38,91 +49,28 @@ function CacheBuildingsBulkPP(target) {
*/
export default function CacheBuildingsPP() {
CacheMinPP = Infinity;
CacheMaxPP = 1;
CacheArrayOfPPs = [];
CachePPArray = [];
if (typeof CMOptions.PPExcludeTop === 'undefined') CMOptions.PPExcludeTop = 0; // Otherwise breaks during initialization
// Calculate PP and colors when compared to purchase of optimal building in single-purchase mode
if (CMOptions.ColorPPBulkMode === 0 && Game.buyMode > 0) {
Object.keys(CacheObjects1).forEach((i) => {
if (Game.cookiesPs) {
CacheObjects1[i].pp =
Math.max(
Game.Objects[i].getPrice() - (Game.cookies + GetWrinkConfigBank()),
0,
) /
Game.cookiesPs +
Game.Objects[i].getPrice() / CacheObjects1[i].bonus;
} else
CacheObjects1[i].pp =
Game.Objects[i].getPrice() / CacheObjects1[i].bonus;
CacheArrayOfPPs.push([CacheObjects1[i].pp, Game.Objects[i].getPrice()]);
});
// Set CM.Cache.min to best non-excluded buidliung
CacheArrayOfPPs.sort((a, b) => a[0] - b[0]);
if (CMOptions.PPOnlyConsiderBuyable) {
while (CacheArrayOfPPs[0][1] > Game.cookies) {
if (CacheArrayOfPPs.length === 1) {
break;
}
CacheArrayOfPPs.shift();
}
}
CacheMinPP = CacheArrayOfPPs[CMOptions.PPExcludeTop][0];
CacheMaxPP = CacheArrayOfPPs[CacheArrayOfPPs.length - 1][0];
CacheMidPP = (CacheMaxPP - CacheMinPP) / 2 + CacheMinPP;
Object.keys(CacheObjects1).forEach((i) => {
CacheObjects1[i].color = ColourOfPP(
CacheObjects1[i],
Game.Objects[i].getPrice(),
);
// Colour based on excluding certain top-buildings
for (let j = 0; j < CMOptions.PPExcludeTop; j++) {
if (CacheObjects1[i].pp === CacheArrayOfPPs[j][0])
CacheObjects1[i].color = ColorGray;
}
});
// Calculate PP of bulk-buy modes
CacheBuildingsBulkPP(CacheObjects10);
CacheBuildingsBulkPP(CacheObjects100);
} else if (Game.buyMode > 0) {
// Calculate PP and colors when compared to purchase of selected bulk mode
let target;
if (Game.buyBulk === 1) target = CacheObjects1;
else if (Game.buyBulk === 10) target = CacheObjects10;
else if (Game.buyBulk === 100) target = CacheObjects100;
Object.keys(target).forEach((i) => {
if (Game.cookiesPs) {
target[i].pp =
Math.max(
Game.Objects[i].bulkPrice - (Game.cookies + GetWrinkConfigBank()),
0,
) /
Game.cookiesPs +
Game.Objects[i].bulkPrice / target[i].bonus;
} else target[i].pp = Game.Objects[i].bulkPrice / target[i].bonus;
CacheArrayOfPPs.push([target[i].pp, Game.Objects[i].bulkPrice]);
});
// Set CM.Cache.min to best non-excluded buidliung
CacheArrayOfPPs.sort((a, b) => a[0] - b[0]);
if (CMOptions.PPOnlyConsiderBuyable) {
while (CacheArrayOfPPs[0][1] > Game.cookies) {
if (CacheArrayOfPPs.length === 1) {
break;
}
CacheArrayOfPPs.shift();
}
}
CacheMinPP = CacheArrayOfPPs[CMOptions.PPExcludeTop][0];
CacheMaxPP = CacheArrayOfPPs[CacheArrayOfPPs.length - 1][0];
CacheMidPP = (CacheMaxPP - CacheMinPP) / 2 + CacheMinPP;
// Calculate PP and colors
CachePP(CacheObjects1, 1);
CachePP(CacheObjects10, 10);
CachePP(CacheObjects100, 100);
Object.keys(CacheObjects1).forEach((i) => {
target[i].color = ColourOfPP(target[i], Game.Objects[i].bulkPrice);
// Colour based on excluding certain top-buildings
for (let j = 0; j < CMOptions.PPExcludeTop; j++) {
if (target[i].pp === CacheArrayOfPPs[j][0]) target[i].color = ColorGray;
// Set CM.Cache.min to best non-excluded buidliung
CachePPArray.sort((a, b) => a[0] - b[0]);
let indexOfMin = 0;
if (CMOptions.PPOnlyConsiderBuyable) {
while (CachePPArray[indexOfMin][1] > Game.cookies) {
indexOfMin += 1;
if (CachePPArray.length === indexOfMin + 1) {
break;
}
});
}
}
CacheMinPP = CachePPArray[CMOptions.PPExcludeTop][indexOfMin];
CacheColor(CacheObjects1, 1);
CacheColor(CacheObjects10, 10);
CacheColor(CacheObjects100, 100);
}

View File

@@ -9,7 +9,7 @@ import {
ColorRed,
ColorYellow,
} from '../../Disp/VariablesAndData';
import { CacheMaxPP, CacheMidPP, CacheMinPP } from '../VariablesAndData';
import { CacheMinPP, CachePPArray } from '../VariablesAndData';
/**
* This functions return the colour assosciated with the given pp value
@@ -24,10 +24,10 @@ export default function ColourOfPP(me, price) {
if (me.pp <= 0 || me.pp === Infinity) color = ColorGray;
else if (me.pp < CacheMinPP) color = ColorBlue;
else if (me.pp === CacheMinPP) color = ColorGreen;
else if (me.pp === CacheMaxPP) color = ColorRed;
else if (me.pp > CacheMaxPP) color = ColorPurple;
else if (me.pp > CacheMidPP) color = ColorOrange;
else color = ColorYellow;
else if (me.pp < CachePPArray[10][0]) color = ColorYellow;
else if (me.pp < CachePPArray[20][0]) color = ColorOrange;
else if (me.pp > CachePPArray[30][0]) color = ColorRed;
else color = ColorPurple;
// Colour based on price in terms of CPS
if (Number(CMOptions.PPSecondsLowerLimit) !== 0) {

View File

@@ -1,10 +1,16 @@
/* eslint-disable no-unused-vars */
/** Section: Functions related to caching income */
import { CMOptions } from '../../Config/VariablesAndData';
import GetCPS from '../../Disp/HelperFunctions/GetCPS';
import BuildingGetPrice from '../../Sim/SimulationEvents/BuyBuilding';
import BuyBuildingsBonusIncome from '../../Sim/SimulationEvents/BuyBuildingBonusIncome';
import BuyUpgradesBonusIncome from '../../Sim/SimulationEvents/BuyUpgrades';
import {
CacheAverageCPS,
CacheAverageGainBank,
CacheAverageGainWrink,
CacheAverageGainWrinkFattest,
CacheDoRemakeBuildPrices,
CacheObjects1,
CacheObjects10,
@@ -38,9 +44,18 @@ function CacheUpgradeIncome() {
CacheUpgrades = [];
Object.keys(Game.Upgrades).forEach((i) => {
const bonusIncome = BuyUpgradesBonusIncome(i);
CacheUpgrades[i] = {};
if (bonusIncome[0]) CacheUpgrades[i].bonus = bonusIncome[0];
if (bonusIncome[1]) CacheUpgrades[i].bonusMouse = bonusIncome[1];
if (i === 'Elder Pledge') {
CacheUpgrades[i] = { bonus: Game.cookiesPs - CacheAverageGainBank };
if (CMOptions.CalcWrink === 1)
CacheUpgrades[i].bonus -= CacheAverageGainWrink;
else if (CMOptions.CalcWrink === 2)
CacheUpgrades[i].bonus -= CacheAverageGainWrinkFattest;
if (!Number.isFinite(CacheUpgrades[i].bonus)) CacheUpgrades[i].bonus = 0;
} else {
CacheUpgrades[i] = {};
if (bonusIncome[0]) CacheUpgrades[i].bonus = bonusIncome[0];
if (bonusIncome[1]) CacheUpgrades[i].bonusMouse = bonusIncome[1];
}
});
}

View File

@@ -65,10 +65,10 @@ export let CacheSeasonPopShimmer = {};
export let CacheTimeTillNextPrestige = 0;
/** Stores lowest PP value */
export let CacheMinPP = 0;
export let CacheMidPP = 0;
export let CacheMaxPP = 0;
export let CacheArrayOfPPs = [];
/** Stores all PP values of all buildings for all buy settings (1, 10, 100) */
export let CachePPArray = [];
export let CacheGoldenShimmersByID = {};
@@ -100,6 +100,7 @@ export let CacheDoRemakeBuildPrices;
export let CacheHadBuildAura;
/** Store the CPS effect of each god if it was put into each slot */
export let CacheGods = {
0: [0, 0, 0],
1: [0, 0, 0],

View File

@@ -1,4 +1,4 @@
import CachePP from '../Cache/PP/PP';
/* eslint-disable no-unused-vars */
import CheckNotificationPermissions from '../Config/CheckNotificationPermissions';
import { ToggleTimerBar, ToggleTimerBarPos } from '../Config/SpecificToggles';
import ToggleBotBar from '../Config/Toggles/ToggleBotBar';
@@ -14,6 +14,7 @@ import UpdateUpgrades from '../Disp/BuildingsUpgrades/Upgrades';
import RefreshScale from '../Disp/HelperFunctions/RefreshScale';
import UpdateColors from '../Disp/HelperFunctions/UpdateColors';
import { UpdateFavicon } from '../Disp/TabTitle/FavIcon';
import { SimDoSims } from '../Sim/VariablesAndData';
import {
SettingStandard,
SettingColours,
@@ -68,7 +69,11 @@ const Config = {
SortBuildings: new SettingStandard(
'bool',
'BarsColors',
['Sort Buildings: Default', 'Sort Buildings: PP'],
[
'Sort Buildings: Default',
'Sort Buildings: PP of x1 purchase',
'Sort Buildings: PP of selected bulk mode',
],
'Sort the display of buildings in either default order or by PP',
false,
function () {
@@ -95,19 +100,6 @@ const Config = {
UpdateBuildings();
},
),
BulkBuildColor: new SettingStandard(
'bool',
'BarsColors',
[
'Bulk Building Colors (Single Building Color)',
'Bulk Building Colors (Calculated Bulk Color)',
],
'Color code bulk buildings based on single buildings color or calculated bulk value color',
false,
function () {
UpdateBuildings();
},
),
UpBarColor: new SettingStandard(
'bool',
'BarsColors',
@@ -127,17 +119,17 @@ const Config = {
'BarsColors',
{
Blue:
'Color Blue. Used to show better than best PP building, for Click Frenzy bar, and for various labels',
'Color Blue. Used to show upgrades better than best PP building, for Click Frenzy bar, and for various labels',
Green:
'Color Green. Used to show best PP building, for Blood Frenzy bar, and for various labels',
Yellow:
'Color Yellow. Used to show between best and worst PP buildings closer to best, for Frenzy bar, and for various labels',
'Color Yellow. Used to show buildings within the top 10 of PP, for Frenzy bar, and for various labels',
Orange:
'Color Orange. Used to show between best and worst PP buildings closer to worst, for Next Reindeer bar, and for various labels',
'Color Orange. Used to show buildings within the top 20 of PP, for Next Reindeer bar, and for various labels',
Red:
'Color Red. Used to show worst PP building, for Clot bar, and for various labels',
'Color Red. Used to show buildings within the top 30 of PP, for Clot bar, and for various labels',
Purple:
'Color Purple. Used to show worse than worst PP building, for Next Cookie bar, and for various labels',
'Color Purple. Used to show buildings outside of the top 30 of PP, for Next Cookie bar, and for various labels',
Gray:
'Color Gray. Used to show negative or infinity PP, and for Next Cookie/Next Reindeer bar',
Pink: 'Color Pink. Used for Dragonflight bar',
@@ -169,6 +161,9 @@ const Config = {
],
'Calculate times and average Cookies Per Second with (only the single non-shiny fattest) Wrinklers',
true,
function () {
SimDoSims = true;
},
),
CPSMode: new SettingStandard(
'bool',
@@ -206,16 +201,6 @@ const Config = {
'How much time average Cookie Clicks should consider',
false,
),
ColorPPBulkMode: new SettingStandard(
'bool',
'Calculation',
['Color of PP (Compared to Single)', 'Color of PP (Compared to Bulk)'],
'Color PP-values based on comparison with single purchase or with selected bulk-buy mode',
false,
function () {
CachePP();
},
),
PPExcludeTop: new SettingStandard(
'bool',
'Calculation',

View File

@@ -5,18 +5,16 @@ const ConfigDefault = {
TimerBarPos: 0,
TimerBarOverlay: 2,
BuildColor: 1,
BulkBuildColor: 0,
UpBarColor: 1,
UpgradeBarFixedPos: 1,
CalcWrink: 0,
CPSMode: 1,
AvgCPSHist: 3,
AvgClicksHist: 0,
ColorPPBulkMode: 1,
PPExcludeTop: 0,
PPSecondsLowerLimit: 0,
PPOnlyConsiderBuyable: 0,
ToolWarnBon: 0,
ToolWarnBon: 1,
Title: 1,
GeneralSound: 1,
GCNotification: 0,

View File

@@ -62,22 +62,42 @@ export default function UpdateBuildings() {
// (grid rows are 1-based indexing, and row 1 is the bulk buy/sell options)
// This regulates sorting of buildings
if (Game.buyMode === 1 && CMOptions.SortBuildings) {
const arr = Object.keys(target).map((k) => {
const o = target[k];
o.name = k;
o.id = Game.Objects[k].id;
return o;
});
let arr;
if (CMOptions.SortBuildings === 1) {
arr = Object.keys(CacheObjects1).map((k) => {
const o = CacheObjects1[k];
o.name = k;
o.id = Game.Objects[k].id;
return o;
});
arr.sort(function (a, b) {
return Colors.indexOf(a.color) > Colors.indexOf(b.color)
? 1
: Colors.indexOf(a.color) < Colors.indexOf(b.color)
? -1
: a.pp < b.pp
? -1
: 0;
});
arr.sort(function (a, b) {
return Colors.indexOf(a.color) > Colors.indexOf(b.color)
? 1
: Colors.indexOf(a.color) < Colors.indexOf(b.color)
? -1
: a.pp < b.pp
? -1
: 0;
});
} else if (CMOptions.SortBuildings === 2) {
arr = Object.keys(target).map((k) => {
const o = target[k];
o.name = k;
o.id = Game.Objects[k].id;
return o;
});
arr.sort(function (a, b) {
return Colors.indexOf(a.color) > Colors.indexOf(b.color)
? 1
: Colors.indexOf(a.color) < Colors.indexOf(b.color)
? -1
: a.pp < b.pp
? -1
: 0;
});
}
for (let x = 0; x < arr.length; x++) {
Game.Objects[arr[x].name].l.style.gridRow = `${x + 2}/${x + 2}`;

View File

@@ -96,7 +96,7 @@ export function UpdateBotBar() {
].className = ColorTextPre + target[i].color;
l('CMBotBar').firstChild.firstChild.childNodes[2].childNodes[
count
].textContent = Beautify(target[i].pp, 2);
].textContent = Beautify(Math.round(target[i].pp), 2);
const timeColor = GetTimeColor(
(Game.Objects[i].bulkPrice - (Game.cookies + GetWrinkConfigBank())) /
GetCPS(),

View File

@@ -86,8 +86,12 @@ export function CreateBotBarBuildingColumn(buildingName) {
span.className = ColorTextPre + ColorBlue;
header.appendChild(document.createTextNode(')'));
type.lastChild.style.paddingLeft = '8px';
bonus.appendChild(document.createElement('td'));
bonus.lastChild.style.paddingLeft = '8px';
pp.appendChild(document.createElement('td'));
pp.lastChild.style.paddingLeft = '8px';
time.appendChild(document.createElement('td'));
time.lastChild.style.paddingLeft = '2px';
}
}

View File

@@ -2,7 +2,7 @@
import { ToggleHeader } from '../../Config/ToggleSetting';
import { CMOptions } from '../../Config/VariablesAndData';
import { TooltipText } from '../VariablesAndData';
import { SimpleTooltipElements } from '../VariablesAndData';
/**
* This function creates a header-object for the stats page
@@ -64,7 +64,10 @@ export function StatsListing(type, name, text, placeholder) {
Game.tooltip.hide();
};
tooltip.onmouseover = function () {
Game.tooltip.draw(this, escape(TooltipText[placeholder].innerHTML));
Game.tooltip.draw(
this,
escape(SimpleTooltipElements[placeholder].innerHTML),
);
};
tooltip.style.cursor = 'default';
tooltip.style.display = 'inline-block';

View File

@@ -183,7 +183,8 @@ function CreatePrefOption(config) {
SaveConfig();
Game.UpdateMenu();
};
JsColor(input, { hash: true, position: 'right', onInput: change });
// eslint-disable-next-line no-new
new JsColor(input, { hash: true, position: 'right', onInput: change });
const label = document.createElement('label');
label.textContent = Config.Colors.desc[Colors[i]];
innerDiv.appendChild(label);

View File

@@ -6,7 +6,11 @@ import {
GetTimeColor,
} from '../BeautifyAndFormatting/BeautifyFormatting';
import CopyData from '../../Sim/SimulationData/CopyData';
import { TooltipName, TooltipType } from '../VariablesAndData';
import {
SimpleTooltipElements,
TooltipName,
TooltipType,
} from '../VariablesAndData';
import { CMOptions } from '../../Config/VariablesAndData';
import BuildingGetPrice from '../../Sim/SimulationEvents/BuyBuilding';
@@ -30,6 +34,7 @@ export function CreateSimpleTooltip(placeholder, text, minWidth) {
div.textContent = text;
desc.appendChild(div);
Tooltip.appendChild(desc);
SimpleTooltipElements[placeholder] = Tooltip;
}
/**

View File

@@ -80,6 +80,7 @@ export const TooltipText = [
'250px',
],
];
export const SimpleTooltipElements = {};
/**
* These are variables used by the functions that create tooltips for wrinklers

View File

@@ -1,19 +1,22 @@
/** We know this is not how Webpack should be used, but we are slowly transferring our code.
* For now this is how at least start to create a structure that allows us to transfer towards
* more modular code. Any help is highly appreciated.
*/
*/
const path = require('path');
module.exports = function (env) {
return {
mode: 'production',
devtool: env.production ? 'source-map' : 'eval-source-map',
entry: {
CookieMonster: { import: './src/CookieMonster.js', filename: './CookieMonster.js' },
},
output: {
filename: 'CookieMonster.js',
path: path.resolve(__dirname, 'dist'),
},
};
return {
mode: 'production',
devtool: env.production ? 'source-map' : 'eval-source-map',
entry: {
CookieMonster: {
import: './src/CookieMonster.js',
filename: './CookieMonster.js',
},
},
output: {
filename: 'CookieMonster.js',
path: path.resolve(__dirname, 'dist'),
},
};
};