Changed PP colour coding #683

This commit is contained in:
Daniël van Noord
2021-03-16 22:28:54 +01:00
parent e3d3f649c3
commit 6caee4d8fb
11 changed files with 106 additions and 158 deletions

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) {
if (CachePPArray.length === indexOfMin - 1) {
break;
}
});
indexOfMin += 1;
}
}
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

@@ -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,3 @@
import CachePP from '../Cache/PP/PP';
import CheckNotificationPermissions from '../Config/CheckNotificationPermissions';
import { ToggleTimerBar, ToggleTimerBarPos } from '../Config/SpecificToggles';
import ToggleBotBar from '../Config/Toggles/ToggleBotBar';
@@ -68,7 +67,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 +98,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 +117,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',
@@ -206,16 +196,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

@@ -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);