-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserListPanel.js
More file actions
91 lines (74 loc) · 2.63 KB
/
UserListPanel.js
File metadata and controls
91 lines (74 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/**
* Display the users in the clientUserManager
* in the Lobby
*/
export class UserListPanel {
gamePanel;
clientUserManager;
constructor(gamePanel) {
this.gamePanel = gamePanel;
this.clientUserManager = gamePanel.gameNetLogic.clientUserManager;
}
toHtml() {
const userListPanelDiv = document.createElement("div");
userListPanelDiv.className = "userListPanelDiv";
userListPanelDiv.id = "userListPanelDiv";
// add a table for the users
const userListPanelTable = document.createElement("table");
userListPanelTable.id = "userListPanelTable";
userListPanelTable.className = "userListPanelTable";
const tableHeaderRow = document.createElement("tr");
tableHeaderRow.className = "userElementHeader";
const clanHeader = document.createElement("th");
const usernameHeader = document.createElement("th");
const roomHeader = document.createElement("th");
const rankHeader = document.createElement("th");
clanHeader.innerText = "Clan";
usernameHeader.innerText = "User";
roomHeader.innerText = "Room";
rankHeader.innerText = "Rank";
tableHeaderRow.appendChild(clanHeader);
tableHeaderRow.appendChild(usernameHeader);
tableHeaderRow.appendChild(roomHeader);
tableHeaderRow.appendChild(rankHeader);
userListPanelTable.appendChild(tableHeaderRow);
this.clientUserManager.users.forEach((user) => {
const newRow = userListPanelDiv.insertRow(-1);
this.toHtml(newRow);
});
userListPanelDiv.appendChild(userListPanelTable);
return userListPanelDiv;
}
// method for modifying the html
// used when a user logs out
removeUserFromList(userId) {
this.users.delete(username);
}
// add the user to the panel
addUserToList(userId) {
const user = this.clientUserManager.users.get(userId);
if (user == null) {
return;
}
// let newUserElement = new UserElement(this, username, clan, rank, icons);
// make a function to add a sorted element to the panel
// this.addSortedElement(newUserElement);
// TODO - check if the element is already on the userListPanel
// also add to the DOM here
let userListPanelTable = document.getElementById("userListPanelTable");
userListPanelTable.appendChild(user.toHtml());
}
addSortedElement(element) {
// TODO - add an element to the user panel
// add the user element to the map in a sorted way
// use the username as the key and the value for now
this.users.set(element, element);
}
clearUsers() {
// create a new map for the users
this.users.clear();
}
setUserRank(username, rank) {
this.users.get(username).rank = rank;
}
}