Merge pull request #848 from tsr488/achievementsort
Adding option to sort buildings by price until next achievement
This commit is contained in:
2
dist/CookieMonsterDev.js
vendored
2
dist/CookieMonsterDev.js
vendored
File diff suppressed because one or more lines are too long
2
dist/CookieMonsterDev.js.map
vendored
2
dist/CookieMonsterDev.js.map
vendored
File diff suppressed because one or more lines are too long
@@ -308,8 +308,9 @@ const Config = {
|
|||||||
'Sort buildings: default',
|
'Sort buildings: default',
|
||||||
'Sort buildings: PP of x1 purchase',
|
'Sort buildings: PP of x1 purchase',
|
||||||
'Sort buildings: PP of selected bulk mode',
|
'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,
|
false,
|
||||||
() => {
|
() => {
|
||||||
UpdateBuildings();
|
UpdateBuildings();
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import {
|
|||||||
CacheObjects1,
|
CacheObjects1,
|
||||||
CacheObjects10,
|
CacheObjects10,
|
||||||
CacheObjects100,
|
CacheObjects100,
|
||||||
|
CacheObjectsNextAchievement,
|
||||||
} from '../../Cache/VariablesAndData';
|
} from '../../Cache/VariablesAndData';
|
||||||
import { CMOptions } from '../../Config/VariablesAndData';
|
import { CMOptions } from '../../Config/VariablesAndData';
|
||||||
import BuildingSell from '../../Sim/SimulationEvents/SellBuilding';
|
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
|
// Build array of pointers and sort according to the user's configured sort option.
|
||||||
// (grid rows are 1-based indexing, and row 1 is the bulk buy/sell options)
|
// This regulates sorting of buildings.
|
||||||
// This regulates sorting of buildings
|
let arr;
|
||||||
if (Game.buyMode === 1 && CMOptions.SortBuildings) {
|
if (Game.buyMode !== 1 || !CMOptions.SortBuildings) {
|
||||||
let arr;
|
arr = Object.keys(CacheObjects1).map(k => {
|
||||||
if (CMOptions.SortBuildings === 1) {
|
const o = {};
|
||||||
arr = Object.keys(CacheObjects1).map(k => {
|
o.name = k;
|
||||||
const o = {};
|
o.id = Game.Objects[k].id;
|
||||||
o.name = k;
|
return o;
|
||||||
o.pp = CacheObjects1[k].pp;
|
});
|
||||||
o.color = CacheObjects1[k].color;
|
// Sort using default order.
|
||||||
return o;
|
arr.sort((a, b) => a.id - b.id);
|
||||||
});
|
} else if (CMOptions.SortBuildings === 1) {
|
||||||
} else if (CMOptions.SortBuildings === 2) {
|
arr = Object.keys(CacheObjects1).map(k => {
|
||||||
arr = Object.keys(target).map(k => {
|
const o = {};
|
||||||
const o = {};
|
o.name = k;
|
||||||
o.name = k;
|
o.pp = CacheObjects1[k].pp;
|
||||||
o.pp = target[k].pp;
|
o.color = CacheObjects1[k].color;
|
||||||
o.color = target[k].color;
|
return o;
|
||||||
return o;
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
// Sort by pp colour group, then by pp.
|
// Sort by pp colour group, then by pp.
|
||||||
arr.sort((a, b) =>
|
arr.sort((a, b) =>
|
||||||
ColoursOrdering.indexOf(a.color) === ColoursOrdering.indexOf(b.color)
|
ColoursOrdering.indexOf(a.color) === ColoursOrdering.indexOf(b.color)
|
||||||
? a.pp - b.pp
|
? a.pp - b.pp
|
||||||
: ColoursOrdering.indexOf(a.color) - ColoursOrdering.indexOf(b.color)
|
: ColoursOrdering.indexOf(a.color) - ColoursOrdering.indexOf(b.color)
|
||||||
);
|
);
|
||||||
for (let x = 0; x < arr.length; x++) {
|
} else if (CMOptions.SortBuildings === 2) {
|
||||||
Game.Objects[arr[x].name].l.style.gridRow = `${x + 2}/${x + 2}`;
|
arr = Object.keys(target).map(k => {
|
||||||
}
|
const o = {};
|
||||||
} else {
|
o.name = k;
|
||||||
const arr = Object.keys(CacheObjects1).map(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 = {};
|
const o = {};
|
||||||
o.name = k;
|
o.name = k;
|
||||||
o.id = Game.Objects[k].id;
|
o.id = Game.Objects[k].id;
|
||||||
|
o.amountUntilNext = CacheObjectsNextAchievement[k].AmountNeeded;
|
||||||
|
o.priceUntilNext = CacheObjectsNextAchievement[k].price;
|
||||||
return o;
|
return o;
|
||||||
});
|
});
|
||||||
|
// First, sort using default order.
|
||||||
arr.sort((a, b) => a.id - b.id);
|
arr.sort((a, b) => a.id - b.id);
|
||||||
for (let x = 0; x < arr.length; x++) {
|
// Sort by price until next achievement.
|
||||||
Game.Objects[arr[x].name].l.style.gridRow = `${x + 2}/${x + 2}`;
|
// 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}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user