[Automated] Merge dev into gh-pages

This commit is contained in:
github-actions[bot]
2021-06-08 06:57:48 +00:00
committed by GitHub
4 changed files with 57 additions and 33 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -308,8 +308,9 @@ const Config = {
'Sort buildings: default',
'Sort buildings: PP of x1 purchase',
'Sort buildings: PP of selected bulk mode',
'Sort buildings: price until next achievement',
],
'Sort the display of buildings in either default order or by PP',
'Sort the display of buildings in default order, by PP, or until next achievement',
false,
() => {
UpdateBuildings();

View File

@@ -3,6 +3,7 @@ import {
CacheObjects1,
CacheObjects10,
CacheObjects100,
CacheObjectsNextAchievement,
} from '../../Cache/VariablesAndData';
import { CMOptions } from '../../Config/VariablesAndData';
import BuildingSell from '../../Sim/SimulationEvents/SellBuilding';
@@ -63,47 +64,69 @@ export default function UpdateBuildings() {
});
}
// 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) {
let arr;
if (CMOptions.SortBuildings === 1) {
arr = Object.keys(CacheObjects1).map(k => {
const o = {};
o.name = k;
o.pp = CacheObjects1[k].pp;
o.color = CacheObjects1[k].color;
return o;
});
} else if (CMOptions.SortBuildings === 2) {
arr = Object.keys(target).map(k => {
const o = {};
o.name = k;
o.pp = target[k].pp;
o.color = target[k].color;
return o;
});
}
// Build array of pointers and sort according to the user's configured sort option.
// This regulates sorting of buildings.
let arr;
if (Game.buyMode !== 1 || !CMOptions.SortBuildings) {
arr = Object.keys(CacheObjects1).map(k => {
const o = {};
o.name = k;
o.id = Game.Objects[k].id;
return o;
});
// Sort using default order.
arr.sort((a, b) => a.id - b.id);
} else if (CMOptions.SortBuildings === 1) {
arr = Object.keys(CacheObjects1).map(k => {
const o = {};
o.name = k;
o.pp = CacheObjects1[k].pp;
o.color = CacheObjects1[k].color;
return o;
});
// Sort by pp colour group, then by pp.
arr.sort((a, b) =>
ColoursOrdering.indexOf(a.color) === ColoursOrdering.indexOf(b.color)
? a.pp - b.pp
: ColoursOrdering.indexOf(a.color) - ColoursOrdering.indexOf(b.color)
);
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 => {
} else if (CMOptions.SortBuildings === 2) {
arr = Object.keys(target).map(k => {
const o = {};
o.name = k;
o.pp = target[k].pp;
o.color = target[k].color;
return o;
});
// Sort by pp colour group, then by pp.
arr.sort((a, b) =>
ColoursOrdering.indexOf(a.color) === ColoursOrdering.indexOf(b.color)
? a.pp - b.pp
: ColoursOrdering.indexOf(a.color) - ColoursOrdering.indexOf(b.color)
);
} else if (CMOptions.SortBuildings === 3) {
arr = Object.keys(CacheObjectsNextAchievement).map(k => {
const o = {};
o.name = k;
o.id = Game.Objects[k].id;
o.amountUntilNext = CacheObjectsNextAchievement[k].AmountNeeded;
o.priceUntilNext = CacheObjectsNextAchievement[k].price;
return o;
});
// First, sort using default order.
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}`;
}
// Sort by price until next achievement.
// Buildings that aren't within 100 of an achievement are placed at the end, still in
// default order relative to each other because sort() is guaranteed stable.
arr.sort((a, b) =>
(a.amountUntilNext !== 101 ? a.priceUntilNext : Infinity) -
(b.amountUntilNext !== 101 ? b.priceUntilNext : Infinity)
);
}
// Use array index (+2) as the grid row number.
// (grid rows are 1-based indexing, and row 1 is the bulk buy/sell options)
for (let x = 0; x < arr.length; x++) {
Game.Objects[arr[x].name].l.style.gridRow = `${x + 2}/${x + 2}`;
}
}