-
Notifications
You must be signed in to change notification settings - Fork 34
/
users.js
72 lines (62 loc) · 2.1 KB
/
users.js
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
function Users() {
this.characters = [];
this.listElement = document.createElement("ul");
var usersLabel = document.createElement("div");
usersLabel.textContent = T("Users online:");
var total = document.createElement("div");
this.panel = new Panel(
"users",
"Users",
[usersLabel, this.listElement, total]
);
this.playersList = {};
this.addCharacter = function(name) {
var user = this.playersList[name];
if (!user) {
user = document.createElement("li");;
user.className = "user";
user.href = "javascript://";
user.textContent = name;
if (game.player.IsAdmin) {
var teleport = document.createElement("a");
teleport.textContent = "[Teleport]";
teleport.addEventListener('click', function() {
game.network.send('teleport', {name: name});
});
user.appendChild(teleport);
var summon = document.createElement("a");
summon.textContent = '[Summon]';
summon.onclick = function() {
game.network.send('summon', {name: name});
return false;
}
user.appendChild(summon);
}
this.listElement.appendChild(user);
this.playersList[name] = user;
}
};
this.sync = function(data) {
if (!data)
return
this.characters = data;
this.update();
}
this.update = function() {
if (!this.panel.visible)
return;
var count = 0;
for(var name in this.characters) {
count++;
this.addCharacter(name)
}
for(var name in this.playersList) {
if (!this.characters[name]) {
this.playersList[name].parentNode.removeChild(this.playersList[name]);
delete this.playersList[name];
}
}
total.textContent = T("Total") + ": " + count;
}
this.panel.hooks.show = this.update.bind(this);
}