From f13fde31ad8099b35c53e861a6cda4f9831789f0 Mon Sep 17 00:00:00 2001 From: Metritutus <324345+Metritutus@users.noreply.github.com> Date: Wed, 28 Feb 2024 21:07:53 +0000 Subject: [PATCH] * Updated tryMultiSelect() in map.js to fix closeObjects being incorrectly 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. --- client/src/game/map.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/client/src/game/map.js b/client/src/game/map.js index 11c26b333..e841681cd 100644 --- a/client/src/game/map.js +++ b/client/src/game/map.js @@ -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')