-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser.js
73 lines (54 loc) · 1.76 KB
/
user.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
73
const DEFAULT_AVATAR = "Assets/avatar.png";
const ROOM_AVATAR = "Assets/room.png";
const OTHER_AVATARS = {SPORT: 'Assets/Soccer.png', ZEN: 'Assets/Ying-Yang.png', NATURE: 'Assets/Earth.png', CD: 'Assets/cd.png'}
class User {
userName = null
id = null
pic = null
constructor(userName, id, pic){
this.userName = userName || null;
this.id = id || null;
this.pic = pic || DEFAULT_AVATAR;
}
}
function matchClientToUsername(room, username) {
var userId = server.clients.find(cl => {
if(cl.name == username) return cl.id;
});
return userId ? getUsername(room, userId) : undefined
}
function changeAvatar() {
hideElement('webchat');
showElement('avatars');
var new_avatar;
var pic1 = document.querySelector("#pic1");
pic1.src = OTHER_AVATARS.SPORT;
var b2 = document.querySelector("#pic2");
pic2.src = OTHER_AVATARS.ZEN;
var pic3 = document.querySelector("#pic3");
pic3.src = OTHER_AVATARS.NATURE;
var pic4 = document.querySelector("#pic4");
pic4.src = OTHER_AVATARS.CD;
pic1.addEventListener("click", function(e){
new_avatar = OTHER_AVATARS.SPORT;
});
pic2.addEventListener("click", function(e){
new_avatar = OTHER_AVATARS.ZEN;
});
pic3.addEventListener("click", function(e){
new_avatar = OTHER_AVATARS.NATURE;
});
pic4.addEventListener("click", function(e){
new_avatar = OTHER_AVATARS.CD;
});
avatar_button.addEventListener("click", function(e){
myself.pic = new_avatar || DEFAULT_AVATAR;
hideElement('avatars');
showElement('webchat');
setMyAvatar();
});
}
function setMyAvatar() {
var myAvatar = document.querySelector("#my-avatar");
myAvatar.src = myself.pic;
}