Skip to content

Commit 5f2611c

Browse files
committedMay 17, 2019
feat: add sorted player names
Player names are now sorted in the drop down menu by their "name" attribute. This mean "aaa" will appear at the top and, "zzz" will appear at the bottom (woo).
1 parent a3cd6f3 commit 5f2611c

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed
 

‎js/src/socket.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,15 @@ function onOpen(e) {
5151
.removeClass("label-warning")
5252
.addClass("label-success").text("connected");
5353
$("#socket_error").text("");
54+
}
5455

56+
function sorter(plr1, plr2){
57+
var str1 = plr1["name"];
58+
var str2 = plr2["name"];
59+
60+
return (str1 < str2) ? -1 : (str1 > str2) ? 1 : 0;
5561
}
62+
5663
function onMessage(e) {
5764
var m = encodeURIComponent(e.data).match(/%[89ABab]/g);
5865
var byteSize = e.data.length + (m ? m.length : 0);
@@ -85,7 +92,8 @@ function onMessage(e) {
8592
updateBlip(data.payload);
8693

8794
} else if (data.type == "playerData") {
88-
//console.log("updating players: " + JSON.stringify(data));
95+
//console.log("updating players(" + typeof(data.payload) + "): " + JSON.stringify(data.payload));
96+
var sortedPlayers = data.payload.sort(sorter);
8997
doPlayerUpdate(data.payload);
9098

9199
} else if (data.type == "playerLeft") {
@@ -290,6 +298,9 @@ function getPlayerInfoHtml(plr) {
290298

291299
function doPlayerUpdate(players) {
292300

301+
//Quickly sort the names, alphabetical order
302+
players.sort();
303+
293304
if (_SETTINGS_debug) {
294305
console.debug(players);
295306
}

0 commit comments

Comments
 (0)