Skip to content
Permalink
Browse files
sort tab alphabetically and show color in it.
  • Loading branch information
kukelekuuk committed Aug 7, 2020
1 parent e0e1985 commit 3c4b241120f2e0bcaeb7c51ab2c64f0ed3e6894d
Showing 1 changed file with 35 additions and 7 deletions.
@@ -143,20 +143,48 @@ export class ChatScreenComponent implements OnInit, AfterViewChecked, OnDestroy
}

private loadPlayer() {
this.players = []
for (const player of Object.keys(this.bot.players)) {
const extra = this.bot.players[player].displayName.extra;
if (extra === undefined) {
this.players = [];
const botPlayers = this.bot.players;
const botPlayerKeys = Object.keys(botPlayers);
let preSortedUsers: { username: string, message: ChatMessage }[] = [];
for (const player of botPlayerKeys) {
if (botPlayers[player] === undefined) {
continue;
}
const username: string = extra[0].text;
const displayName = botPlayers[player].displayName;
if (displayName.extra === undefined) {
continue;
}
const username: string = displayName.extra[0].text;
const usernameRegex = /^[0-9A-Za-z_]{3,16}$/;
if (!usernameRegex.test(username)) {
continue;
}
this.players.push(username);
const message = new this.ChatMessage(displayName);
preSortedUsers.push({username, message})
}

preSortedUsers = preSortedUsers.sort((a, b) => {
if (a.username.toLowerCase() > b.username.toLowerCase()) {
return 1;
} else if (b.username.toLowerCase() > a.username.toLowerCase()) {
return -1;
} else {
return 0;
}
});
const usernames: string[] = [];
for (const user of preSortedUsers) {

if (usernames.includes(user.username)) {
continue;
}
usernames.push(user.username);
this.motdparser.toHtml(user.message.toMotd(), (err, res: string) => {
this.players.push(res);
this.changeDetector.detectChanges()
});
}
this.changeDetector.detectChanges()
}

disconnectButtonClick(): void {

0 comments on commit 3c4b241

Please sign in to comment.