Added prettier (#661)

* Added prettier

* Added prettier

* Added prettier
This commit is contained in:
Daniël van Noord
2021-03-14 18:57:07 +01:00
committed by GitHub
parent f3e7964262
commit 932509a877
132 changed files with 7143 additions and 4894 deletions

View File

@@ -1,4 +1,8 @@
import { CacheObjects1, CacheObjects10, CacheObjects100 } from '../../Cache/VariablesAndData';
import {
CacheObjects1,
CacheObjects10,
CacheObjects100,
} from '../../Cache/VariablesAndData';
import { CMOptions } from '../../Config/VariablesAndData';
import BuildingSell from '../../Sim/SimulationEvents/SellBuilding';
import { Beautify } from '../BeautifyAndFormatting/BeautifyFormatting';
@@ -14,68 +18,79 @@ import { Colors, LastTargetBuildings } from '../VariablesAndData';
* And by changes in CM.Options.BuildColor, CM.Options.SortBuild & CM.Data.Config.BulkBuildColor
*/
export default function UpdateBuildings() {
let target = Game.buyBulk;
if (Game.buyMode === 1) {
LastTargetBuildings = target;
} else {
target = LastTargetBuildings;
}
if (target === 1) target = CacheObjects1;
else if (target === 10) target = CacheObjects10;
else if (target === 100) target = CacheObjects100;
let target = Game.buyBulk;
if (Game.buyMode === 1) {
LastTargetBuildings = target;
} else {
target = LastTargetBuildings;
}
if (target === 1) target = CacheObjects1;
else if (target === 10) target = CacheObjects10;
else if (target === 100) target = CacheObjects100;
if (Game.buyMode === 1) {
if (CMOptions.BuildColor === 1) {
for (const i of Object.keys(target)) {
l(`productPrice${Game.Objects[i].id}`).style.color = CMOptions.Colors[target[i].color];
}
} else {
for (const i of Object.keys(Game.Objects)) {
l(`productPrice${Game.Objects[i].id}`).style.removeProperty('color');
}
}
} else if (Game.buyMode === -1) {
for (const i of Object.keys(CacheObjects1)) {
const o = Game.Objects[i];
l(`productPrice${o.id}`).style.color = '';
/*
* Fix sell price displayed in the object in the store.
*
* 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(`productPrice${o.id}`).innerHTML = Beautify(BuildingSell(o, o.basePrice, o.amount, o.free, Game.buyBulk, 1));
}
}
if (Game.buyMode === 1) {
if (CMOptions.BuildColor === 1) {
for (const i of Object.keys(target)) {
l(`productPrice${Game.Objects[i].id}`).style.color =
CMOptions.Colors[target[i].color];
}
} else {
for (const i of Object.keys(Game.Objects)) {
l(`productPrice${Game.Objects[i].id}`).style.removeProperty('color');
}
}
} else if (Game.buyMode === -1) {
for (const i of Object.keys(CacheObjects1)) {
const o = Game.Objects[i];
l(`productPrice${o.id}`).style.color = '';
/*
* Fix sell price displayed in the object in the store.
*
* 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(`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
// (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;
});
// Build array of pointers, sort by pp, use array index (+2) as the grid row number
// (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;
});
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;
});
for (let x = 0; x < arr.length; x++) {
Game.Objects[arr[x].name].l.style.gridRow = `${x + 2}/${x + 2}`;
}
} else {
const arr = Object.keys(CacheObjects1).map((k) => {
const o = CacheObjects1[k];
o.name = k;
o.id = Game.Objects[k].id;
return o;
});
arr.sort((a, b) => a.id - b.id);
for (let x = 0; x < arr.length; x++) {
Game.Objects[arr[x].name].l.style.gridRow = `${x + 2}/${x + 2}`;
}
}
for (let x = 0; x < arr.length; x++) {
Game.Objects[arr[x].name].l.style.gridRow = `${x + 2}/${x + 2}`;
}
} else {
const arr = Object.keys(CacheObjects1).map((k) => {
const o = CacheObjects1[k];
o.name = k;
o.id = Game.Objects[k].id;
return o;
});
arr.sort((a, b) => a.id - b.id);
for (let x = 0; x < arr.length; x++) {
Game.Objects[arr[x].name].l.style.gridRow = `${x + 2}/${x + 2}`;
}
}
}