Skip to content

Commit

Permalink
* Updated tryMultiSelect() in map.js to fix closeObjects being incorr…
Browse files Browse the repository at this point in the history
…ectly calculated:

    - localeCompare() return value was incorrectly being treated as a boolean instead of a number.
    - distance calculation was being returned a boolean instead of the difference.

This change fixes stars and carriers being listed in the wrong order on the Select Objects panel.  Stars and carriers should now be listed in the following order:
* stars by whichever was closest to mouse/tap location.  Stars of equal distance from the mouse/tap location will be ordered by name.
* carriers by whichever was closest to mouse/tap location.  Carriers of equal distance from the mouse/tap location will be ordered by name

This behaviour aligns with what I believe was the intention of the original code.
  • Loading branch information
Metritutus committed Feb 29, 2024
1 parent fd1de3e commit f13fde3
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions client/src/game/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -933,12 +933,16 @@ class Map extends EventEmitter {
// Combine the arrays and order by closest first.
let closeObjects = closeStars.concat(closeCarriers)
.sort((a, b) => {
if (a.type.localeCompare(b.type)) { // Sort the star first
return 1
if (a.type !== b.type) { // Sort stars first
return b.type.localeCompare(a.type);
}

return a.distance < b.distance // Then distance ascending.
})
if (a.distance === b.distance) {
return a.data.name.localeCompare(b.data.name); // If the distances are identical, sort by name ascending.
}

return a.distance < b.distance ? -1 : 1; // Finally, sort by distance ascending.
});

if (closeObjects.length > 1) {
let star = closeObjects.find(co => co.type === 'star')
Expand Down

0 comments on commit f13fde3

Please sign in to comment.