2023-12-11 15:24:48 +01:00
|
|
|
class Phone{
|
|
|
|
constructor(){
|
|
|
|
this.position = 0;
|
|
|
|
this.messages = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
addMessage(message){
|
|
|
|
this.messages.push(message);
|
|
|
|
|
|
|
|
let msg = document.createElement("div");
|
|
|
|
msg.className = "message";
|
|
|
|
|
|
|
|
let h2 = document.createElement("h2");
|
|
|
|
h2.className = "messageTitle";
|
2023-12-13 23:14:45 +01:00
|
|
|
h2.innerText = message.title;
|
2023-12-11 15:24:48 +01:00
|
|
|
|
2023-12-14 10:44:34 +01:00
|
|
|
let p;
|
|
|
|
let match = message.content.match(/:(\w+):/);
|
|
|
|
if(match){
|
|
|
|
p = document.createElement("img");
|
|
|
|
p.className = "messageImage";
|
|
|
|
p.src = "assets/concord_images/" + match[1] + '.jpg';
|
|
|
|
}else{
|
|
|
|
p = document.createElement("p");
|
|
|
|
p.className = "messageContent";
|
|
|
|
p.innerText = message.content;
|
|
|
|
}
|
2023-12-11 15:24:48 +01:00
|
|
|
|
|
|
|
msg.appendChild(h2);
|
|
|
|
msg.appendChild(p);
|
|
|
|
|
2023-12-11 18:49:13 +01:00
|
|
|
let chatMessages = document.getElementById("chatMessages");
|
|
|
|
chatMessages.appendChild(msg);
|
|
|
|
chatMessages.scrollTop = chatMessages.scrollHeight;
|
2023-12-11 15:24:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
sendMessage(title, content){
|
|
|
|
let message = {
|
|
|
|
title: player.name,
|
|
|
|
content: content
|
|
|
|
}
|
|
|
|
this.addMessage(message);
|
|
|
|
net.sendMessage(title, content);
|
|
|
|
}
|
|
|
|
|
|
|
|
keyPress(input){
|
|
|
|
if(event.key=='Enter'){
|
|
|
|
if(input.value!=''){
|
|
|
|
this.sendMessage(player.name, input.value);
|
|
|
|
input.value = '';
|
2023-12-13 13:58:34 +01:00
|
|
|
input.blur()
|
2023-12-11 15:24:48 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-12-11 18:49:13 +01:00
|
|
|
|
|
|
|
changePosition(){
|
2023-12-14 10:44:34 +01:00
|
|
|
if(!document.getElementById("phoneContainer").contains(document.activeElement)){
|
|
|
|
if(this.position == 0){
|
|
|
|
document.getElementById("phoneContainer").className = "visible";
|
|
|
|
this.position = 1;
|
|
|
|
}else{
|
|
|
|
document.getElementById("phoneContainer").className = "hidden";
|
|
|
|
this.position = 0;
|
|
|
|
}
|
2023-12-11 18:49:13 +01:00
|
|
|
}
|
2023-12-14 10:44:34 +01:00
|
|
|
|
2023-12-11 18:49:13 +01:00
|
|
|
}
|
2023-12-11 15:24:48 +01:00
|
|
|
}
|