-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
131 lines (122 loc) · 3.4 KB
/
app.js
File metadata and controls
131 lines (122 loc) · 3.4 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
"use strict";
function id(e) {
return document.getElementById(e)
}
var user = {
name: '',
friends: [],
contacts: [],
current: undefined,
}
function updateContacts() {
if(user.contacts.length === 0) {
id('contacts').innerHTML = '<div id="nocontacts" align="center" style="bottom:100px;">No contacts</div>'
} else {
user.contacts.forEach(contact => {
if(contact instanceof Contact) {
contact.display()
}
})
}
}
function parsename() {
var a = id('playername')
if(a.value) {
user.name = a.value
}
id('main_game_window').style.display = 'block'
id('title_screen').style.display = 'none'
id('message').focus()
updateContacts()
}
function msg(e) {
if(e.keyCode == 13 && id('message').value) {
sendmsg(id('message').value)
id('message').value = ''
}
}
function sendmsg(content) {
var a = new UserMessage(content)
socket.emit('chat message', $('#message').val());
}
class BotMessage {
constructor(name, content) {
this.content = content
var p = document.createElement('div')
id('main_container').appendChild(p)
p.className = 'message'
p.style.background = 'lightgrey'
p.innerHTML = `${name} > ${content}`
p.style.opacity = 0;
var a = 0;
var op = setInterval(function() {
p.style.opacity = a
a += 0.1
if(p.style.opacity == 1) {
clearInterval(op)
}
}, 20)
this.e = p
}
}
class Contact {
constructor(name, profilesrc) {
this.name = name
this.profilesrc = profilesrc
this.elem = document.createElement('div')
this.elem.outerHTML = `<div class="contact">
<img class="contact-profile" src="${this.profilesrc}"</img>
<div class="contact-name">${this.name}</div>
</div>`
this.elem.addEventListner('click', () => {
this.openDM()
})
}
add() {
user.contacts.push(this)
}
display() {
id('contacts').appendChild(this.elem)
}
openDM() {
current = this
// anything else?
}
}
class Dialogue {
constructor(text) {
var p = document.createElement('div')
id('main_container').appendChild(p)
p.style.background = '#eeeeee'
p.innerHTML = text
p.className = 'message'
p.style.opacity = 0;
var a = 0;
var op = setInterval(function() {
p.style.opacity = a
a += 0.1
if(p.style.opacity == 1) {
clearInterval(op)
}
}, 20)
this.e = p
}
}
class UserMessage {
constructor(content) {
var p = document.createElement('div')
id('main_container').appendChild(p)
p.className = 'message'
p.innerHTML = `${user.name} > ${content}`
p.style.opacity = 0;
var a = 0;
var op = setInterval(function() {
p.style.opacity = a
a += 0.1
if(p.style.opacity == 1) {
clearInterval(op)
}
}, 20)
this.e = p
}
}