-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayerPanel.js
More file actions
66 lines (55 loc) · 1.75 KB
/
PlayerPanel.js
File metadata and controls
66 lines (55 loc) · 1.75 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
// add a player to here,
// this displays the players in the Lobby
import PlayerElement from "./PlayerElement.js";
export default class PlayerPanel {
players;
gamePanel;
constructor(gamePanel) {
this.players = new Map();
this.gamePanel = gamePanel;
}
toHtml() {
const playerPanelDiv = document.createElement("div");
playerPanelDiv.style.border = "6px solid";
playerPanelDiv.style.borderColor = "#cccccc";
playerPanelDiv.style.backgroundColor = "#3F1710";
playerPanelDiv.id = "playerPanelDiv";
this.players.forEach((player) => {
const el = player.toHtml();
playerPanelDiv.appendChild(el);
});
return playerPanelDiv;
}
getPlayer(username) {
return this.players.get(username);
}
removePlayer(username) {
this.players.delete(username);
}
// add the player to the panel
addPlayer(username, clan, rank, icons) {
if (this.getPlayer(username) != null) {
return;
}
let newPlayerElement = new PlayerElement(username, clan, rank, icons);
// make a function to add a sorted element to the panel
this.addSortedElement(newPlayerElement);
// TODO - check if the element is already on the playerPanel
// also add to the DOM here
let playerPanelDiv = document.getElementById("playerPanelDiv");
playerPanelDiv.appendChild(newPlayerElement.toHTML());
}
addSortedElement(element) {
// TODO - add an element to the player panel
// add the player element to the map in a sorted way
// use the username as the key and the value for now
this.players.set(element, element);
}
clearPlayers() {
// create a new map for the players
this.players = new Map();
}
setPlayerRank(username, rank) {
this.players.get(username).rank = rank;
}
}