Update sort to handle the case where the source data is out of order
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
@@ -108,11 +108,16 @@ export default function UpdateBuildings() {
|
|||||||
arr = Object.keys(CacheObjectsNextAchievement).map(k => {
|
arr = Object.keys(CacheObjectsNextAchievement).map(k => {
|
||||||
const o = {};
|
const o = {};
|
||||||
o.name = k;
|
o.name = k;
|
||||||
|
o.id = Game.Objects[k].id;
|
||||||
o.amountUntilNext = CacheObjectsNextAchievement[k].AmountNeeded;
|
o.amountUntilNext = CacheObjectsNextAchievement[k].AmountNeeded;
|
||||||
o.priceUntilNext = CacheObjectsNextAchievement[k].price;
|
o.priceUntilNext = CacheObjectsNextAchievement[k].price;
|
||||||
return o;
|
return o;
|
||||||
});
|
});
|
||||||
// Sort by price until next achievement. Buildings that aren't close to an achievement are always last.
|
// First, sort using default order.
|
||||||
|
arr.sort((a, b) => a.id - b.id);
|
||||||
|
// 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) =>
|
arr.sort((a, b) =>
|
||||||
(a.amountUntilNext !== 101 ? a.priceUntilNext : Infinity) -
|
(a.amountUntilNext !== 101 ? a.priceUntilNext : Infinity) -
|
||||||
(b.amountUntilNext !== 101 ? b.priceUntilNext : Infinity)
|
(b.amountUntilNext !== 101 ? b.priceUntilNext : Infinity)
|
||||||
|
|||||||
Reference in New Issue
Block a user