Merge pull request #807 from tsr488/patch-1
Fix edge cases when sorting buildings/upgrades by PP
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
@@ -69,49 +69,34 @@ export default function UpdateBuildings() {
|
|||||||
if (Game.buyMode === 1 && CMOptions.SortBuildings) {
|
if (Game.buyMode === 1 && CMOptions.SortBuildings) {
|
||||||
let arr;
|
let arr;
|
||||||
if (CMOptions.SortBuildings === 1) {
|
if (CMOptions.SortBuildings === 1) {
|
||||||
arr = Object.keys(CacheObjects1).map((k) => {
|
arr = Object.keys(CacheObjects1).map(k => {
|
||||||
const o = CacheObjects1[k];
|
const o = {};
|
||||||
o.name = k;
|
o.name = k;
|
||||||
o.id = Game.Objects[k].id;
|
o.pp = CacheObjects1[k].pp;
|
||||||
|
o.color = CacheObjects1[k].color;
|
||||||
return o;
|
return o;
|
||||||
});
|
});
|
||||||
|
|
||||||
arr.sort((a, b) =>
|
|
||||||
ColoursOrdering.indexOf(a.color) > // eslint-disable-line no-nested-ternary
|
|
||||||
ColoursOrdering.indexOf(b.color)
|
|
||||||
? 1
|
|
||||||
: ColoursOrdering.indexOf(a.color) < ColoursOrdering.indexOf(b.color) // eslint-disable-line no-nested-ternary
|
|
||||||
? -1
|
|
||||||
: a.pp < b.pp
|
|
||||||
? -1
|
|
||||||
: 0,
|
|
||||||
);
|
|
||||||
} else if (CMOptions.SortBuildings === 2) {
|
} else if (CMOptions.SortBuildings === 2) {
|
||||||
arr = Object.keys(target).map((k) => {
|
arr = Object.keys(target).map(k => {
|
||||||
const o = target[k];
|
const o = {};
|
||||||
o.name = k;
|
o.name = k;
|
||||||
o.id = Game.Objects[k].id;
|
o.pp = target[k].pp;
|
||||||
|
o.color = target[k].color;
|
||||||
return o;
|
return o;
|
||||||
});
|
});
|
||||||
|
|
||||||
arr.sort((a, b) =>
|
|
||||||
ColoursOrdering.indexOf(a.color) > // eslint-disable-line no-nested-ternary
|
|
||||||
ColoursOrdering.indexOf(b.color)
|
|
||||||
? 1
|
|
||||||
: ColoursOrdering.indexOf(a.color) < ColoursOrdering.indexOf(b.color) // eslint-disable-line no-nested-ternary
|
|
||||||
? -1
|
|
||||||
: a.pp < b.pp
|
|
||||||
? -1
|
|
||||||
: 0,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
// 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++) {
|
for (let x = 0; x < arr.length; x++) {
|
||||||
Game.Objects[arr[x].name].l.style.gridRow = `${x + 2}/${x + 2}`;
|
Game.Objects[arr[x].name].l.style.gridRow = `${x + 2}/${x + 2}`;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const arr = Object.keys(CacheObjects1).map((k) => {
|
const arr = Object.keys(CacheObjects1).map(k => {
|
||||||
const o = CacheObjects1[k];
|
const o = {};
|
||||||
o.name = k;
|
o.name = k;
|
||||||
o.id = Game.Objects[k].id;
|
o.id = Game.Objects[k].id;
|
||||||
return o;
|
return o;
|
||||||
|
|||||||
@@ -77,14 +77,11 @@ export default function UpdateUpgrades() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (CMOptions.SortUpgrades) {
|
if (CMOptions.SortUpgrades) {
|
||||||
|
// Sort by pp colour group, then by pp.
|
||||||
arr.sort((a, b) =>
|
arr.sort((a, b) =>
|
||||||
ColoursOrdering.indexOf(a.color) > ColoursOrdering.indexOf(b.color) // eslint-disable-line no-nested-ternary
|
ColoursOrdering.indexOf(a.color) === ColoursOrdering.indexOf(b.color)
|
||||||
? 1
|
? a.pp - b.pp
|
||||||
: ColoursOrdering.indexOf(a.color) < ColoursOrdering.indexOf(b.color) // eslint-disable-line no-nested-ternary
|
: ColoursOrdering.indexOf(a.color) - ColoursOrdering.indexOf(b.color)
|
||||||
? -1
|
|
||||||
: a.pp < b.pp
|
|
||||||
? -1
|
|
||||||
: 0,
|
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
arr.sort((a, b) => a.price - b.price);
|
arr.sort((a, b) => a.price - b.price);
|
||||||
|
|||||||
Reference in New Issue
Block a user